Overview
Features
Download
Documentation
Community
Add-Ons & Services

notification question

Please post support and help requests here.

notification question

Postby eswanson » 29 Jan 2009, 16:09

I am new to poco, but I am very impressed the product. I have one question about using the notifications. Is there a way to be notified by multiple notifications?

I have several instances where we would like to listen for multple notifications at the same time, like in Windows WaitForMultipleObjects. Can this be done in Poco and how?

Thanks

Eric
eswanson
 
Posts: 13
Joined: 29 Jan 2009, 16:01

Re: notification question

Postby guenter » 29 Jan 2009, 18:41

I am not sure I understand what you want to achieve correctly, so maybe you could give me an example for how this should work.

Anyway, what you can do is to register the same callback function for multiple and different notifications, e.g.
Code: Select all
Observer<MyClass, MyNotification> obs1(*this, &MyClass::handleNotification);
notificationCenter.addObserver(obs1);
Observer<MyClass, MyOtherNotification> obs2(*this, &MyClass::handleNotification);
notificationCenter.addObserver(obs2);


handleNotification() will be called whenever either MyNotification or MyOtherNotification has been posted.
guenter
 
Posts: 1129
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: notification question

Postby eswanson » 29 Jan 2009, 19:07

In our application we have something like this:

Handle m_hStopEvent = createEvent();
Handle m_hDoneProcessingEvent = createEvent();

Handle handles[m_hStopEvent, m_hDoneProcessingEvent];

dwstatus = Waitformultipleobjects(handles,....);

the dwstatus either returns the object that fired the notification or timeout.

I thought that the notifications could do the same thing.

My replacement looks like this:

NotificationQueue m_NfStopEvent;
NotificationQueue m_NfDoneProcessingEvent;

Then in my wait function, I am calling:

AutoPtr<Notification> pNf(m_NfStopEvent.waitDequeueNotification(1000));
if (pNf)
{
}

AutoPtr<Notification> pNfA(m_m_NfDoneProcessingEvent.waitDequeueNotification(1000));
if (pNfA)
{
}

I was looking at a way to combine these 2 notification processors.

Thanks

Eric
eswanson
 
Posts: 13
Joined: 29 Jan 2009, 16:01

Re: notification question

Postby guenter » 29 Jan 2009, 19:44

You can use a single NotificationQueue for both notifications.
After dequeueing the notification, you'll have to use dynamic_cast to find out the type of the notification.

Code: Select all
class StopNotification: public Notification
{
};

class DoneNotification: public Notification
{
};
...
AutoPtr<Notification> pNf(m_NfEvent.waitDequeueNotification(1000));
AutoPtr<StopNotification> pStopNf = pNf.cast<StopNotification>();
AutoPtr<DoneNotification> pDoneNf = pNf.cast<DoneNotification>();
if (pStopNf)
{
    // handle Stop Notification
}
else if (pDoneNf)
{
    // handle Done Processing Notification
}
guenter
 
Posts: 1129
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: notification question

Postby eswanson » 29 Jan 2009, 21:06

Thanks

Eric
eswanson
 
Posts: 13
Joined: 29 Jan 2009, 16:01


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron