Mailinglist Archive: yast-commit (683 mails)

< Previous Next >
[yast-commit] r42707 - in /trunk/pkg-bindings/src: Makefile.am PkgModuleFunctions.h PkgProgress.cc PkgProgress.h Source.cc
  • From: lslezak@xxxxxxxxxxxxxxxx
  • Date: Wed, 05 Dec 2007 11:56:50 -0000
  • Message-id: <20071205115650.7D52F2F61A@xxxxxxxxxxxxxxxx>
Author: lslezak
Date: Wed Dec 5 12:56:50 2007
New Revision: 42707

URL: http://svn.opensuse.org/viewcvs/yast?rev=42707&view=rev
Log:
- moved progress handling to a separate class (PkgProgress)

Added:
trunk/pkg-bindings/src/PkgProgress.cc
trunk/pkg-bindings/src/PkgProgress.h
Modified:
trunk/pkg-bindings/src/Makefile.am
trunk/pkg-bindings/src/PkgModuleFunctions.h
trunk/pkg-bindings/src/Source.cc

Modified: trunk/pkg-bindings/src/Makefile.am
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Makefile.am?rev=42707&r1=42706&r2=42707&view=diff
==============================================================================
--- trunk/pkg-bindings/src/Makefile.am (original)
+++ trunk/pkg-bindings/src/Makefile.am Wed Dec 5 12:56:50 2007
@@ -22,6 +22,7 @@
Y2CCPkg.cc Y2CCPkg.h \
ycpTools.cc ycpTools.h \
PkgModule.cc PkgModule.h \
+ PkgProgress.cc PkgProgress.h \
PkgModuleFunctions.h \
PkgModuleFunctions.cc \
Package.cc \

Modified: trunk/pkg-bindings/src/PkgModuleFunctions.h
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/PkgModuleFunctions.h?rev=42707&r1=42706&r2=42707&view=diff
==============================================================================
--- trunk/pkg-bindings/src/PkgModuleFunctions.h (original)
+++ trunk/pkg-bindings/src/PkgModuleFunctions.h Wed Dec 5 12:56:50 2007
@@ -53,7 +53,8 @@
#include <zypp/ProgressData.h>

#include "PkgError.h"
-
+//#include "PkgProgress.h"
+class PkgProgress;

// textdomain
extern "C" {
@@ -172,13 +173,8 @@
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());
- YCPValue SourceStartManagerImpl(const YCPBoolean&, const
zypp::ProgressData::ReceiverFnc & progress = zypp::ProgressData::ReceiverFnc());
+ YCPValue SourceLoadImpl(PkgProgress &progress);
+ YCPValue SourceStartManagerImpl(const YCPBoolean& enable, PkgProgress
&progress);

// 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

