forked from mutability/dump978
-
Notifications
You must be signed in to change notification settings - Fork 17
/
message_source.h
48 lines (36 loc) · 1.24 KB
/
message_source.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
// -*- c++ -*-
// Copyright (c) 2019, FlightAware LLC.
// All rights reserved.
// Licensed under the 2-clause BSD license; see the LICENSE file
#ifndef DUMP978_MESSAGE_SOURCE_H
#define DUMP978_MESSAGE_SOURCE_H
#include <boost/system/error_code.hpp>
#include "uat_message.h"
namespace flightaware::uat {
class MessageSource {
public:
typedef std::shared_ptr<MessageSource> Pointer;
typedef std::function<void(SharedMessageVector)> Consumer;
typedef std::function<void(const boost::system::error_code &)> ErrorHandler;
virtual ~MessageSource() {}
void SetConsumer(Consumer consumer) { consumer_ = consumer; }
void SetErrorHandler(ErrorHandler handler) { error_handler_ = handler; }
virtual void Start() {}
virtual void Stop() {}
protected:
void DispatchMessages(SharedMessageVector messages) {
if (consumer_) {
consumer_(messages);
}
}
void DispatchError(const boost::system::error_code &ec) {
if (error_handler_) {
error_handler_(ec);
}
}
private:
Consumer consumer_;
ErrorHandler error_handler_;
};
}; // namespace flightaware::uat
#endif