Woman, Life, Freedom


Adaptive AUTOSAR
ARA public interface header documentation
network_layer.h
1#ifndef NETWORK_LAYER_H
2#define NETWORK_LAYER_H
3
4#include <map>
5#include <functional>
6#include <type_traits>
7
8namespace ara
9{
10 namespace com
11 {
12 namespace helper
13 {
16 template <typename T>
18 {
19 private:
20 std::map<void *, std::function<void(T)>> mReceiverCallbacks;
21
22 protected:
25 void FireReceiverCallbacks(const std::vector<uint8_t> &payload)
26 {
27 for (auto objectCallbackPair : mReceiverCallbacks)
28 {
29 // Create the received message from the received payload
30 T _receivedMessage{T::Deserialize(payload)};
31
32 std::function<void(T)> _callback = objectCallbackPair.second;
33 _callback(std::move(_receivedMessage));
34 }
35 }
36
37 public:
38 NetworkLayer() noexcept = default;
39 virtual ~NetworkLayer() noexcept = default;
40
43 virtual void Send(const T &message) = 0;
44
48 void SetReceiver(void *object, std::function<void(T)> receiver)
49 {
50 mReceiverCallbacks[object] = receiver;
51 }
52 };
53 }
54 }
55}
56
57#endif
Network communication abstraction layer.
Definition: network_layer.h:18
void FireReceiverCallbacks(const std::vector< uint8_t > &payload)
Fire all the set receiver callaback.
Definition: network_layer.h:25
virtual void Send(const T &message)=0
Send a message through the network.
void SetReceiver(void *object, std::function< void(T)> receiver)
Set a receiver callback.
Definition: network_layer.h:48