mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 02:18:04 +01:00
AsyncObserver (#4444)
* feat(AsyncObserver): Improve NotificationCenter speed and usability #4414 * fix(Notification): add missing header * feat(Any): add checkers for holding nullptr #4447 * feat(NotificationCenter): g++ build and refactoring #4414 * fix(Observer): compile errors on some compilers #4414 * fix(NotificationCenter): compile errors #4414 * chore(ParallelSocketAcceptor): remove unnecessary include and using from header * feat(AsyncNotificationCenter): add #4414 * test(AsyncNotificationCenter): add mixed observer types to the test #4414 * fix(AsyncNotificationCenter): hangs on program exit #4414 * fix(dev): friend not honored, temporarily make private members public * fix(AsyncNotificationCenter); remove default #4414
This commit is contained in:
committed by
GitHub
parent
30a0a06bac
commit
88be66972a
77
Foundation/include/Poco/AsyncNotificationCenter.h
Normal file
77
Foundation/include/Poco/AsyncNotificationCenter.h
Normal file
@@ -0,0 +1,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
|
||||
Reference in New Issue
Block a user