[zypp-devel] zypp::ProgressData question
Hello all,
I'm improving callback implementation in pkg-bindings,
I'd like to add a total progress and the callbacks should be displayed
in the main dialog (instead of popups).
I'm reusing zypp::ProgressData class with zypp::CombinedProgressData class which
provides a sub progress for a sub task. That's nice.
But I have a problem, I can register only
bool function(const zypp::ProgressData&)
as the receiver function, I'd like to register
bool MyClass::function(const zypp::ProgressData&)
Is it possible somehow? Maybe I'm not using the classes correctly...
Currently I'm using this really ugly hack (a global pointer):
PkgModuleFunctions *ptr = NULL;
bool source_receiver(const zypp::ProgressData &progress)
{
if (ptr != NULL)
{
return ptr->SourceLoadReceiver(progress);
}
return true;
}
bool PkgModuleFunctions::SourceLoadReceiver(const zypp::ProgressData &progress)
{
// handle the progress here...
}
YCPValue PkgModuleFunctions::SourceLoad()
{
ptr = this;
YCPValue ret = SourceLoadImpl(source_receiver);
// ^^^^^^^^^^^^^^^^^^
// here I'd like to use PkgModuleFunctions::SourceLoadReceiver
return ret;
}
PkgModuleFunctions::SourceLoadReceiver doesn't work for this reason:
Source.cc: In member function 'YCPValue PkgModuleFunctions::SourceLoad()':
Source.cc:442: error: no matching function for call to
'PkgModuleFunctions::SourceLoadImpl(<unresolved overloaded function type>)'
./PkgModuleFunctions.h:180: note: candidates are: YCPValue
PkgModuleFunctions::SourceLoadImpl(const boost::function
On Tuesday 04 December 2007 05:54:04 pm Ladislav Slezak wrote:
Hello all,
I'm improving callback implementation in pkg-bindings, I'd like to add a total progress and the callbacks should be displayed in the main dialog (instead of popups).
I'm reusing zypp::ProgressData class with zypp::CombinedProgressData class which provides a sub progress for a sub task. That's nice.
But I have a problem, I can register only bool function(const zypp::ProgressData&) as the receiver function, I'd like to register bool MyClass::function(const zypp::ProgressData&)
Hi Ladislav Well, you can't register a function of a class because if the function is not static, you actually need an instance of the class. The solution for this is to use boost::bind, which we use a lot in ZYpp. If you look at the YUM parser code, which uses callbacks a lot for data consuming, you can use boost bind to get a functor object using it like this: bind(&RepoParser::Impl::repomd_CB, this, _1, _2)); That means, use the repomd_CB function of that class, on the this object, and then the parameters order (you can even invert or ignore parameters when binding), the result of that expression is a functor you can use in place of any functor, so you can set the ProgressData progress callback to the result of a bind expression. Don't hesitate to ask again in doubt! boost is tricky, Duncan -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
participants (2)
-
Duncan Mac-Vicar P.
-
Ladislav Slezak