Added: trunk/pkg-bindings/src/PkgProgress.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/PkgProgress.cc?rev=42707&view=auto
==============================================================================
--- trunk/pkg-bindings/src/PkgProgress.cc (added)
+++ trunk/pkg-bindings/src/PkgProgress.cc Wed Dec 5 12:56:50 2007
@@ -0,0 +1,106 @@
+
+
+#include "PkgProgress.h"
+
+#include <Callbacks.YCP.h>
+
+#include <y2/Y2Function.h>
+
+void PkgProgress::Start( 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 =
callback_handler._ycpCallbacks.createCallback(PkgModuleFunctions::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();
+ }
+
+ running = true;
+
+ if (stages.size() > 0)
+ {
+ // set the first stage to 'in progress' state
+ pkgprogress.NextStage();
+ }
+}
+
+
+void PkgProgress::NextStage()
+{
+ // get the YCP callback handler for destroy event
+ Y2Function* ycp_handler =
callback_handler._ycpCallbacks.createCallback(PkgModuleFunctions::CallbackHandler::YCPCallbacks::CB_ProcessNextStage);
+
+ // is the callback registered?
+ if (ycp_handler != NULL)
+ {
+ // evaluate the callback function
+ ycp_handler->evaluateCall();
+ }
+}
+
+void PkgProgress::Done()
+{
+ y2debug("ProcessDone");
+ // get the YCP callback handler for destroy event
+ Y2Function* ycp_handler =
callback_handler._ycpCallbacks.createCallback(PkgModuleFunctions::CallbackHandler::YCPCallbacks::CB_ProcessFinished);
+
+ // is the callback registered?
+ if (ycp_handler != NULL)
+ {
+ y2milestone("Evaluating ProcessDone callback...");
+ // evaluate the callback function
+ ycp_handler->evaluateCall();
+ }
+
+ running = false;
+}
+
+bool PkgProgress::Receiver(const zypp::ProgressData &progress)
+{
+ y2milestone("PkgReceiver progress: %lld (%lld%%)", progress.val(),
progress.reportValue());
+
+ // get the YCP callback handler for destroy event
+ Y2Function* ycp_handler =
callback_handler._ycpCallbacks.createCallback(PkgModuleFunctions::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;
+}
+
+PkgProgress::~PkgProgress()
+{
+ // report done if it hasn't been called
+ if (running)
+ {
+ Done();
+ }
+}
+

Added: trunk/pkg-bindings/src/PkgProgress.h
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/PkgProgress.h?rev=42707&view=auto
==============================================================================
--- trunk/pkg-bindings/src/PkgProgress.h (added)
+++ trunk/pkg-bindings/src/PkgProgress.h Wed Dec 5 12:56:50 2007
@@ -0,0 +1,52 @@
+/*
+ File: PkgProgress.h
+
+ Author: Ladislav Slezák <lslezak@xxxxxxxxxx>
+/-*/
+
+#ifndef PkgProgress_h
+#define PkgProgress_h
+
+#include <string>
+#include <list>
+
+#include <PkgModuleFunctions.h>
+#include <Callbacks.YCP.h>
+
+#include <zypp/ProgressData.h>
+#include <boost/bind.hpp>
+
+class PkgProgress
+{
+ public:
+
+ PkgProgress(PkgModuleFunctions::CallbackHandler &handler_ref)
+ : callback_handler(handler_ref),
+ progress_handler(boost::bind(&PkgProgress::Receiver, this, _1)),
+ running(false)
+ {}
+
+ void Start( const std::string &process, const std::list<std::string>
&stages, const std::string &help);
+
+ void NextStage();
+
+ void Done();
+
+ const zypp::ProgressData::ReceiverFnc & Receiver()
+ {
+ return progress_handler;
+ }
+
+ ~PkgProgress();
+
+ private:
+ PkgModuleFunctions::CallbackHandler &callback_handler;
+ zypp::ProgressData::ReceiverFnc progress_handler;
+ bool running;
+
+ protected:
+ bool Receiver(const zypp::ProgressData &progress);
+};
+
+#endif
+

Modified: trunk/pkg-bindings/src/Source.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Source.cc?rev=42707&r1=42706&r2=42707&view=diff
==============================================================================
--- trunk/pkg-bindings/src/Source.cc (original)
+++ trunk/pkg-bindings/src/Source.cc Wed Dec 5 12:56:50 2007
@@ -48,7 +48,7 @@

#include <sstream> // ostringstream

-#include <boost/bind.hpp>
+#include <PkgProgress.h>

/*
Textdomain "pkg-bindings"
@@ -417,16 +417,14 @@
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");
+ PkgProgress pkgprogress(_callbackHandler);

- // mark refreshing as in progress now
- ProcessNextStage();
+ // 3 steps per repository (download, cache rebuild, load resolvables)
+ pkgprogress.Start("Loading the Package Manager...", stages, "help");

- // boost::bind(&PkgModuleFunctions::SourceLoadReceiver, this, _1);
- YCPValue ret =
SourceLoadImpl(boost::bind(&PkgModuleFunctions::SourceLoadReceiver, this, _1));
+ YCPValue ret = SourceLoadImpl(pkgprogress);

- ProcessDone();
+ pkgprogress.Done();

return ret;
}
@@ -441,7 +439,7 @@
* @return boolean True on success
**/
YCPValue
-PkgModuleFunctions::SourceLoadImpl(const zypp::ProgressData::ReceiverFnc
&progress)
+PkgModuleFunctions::SourceLoadImpl(PkgProgress &progress)
{
bool success = true;

@@ -457,7 +455,7 @@

// set max. value (3 steps per repository - refresh, rebuild, load)
zypp::ProgressData prog_total(repos_to_load * 3);
- prog_total.sendTo(progress);
+ prog_total.sendTo(progress.Receiver());

zypp::RepoManager repomanager = CreateRepoManager();

@@ -503,7 +501,7 @@
}
}

- ProcessNextStage();
+ progress.NextStage();

// rebuild cache
for (std::vector<YRepo_Ptr>::iterator it = repos.begin();
@@ -547,7 +545,7 @@
}
}

- ProcessNextStage();
+ progress.NextStage();

for (std::vector<YRepo_Ptr>::iterator it = repos.begin();
it != repos.end(); ++it)
@@ -595,6 +593,8 @@
YCPValue
PkgModuleFunctions::SourceStartManager (const YCPBoolean& enable)
{
+ PkgProgress pkgprogress(_callbackHandler);
+
// display the progress only when 'enable' is true
if (enable->value())
{
@@ -603,19 +603,16 @@
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");
-
- // mark refreshing as in progress now
- ProcessNextStage();
+ pkgprogress.Start("Loading the Package Manager...", stages, "help");
}

- YCPValue ret = SourceStartManagerImpl(enable,
boost::bind(&PkgModuleFunctions::SourceLoadReceiver, this, _1));
+ YCPValue ret = SourceStartManagerImpl(enable, pkgprogress);

if (enable->value())
{
- ProcessDone();
+ pkgprogress.Done();
}

return ret;
@@ -632,11 +629,11 @@
* @return boolean
**/
YCPValue
-PkgModuleFunctions::SourceStartManagerImpl(const YCPBoolean& enable, const
zypp::ProgressData::ReceiverFnc &progress)
+PkgModuleFunctions::SourceStartManagerImpl(const YCPBoolean& enable,
PkgProgress &progress)
{
YCPValue success = SourceRestore();

- ProcessNextStage();
+ progress.NextStage();

if( enable->value() )
{
@@ -2941,79 +2938,3 @@
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@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages