-
Notifications
You must be signed in to change notification settings - Fork 0
/
Memory.cpp
34 lines (30 loc) · 996 Bytes
/
Memory.cpp
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
#include "Memory.h"
Memory::Memory(const char* name) :Actor(name)
{
}
Memory::~Memory()
{
}
void Memory::setup()
{
eb.onDst(id()).call(this);
timeout(5000);
}
void Memory::onEvent(Cbor& msg)
{
if ( timeout() ) {
timeout(5000);
eb.event(H("services"),H("memory")).addKeyValue(H("#data"),id()).addKeyValue(H("public"),true);
eb.send();
} else if ( eb.isRequest(H("set")) && msg.getKeyValue(H("address"),_address) && msg.getKeyValue(H("value"),_value)) {
*(uint32_t*)_address = _value;
eb.reply().addKeyValue(H("address"),_address).addKeyValue(H("value"),*(uint32_t*)_address);
eb.send();
} else if ( eb.isRequest(H("get")) && msg.getKeyValue(H("address"),_address) ) {
eb.reply().addKeyValue(H("address"),_address).addKeyValue(H("value"),*(uint32_t*)_address);
eb.send();
} else {
eb.reply().addKeyValue(H("error"),EINVAL).addKeyValue(H("error-msg"),"invalid request");
eb.send();
}
};