Boost logo

Boost :

From: Mark Blewett (boost_at_[hidden])
Date: 2004-02-28 08:08:23


At 01:02 28/02/2004, you wrote:

>scott <scottw <at> qbik.com> writes:
> > ps:
> > the sample code from mark blewett looks very promising?
> >
>
>Yes. Although from my point of view, it has the same drawback with switching
>on messages that you have. I wonder if the queue of messages in the servant
>class could be a queue of fully-bound function calls,

I'm halfway there, in that the queue holds callbacks, eg in
Servant::dispatch the "do something with m" simply executes the callback.

To give a usage example

class MyServant : public Servant
{
public:
         MyServant(Scheduler* scheduler) : Servant(scheduler) {}
         void do_fn(int x, int y) { std::cout << x << " " << y << std::endl; }
};

int main()
{
         Scheduler scheduler;
         scheduler.start(1,1);

         MyServant my_servant(&scheduler);
         my_servant.post_call(new
CallbackVAA<MyServant,int,int>(&my_servant, &MyServant::do_fn, 1, 2));

         scheduler.stop();
         return 0;
}

will result in the output "1 2" via one of the schedulers worker threads

>generated by proxy
>objects which describe interfaces? (Yes, I am quite enamoured of that
>idea :))

Interesting idea... assuming I'm understanding correctly.. in that the
callback is created by an object in the servant class, the above becomes;

class MyServant : public Servant
{
public:
         MyServant(Scheduler* scheduler) : Servant(scheduler), fn(this,
&MyServant::do_fn) {}
         MethodProxy<MyServant, int, int> fn;
private:
         void do_fn(int x, int y) { std::cout << x << " " << y << std::endl; }
};

int main()
{
         Scheduler scheduler;
         scheduler.start(1,1);

         MyServant my_servant(&scheduler);
         my_servant.fn(1, 2); // certainly a lot easier to understand
than previous example!

         scheduler.stop();
         return 0;
}

Regards
Mark


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.573 / Virus Database: 363 - Release Date: 28/01/2004

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk