forked from mutability/dump978
-
Notifications
You must be signed in to change notification settings - Fork 17
/
message_dispatch.h
49 lines (36 loc) · 1.1 KB
/
message_dispatch.h
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
// -*- c++ -*-
// Copyright (c) 2019, FlightAware LLC.
// All rights reserved.
// Licensed under the 2-clause BSD license; see the LICENSE file
#ifndef MESSAGE_DISPATCH_H
#define MESSAGE_DISPATCH_H
#include <atomic>
#include <functional>
#include <map>
#include <mutex>
#include "uat_message.h"
namespace flightaware::uat {
class MessageDispatch {
public:
typedef unsigned Handle;
typedef std::function<void(SharedMessageVector)> MessageHandler;
MessageDispatch();
MessageDispatch(const MessageDispatch &) = delete;
MessageDispatch &operator=(const MessageDispatch &) = delete;
Handle AddClient(MessageHandler handler);
void RemoveClient(Handle client);
void Dispatch(SharedMessageVector messages);
protected:
void PurgeDeadClients();
private:
std::recursive_mutex mutex_;
Handle next_handle_;
unsigned busy_;
struct Client {
MessageHandler handler;
bool deleted;
};
std::map<Handle, Client> clients_;
};
}; // namespace flightaware::uat
#endif