|
Boost Users : |
From: Igor R (boost.lists_at_[hidden])
Date: 2008-07-16 14:18:15
Hello,
I've got the following design: several functors ("Tasks"), when
executed, "delegate" to a shared Processor object that performs some
coordination between the tasks. The Processor runs the tasks at some
stage, and wants to be notified by the task when it's over.
However, I wouldn't like them to "know" each other. I even wouldn't
like the Processor making assumptions about exact Task's "connection
point" signature/name.
For this purpose I want the Task to pass its "connection point" as a
generic functor - so that the Processor would execute it to subscribe.
However, I haven't managed to bind signal::connect. I'd appreciate any
idea about what's wrong in the following schematic code:
(In the real code the life-time of the objects is managed by means of
shared/weak pointers, which are omitted here for the sake of
simplicity!)
//task.hpp
class Task
{
public:
typedef signal<void (void)> CompletionEvent;
void operator ()()
{
// forward the execution to the processor;
(*processor)(bind(&Task::run, this),
bind(&CompetionEvent::connect, &done_, _1)); // this bind dosen't compile!
}
private:
void run();
Processor *processor_;
signal<void(void)> done_;
};
// processor.hpp
class Processor
{
public:
void operator ()(boost::function<void(void)> task,
boost::function<void(boost::function<void(void)>)> completionNotifier)
{
// this way I'd like to call
signal::connect(bind(&Processor::taskDone, this));
completionNotifier(bind(&Processor::taskDone, this));
}
private:
void taskDone();
};
Thank you!
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net