1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
//
// AsyncNotificationCenter.h
//
// Library: Foundation
// Package: Notifications
// Module: AsyncNotificationCenter
//
// Definition of the AsyncNotificationCenter class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// Aleph ONE Software Engineering d.o.o.,
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Foundation_AsyncNotificationCenter_INCLUDED
#define Foundation_AsyncNotificationCenter_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/NotificationCenter.h"
#include "Poco/Thread.h"
#include "Poco/Stopwatch.h"
#include "Poco/Debugger.h"
#include "Poco/ErrorHandler.h"
#include "Poco/Format.h"
#include "Poco/RunnableAdapter.h"
#include "Poco/NotificationQueue.h"
namespace Poco {
class Foundation_API AsyncNotificationCenter: public NotificationCenter
/// AsyncNotificationCenter decouples posting of notifications
/// from notifying subscribers by calling observers' notification
/// handler in a dedicated thread.
{
public:
AsyncNotificationCenter();
/// Creates the AsyncNotificationCenter and starts the notifying thread.
~AsyncNotificationCenter();
/// Stops the notifying thread and destroys the AsyncNotificationCenter.
AsyncNotificationCenter& operator = (const AsyncNotificationCenter&) = delete;
AsyncNotificationCenter(const AsyncNotificationCenter&) = delete;
AsyncNotificationCenter& operator = (AsyncNotificationCenter&&) = delete;
AsyncNotificationCenter(AsyncNotificationCenter&&) = delete;
virtual void postNotification(Notification::Ptr pNotification);
/// Enqueues notification into the notification queue.
virtual int backlog() const;
/// Returns the numbner of notifications in the notification queue.
private:
void start();
void stop();
void dequeue();
using Adapter = RunnableAdapter<AsyncNotificationCenter>;
Thread _thread;
NotificationQueue _nq;
Adapter _ra;
std::atomic<bool> _started;
std::atomic<bool> _done;
};
} // namespace Poco
#endif // Foundation_AsyncNotificationCenter_INCLUDED
|