[yast-commit] r42663 - in /trunk/pkg-bindings/src: Callbacks.YCP.h Callbacks.cc PkgModuleFunctions.h Source.cc
Author: lslezak Date: Tue Dec 4 15:22:42 2007 New Revision: 42663 URL: http://svn.opensuse.org/viewcvs/yast?rev=42663&view=rev Log: - added Process*() callbacks - added use total progress in SourceLoad() Modified: trunk/pkg-bindings/src/Callbacks.YCP.h trunk/pkg-bindings/src/Callbacks.cc trunk/pkg-bindings/src/PkgModuleFunctions.h trunk/pkg-bindings/src/Source.cc Modified: trunk/pkg-bindings/src/Callbacks.YCP.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Callbacks.YCP.h?rev=42663&r1=42662&r2=42663&view=diff ============================================================================== --- trunk/pkg-bindings/src/Callbacks.YCP.h (original) +++ trunk/pkg-bindings/src/Callbacks.YCP.h Tue Dec 4 15:22:42 2007 @@ -103,7 +103,12 @@ CB_AcceptVerificationFailed, CB_AcceptWrongDigest, CB_AcceptUnknownDigest, CB_TrustedKeyAdded, - CB_TrustedKeyRemoved + CB_TrustedKeyRemoved, + + CB_ProcessStart, + CB_ProcessNextStage, + CB_ProcessProgress, + CB_ProcessFinished, }; /** @@ -201,6 +206,11 @@ ENUM_OUT( TrustedKeyRemoved ); ENUM_OUT( AcceptWrongDigest ); ENUM_OUT( AcceptUnknownDigest ); + + ENUM_OUT( ProcessStart ); + ENUM_OUT( ProcessNextStage ); + ENUM_OUT( ProcessProgress ); + ENUM_OUT( ProcessFinished ); #undef ENUM_OUT // no default! let compiler warn missing values } Modified: trunk/pkg-bindings/src/Callbacks.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Callbacks.cc?rev=42663&r1=42662&r2=42663&view=diff ============================================================================== --- trunk/pkg-bindings/src/Callbacks.cc (original) +++ trunk/pkg-bindings/src/Callbacks.cc Tue Dec 4 15:22:42 2007 @@ -2538,4 +2538,25 @@ YCPValue PkgModuleFunctions::CallbackDestDownload( const YCPString& args ) { return SET_YCP_CB( CB_DestDownload, args ); } + +YCPValue PkgModuleFunctions::CallbackProcessStart( const YCPString& func ) +{ + return SET_YCP_CB( CB_ProcessStart, func ); +} + +YCPValue PkgModuleFunctions::CallbackProcessNextStage( const YCPString& func ) +{ + return SET_YCP_CB( CB_ProcessNextStage, func ); +} + +YCPValue PkgModuleFunctions::CallbackProcessDone( const YCPString& func ) +{ + return SET_YCP_CB( CB_ProcessFinished, func ); +} + +YCPValue PkgModuleFunctions::CallbackProcessProgress( const YCPString& func ) +{ + return SET_YCP_CB( CB_ProcessProgress, func); +} + #undef SET_YCP_CB Modified: trunk/pkg-bindings/src/PkgModuleFunctions.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/PkgModuleFunctions.h?rev=42663&r1=42662&r2=42663&view=diff ============================================================================== --- trunk/pkg-bindings/src/PkgModuleFunctions.h (original) +++ trunk/pkg-bindings/src/PkgModuleFunctions.h Tue Dec 4 15:22:42 2007 @@ -50,6 +50,7 @@ #include <zypp/RepoInfo.h> #include <zypp/RepoManager.h> #include <zypp/MediaSetAccess.h> +#include <zypp/ProgressData.h> #include "PkgError.h" @@ -171,6 +172,13 @@ zypp::repo::RepoType ProbeWithCallbacks(const zypp::Url &url); void ScanProductsWithCallBacks(const zypp::Url &url); + void ProcessStart(const std::string &process, const std::list<std::string> &stages, const std::string &help); + void ProcessProgress(int percent); + void ProcessNextStage(); + void ProcessDone(); + + YCPValue SourceLoadImpl(const zypp::ProgressData::ReceiverFnc & progress = zypp::ProgressData::ReceiverFnc()); + // After all, APPL_HIGH might be more appropriate, because we suggest // the user what he should do and if it does not work, it's his job to // fix it (using USER). --ma @@ -420,6 +428,17 @@ /* TYPEINFO: void(string) */ YCPValue CallbackAcceptFileWithoutChecksum( const YCPString& func ); + + /* TYPEINFO: void(string) */ + YCPValue CallbackProcessStart( const YCPString& func ); + /* TYPEINFO: void(string) */ + YCPValue CallbackProcessProgress( const YCPString& func ); + /* TYPEINFO: void(string) */ + YCPValue CallbackProcessNextStage( const YCPString& func ); + /* TYPEINFO: void(string) */ + YCPValue CallbackProcessDone( const YCPString& func ); + + // source related /* TYPEINFO: boolean(boolean)*/ YCPValue SourceStartManager (const YCPBoolean&); @@ -725,6 +744,8 @@ * Constructor. */ PkgModuleFunctions (); + + bool SourceLoadReceiver(const zypp::ProgressData &progress); /** * Destructor. Modified: trunk/pkg-bindings/src/Source.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Source.cc?rev=42663&r1=42662&r2=42663&view=diff ============================================================================== --- trunk/pkg-bindings/src/Source.cc (original) +++ trunk/pkg-bindings/src/Source.cc Tue Dec 4 15:22:42 2007 @@ -45,6 +45,7 @@ #include <zypp/repo/RepoType.h> #include <zypp/MediaProducts.h> #include <zypp/ExternalProgram.h> +#include <zypp/ProgressData.h> #include <zypp/base/String.h> @@ -384,6 +385,35 @@ return YCPList(); } +bool PkgModuleFunctions::SourceLoadReceiver(const zypp::ProgressData &progress) +{ + y2milestone("Source Load receiver: %lld (%lld%%)", progress.val(), progress.reportValue()); + + // get the YCP callback handler for destroy event + Y2Function* ycp_handler = _callbackHandler._ycpCallbacks.createCallback(CallbackHandler::YCPCallbacks::CB_ProcessProgress); + + // is the callback registered? + if (ycp_handler != NULL) + { + ycp_handler->appendParameter(YCPInteger(progress.reportValue())); + // evaluate the callback function + ycp_handler->evaluateCall(); + } + + return true; +} + +PkgModuleFunctions *ptr = NULL; + +bool source_receiver(const zypp::ProgressData &progress) +{ + if (ptr != NULL) + { + return ptr->SourceLoadReceiver(progress); + } + + return true; +} /**************************************************************************************** * @builtin SourceLoad @@ -396,14 +426,64 @@ YCPValue PkgModuleFunctions::SourceLoad() { + std::list<std::string> stages; + stages.push_back("Refresh Sources"); + stages.push_back("Rebuild Cache"); + stages.push_back("Load Data"); + + // 3 steps per repository (download, cache rebuild, load resolvables) + ProcessStart("Loading the Package Manager...", stages, "help"); + + ptr = this; + + YCPValue ret = SourceLoadImpl(source_receiver); + + ProcessDone(); + + ptr = NULL; + + return ret; +} + + +/**************************************************************************************** + * @builtin SourceLoad + * + * @short Load resolvables from the installation sources + * @description + * Refresh the pool - Add/remove resolvables from the enabled/disabled sources. + * @return boolean True on success + **/ +YCPValue +PkgModuleFunctions::SourceLoadImpl(const zypp::ProgressData::ReceiverFnc &progress) +{ bool success = true; + int repos_to_load = 0; + for (std::vector<YRepo_Ptr>::iterator it = repos.begin(); + it != repos.end(); ++it) + { + if ((*it)->repoInfo().enabled() && !(*it)->isDeleted()) + { + repos_to_load++; + } + } + + // set max. value (3 steps per repository) + zypp::ProgressData prog_total(repos_to_load * 3); + prog_total.sendTo(progress); + for (std::vector<YRepo_Ptr>::iterator it = repos.begin(); it != repos.end(); ++it) { // load resolvables only from enabled repos which are not deleted if ((*it)->repoInfo().enabled() && !(*it)->isDeleted()) { + // sub tasks + zypp::CombinedProgressData refresh_subprogress(prog_total, 1); + zypp::CombinedProgressData rebuild_subprogress(prog_total, 1); + zypp::CombinedProgressData load_subprogress(prog_total, 1); + if (AnyResolvableFrom((*it)->repoInfo().alias())) { y2milestone("Resolvables from '%s' are already present, not loading", (*it)->repoInfo().alias().c_str()); @@ -418,12 +498,23 @@ try { y2milestone("Autorefreshing source: %s", (*it)->repoInfo().alias().c_str()); + + zypp::ProgressData prog(1); + prog.sendTo(refresh_subprogress); + // TODO pass progress to RefreshWithCallbacks RefreshWithCallbacks((*it)->repoInfo()); + prog.toMax(); // rebuild cache (the default policy is "if needed") y2milestone("Rebuilding cache for '%s'...", (*it)->repoInfo().alias().c_str()); + + zypp::ProgressData prog_build(1); + prog.sendTo(rebuild_subprogress); repomanager.buildCache((*it)->repoInfo()); + prog_build.toMax(); } + // NOTE: subtask progresses are reported as done in the descructor + // no need to handle them in the exception code catch (const zypp::Exception& excpt) { y2error ("Error in SourceLoad: %s", excpt.asString().c_str()); @@ -438,6 +529,9 @@ } } + // report 100% + prog_total.toMax(); + return YCPBoolean(success); } @@ -465,7 +559,7 @@ } // enable all sources and load the resolvables - success = YCPBoolean(SourceLoad()->asBoolean()->value() && success->asBoolean()->value()); + success = YCPBoolean(SourceLoadImpl()->asBoolean()->value() && success->asBoolean()->value()); } return success; @@ -2760,4 +2854,79 @@ return zypp::str::toLower(type); } +void PkgModuleFunctions::ProcessStart( const std::string &process, const std::list<std::string> &stages, + const std::string &help) +{ + // get the YCP callback handler for destroy event + Y2Function* ycp_handler = _callbackHandler._ycpCallbacks.createCallback(CallbackHandler::YCPCallbacks::CB_ProcessStart); + + y2debug("ProcessStart"); + + // is the callback registered? + if (ycp_handler != NULL) + { + y2debug("Evaluating ProcessStart callback..."); + ycp_handler->appendParameter(YCPString(process)); + + // create list of stages + YCPList lst; + + for(std::list<std::string>::const_iterator it = stages.begin(); + it != stages.end() ; ++it ) + { + lst->add(YCPString(*it) ); + } + + ycp_handler->appendParameter(lst); + + ycp_handler->appendParameter(YCPString(help)); + + // evaluate the callback function + ycp_handler->evaluateCall(); + } +} + + +void PkgModuleFunctions::ProcessNextStage() +{ + // get the YCP callback handler for destroy event + Y2Function* ycp_handler = _callbackHandler._ycpCallbacks.createCallback(CallbackHandler::YCPCallbacks::CB_ProcessNextStage); + + // is the callback registered? + if (ycp_handler != NULL) + { + // evaluate the callback function + ycp_handler->evaluateCall(); + } +} + +void PkgModuleFunctions::ProcessProgress(int percent) +{ + // get the YCP callback handler for destroy event + Y2Function* ycp_handler = _callbackHandler._ycpCallbacks.createCallback(CallbackHandler::YCPCallbacks::CB_ProcessProgress); + + // is the callback registered? + if (ycp_handler != NULL) + { + ycp_handler->appendParameter( YCPInteger((long long) percent)); + // evaluate the callback function + ycp_handler->evaluateCall(); + } +} + +void PkgModuleFunctions::ProcessDone() +{ + y2debug("ProcessDone"); + // get the YCP callback handler for destroy event + Y2Function* ycp_handler = _callbackHandler._ycpCallbacks.createCallback(CallbackHandler::YCPCallbacks::CB_ProcessFinished); + + // is the callback registered? + if (ycp_handler != NULL) + { + y2milestone("Evaluating ProcessDone callback..."); + // evaluate the callback function + ycp_handler->evaluateCall(); + } +} + -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
lslezak@svn.opensuse.org