-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommunication_handler.hpp
84 lines (69 loc) · 1.98 KB
/
communication_handler.hpp
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
78
79
80
81
82
83
84
#pragma once
#include <tuple>
#include <variant>
#include "communication_error.hpp"
#include "object/data_header.hpp"
#include "object/data_object.hpp"
#include "object/binary_data.hpp"
#include "object/java_symbol.hpp"
#include "object/ping.hpp"
namespace ipc {
/// Variant for all data types
using DataObject = std::variant<Ping, JavaSymbol, BinaryData>;
/**
* Interface for all inter-process communication handlers.
*/
class ICommunicationHandler {
public:
/// Size of the buffer and limit of header and body combined.
static constexpr short BUFFER_SIZE = 512 + sizeof(DataHeader);
/// Time to wait for each poll in milliseconds.
static constexpr short WAIT_TIME = 5000;
virtual ~ICommunicationHandler() = default;
/**
* Open handler.
*
* @return True, if handler was successfully opened.
*/
virtual bool open() = 0;
/**
* Close the handler.
*
* @return True, if handler was successfully closed.
*/
virtual bool close() = 0;
/**
* Check if the handler is opened.
*
* @return True, if handler is open.
*/
virtual bool is_open() const = 0;
/**
* Poll new data from the handler.
*
* @return True, if poll was successful.
* @remark Method will block until an event or timeout occurred.
*/
virtual bool await_data() = 0;
/**
* Check if new data is available.
*
* @return True, if data is available.
*/
virtual bool has_data() const = 0;
/**
* Write a data object into the inter-process communication handler.
*
* @param obj Object to write into the handler.
*
* @return True, if write was successful.
*/
virtual bool write(const IDataObject &obj) = 0;
/**
* Read a data objects from the inter-process communication handler.
*
* @return Objects received from the handler or an error.
*/
virtual std::variant<std::tuple<DataHeader, DataObject>, CommunicationError> read() = 0;
};
}