Woman, Life, Freedom


OBD-II Emulator
Linux ODB-II Emulator public and protected interfaces documentation
communication_layer.h
1#ifndef COMMUNICATION_LAYER_H
2#define COMMUNICATION_LAYER_H
3
4#include <functional>
5#include <vector>
6#include <stdint.h>
7
8namespace ObdEmulator
9{
12 {
13 public:
16 using CallbackType = std::function<bool(std::vector<uint8_t> &&, std::vector<uint8_t> &)>;
17
19 using AsyncCallbackType = std::function<void(std::vector<uint8_t> &&)>;
20
21 protected:
24
27
28 public:
29 CommunicationLayer() noexcept;
30 virtual ~CommunicationLayer() noexcept = default;
31
35 virtual bool TryStart(std::vector<uint8_t> &&configuration) = 0;
36
40 virtual bool TrySendAsync(std::vector<uint8_t> &&data) = 0;
41
44 void SetCallback(CallbackType &&callback);
45
48 void SetCallback(AsyncCallbackType &&asyncCallback);
49
53 void ResetCallback() noexcept;
54
58 virtual bool TryStop() = 0;
59 };
60}
61
62#endif
Communication medium abstraction layer to send and receive data.
Definition: communication_layer.h:12
std::function< void(std::vector< uint8_t > &&)> AsyncCallbackType
Data received callback type to handle the data asynchronously.
Definition: communication_layer.h:19
CallbackType Callback
Callback to be invoked when data received.
Definition: communication_layer.h:23
AsyncCallbackType AsyncCallback
Callback to be invoked when data received asynch.
Definition: communication_layer.h:26
virtual bool TrySendAsync(std::vector< uint8_t > &&data)=0
Try to buffer data for sending.
void ResetCallback() noexcept
Reset both data received synchronized and asynchronized callbacks.
void SetCallback(CallbackType &&callback)
Set a data received callback and reset the asynchronized callback.
std::function< bool(std::vector< uint8_t > &&, std::vector< uint8_t > &)> CallbackType
Data received callback type.
Definition: communication_layer.h:16
virtual bool TryStart(std::vector< uint8_t > &&configuration)=0
Try to start the communication.
virtual bool TryStop()=0
Try to stop the communication.