forked from Dashark/dam0888socket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessager.cpp
More file actions
125 lines (92 loc) · 2.55 KB
/
Copy pathMessager.cpp
File metadata and controls
125 lines (92 loc) · 2.55 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "Messager.hpp"
#include <iostream>
//#include "json.hpp"
#include <syslog.h>
//using json = nlohmann::json;
Messager::Messager() {
}
Messager::~Messager() {
}
//////////////////////////////////////////////////////////////////////////
Messager* MessagerDefine::create(const std::string &name) {
if(name == "AGVButtonMessager")
return new AGVButtonMessager();
if(name == "DeviceStatusMessager")
return new DeviceStatusMessager();
return nullptr;
}
///////////////////////////////////////////////////////////////////////////
AGVButtonMessager::AGVButtonMessager() {
js_ = R"(
{
"kafkaType" : "XXXType",
"data" : {
"mpos" : "xxxx-xxx-xx-xx-xx",
"astep" : "xxxx-xxx-xx-xx-xx",
"time" : "2018/08/08 09:10:10"
}
}
)"_json;
js_["kafkaType"] = "123";
}
AGVButtonMessager::~AGVButtonMessager() {
}
void AGVButtonMessager::setID(const std::string &id) {
js_["data"]["mpos"] = id;
}
bool AGVButtonMessager::setAStep(const std::string &step) {
js_["data"]["astep"] = step;
return true;
}
bool AGVButtonMessager::setTime(const std::string &time) {
js_["data"]["time"] = time;
return true;
}
bool AGVButtonMessager::setKV(const std::string &key, const std::string &val) {
js_["data"][key] = val;
return true;
}
void AGVButtonMessager::dump() {
syslog(LOG_INFO, "Message String : %s", js_.dump().c_str());
}
bool AGVButtonMessager::send(Broker *bro) {
bro->write(js_.dump());
return true;
}
/////////////////////////////////////////////////////////////////////////
DeviceStatusMessager::DeviceStatusMessager() {
js_ = R"(
{
"kafkaType" : "XXXType",
"data" : {
"deviceid" : "xxxx-xxx-xx-xx-xx",
"time" : "2018/08/08 09:10:10"
}
}
)"_json;
js_["kafkaType"] = "123";
}
DeviceStatusMessager::~DeviceStatusMessager() {
}
void DeviceStatusMessager::setID(const std::string &id) {
js_["data"]["deviceid"] = id;
}
bool DeviceStatusMessager::setAStep(const std::string &step) {
js_["data"]["astep"] = step;
return true;
}
bool DeviceStatusMessager::setTime(const std::string &time) {
js_["data"]["time"] = time;
return true;
}
bool DeviceStatusMessager::setKV(const std::string &key, const std::string &val) {
js_["data"][key] = val;
return true;
}
void DeviceStatusMessager::dump() {
syslog(LOG_INFO, "Message String : %s", js_.dump().c_str());
}
bool DeviceStatusMessager::send(Broker *bro) {
bro->write(js_.dump());
return true;
}