@@ -196,6 +196,37 @@ int sys_hwinfo(int com_id, const nlohmann::json &json_obj)
196196 return out;
197197}
198198
199+ int _sys_unit_call (int com_id, const nlohmann::json &json_obj)
200+ {
201+ std::string json_obj_raw = json_obj.dump ();
202+ std::string object = sample_json_str_get (json_obj_raw, " object" );
203+ std::string data = sample_json_str_get (json_obj_raw, " data" );
204+ std::string out = unit_call (object.substr (0 , object.find (" ." )), object.substr (object.find (" ." ) + 1 ), data);
205+ {
206+ nlohmann::json out_body;
207+ out_body[" request_id" ] = json_obj[" request_id" ];
208+ out_body[" work_id" ] = json_obj[" work_id" ];
209+ out_body[" created" ] = time (NULL );
210+ out_body[" object" ] = json_obj[" object" ];
211+ try {
212+ out_body[" data" ] = nlohmann::json::parse (out);
213+ } catch (...) {
214+ out_body[" data" ] = out;
215+ }
216+ out_body[" error" ] = nlohmann::json::parse (" {\" code\" :0, \" message\" :\"\" }" );
217+ zmq_com_send (com_id, out_body.dump ());
218+ }
219+ return 0 ;
220+ }
221+
222+ int sys_unit_call (int com_id, const nlohmann::json &json_obj)
223+ {
224+ int out = 0 ;
225+ std::thread t (_sys_unit_call, com_id, json_obj);
226+ t.detach ();
227+ return out;
228+ }
229+
199230int sys_lsmode (int com_id, const nlohmann::json &json_obj)
200231{
201232 int out;
@@ -643,6 +674,7 @@ void server_work()
643674 key_sql[" sys.reboot" ] = sys_reboot;
644675 key_sql[" sys.version" ] = sys_version;
645676 key_sql[" sys.rmmode" ] = sys_rmmode;
677+ key_sql[" sys.unit_call" ] = sys_unit_call;
646678}
647679
648680void server_stop_work ()
0 commit comments