120 return tv.tv_sec*1.0 +
tv.tv_usec/1000000.0;
125 MJsonNode* errnode = MJsonNode::MakeObject();
126 errnode->AddToObject(
"code", MJsonNode::MakeInt(code));
127 errnode->AddToObject(
"message", MJsonNode::MakeString(
message));
128 errnode->AddToObject(
"data", MJsonNode::MakeString(
data));
130 MJsonNode* result = MJsonNode::MakeObject();
131 result->AddToObject(
"error", errnode);
137 MJsonNode* result = MJsonNode::MakeObject();
138 result->AddToObject(
"result", node);
144 MJsonNode* node = MJsonNode::MakeObject();
149 node->AddToObject(name2, value2);
151 node->AddToObject(name3, value3);
153 MJsonNode* result = MJsonNode::MakeObject();
154 result->AddToObject(
"result", node);
158MJsonNode*
mjsonrpc_make_result(
const char*
name, MJsonNode*
value,
const char* name2, MJsonNode* value2,
const char* name3, MJsonNode* value3,
const char* name4, MJsonNode* value4)
160 MJsonNode* node = MJsonNode::MakeObject();
165 node->AddToObject(name2, value2);
167 node->AddToObject(name3, value3);
169 node->AddToObject(name4, value4);
171 MJsonNode* result = MJsonNode::MakeObject();
172 result->AddToObject(
"result", node);
185 *error = MJsonNode::MakeObject();
189 const MJsonNode* obj = params->FindObjectNode(
name);
206 *error = MJsonNode::MakeObject();
213 if (error && *error) {
217 const MJsonNodeVector* v = node->GetArray();
221 *error =
mjsonrpc_make_error(-32602,
"Invalid params", (std::string(
"parameter must be an array: ") +
name).c_str());
234 p->AddToObject(
"description", MJsonNode::MakeString(
description));
235 p->AddToObject(
"type", MJsonNode::MakeString(
"object"));
237 p->
required = MJsonNode::MakeArray();
239 p->AddToObject(
"required", p->
required);
246 p->AddToObject(
"description", MJsonNode::MakeString(
description));
247 p->AddToObject(
"type", MJsonNode::MakeString(
"array"));
248 p->
items = MJsonNode::MakeArray();
249 p->AddToObject(
"items", p->
items);
253static std::string
remove(
const std::string s,
char c)
255 std::string::size_type pos = s.find(
c);
256 if (pos == std::string::npos)
259 return s.substr(0, pos);
267 bool optional = strchr(xname,
'?');
268 bool array = strchr(xname,
'[');
271 std::string
name = xname;
277 s->AddToObject(
"optional", MJsonNode::MakeBool(
true));
281 s->DeleteObjectNode(
"description");
287 items->AddToArray(s);
293 required->AddToArray(MJsonNode::MakeString(
name.c_str()));
305 this->AddToObject(
"description", MJsonNode::MakeString(
description));
358 MJsonNode* p = MJsonNode::MakeObject();
359 p->AddToObject(
"description", MJsonNode::MakeString(
description));
360 if (mjson_type == MJSON_ARRAY)
361 p->AddToObject(
"type", MJsonNode::MakeString(
"array"));
362 else if (mjson_type == MJSON_OBJECT)
363 p->AddToObject(
"type", MJsonNode::MakeString(
"object"));
364 else if (mjson_type == MJSON_STRING)
365 p->AddToObject(
"type", MJsonNode::MakeString(
"string"));
366 else if (mjson_type == MJSON_INT)
367 p->AddToObject(
"type", MJsonNode::MakeString(
"integer"));
368 else if (mjson_type == MJSON_NUMBER)
369 p->AddToObject(
"type", MJsonNode::MakeString(
"number"));
370 else if (mjson_type == MJSON_BOOL)
371 p->AddToObject(
"type", MJsonNode::MakeString(
"bool"));
372 else if (mjson_type == MJSON_NULL)
373 p->AddToObject(
"type", MJsonNode::MakeString(
"null"));
374 else if (mjson_type == MJSON_ARRAYBUFFER)
375 p->AddToObject(
"type", MJsonNode::MakeString(
"arraybuffer"));
376 else if (mjson_type == MJSON_JSON)
377 p->AddToObject(
"type", MJsonNode::MakeString(
"json"));
378 else if (mjson_type == 0)
381 assert(!
"invalid value of mjson_type");
388 s->AddToObject(
"description", MJsonNode::MakeString(
description));
389 s->AddToObject(
"type", MJsonNode::MakeString(
"object"));
397 s->AddToObject(
"description", MJsonNode::MakeString(
description));
398 s->AddToObject(
"type", MJsonNode::MakeString(
"array"));
404 : MJsonNode(MJSON_OBJECT)
413static MJsonNode*
xnull(
const MJsonNode* params)
417 doc->
D(
"RPC method always returns null");
418 doc->
P(NULL, 0,
"method parameters are ignored");
419 doc->
R(NULL, MJSON_NULL,
"always returns null");
436 doc->
D(
"calls MIDAS cm_exist() to check if given MIDAS program is running");
437 doc->
P(
"name", MJSON_STRING,
"name of the program, corresponding to ODB /Programs/name");
438 doc->
P(
"unique?", MJSON_BOOL,
"bUnique argument to cm_exist()");
439 doc->
R(
"status", MJSON_INT,
"return status of cm_exist()");
443 MJsonNode* error = NULL;
454 printf(
"cm_exist(%s,%d) -> %d\n",
name.c_str(), unique,
status);
463 doc->
D(
"calls MIDAS cm_shutdown() to stop given MIDAS program");
464 doc->
P(
"name", MJSON_STRING,
"name of the program, corresponding to ODB /Programs/name");
465 doc->
P(
"unique?", MJSON_BOOL,
"bUnique argument to cm_shutdown()");
466 doc->
R(
"status", MJSON_INT,
"return status of cm_shutdown()");
470 MJsonNode* error = NULL;
481 printf(
"cm_shutdown(%s,%d) -> %d\n",
name.c_str(), unique,
status);
490 doc->
D(
"start MIDAS program defined in ODB /Programs/name");
491 doc->
P(
"name", MJSON_STRING,
"name of the program, corresponding to ODB /Programs/name");
492 doc->
R(
"status", MJSON_INT,
"return status of ss_system()");
496 MJsonNode* error = NULL;
500 std::string path =
"";
501 path +=
"/Programs/";
503 path +=
"/Start command";
509 int size =
sizeof(command);
523 doc->
D(
"execute custom script defined in ODB /Script (scripts show in the menu) or /CustomScript (scripts from custom pages)");
524 doc->
P(
"script?", MJSON_STRING,
"Execute ODB /Script/xxx");
525 doc->
P(
"customscript?", MJSON_STRING,
"Execute ODB /CustomScript/xxx");
526 doc->
R(
"status", MJSON_INT,
"return status of cm_exec_script()");
531 std::string customscript =
mjsonrpc_get_param(params,
"customscript", NULL)->GetString();
535 if (script.length() > 0) {
539 }
else if (customscript.length() > 0) {
540 path +=
"/CustomScript";
542 path += customscript;
547 if (path.length() > 0) {
568 const char*s = strchr(path,
'[');
571 cm_msg(
MERROR, method,
"expected an array index character \'[\' in \"%s\"", path);
577 while (s && (*s != 0)) {
581 cm_msg(
MERROR, method,
"expected a number in array index in \"%s\" at \"%s\"", path, s);
585 unsigned value1 = strtoul(s, (
char**)&s, 10);
592 cm_msg(
MERROR, method,
"expected a number in array index in \"%s\" at \"%s\"", path, s);
596 unsigned value2 = strtoul(s, (
char**)&s, 10);
598 if (value2 >= value1)
599 for (
unsigned i=value1;
i<=value2;
i++)
607 for (
unsigned i=value1;
i!=value2;
i--)
609 list->push_back(value2);
612 list->push_back(value1);
626 cm_msg(
MERROR, method,
"invalid char in array index in \"%s\" at \"%s\"", path, s);
631 printf(
"parsed array indices for \"%s\" size is %d: ", path, (
int)
list->size());
632 for (
unsigned i=0;
i<
list->size();
i++)
633 printf(
" %d", (*
list)[
i]);
644 doc->
D(
"get values of ODB data from given subtrees");
645 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB subtree paths, see note on array indices");
646 doc->
P(
"omit_names?", MJSON_BOOL,
"omit the /name entries");
647 doc->
P(
"omit_last_written?", MJSON_BOOL,
"omit the /last_written entries and the last_written[] result");
648 doc->
P(
"omit_tid?", MJSON_BOOL,
"omit the tid[] result");
649 doc->
P(
"omit_old_timestamp?", MJSON_NUMBER,
"omit data older than given ODB timestamp");
650 doc->
P(
"preserve_case?", MJSON_BOOL,
"preserve the capitalization of ODB key names (WARNING: ODB is not case sensitive); note that this will also have side effect of setting the omit_names option");
651 doc->
R(
"data[]", 0,
"values of ODB data for each path, all key names are in lower case, all symlinks are followed");
652 doc->
R(
"status[]", MJSON_INT,
"return status of db_copy_json_values() or db_copy_json_index() for each path");
653 doc->
R(
"tid?[]", MJSON_INT,
"odb type id for each path, absent if omit_tid is true");
654 doc->
R(
"last_written?[]", MJSON_NUMBER,
"last_written value of the ODB subtree for each path, absent if omit_last_written is true");
658 MJsonNode* error = NULL;
663 bool omit_last_written =
mjsonrpc_get_param(params,
"omit_last_written", NULL)->GetBool();
665 double xomit_old_timestamp =
mjsonrpc_get_param(params,
"omit_old_timestamp", NULL)->GetDouble();
666 time_t omit_old_timestamp = (time_t)xomit_old_timestamp;
669 MJsonNode* dresult = MJsonNode::MakeArray();
670 MJsonNode* sresult = MJsonNode::MakeArray();
671 MJsonNode* tresult = MJsonNode::MakeArray();
672 MJsonNode* lwresult = MJsonNode::MakeArray();
677 for (
unsigned i=0;
i<paths->size();
i++) {
681 std::string path = (*paths)[
i]->GetString();
685 dresult->AddToArray(MJsonNode::MakeNull());
686 sresult->AddToArray(MJsonNode::MakeInt(
status));
687 tresult->AddToArray(MJsonNode::MakeNull());
688 lwresult->AddToArray(MJsonNode::MakeNull());
694 dresult->AddToArray(MJsonNode::MakeNull());
695 sresult->AddToArray(MJsonNode::MakeInt(
status));
696 tresult->AddToArray(MJsonNode::MakeNull());
697 lwresult->AddToArray(MJsonNode::MakeNull());
701 if (path.find(
"[") != std::string::npos) {
702 std::vector<unsigned>
list;
706 dresult->AddToArray(MJsonNode::MakeNull());
707 sresult->AddToArray(MJsonNode::MakeInt(
status));
708 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
713 if (
list.size() > 1) {
714 MJsonNode *ddresult = MJsonNode::MakeArray();
715 MJsonNode *ssresult = MJsonNode::MakeArray();
717 for (
unsigned i=0;
i<
list.size();
i++) {
725 ddresult->AddToArray(MJsonNode::MakeJSON(buf));
726 ssresult->AddToArray(MJsonNode::MakeInt(
status));
728 ddresult->AddToArray(MJsonNode::MakeNull());
729 ssresult->AddToArray(MJsonNode::MakeInt(
status));
736 dresult->AddToArray(ddresult);
737 sresult->AddToArray(ssresult);
738 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
749 dresult->AddToArray(MJsonNode::MakeJSON(buf));
750 sresult->AddToArray(MJsonNode::MakeInt(
status));
751 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
754 dresult->AddToArray(MJsonNode::MakeNull());
755 sresult->AddToArray(MJsonNode::MakeInt(
status));
756 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
769 omit_last_written, omit_old_timestamp, preserve_case);
773 dresult->AddToArray(MJsonNode::MakeJSON(buf));
774 sresult->AddToArray(MJsonNode::MakeInt(
status));
775 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
778 dresult->AddToArray(MJsonNode::MakeNull());
779 sresult->AddToArray(MJsonNode::MakeInt(
status));
780 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
789 MJsonNode* result = MJsonNode::MakeObject();
791 result->AddToObject(
"data", dresult);
792 result->AddToObject(
"status", sresult);
794 result->AddToObject(
"tid", tresult);
797 if (!omit_last_written)
798 result->AddToObject(
"last_written", lwresult);
809 doc->
D(
"get contents of given ODB subdirectory in the \"ls\" json encoding - similar to odbedit command \"ls -l\"");
810 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB subtree paths");
811 doc->
R(
"data[]", MJSON_OBJECT,
"keys and values of ODB data for each path");
812 doc->
R(
"status[]", MJSON_INT,
"return status of db_copy_json_ls() for each path");
816 MJsonNode* error = NULL;
820 MJsonNode* dresult = MJsonNode::MakeArray();
821 MJsonNode* sresult = MJsonNode::MakeArray();
826 for (
unsigned i=0;
i<paths->size();
i++) {
829 std::string path = (*paths)[
i]->GetString();
833 dresult->AddToArray(MJsonNode::MakeNull());
834 sresult->AddToArray(MJsonNode::MakeInt(
status));
846 dresult->AddToArray(MJsonNode::MakeJSON(buf));
847 sresult->AddToArray(MJsonNode::MakeInt(
status));
849 dresult->AddToArray(MJsonNode::MakeNull());
850 sresult->AddToArray(MJsonNode::MakeInt(
status));
864 doc->
D(
"get complete ODB data in the \"save\" json encoding, suitable for reloading with odbedit command \"load\"");
865 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB subtree paths");
866 doc->
R(
"data[]", MJSON_OBJECT,
"keys and values of ODB data for each path");
867 doc->
R(
"status[]", MJSON_INT,
"return status of db_copy_json_save() for each path");
871 MJsonNode* error = NULL;
875 MJsonNode* dresult = MJsonNode::MakeArray();
876 MJsonNode* sresult = MJsonNode::MakeArray();
881 for (
unsigned i=0;
i<paths->size();
i++) {
884 std::string path = (*paths)[
i]->GetString();
888 dresult->AddToArray(MJsonNode::MakeNull());
889 sresult->AddToArray(MJsonNode::MakeInt(
status));
901 dresult->AddToArray(MJsonNode::MakeJSON(buf));
902 sresult->AddToArray(MJsonNode::MakeInt(
status));
904 dresult->AddToArray(MJsonNode::MakeNull());
905 sresult->AddToArray(MJsonNode::MakeInt(
status));
919 doc->
D(
"write data into ODB");
920 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB subtree paths, see note on array indices");
921 doc->
P(
"values[]", 0,
"array of data values written to ODB via db_paste_json() for each path");
922 doc->
R(
"status[]", MJSON_INT,
"array of return status of db_paste_json() for each path");
926 MJsonNode* error = NULL;
931 if (paths->size() != values->size()) {
932 return mjsonrpc_make_error(-32602,
"Invalid params",
"paths and values should have the same length");
935 MJsonNode* sresult = MJsonNode::MakeArray();
940 for (
unsigned i=0;
i<paths->size();
i++) {
943 std::string path = (*paths)[
i]->GetString();
947 sresult->AddToArray(MJsonNode::MakeInt(
status));
951 const MJsonNode* v = (*values)[
i];
954 if (path.find(
"[*]") != std::string::npos) {
961 }
else if (path.find(
"[") != std::string::npos) {
962 std::vector<unsigned>
list;
966 sresult->AddToArray(MJsonNode::MakeInt(
status));
975 if (
list.size() < 1) {
976 cm_msg(
MERROR,
"js_db_paste",
"invalid array indices for array path \"%s\"", path.c_str());
979 }
else if (
list.size() == 1) {
980 if (v->GetType() == MJSON_ARRAY) {
981 cm_msg(
MERROR,
"js_db_paste",
"unexpected array of values for array path \"%s\"", path.c_str());
987 sresult->AddToArray(MJsonNode::MakeInt(
status));
988 }
else if ((
list.size() > 1) && (v->GetType() == MJSON_ARRAY)) {
989 const MJsonNodeVector* vvalues = v->GetArray();
991 if (
list.size() != vvalues->size()) {
992 cm_msg(
MERROR,
"js_db_paste",
"length of values array %d should be same as number of indices %d for array path \"%s\"", (
int)vvalues->size(), (
int)
list.size(), path.c_str());
997 MJsonNode *ssresult = MJsonNode::MakeArray();
999 for (
unsigned j =0;
j <
list.size();
j++) {
1000 const MJsonNode* vv = (*vvalues)[
j];
1003 cm_msg(
MERROR,
"js_db_paste",
"internal error: NULL array value at index %d for array path \"%s\"",
j, path.c_str());
1009 ssresult->AddToArray(MJsonNode::MakeInt(
status));
1012 sresult->AddToArray(ssresult);
1014 MJsonNode *ssresult = MJsonNode::MakeArray();
1015 for (
unsigned j =0;
j <
list.size();
j++) {
1017 ssresult->AddToArray(MJsonNode::MakeInt(
status));
1019 sresult->AddToArray(ssresult);
1023 sresult->AddToArray(MJsonNode::MakeInt(
status));
1034 doc->
D(
"Create new ODB entries");
1035 MJSO* o = doc->
PA(
"array of ODB paths to be created")->
AddObject(
"",
"arguments to db_create_key() and db_set_num_values()");
1036 o->
Add(
"path", MJSON_STRING,
"ODB path to be created");
1037 o->
Add(
"type", MJSON_INT,
"MIDAS TID_xxx type");
1038 o->
Add(
"array_length?", MJSON_INT,
"optional array length, default is 1");
1039 o->
Add(
"string_length?", MJSON_INT,
"for TID_STRING, optional string length, default is NAME_LENGTH");
1040 doc->
R(
"status[]", MJSON_INT,
"return status of db_create_key(), db_set_num_values() and db_set_data() (for TID_STRING) for each path");
1044 MJsonNode* sresult = MJsonNode::MakeArray();
1046 const MJsonNodeVector* pp = params->GetArray();
1050 return mjsonrpc_make_error(-32602,
"Invalid params",
"parameters must be an array of objects");
1056 for (
unsigned i=0;
i<pp->size();
i++) {
1057 const MJsonNode* p = (*pp)[
i];
1065 if (string_length == 0)
1074 char* buf = (
char*)calloc(1, string_length);
1075 assert(buf != NULL);
1076 int size = string_length;
1089 sresult->AddToArray(MJsonNode::MakeInt(
status));
1099 doc->
D(
"delete ODB keys");
1100 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths to delete");
1101 doc->
R(
"status[]", MJSON_INT,
"return status of db_delete_key() for each path");
1105 MJsonNode* error = NULL;
1109 MJsonNode* sresult = MJsonNode::MakeArray();
1114 for (
unsigned i=0;
i<paths->size();
i++) {
1115 std::string path = (*paths)[
i]->GetString();
1117 sresult->AddToArray(MJsonNode::MakeInt(
status));
1127 doc->
D(
"Change size of ODB arrays");
1128 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths to resize");
1129 doc->
P(
"new_lengths[]", MJSON_INT,
"array of new lengths for each ODB path");
1130 doc->
R(
"status[]", MJSON_INT,
"return status of db_set_num_values() for each path");
1134 MJsonNode* error = NULL;
1139 if (paths->size() != lengths->size()) {
1140 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"new_lengths\" should have the same length");
1143 MJsonNode* sresult = MJsonNode::MakeArray();
1148 for (
unsigned i=0;
i<paths->size();
i++) {
1151 std::string path = (*paths)[
i]->GetString();
1155 sresult->AddToArray(MJsonNode::MakeInt(
status));
1159 int length = (*lengths)[
i]->GetInt();
1166 sresult->AddToArray(MJsonNode::MakeInt(
status));
1176 doc->
D(
"Change size of ODB string arrays");
1177 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths to resize");
1178 doc->
P(
"new_lengths[]", MJSON_INT,
"array of new lengths for each ODB path");
1179 doc->
P(
"new_string_lengths[]", MJSON_INT,
"array of new string lengths for each ODB path");
1180 doc->
R(
"status[]", MJSON_INT,
"return status of db_resize_string() for each path");
1184 MJsonNode* error = NULL;
1188 const MJsonNodeVector* string_lengths =
mjsonrpc_get_param_array(params,
"new_string_lengths", &error);
if (error)
return error;
1190 if (paths->size() != lengths->size()) {
1191 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"new_lengths\" should have the same length");
1194 if (paths->size() != string_lengths->size()) {
1195 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"new_string_lengths\" should have the same length");
1198 MJsonNode* sresult = MJsonNode::MakeArray();
1203 for (
unsigned i=0;
i<paths->size();
i++) {
1204 std::string path = (*paths)[
i]->GetString();
1206 int length = (*lengths)[
i]->GetInt();
1212 int string_length = (*string_lengths)[
i]->GetInt();
1219 sresult->AddToArray(MJsonNode::MakeInt(
status));
1229 doc->
D(
"get ODB keys");
1230 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths");
1231 doc->
R(
"status[]", MJSON_INT,
"return status of db_key() for each path");
1232 doc->
R(
"keys[]", MJSON_OBJECT,
"key data for each path");
1233 doc->
R(
"keys[].type", MJSON_INT,
"key type TID_xxx");
1234 doc->
R(
"keys[].num_values", MJSON_INT,
"array length, 1 for normal entries");
1235 doc->
R(
"keys[].name", MJSON_STRING,
"key name");
1236 doc->
R(
"keys[].total_size", MJSON_INT,
"data total size in bytes");
1237 doc->
R(
"keys[].item_size", MJSON_INT,
"array element size, string length for TID_STRING");
1238 doc->
R(
"keys[].access_mode", MJSON_INT,
"access mode bitmap of MODE_xxx");
1239 doc->
R(
"keys[].notify_count", MJSON_INT,
"number of hotlinks attached to this key");
1240 doc->
R(
"keys[].last_written", MJSON_INT,
"timestamp when data was last updated");
1244 MJsonNode* error = NULL;
1248 MJsonNode* kresult = MJsonNode::MakeArray();
1249 MJsonNode* sresult = MJsonNode::MakeArray();
1254 for (
unsigned i=0;
i<paths->size();
i++) {
1258 std::string path = (*paths)[
i]->GetString();
1262 kresult->AddToArray(MJsonNode::MakeNull());
1263 sresult->AddToArray(MJsonNode::MakeInt(
status));
1269 kresult->AddToArray(MJsonNode::MakeNull());
1270 sresult->AddToArray(MJsonNode::MakeInt(
status));
1274 MJsonNode* jkey = MJsonNode::MakeObject();
1276 jkey->AddToObject(
"type", MJsonNode::MakeInt(
key.
type));
1277 jkey->AddToObject(
"num_values", MJsonNode::MakeInt(
key.
num_values));
1279 jkey->AddToObject(
"name", MJsonNode::MakeString(
key.
name));
1280 jkey->AddToObject(
"total_size", MJsonNode::MakeInt(
key.
total_size));
1281 jkey->AddToObject(
"item_size", MJsonNode::MakeInt(
key.
item_size));
1282 jkey->AddToObject(
"access_mode", MJsonNode::MakeInt(
key.
access_mode));
1283 jkey->AddToObject(
"notify_count", MJsonNode::MakeInt(
key.
notify_count));
1284 jkey->AddToObject(
"last_written", MJsonNode::MakeInt(
key.
last_written));
1286 kresult->AddToArray(jkey);
1287 sresult->AddToArray(MJsonNode::MakeInt(
status));
1297 doc->
D(
"Change size of ODB arrays");
1298 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths to rename");
1299 doc->
P(
"new_names[]", MJSON_STRING,
"array of new names for each ODB path");
1300 doc->
R(
"status[]", MJSON_INT,
"return status of db_rename_key() for each path");
1304 MJsonNode* error = NULL;
1309 if (paths->size() != names->size()) {
1310 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"new_names\" should have the same length");
1313 MJsonNode* sresult = MJsonNode::MakeArray();
1318 for (
unsigned i=0;
i<paths->size();
i++) {
1321 std::string path = (*paths)[
i]->GetString();
1325 sresult->AddToArray(MJsonNode::MakeInt(
status));
1329 std::string new_name = (*names)[
i]->GetString();
1330 if (new_name.length() < 1) {
1337 sresult->AddToArray(MJsonNode::MakeInt(
status));
1347 doc->
D(
"Create ODB symlinks");
1348 doc->
P(
"new_links[]", MJSON_STRING,
"array of new symlinks to be created");
1349 doc->
P(
"target_paths[]", MJSON_STRING,
"array of existing ODB paths for each link");
1350 doc->
R(
"status[]", MJSON_INT,
"return status of db_create_link() for each path");
1354 MJsonNode* error = NULL;
1356 const MJsonNodeVector* target_paths =
mjsonrpc_get_param_array(params,
"target_paths", &error);
if (error)
return error;
1359 if (target_paths->size() != new_links->size()) {
1360 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"target_paths\" and \"new_links\" should have the same length");
1363 MJsonNode* sresult = MJsonNode::MakeArray();
1368 for (
unsigned i=0;
i<new_links->size();
i++) {
1370 std::string target_path = (*target_paths)[
i]->GetString();
1371 std::string new_link = (*new_links)[
i]->GetString();
1372 if (new_link.length() < 1) {
1379 sresult->AddToArray(MJsonNode::MakeInt(
status));
1389 doc->
D(
"Change order of ODB keys in a subdirectory");
1390 doc->
P(
"paths[]", MJSON_STRING,
"array of new symlinks to be created");
1391 doc->
P(
"indices[]", MJSON_INT,
"array of existing ODB paths for each link");
1392 doc->
R(
"status[]", MJSON_INT,
"return status of db_reorder_key() for each path");
1396 MJsonNode* error = NULL;
1401 if (paths->size() != indices->size()) {
1402 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"indices\" should have the same length");
1405 MJsonNode* sresult = MJsonNode::MakeArray();
1410 for (
unsigned i=0;
i<paths->size();
i++) {
1413 std::string path = (*paths)[
i]->GetString();
1414 int index = (*indices)[
i]->GetInt();
1418 sresult->AddToArray(MJsonNode::MakeInt(
status));
1424 sresult->AddToArray(MJsonNode::MakeInt(
status));
1434 doc->
D(
"Show ODB open records starting from given ODB path");
1435 doc->
P(
"path?", MJSON_STRING,
"ODB path");
1436 doc->
R(
"sor", MJSON_JSON,
"return value of db_sor()");
1440 MJsonNode* error = NULL;
1442 std::string path =
mjsonrpc_get_param(params,
"path", NULL)->GetString();
if (error)
return error;
1447 MJsonNode* sor =
db_sor(
hDB, path.c_str());
1456 doc->
D(
"Show ODB clients");
1457 doc->
R(
"scl", MJSON_JSON,
"return value of db_scl()");
1479 doc->
D(
"get message facilities using cm_msg_facilities()");
1480 doc->
R(
"status", MJSON_INT,
"return status of cm_msg_facilities()");
1481 doc->
R(
"facilities[]", MJSON_STRING,
"array of facility names");
1489 MJsonNode* facilities = MJsonNode::MakeArray();
1491 for (
unsigned i=0;
i<
list.size();
i++) {
1493 facilities->AddToArray(MJsonNode::MakeString(
list[
i].c_str()));
1497 "facilities", facilities);
1504 doc->
D(
"Generate a midas message using cm_msg1()");
1505 doc->
P(
"facility?", MJSON_STRING,
"message facility, default is \"midas\"");
1506 doc->
P(
"user?", MJSON_STRING,
"message user, default is \"javascript_commands\"");
1507 doc->
P(
"type?", MJSON_INT,
"message type, MT_xxx from midas.h, default is MT_INFO");
1508 doc->
P(
"message", MJSON_STRING,
"message text");
1509 doc->
R(
"status", MJSON_INT,
"return status of cm_msg1()");
1513 MJsonNode* error = NULL;
1520 if (facility.size() <1)
1523 user =
"javascript_commands";
1536 doc->
D(
"Retrieve midas messages using cm_msg_retrieve2()");
1537 doc->
P(
"facility?", MJSON_STRING,
"message facility, default is \"midas\"");
1538 doc->
P(
"min_messages?", MJSON_INT,
"get at least this many messages, default is 1");
1539 doc->
P(
"time?", MJSON_NUMBER,
"start from given timestamp, value 0 means give me newest messages, default is 0");
1540 doc->
R(
"num_messages", MJSON_INT,
"number of messages returned");
1541 doc->
R(
"messages", MJSON_STRING,
"messages separated by \\n");
1542 doc->
R(
"status", MJSON_INT,
"return status of cm_msg_retrieve2()");
1550 if (facility.size() < 1)
1553 int num_messages = 0;
1554 char* messages = NULL;
1558 MJsonNode* result = MJsonNode::MakeObject();
1560 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
1561 result->AddToObject(
"num_messages", MJsonNode::MakeInt(num_messages));
1565 result->AddToObject(
"messages", MJsonNode::MakeString(messages));
1583 doc->
D(
"reset alarms");
1584 doc->
P(
"alarms[]", MJSON_STRING,
"array of alarm names");
1585 doc->
R(
"status[]", MJSON_INT,
"return status of al_reset_alarm() for each alarm");
1589 MJsonNode* error = NULL;
1593 MJsonNode* sresult = MJsonNode::MakeArray();
1595 for (
unsigned i=0;
i<alarms->size();
i++) {
1597 sresult->AddToArray(MJsonNode::MakeInt(
status));
1607 doc->
D(
"trigger an alarm");
1608 doc->
P(
"name", MJSON_STRING,
"alarm name");
1609 doc->
P(
"message", MJSON_STRING,
"alarm message");
1610 doc->
P(
"class", MJSON_STRING,
"alarm class");
1611 doc->
P(
"condition", MJSON_STRING,
"alarm condition");
1612 doc->
P(
"type", MJSON_INT,
"alarm type (AT_xxx)");
1613 doc->
R(
"status", MJSON_INT,
"return status of al_trigger_alarm()");
1617 MJsonNode* error = NULL;
1621 std::string xclass =
mjsonrpc_get_param(params,
"class", &error)->GetString();
if (error)
return error;
1622 std::string condition =
mjsonrpc_get_param(params,
"condition", &error)->GetString();
if (error)
return error;
1634 doc->
D(
"trigger an alarm");
1635 doc->
P(
"class", MJSON_STRING,
"alarm class");
1636 doc->
P(
"message", MJSON_STRING,
"alarm message");
1637 doc->
P(
"first?", MJSON_BOOL,
"see al_trigger_class() in midas.c");
1638 doc->
R(
"status", MJSON_INT,
"return status of al_trigger_class()");
1642 MJsonNode* error = NULL;
1644 std::string xclass =
mjsonrpc_get_param(params,
"class", &error)->GetString();
if (error)
return error;
1665 doc->
D(
"get list of active history events using hs_read_event_list()");
1666 doc->
R(
"status", MJSON_INT,
"return status of hs_read_event_list()");
1667 doc->
R(
"events[]", MJSON_STRING,
"array of history event names");
1675 MJsonNode* events = MJsonNode::MakeArray();
1677 for (
unsigned i=0;
i<
list.size();
i++) {
1679 events->AddToArray(MJsonNode::MakeString(
list[
i].c_str()));
1685typedef std::map<std::string,MidasHistoryInterface*>
MhiMap;
1705 if (strlen(
name) < 1) {
1726 cm_msg(
MERROR,
"GetHistory",
"Cannot configure history, hs_get_history() status %d",
status);
1752 doc->
D(
"get list of history channels in /Logger/History");
1753 doc->
R(
"status", MJSON_INT,
"return success or failure status");
1754 doc->
R(
"default_channel", MJSON_STRING,
"name of the default logger history channel");
1755 doc->
R(
"channels[]", MJSON_STRING,
"all logger history channel names");
1756 doc->
R(
"active_channels[]", MJSON_STRING,
"active logger history channel names");
1760 MJsonNode* channels = MJsonNode::MakeArray();
1761 MJsonNode* active_channels = MJsonNode::MakeArray();
1776 for (
int ichan=0; ; ichan++) {
1792 channels->AddToArray(MJsonNode::MakeString(
key.
name));
1795 INT size =
sizeof(active);
1799 active_channels->AddToArray(MJsonNode::MakeString(
key.
name));
1806 std::string default_channel;
1820 "default_channel", MJsonNode::MakeString(default_channel.c_str()),
1821 "active_channels", active_channels,
1822 "channels", channels);
1829 doc->
D(
"get list of history events that existed at give time using hs_get_events()");
1830 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
1831 doc->
P(
"time?", MJSON_NUMBER,
"timestamp, value 0 means current time, default is 0");
1832 doc->
R(
"status", MJSON_INT,
"return status of hs_get_events()");
1833 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
1834 doc->
R(
"events[]", MJSON_STRING,
"array of history event names");
1843 MJsonNode* events = MJsonNode::MakeArray();
1851 time = ::time(NULL);
1858 for (
unsigned i=0;
i<
list.size();
i++) {
1860 events->AddToArray(MJsonNode::MakeString(
list[
i].c_str()));
1870 doc->
D(
"reopen the history channel to make sure we see the latest list of events using hs_clear_cache()");
1871 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
1872 doc->
R(
"status", MJSON_INT,
"return status of hs_get_events()");
1873 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
1895 doc->
D(
"get list of history tags for given history events that existed at give time using hs_get_tags()");
1896 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
1897 doc->
P(
"time?", MJSON_NUMBER,
"timestamp, value 0 means current time, default is 0");
1898 doc->
P(
"events[]?", MJSON_STRING,
"array of history event names, default is get all events using hs_get_events()");
1899 doc->
R(
"status", MJSON_INT,
"return status");
1900 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
1901 doc->
R(
"events[].name", MJSON_STRING,
"array of history event names for each history event");
1902 doc->
R(
"events[].status", MJSON_INT,
"array of status ohistory tags for each history event");
1903 doc->
R(
"events[].tags[]", MJSON_STRING,
"array of history tags for each history event");
1904 doc->
R(
"events[].tags[].name", MJSON_STRING,
"history tag name");
1905 doc->
R(
"events[].tags[].type", MJSON_INT,
"history tag midas data type");
1906 doc->
R(
"events[].tags[].n_data?", MJSON_INT,
"history tag number of array elements, omitted if 1");
1915 time = ::time(NULL);
1920 MJsonNode* events = MJsonNode::MakeArray();
1927 std::vector<std::string> event_names;
1929 if (events_array && events_array->size() > 0) {
1930 for (
unsigned i=0;
i<events_array->size();
i++) {
1931 event_names.push_back((*events_array)[
i]->GetString());
1935 if (event_names.size() < 1) {
1942 for (
unsigned i=0;
i<event_names.size();
i++) {
1943 MJsonNode* o = MJsonNode::MakeObject();
1944 const char* event_name = event_names[
i].c_str();
1945 std::vector<TAG> tags;
1948 o->AddToObject(
"name", MJsonNode::MakeString(event_name));
1949 o->AddToObject(
"status", MJsonNode::MakeInt(
status));
1950 MJsonNode *ta = MJsonNode::MakeArray();
1951 for (
unsigned j=0;
j<tags.size();
j++) {
1952 MJsonNode* to = MJsonNode::MakeObject();
1954 to->AddToObject(
"name", MJsonNode::MakeString(tags[
j].
name));
1955 to->AddToObject(
"type", MJsonNode::MakeInt(tags[
j].
type));
1956 if (tags[
j].n_data != 1) {
1957 to->AddToObject(
"n_data", MJsonNode::MakeInt(tags[
j].n_data));
1961 o->AddToObject(
"tags", ta);
1962 events->AddToArray(o);
1973 doc->
D(
"get list of history tags for given history events that existed at give time using hs_get_last_written()");
1974 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
1975 doc->
P(
"time?", MJSON_NUMBER,
"timestamp, value 0 means current time, default is 0");
1976 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
1977 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
1978 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
1979 doc->
R(
"status", MJSON_INT,
"return status");
1980 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
1981 doc->
R(
"last_written[]", MJSON_NUMBER,
"array of last-written times for each history event");
1994 MJsonNode* lw = MJsonNode::MakeArray();
2001 unsigned num_var = events_array->size();
2003 if (tags_array->size() != num_var) {
2004 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2007 if (index_array->size() != num_var) {
2008 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2011 std::vector<std::string> event_names(num_var);
2012 std::vector<std::string> tag_names(num_var);
2015 int* var_index =
new int[num_var];
2016 time_t* last_written =
new time_t[num_var];
2018 for (
unsigned i=0;
i<num_var;
i++) {
2021 event_names[
i] = (*events_array)[
i]->GetString();
2022 tag_names[
i] = (*tags_array)[
i]->GetString();
2023 var_index[
i] = (*index_array)[
i]->GetInt();
2027 printf(
"time %f, num_vars %d:\n", time, num_var);
2028 for (
unsigned i=0;
i<num_var;
i++) {
2029 printf(
"%d: [%s] [%s] [%d]\n",
i, event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2034 time = ::time(NULL);
2038 const char** event_name =
new const char*[num_var];
2039 const char** tag_name =
new const char*[num_var];
2040 for (
unsigned i=0;
i<num_var;
i++) {
2041 event_name[
i] = event_names[
i].c_str();
2042 tag_name[
i] = tag_names[
i].c_str();
2046 for (
unsigned i=0;
i<num_var;
i++) {
2048 printf(
"%d: last_written %d\n",
i, (
int)last_written[
i]);
2050 lw->AddToArray(MJsonNode::MakeNumber(last_written[
i]));
2053 delete[] event_name;
2056 delete[] last_written;
2087 fTimeJson += MJsonNode::EncodeDouble(t);
2102 doc->
D(
"get history data for given history events that existed at give time using hs_read_buffer()");
2103 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
2104 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2105 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2106 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
2107 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
2108 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
2109 doc->
R(
"status", MJSON_INT,
"return status");
2110 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
2111 doc->
R(
"data[]", MJSON_ARRAY,
"array of history data");
2112 doc->
R(
"data[].status", MJSON_INT,
"status for each event");
2113 doc->
R(
"data[].count", MJSON_INT,
"number of data for each event");
2114 doc->
R(
"data[].time[]", MJSON_NUMBER,
"time data");
2115 doc->
R(
"data[].value[]", MJSON_NUMBER,
"value data");
2119 MJsonNode* error = NULL;
2122 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2123 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2131 MJsonNode*
data = MJsonNode::MakeArray();
2138 unsigned num_var = events_array->size();
2140 if (tags_array->size() != num_var) {
2141 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2144 if (index_array->size() != num_var) {
2145 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2148 std::vector<std::string> event_names(num_var);
2149 std::vector<std::string> tag_names(num_var);
2150 int* var_index =
new int[num_var];
2153 int* hs_status =
new int[num_var];
2155 for (
unsigned i=0;
i<num_var;
i++) {
2158 event_names[
i] = (*events_array)[
i]->GetString();
2159 tag_names[
i] = (*tags_array)[
i]->GetString();
2160 var_index[
i] = (*index_array)[
i]->GetInt();
2167 printf(
"time %f %f, num_vars %d:\n", start_time, end_time, num_var);
2168 for (
unsigned i=0;
i<num_var;
i++) {
2169 printf(
"%d: [%s] [%s] [%d]\n",
i, event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2173 const char** event_name =
new const char*[num_var];
2174 const char** tag_name =
new const char*[num_var];
2175 for (
unsigned i=0;
i<num_var;
i++) {
2176 event_name[
i] = event_names[
i].c_str();
2177 tag_name[
i] = tag_names[
i].c_str();
2180 int status =
mh->
hs_read_buffer(start_time, end_time, num_var, event_name, tag_name, var_index, buf, hs_status);
2182 for (
unsigned i=0;
i<num_var;
i++) {
2185 MJsonNode* obj = MJsonNode::MakeObject();
2186 obj->AddToObject(
"status", MJsonNode::MakeInt(hs_status[
i]));
2187 obj->AddToObject(
"count", MJsonNode::MakeInt(jbuf[
i]->fCount));
2188 obj->AddToObject(
"time", MJsonNode::MakeJSON(jbuf[
i]->fTimeJson.c_str()));
2189 obj->AddToObject(
"value", MJsonNode::MakeJSON(jbuf[
i]->fValueJson.c_str()));
2190 data->AddToArray(obj);
2197 delete[] event_name;
2211 doc->
D(
"get history data for given history events that existed at give time using hs_read_buffer()");
2212 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
2213 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2214 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2215 doc->
P(
"num_bins", MJSON_INT,
"number of time bins");
2216 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
2217 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
2218 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
2219 doc->
R(
"status", MJSON_INT,
"return status");
2220 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
2221 doc->
R(
"data[]", MJSON_ARRAY,
"array of history data");
2222 doc->
R(
"data[].status", MJSON_INT,
"status for each event");
2223 doc->
R(
"data[].num_entries", MJSON_INT,
"number of data points for each event");
2224 doc->
R(
"data[].count[]", MJSON_INT,
"number of data points for each bin");
2225 doc->
R(
"data[].mean[]", MJSON_NUMBER,
"mean for each bin");
2226 doc->
R(
"data[].rms[]", MJSON_NUMBER,
"rms for each bin");
2227 doc->
R(
"data[].min[]", MJSON_NUMBER,
"minimum value for each bin");
2228 doc->
R(
"data[].max[]", MJSON_NUMBER,
"maximum value for each bin");
2229 doc->
R(
"data[].bins_first_time[]", MJSON_NUMBER,
"first data point in each bin");
2230 doc->
R(
"data[].bins_first_value[]", MJSON_NUMBER,
"first data point in each bin");
2231 doc->
R(
"data[].bins_last_time[]", MJSON_NUMBER,
"last data point in each bin");
2232 doc->
R(
"data[].bins_last_value[]", MJSON_NUMBER,
"last data point in each bin");
2233 doc->
R(
"data[].last_time", MJSON_NUMBER,
"time of last data entry");
2234 doc->
R(
"data[].last_value", MJSON_NUMBER,
"value of last data entry");
2238 MJsonNode* error = NULL;
2241 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2242 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2243 int num_bins =
mjsonrpc_get_param(params,
"num_bins", &error)->GetInt();
if (error)
return error;
2246 return mjsonrpc_make_error(-32602,
"Invalid params",
"Value of num_bins should be 1 or more");
2255 MJsonNode*
data = MJsonNode::MakeArray();
2262 unsigned num_var = events_array->size();
2265 return mjsonrpc_make_error(-32602,
"Invalid params",
"Array of events should have 1 or more elements");
2268 if (tags_array->size() != num_var) {
2269 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2272 if (index_array->size() != num_var) {
2273 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2276 std::vector<std::string> event_names(num_var);
2277 std::vector<std::string> tag_names(num_var);
2280 int* var_index =
new int[num_var];
2282 int* num_entries =
new int[num_var];
2283 time_t*
last_time =
new time_t[num_var];
2284 double* last_value =
new double[num_var];
2285 int* hs_status =
new int[num_var];
2287 int** count_bins =
new int*[num_var];
2288 double** mean_bins =
new double*[num_var];
2289 double** rms_bins =
new double*[num_var];
2290 double** min_bins =
new double*[num_var];
2291 double** max_bins =
new double*[num_var];
2293 time_t** bins_first_time =
new time_t*[num_var];
2294 time_t** bins_last_time =
new time_t*[num_var];
2296 double** bins_first_value =
new double*[num_var];
2297 double** bins_last_value =
new double*[num_var];
2299 for (
unsigned i=0;
i<num_var;
i++) {
2302 event_names[
i] = (*events_array)[
i]->GetString();
2303 tag_names[
i] = (*tags_array)[
i]->GetString();
2304 var_index[
i] = (*index_array)[
i]->GetInt();
2309 count_bins[
i] =
new int[num_bins];
2310 mean_bins[
i] =
new double[num_bins];
2311 rms_bins[
i] =
new double[num_bins];
2312 min_bins[
i] =
new double[num_bins];
2313 max_bins[
i] =
new double[num_bins];
2315 bins_first_time[
i] =
new time_t[num_bins];
2316 bins_last_time[
i] =
new time_t[num_bins];
2318 bins_first_value[
i] =
new double[num_bins];
2319 bins_last_value[
i] =
new double[num_bins];
2323 printf(
"time %f %f, num_vars %d:\n", start_time, end_time, num_var);
2324 for (
unsigned i=0;
i<num_var;
i++) {
2325 printf(
"%d: [%s] [%s] [%d]\n",
i, event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2329 const char** event_name =
new const char*[num_var];
2330 const char** tag_name =
new const char*[num_var];
2331 for (
unsigned i=0;
i<num_var;
i++) {
2332 event_name[
i] = event_names[
i].c_str();
2333 tag_name[
i] = tag_names[
i].c_str();
2336 int status =
mh->
hs_read_binned(start_time, end_time, num_bins, num_var, event_name, tag_name, var_index, num_entries, count_bins, mean_bins, rms_bins, min_bins, max_bins, bins_first_time, bins_first_value, bins_last_time, bins_last_value,
last_time, last_value, hs_status);
2338 for (
unsigned i=0;
i<num_var;
i++) {
2339 MJsonNode* obj = MJsonNode::MakeObject();
2340 obj->AddToObject(
"status", MJsonNode::MakeInt(hs_status[
i]));
2341 obj->AddToObject(
"num_entries", MJsonNode::MakeInt(num_entries[
i]));
2343 MJsonNode* a1 = MJsonNode::MakeArray();
2344 MJsonNode* a2 = MJsonNode::MakeArray();
2345 MJsonNode* a3 = MJsonNode::MakeArray();
2346 MJsonNode* a4 = MJsonNode::MakeArray();
2347 MJsonNode* a5 = MJsonNode::MakeArray();
2349 MJsonNode* b1 = MJsonNode::MakeArray();
2350 MJsonNode* b2 = MJsonNode::MakeArray();
2351 MJsonNode* b3 = MJsonNode::MakeArray();
2352 MJsonNode* b4 = MJsonNode::MakeArray();
2354 for (
int j=0;
j<num_bins;
j++) {
2355 a1->AddToArray(MJsonNode::MakeInt(count_bins[
i][
j]));
2356 a2->AddToArray(MJsonNode::MakeNumber(mean_bins[
i][
j]));
2357 a3->AddToArray(MJsonNode::MakeNumber(rms_bins[
i][
j]));
2358 a4->AddToArray(MJsonNode::MakeNumber(min_bins[
i][
j]));
2359 a5->AddToArray(MJsonNode::MakeNumber(max_bins[
i][
j]));
2361 b1->AddToArray(MJsonNode::MakeNumber(bins_first_time[
i][
j]));
2362 b2->AddToArray(MJsonNode::MakeNumber(bins_first_value[
i][
j]));
2363 b3->AddToArray(MJsonNode::MakeNumber(bins_last_time[
i][
j]));
2364 b4->AddToArray(MJsonNode::MakeNumber(bins_last_value[
i][
j]));
2367 obj->AddToObject(
"count", a1);
2368 obj->AddToObject(
"mean", a2);
2369 obj->AddToObject(
"rms", a3);
2370 obj->AddToObject(
"min", a4);
2371 obj->AddToObject(
"max", a5);
2372 obj->AddToObject(
"bins_first_time", b1);
2373 obj->AddToObject(
"bins_first_value", b2);
2374 obj->AddToObject(
"bins_last_time", b3);
2375 obj->AddToObject(
"bins_last_value", b4);
2376 obj->AddToObject(
"last_time", MJsonNode::MakeNumber(
last_time[
i]));
2377 obj->AddToObject(
"last_value", MJsonNode::MakeNumber(last_value[
i]));
2378 data->AddToArray(obj);
2380 delete count_bins[
i];
2381 delete mean_bins[
i];
2386 delete bins_first_time[
i];
2387 delete bins_first_value[
i];
2388 delete bins_last_time[
i];
2389 delete bins_last_value[
i];
2392 delete[] count_bins;
2398 delete[] bins_first_time;
2399 delete[] bins_first_value;
2400 delete[] bins_last_time;
2401 delete[] bins_last_value;
2403 delete[] event_name;
2407 delete[] num_entries;
2409 delete[] last_value;
2445 doc->
D(
"get history data for given history events that existed at give time using hs_read_buffer()");
2446 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
2447 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2448 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2449 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
2450 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
2451 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
2452 doc->
R(
"binary data", MJSON_ARRAYBUFFER,
"binary data, see documentation");
2456 MJsonNode* error = NULL;
2459 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2460 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2473 size_t num_var = events_array->size();
2475 if (tags_array->size() != num_var) {
2476 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2479 if (index_array->size() != num_var) {
2480 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2483 std::vector<std::string> event_names(num_var);
2484 std::vector<std::string> tag_names(num_var);
2485 int* var_index =
new int[num_var];
2488 int* hs_status =
new int[num_var];
2490 for (
size_t i=0;
i<num_var;
i++) {
2493 event_names[
i] = (*events_array)[
i]->GetString();
2494 tag_names[
i] = (*tags_array)[
i]->GetString();
2495 var_index[
i] = (*index_array)[
i]->GetInt();
2502 printf(
"time %f %f, num_vars %d:\n", start_time, end_time,
int(num_var));
2503 for (
size_t i=0;
i<num_var;
i++) {
2504 printf(
"%d: [%s] [%s] [%d]\n",
int(
i), event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2508 const char** event_name =
new const char*[num_var];
2509 const char** tag_name =
new const char*[num_var];
2510 for (
unsigned i=0;
i<num_var;
i++) {
2511 event_name[
i] = event_names[
i].c_str();
2512 tag_name[
i] = tag_names[
i].c_str();
2515 int status =
mh->
hs_read_buffer(start_time, end_time, num_var, event_name, tag_name, var_index, buf, hs_status);
2517 size_t num_values = 0;
2519 for (
unsigned i=0;
i<num_var;
i++) {
2521 num_values += jbuf[
i]->
fValues.size();
2525 size_t p0_size =
sizeof(double)*(2+2*num_var+2*num_values);
2527 size_t size_limit = 1000*1024*1024;
2529 if (p0_size > size_limit) {
2530 cm_msg(
MERROR,
"js_hs_read_binned_arraybuffer",
"Refusing to return %zu bytes of history data, limit is %zu bytes\n", p0_size, size_limit);
2532 for (
size_t i=0;
i<num_var;
i++) {
2538 delete[] event_name;
2548 double* p0 = (
double*)malloc(p0_size);
2551 cm_msg(
MERROR,
"js_hs_read_binned_arraybuffer",
"Cannot allocate return buffer %d bytes\n",
int(p0_size));
2553 for (
size_t i=0;
i<num_var;
i++) {
2559 delete[] event_name;
2566 return mjsonrpc_make_error(-32603,
"Internal error",
"Cannot allocate buffer, too much data");
2590 for (
size_t i=0;
i<num_var;
i++) {
2591 *pptr++ = hs_status[
i];
2594 for (
size_t i=0;
i<num_var;
i++) {
2598 for (
size_t i=0;
i<num_var;
i++) {
2599 size_t nv = jbuf[
i]->
fValues.size();
2600 for (
size_t j=0;
j<nv;
j++) {
2612 assert(p0_size == ((pptr-p0)*
sizeof(
double)));
2614 delete[] event_name;
2621 MJsonNode* result = MJsonNode::MakeArrayBuffer((
char*)p0, p0_size);
2630 doc->
D(
"get history data for given history events that existed at give time using hs_read_buffer()");
2631 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
2632 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2633 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2634 doc->
P(
"num_bins", MJSON_INT,
"number of time bins");
2635 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
2636 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
2637 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
2638 doc->
R(
"binary data", MJSON_ARRAYBUFFER,
"binary data, see documentation");
2642 MJsonNode* error = NULL;
2645 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2646 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2647 int inum_bins =
mjsonrpc_get_param(params,
"num_bins", &error)->GetInt();
if (error)
return error;
2649 if (inum_bins < 1) {
2650 return mjsonrpc_make_error(-32602,
"Invalid params",
"Value of num_bins should be 1 or more");
2653 size_t num_bins = inum_bins;
2666 size_t num_var = events_array->size();
2669 return mjsonrpc_make_error(-32602,
"Invalid params",
"Array of events should have 1 or more elements");
2672 if (tags_array->size() != num_var) {
2673 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2676 if (index_array->size() != num_var) {
2677 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2680 std::vector<std::string> event_names(num_var);
2681 std::vector<std::string> tag_names(num_var);
2684 int* var_index =
new int[num_var];
2686 int* num_entries =
new int[num_var];
2687 time_t*
last_time =
new time_t[num_var];
2688 double* last_value =
new double[num_var];
2689 int* hs_status =
new int[num_var];
2691 int** count_bins =
new int*[num_var];
2692 double** mean_bins =
new double*[num_var];
2693 double** rms_bins =
new double*[num_var];
2694 double** min_bins =
new double*[num_var];
2695 double** max_bins =
new double*[num_var];
2697 time_t** bins_first_time =
new time_t*[num_var];
2698 time_t** bins_last_time =
new time_t*[num_var];
2700 double** bins_first_value =
new double*[num_var];
2701 double** bins_last_value =
new double*[num_var];
2703 for (
unsigned i=0;
i<num_var;
i++) {
2706 event_names[
i] = (*events_array)[
i]->GetString();
2707 tag_names[
i] = (*tags_array)[
i]->GetString();
2708 var_index[
i] = (*index_array)[
i]->GetInt();
2713 count_bins[
i] =
new int[num_bins];
2714 mean_bins[
i] =
new double[num_bins];
2715 rms_bins[
i] =
new double[num_bins];
2716 min_bins[
i] =
new double[num_bins];
2717 max_bins[
i] =
new double[num_bins];
2718 bins_first_time[
i] =
new time_t[num_bins];
2719 bins_last_time[
i] =
new time_t[num_bins];
2720 bins_first_value[
i] =
new double[num_bins];
2721 bins_last_value[
i] =
new double[num_bins];
2725 printf(
"time %f %f, num_vars %d:\n", start_time, end_time,
int(num_var));
2726 for (
size_t i=0;
i<num_var;
i++) {
2727 printf(
"%d: [%s] [%s] [%d]\n",
int(
i), event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2731 const char** event_name =
new const char*[num_var];
2732 const char** tag_name =
new const char*[num_var];
2733 for (
size_t i=0;
i<num_var;
i++) {
2734 event_name[
i] = event_names[
i].c_str();
2735 tag_name[
i] = tag_names[
i].c_str();
2738 int status =
mh->
hs_read_binned(start_time, end_time, num_bins, num_var, event_name, tag_name, var_index, num_entries, count_bins, mean_bins, rms_bins, min_bins, max_bins, bins_first_time, bins_first_value, bins_last_time, bins_last_value,
last_time, last_value, hs_status);
2741 size_t p0_size =
sizeof(double)*(5+4*num_var+9*num_var*num_bins);
2743 size_t size_limit = 100*1024*1024;
2745 if (p0_size > size_limit) {
2746 cm_msg(
MERROR,
"js_hs_read_binned_arraybuffer",
"Refusing to return %d bytes. limit is %d bytes\n",
int(p0_size),
int(size_limit));
2748 for (
size_t i=0;
i<num_var;
i++) {
2749 delete count_bins[
i];
2750 delete mean_bins[
i];
2754 delete bins_first_time[
i];
2755 delete bins_first_value[
i];
2756 delete bins_last_time[
i];
2757 delete bins_last_value[
i];
2760 delete[] count_bins;
2766 delete[] bins_first_time;
2767 delete[] bins_first_value;
2768 delete[] bins_last_time;
2769 delete[] bins_last_value;
2771 delete[] event_name;
2775 delete[] num_entries;
2777 delete[] last_value;
2783 double* p0 = (
double*)malloc(p0_size);
2786 cm_msg(
MERROR,
"js_hs_read_binned_arraybuffer",
"Cannot allocate return buffer %d bytes\n",
int(p0_size));
2788 for (
size_t i=0;
i<num_var;
i++) {
2789 delete count_bins[
i];
2790 delete mean_bins[
i];
2794 delete bins_first_time[
i];
2795 delete bins_first_value[
i];
2796 delete bins_last_time[
i];
2797 delete bins_last_value[
i];
2800 delete[] count_bins;
2806 delete[] bins_first_time;
2807 delete[] bins_first_value;
2808 delete[] bins_last_time;
2809 delete[] bins_last_value;
2811 delete[] event_name;
2815 delete[] num_entries;
2817 delete[] last_value;
2820 return mjsonrpc_make_error(-32603,
"Internal error",
"Cannot allocate buffer, too much data");
2859 *pptr++ = start_time;
2864 for (
unsigned i=0;
i<num_var;
i++) {
2865 *pptr++ = hs_status[
i];
2868 for (
unsigned i=0;
i<num_var;
i++) {
2869 *pptr++ = num_entries[
i];
2872 for (
unsigned i=0;
i<num_var;
i++) {
2876 for (
unsigned i=0;
i<num_var;
i++) {
2877 *pptr++ = last_value[
i];
2880 for (
size_t i=0;
i<num_var;
i++) {
2881 for (
size_t j=0;
j<num_bins;
j++) {
2882 *pptr++ = count_bins[
i][
j];
2883 *pptr++ = mean_bins[
i][
j];
2884 *pptr++ = rms_bins[
i][
j];
2885 *pptr++ = min_bins[
i][
j];
2886 *pptr++ = max_bins[
i][
j];
2887 *pptr++ = bins_first_time[
i][
j];
2888 *pptr++ = bins_first_value[
i][
j];
2889 *pptr++ = bins_last_time[
i][
j];
2890 *pptr++ = bins_last_value[
i][
j];
2893 delete count_bins[
i];
2894 delete mean_bins[
i];
2898 delete bins_first_time[
i];
2899 delete bins_first_value[
i];
2900 delete bins_last_time[
i];
2901 delete bins_last_value[
i];
2906 assert(p0_size == ((pptr-p0)*
sizeof(
double)));
2908 delete[] count_bins;
2914 delete[] bins_first_time;
2915 delete[] bins_first_value;
2916 delete[] bins_last_time;
2917 delete[] bins_last_value;
2919 delete[] event_name;
2923 delete[] num_entries;
2925 delete[] last_value;
2928 MJsonNode* result = MJsonNode::MakeArrayBuffer((
char*)p0, p0_size);
2942 doc->
D(
"Get a list of history image files");
2943 doc->
P(
"image?", MJSON_STRING,
"image name as defined under /History/Images/<image>");
2944 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2945 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2946 doc->
R(
"time[]", MJSON_ARRAYBUFFER,
"array of time stamps in seconds");
2947 doc->
R(
"filename[]", MJSON_ARRAYBUFFER,
"array of file names");
2951 MJsonNode* error = NULL;
2954 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2955 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2957 std::vector<time_t>vtime{};
2958 std::vector<std::string>vfilename{};
2962 MJsonNode *tj = MJsonNode::MakeArray();
2963 MJsonNode *fj = MJsonNode::MakeArray();
2965 for (
int i=0 ;
i<(int)vtime.size() ;
i++) {
2966 tj->AddToArray(MJsonNode::MakeInt(vtime[
i]));
2968 fj->AddToArray(MJsonNode::MakeString(vfilename[
i].c_str()));
2970 MJsonNode*
data = MJsonNode::MakeObject();
2971 data->AddToObject(
"count", MJsonNode::MakeInt(
count));
2972 data->AddToObject(
"time", tj);
2973 data->AddToObject(
"filename", fj);
2988 doc->
D(
"Get an elog message");
2989 doc->
P(
"tag", MJSON_STRING,
"elog message tag");
2990 doc->
R(
"status", MJSON_INT,
"return status of el_retrieve");
2991 doc->
R(
"msg.tag", MJSON_STRING,
"message tag");
2995 MJsonNode* error = NULL;
2997 std::string tag =
mjsonrpc_get_param(params,
"tag", &error)->GetString();
if (error)
return error;
3000 char date[80], author[80],
type[80], system[80], subject[256], text[10000];
3001 char orig_tag[80], reply_tag[80], attachment[3][256], encoding[80];
3004 mstrlcpy(xtag, tag.c_str(),
sizeof(xtag));
3006 int size =
sizeof(text);
3009 date, &
run, author,
type, system, subject,
3010 text, &size, orig_tag, reply_tag,
3011 attachment[0], attachment[1], attachment[2], encoding);
3015 MJsonNode* msg = MJsonNode::MakeObject();
3019 msg->AddToObject(
"tag", MJsonNode::MakeString(xtag));
3021 msg->AddToObject(
"date", MJsonNode::MakeString(date));
3022 msg->AddToObject(
"run", MJsonNode::MakeInt(
run));
3024 msg->AddToObject(
"author", MJsonNode::MakeString(author));
3026 msg->AddToObject(
"type", MJsonNode::MakeString(
type));
3028 msg->AddToObject(
"system", MJsonNode::MakeString(system));
3030 msg->AddToObject(
"subject", MJsonNode::MakeString(subject));
3032 msg->AddToObject(
"text", MJsonNode::MakeString(text));
3034 msg->AddToObject(
"orig_tag", MJsonNode::MakeString(orig_tag));
3036 msg->AddToObject(
"reply_tag", MJsonNode::MakeString(reply_tag));
3038 msg->AddToObject(
"attachment0", MJsonNode::MakeString(attachment[0]));
3040 msg->AddToObject(
"attachment1", MJsonNode::MakeString(attachment[1]));
3042 msg->AddToObject(
"attachment2", MJsonNode::MakeString(attachment[2]));
3044 msg->AddToObject(
"encoding", MJsonNode::MakeString(encoding));
3054 doc->
D(
"Query elog messages");
3055 doc->
P(
"last_n_hours?", MJSON_INT,
"return messages from the last N hours");
3056 doc->
R(
"status", MJSON_INT,
"return status of el_retrieve");
3057 doc->
R(
"msg[].tag", MJSON_STRING,
"message tag");
3083 MJsonNode* msg_array = MJsonNode::MakeArray();
3086 char date[80], author[80],
type[80], system[80], subject[256], text[10000],
3087 orig_tag[80], reply_tag[80], attachment[3][256], encoding[80];
3088 char str[256], str2[10000], tag[256];
3092 extern const char *
mname[];
3108 r1 = atoi(pr1.c_str());
3111 r2 = atoi(pr2.c_str());
3113 time_t ltime_start = 0;
3114 time_t ltime_end = 0;
3119 if (py1.length() > 0)
3120 y1 = atoi(py1.c_str());
3122 if (pd1.length() > 0)
3123 d1 = atoi(pd1.c_str());
3125 mstrlcpy(
str, pm1.c_str(),
sizeof(
str));
3126 for (m1 = 0; m1 < 12; m1++)
3132 if (pd2.length() > 0) {
3133 d2 = atoi(pd2.c_str());
3136 if (py2.length() > 0) {
3139 mstrlcpy(
str, pm2.c_str(),
sizeof(
str));
3140 for (m2 = 0; m2 < 12; m2++)
3148 if (py2.length() > 0) {
3149 y2 = atoi(py2.c_str());
3152 if (y2>=0 && m2>=0 && d2>=0) {
3153 memset(&tms, 0,
sizeof(
struct tm));
3154 tms.tm_year = y2 % 100;
3159 if (tms.tm_year < 90)
3171 time_t now = time(NULL);
3172 ltime_start = now - 3600 * last_n;
3174 localtime_r(<ime_start, &tms);
3175 sprintf(tag,
"%02d%02d%02d.0", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
3176 }
else if (r1 > 0) {
3179 }
else if (y1>=0 && m1>=0 && d1>=0) {
3181 sprintf(tag,
"%02d%02d%02d.0", y1 % 100, m1 + 1, d1);
3185 printf(
"js_el_query: y1 %d, m1 %d, d1 %d, y2 %d, m2 %d, d2 %d, r1 %d, r2 %d, last_n_hours %d, start time %lu, end time %lu, tag [%s]\n",
3196 size =
sizeof(text);
3198 text, &size, orig_tag, reply_tag,
3199 attachment[0], attachment[1], attachment[2], encoding);
3201 std::string this_tag = tag;
3205 mstrlcat(tag,
"+1",
sizeof(tag));
3208 if ((r2 > 0) && (r2 <
run)) {
3213 memset(&tms, 0,
sizeof(
struct tm));
3214 tms.tm_year = (tag[0] -
'0') * 10 + (tag[1] -
'0');
3215 tms.tm_mon = (tag[2] -
'0') * 10 + (tag[3] -
'0') - 1;
3216 tms.tm_mday = (tag[4] -
'0') * 10 + (tag[5] -
'0');
3217 tms.tm_hour = (date[11] -
'0') * 10 + (date[12] -
'0');
3218 tms.tm_min = (date[14] -
'0') * 10 + (date[15] -
'0');
3219 tms.tm_sec = (date[17] -
'0') * 10 + (date[18] -
'0');
3221 if (tms.tm_year < 90)
3229 if (ltime_start > 0)
3230 if (ltime_current < ltime_start)
3234 if (ltime_end > 0) {
3235 if (ltime_current > ltime_end)
3243 if ((psystem.length()>0) && !
equal_ustring(psystem.c_str(), system))
3246 if (pauthor.length()>0) {
3247 mstrlcpy(
str, pauthor.c_str(),
sizeof(
str));
3248 for (
i = 0;
i < (int) strlen(
str);
i++)
3251 for (
i = 0;
i < (int) strlen(author) && author[
i] !=
'@';
i++)
3252 str2[
i] = toupper(author[
i]);
3255 if (strstr(str2,
str) == NULL)
3259 if (psubject.length()>0) {
3260 mstrlcpy(
str, psubject.c_str(),
sizeof(
str));
3261 for (
i = 0;
i < (int) strlen(
str);
i++)
3264 for (
i = 0;
i < (int) strlen(subject);
i++)
3265 str2[
i] = toupper(subject[
i]);
3268 if (strstr(str2,
str) == NULL)
3272 if (psubtext.length()>0) {
3273 mstrlcpy(
str, psubtext.c_str(),
sizeof(
str));
3274 for (
i = 0;
i < (int) strlen(
str);
i++)
3277 for (
i = 0;
i < (int) strlen(text);
i++)
3278 str2[
i] = toupper(text[
i]);
3281 if (strstr(str2,
str) == NULL)
3287 MJsonNode* msg = MJsonNode::MakeObject();
3290 msg->AddToObject(
"tag", MJsonNode::MakeString(this_tag.c_str()));
3292 msg->AddToObject(
"date", MJsonNode::MakeString(date));
3293 msg->AddToObject(
"run", MJsonNode::MakeInt(
run));
3295 msg->AddToObject(
"author", MJsonNode::MakeString(author));
3297 msg->AddToObject(
"type", MJsonNode::MakeString(
type));
3299 msg->AddToObject(
"system", MJsonNode::MakeString(system));
3301 msg->AddToObject(
"subject", MJsonNode::MakeString(subject));
3303 msg->AddToObject(
"text", MJsonNode::MakeString(text));
3305 msg->AddToObject(
"orig_tag", MJsonNode::MakeString(orig_tag));
3307 msg->AddToObject(
"reply_tag", MJsonNode::MakeString(reply_tag));
3309 msg->AddToObject(
"attachment0", MJsonNode::MakeString(attachment[0]));
3311 msg->AddToObject(
"attachment1", MJsonNode::MakeString(attachment[1]));
3313 msg->AddToObject(
"attachment2", MJsonNode::MakeString(attachment[2]));
3315 msg->AddToObject(
"encoding", MJsonNode::MakeString(encoding));
3317 msg_array->AddToArray(msg);
3329 doc->
D(
"Delete elog message");
3330 doc->
P(
"tag", MJSON_STRING,
"tag of message to delete");
3331 doc->
R(
"status", MJSON_INT,
"return status of el_delete");
3335 MJsonNode* error = NULL;
3336 std::string tag =
mjsonrpc_get_param(params,
"tag", &error)->GetString();
if (error)
return error;
3352 doc->
D(
"make RPC call into frontend program via RPC_JRPC_CXX");
3353 doc->
P(
"client_name", MJSON_STRING,
"Connect to this MIDAS client, see cm_connect_client()");
3354 doc->
P(
"cmd", MJSON_STRING,
"Command passed to client");
3355 doc->
P(
"args", MJSON_STRING,
"Parameters passed to client as a string, could be JSON encoded");
3356 doc->
R(
"reply", MJSON_STRING,
"Reply from client as a string, could be JSON encoded");
3357 doc->
R(
"status", MJSON_INT,
"return status of cm_connect_client() and rpc_client_call()");
3361 MJsonNode* error = NULL;
3363 std::string
name =
mjsonrpc_get_param(params,
"client_name", &error)->GetString();
if (error)
return error;
3364 std::string cmd =
mjsonrpc_get_param(params,
"cmd", &error)->GetString();
if (error)
return error;
3365 std::string args =
mjsonrpc_get_param(params,
"args", &error)->GetString();
if (error)
return error;
3393 MJsonNode*
rn = MJsonNode::MakeString(reply.c_str());
3402 doc->
D(
"make RPC call into frontend program via RPC_JRPC");
3403 doc->
P(
"client_name", MJSON_STRING,
"Connect to this MIDAS client, see cm_connect_client()");
3404 doc->
P(
"cmd", MJSON_STRING,
"Command passed to client");
3405 doc->
P(
"args", MJSON_STRING,
"Parameters passed to client as a string, could be JSON encoded");
3406 doc->
P(
"max_reply_length?", MJSON_INT,
"Optional maximum length of client reply. MIDAS RPC does not support returning strings of arbitrary length, maximum length has to be known ahead of time.");
3407 doc->
R(
"reply", MJSON_STRING,
"Reply from client as a string, could be JSON encoded");
3408 doc->
R(
"status", MJSON_INT,
"return status of cm_connect_client() and rpc_client_call()");
3412 MJsonNode* error = NULL;
3414 std::string
name =
mjsonrpc_get_param(params,
"client_name", &error)->GetString();
if (error)
return error;
3415 std::string cmd =
mjsonrpc_get_param(params,
"cmd", &error)->GetString();
if (error)
return error;
3416 std::string args =
mjsonrpc_get_param(params,
"args", &error)->GetString();
if (error)
return error;
3417 int max_reply_length =
mjsonrpc_get_param(params,
"max_reply_length", NULL)->GetInt();
3421 int buf_length = 1024;
3423 if (max_reply_length > buf_length)
3424 buf_length = max_reply_length;
3426 char* buf = (
char*)malloc(buf_length);
3429 return mjsonrpc_make_error(-32602,
"Invalid params",
msprintf(
"malloc(%d) failed, likely invalid max_reply_length value %d", buf_length, max_reply_length).c_str());
3458 MJsonNode* reply = MJsonNode::MakeString(buf);
3474 doc->
D(
"make RPC call into frontend program via RPC_BRPC_CXX");
3475 doc->
P(
"client_name", MJSON_STRING,
"Connect to this MIDAS client, see cm_connect_client()");
3476 doc->
P(
"cmd", MJSON_STRING,
"Command passed to client");
3477 doc->
P(
"args", MJSON_STRING,
"Parameters passed to client as a string, could be JSON encoded");
3478 doc->
R(
"reply", MJSON_STRING,
"Reply from client as a string, could be JSON encoded");
3479 doc->
R(
"status", MJSON_INT,
"return status of cm_connect_client() and rpc_client_call()");
3483 MJsonNode* error = NULL;
3485 std::string
name =
mjsonrpc_get_param(params,
"client_name", &error)->GetString();
if (error)
return error;
3486 std::string cmd =
mjsonrpc_get_param(params,
"cmd", &error)->GetString();
if (error)
return error;
3487 std::string args =
mjsonrpc_get_param(params,
"args", &error)->GetString();
if (error)
return error;
3499 std::vector<char> *pbuf =
new std::vector<char>;
3513 return MJsonNode::MakeArrayBuffer(pbuf);
3520 doc->
D(
"make RPC call into frontend program via RPC_BRPC");
3521 doc->
P(
"client_name", MJSON_STRING,
"Connect to this MIDAS client, see cm_connect_client()");
3522 doc->
P(
"cmd", MJSON_STRING,
"Command passed to client");
3523 doc->
P(
"args", MJSON_STRING,
"Parameters passed to client as a string, could be JSON encoded");
3524 doc->
P(
"max_reply_length?", MJSON_INT,
"Optional maximum length of client reply. MIDAS RPC does not support returning data of arbitrary length, maximum length has to be known ahead of time.");
3525 doc->
R(
"reply", MJSON_STRING,
"Reply from client as a string, could be JSON encoded");
3526 doc->
R(
"status", MJSON_INT,
"return status of cm_connect_client() and rpc_client_call()");
3530 MJsonNode* error = NULL;
3532 std::string
name =
mjsonrpc_get_param(params,
"client_name", &error)->GetString();
if (error)
return error;
3533 std::string cmd =
mjsonrpc_get_param(params,
"cmd", &error)->GetString();
if (error)
return error;
3534 std::string args =
mjsonrpc_get_param(params,
"args", &error)->GetString();
if (error)
return error;
3535 int max_reply_length =
mjsonrpc_get_param(params,
"max_reply_length", NULL)->GetInt();
3539 int buf_length = 1024;
3541 if (max_reply_length > buf_length)
3542 buf_length = max_reply_length;
3544 char* buf = (
char*)malloc(buf_length);
3547 return mjsonrpc_make_error(-32602,
"Invalid params",
msprintf(
"malloc(%d) failed, likely invalid max_reply_length value %d", buf_length, max_reply_length).c_str());
3574 return MJsonNode::MakeArrayBuffer(buf, buf_length);
3587 doc->
D(
"start and stop runs");
3588 doc->
P(
"transition", MJSON_STRING,
"requested transition: TR_START, TR_STOP, TR_PAUSE, TR_RESUME");
3589 doc->
P(
"run_number?", MJSON_INT,
"New run number, value 0 means /runinfo/run_number + 1, default is 0");
3590 doc->
P(
"async_flag?", MJSON_INT,
"Transition type. Default is multithreaded transition TR_MTHREAD");
3591 doc->
P(
"debug_flag?", MJSON_INT,
"See cm_transition(), value 1: trace to stdout, value 2: trace to midas.log");
3592 doc->
R(
"status", MJSON_INT,
"return status of cm_transition()");
3593 doc->
R(
"error_string?", MJSON_STRING,
"return error string from cm_transition()");
3597 MJsonNode* error = NULL;
3599 std::string xtransition =
mjsonrpc_get_param(params,
"transition", &error)->GetString();
if (error)
return error;
3608 if (xtransition ==
"TR_START")
3610 else if (xtransition ==
"TR_STOP")
3612 else if (xtransition ==
"TR_PAUSE")
3614 else if (xtransition ==
"TR_RESUME")
3620 if (async_flag == 0)
3623 char error_str[1024];
3627 MJsonNode* result = MJsonNode::MakeObject();
3629 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3630 if (strlen(error_str) > 0) {
3632 result->AddToObject(
"error_string", MJsonNode::MakeString(error_str));
3684 printf(
", size %d, serial %d, time %d, event_id %d, trigger_mask %x",
pevent->
data_size,
pevent->
serial_number,
pevent->
time_stamp,
pevent->
event_id,
pevent->
trigger_mask);
3700 s->ReplaceEvent(pevent);
3702 }
else if (
bm_match_event(s->event_id, s->trigger_mask, pevent)) {
3703 s->ReplaceEvent(pevent);
3725 s->ReplaceEvent(pevent);
3749 if (s->pevent->event_id == last_event_id
3750 && s->pevent->trigger_mask == last_trigger_mask
3751 && s->pevent->serial_number == last_serial_number
3752 && s->pevent->time_stamp == last_time_stamp) {
3768 doc->
D(
"read event buffers");
3769 doc->
P(
"buffer_name", MJSON_STRING,
"name of event buffer");
3770 doc->
P(
"event_id?", MJSON_INT,
"requested event id, -1 means any event id");
3771 doc->
P(
"trigger_mask?", MJSON_INT,
"requested trigger mask, -1 means any trigger mask");
3772 doc->
P(
"get_recent?", MJSON_BOOL,
"get last available event that matches this event request");
3773 doc->
P(
"last_event_header[]?", MJSON_INT,
"do not resend an event we already received: event header of last received event [event_id,trigger_mask,serial_number,time_stamp]");
3774 doc->
P(
"timeout_millisec?", MJSON_NUMBER,
"how long to wait for an event");
3775 doc->
R(
"binary data", MJSON_ARRAYBUFFER,
"binary event data");
3776 doc->
R(
"status", MJSON_INT,
"return status of bm_open_buffer(), bm_request_event(), bm_set_cache_size(), bm_receive_alloc()");
3780 MJsonNode* error = NULL;
3786 const MJsonNodeVector* last_event_header =
mjsonrpc_get_param(params,
"last_event_header", NULL)->GetArray();
3787 int timeout_millisec =
mjsonrpc_get_param(params,
"timeout_millisec", NULL)->GetInt();
3789 int last_event_id = 0;
3790 int last_trigger_mask = 0;
3791 int last_serial_number = 0;
3792 int last_time_stamp = 0;
3794 if (last_event_header && last_event_header->size() > 0) {
3795 if (last_event_header->size() != 4) {
3796 return mjsonrpc_make_error(-32602,
"Invalid params",
"last_event_header should be an array with 4 elements");
3799 last_event_id = (*last_event_header)[0]->GetInt();
3800 last_trigger_mask = (*last_event_header)[1]->GetInt();
3801 last_serial_number = (*last_event_header)[2]->GetInt();
3802 last_time_stamp = (*last_event_header)[3]->GetInt();
3817 HNDLE buffer_handle = 0;
3825 static std::mutex
gMutex;
3826 std::lock_guard<std::mutex> lock_guard(
gMutex);
3835 MJsonNode* result = MJsonNode::MakeObject();
3836 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3841 MJsonNode* result = MJsonNode::MakeObject();
3842 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3848 MJsonNode* result = MJsonNode::MakeObject();
3849 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3855 if (timeout_millisec <= 0)
3856 timeout_millisec = 100.0;
3859 double end_time = start_time + timeout_millisec/1000.0;
3887 return MJsonNode::MakeArrayBuffer((
char*)pevent,
event_size);
3902 MJsonNode* result = MJsonNode::MakeObject();
3903 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3917 return MJsonNode::MakeArrayBuffer((
char*)pevent,
event_size);
3920 MJsonNode* result = MJsonNode::MakeObject();
3935 doc->
D(
"get current MIDAS time using ss_millitime()");
3936 doc->
P(NULL, 0,
"there are no input parameters");
3937 doc->
R(NULL, MJSON_INT,
"current value of ss_millitime()");
3954 doc->
D(
"get alarm data");
3955 doc->
P(
"get_all?", MJSON_BOOL,
"get all alarms, even in alarm system not active and alarms not triggered");
3956 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
3957 doc->
R(
"alarm_system_active", MJSON_BOOL,
"value of ODB \"/Alarms/alarm system active\"");
3958 doc->
R(
"alarms", MJSON_OBJECT,
"alarm data, keyed by alarm name");
3959 doc->
R(
"alarms[].triggered", MJSON_BOOL,
"alarm is triggered");
3960 doc->
R(
"alarms[].active", MJSON_BOOL,
"alarm is enabled");
3961 doc->
R(
"alarms[].class", MJSON_STRING,
"alarm class");
3962 doc->
R(
"alarms[].type", MJSON_INT,
"alarm type AT_xxx");
3963 doc->
R(
"alarms[].bgcolor", MJSON_STRING,
"display background color");
3964 doc->
R(
"alarms[].fgcolor", MJSON_STRING,
"display foreground color");
3965 doc->
R(
"alarms[].message", MJSON_STRING,
"alarm ODB message field");
3966 doc->
R(
"alarms[].condition", MJSON_STRING,
"alarm ODB condition field");
3967 doc->
R(
"alarms[].evaluated_value?", MJSON_STRING,
"evaluated alarm condition (AT_EVALUATED alarms only)");
3968 doc->
R(
"alarms[].periodic_next_time?", MJSON_STRING,
"next time the periodic alarm will fire (AT_PERIODIC alarms only)");
3969 doc->
R(
"alarms[].time_triggered_first", MJSON_STRING,
"time when alarm was triggered");
3970 doc->
R(
"alarms[].show_to_user", MJSON_STRING,
"final alarm text shown to user by mhttpd");
3989 int alarm_system_active = 0;
3993 size =
sizeof(flag);
4000 alarm_system_active = flag;
4002 if (!alarm_system_active)
4005 "alarm_system_active", MJsonNode::MakeBool(alarm_system_active!=0),
4006 "alarms", MJsonNode::MakeObject());
4017 MJsonNode* alarms = MJsonNode::MakeObject();
4019 for (
int i = 0;;
i++) {
4033 size =
sizeof(flag);
4041 MJsonNode* a = MJsonNode::MakeObject();
4043 a->AddToObject(
"triggered", MJsonNode::MakeBool(flag!=0));
4046 size =
sizeof(
BOOL);
4049 a->AddToObject(
"active", MJsonNode::MakeBool(flag!=0));
4052 strcpy(alarm_class,
"Alarm");
4053 size =
sizeof(alarm_class);
4057 a->AddToObject(
"class", MJsonNode::MakeString(alarm_class));
4060 size =
sizeof(atype);
4063 a->AddToObject(
"type", MJsonNode::MakeInt(atype));
4068 strcpy(bgcol,
"red");
4070 if (strlen(alarm_class) > 0) {
4071 sprintf(
str,
"/Alarms/Classes/%s/Display BGColor", alarm_class);
4072 size =
sizeof(bgcol);
4077 a->AddToObject(
"bgcolor", MJsonNode::MakeString(bgcol));
4080 strcpy(fgcol,
"black");
4082 if (strlen(alarm_class) > 0) {
4083 sprintf(
str,
"/Alarms/Classes/%s/Display FGColor", alarm_class);
4084 size =
sizeof(fgcol);
4089 a->AddToObject(
"fgcolor", MJsonNode::MakeString(fgcol));
4092 if (strlen(alarm_class) > 0) {
4093 size =
sizeof(
BOOL);
4094 sprintf(
str,
"/Alarms/Classes/%s/Alarm sound", alarm_class);
4097 a->AddToObject(
"alarm_sound", MJsonNode::MakeBool(flag!=0));
4105 a->AddToObject(
"message", MJsonNode::MakeString(msg));
4109 size =
sizeof(cond);
4113 a->AddToObject(
"condition", MJsonNode::MakeString(cond));
4115 std::string show_to_user;
4123 a->AddToObject(
"evaluated_value", MJsonNode::MakeString(
value.c_str()));
4128 a->AddToObject(
"show_to_user", MJsonNode::MakeString(show_to_user.c_str()));
4135 a->AddToObject(
"time_triggered_first", MJsonNode::MakeString(
str));
4139 size =
sizeof(last);
4148 size =
sizeof(interval);
4151 time_t tnext = last + interval;
4154 ctime_r(&tnext, ctimebuf);
4157 a->AddToObject(
"periodic_next_time", MJsonNode::MakeString(ctimebuf));
4160 alarms->AddToObject(
name, a);
4164 "alarm_system_active", MJsonNode::MakeBool(alarm_system_active!=0),
4178 doc->
D(
"js_make_subdir");
4179 doc->
P(
"subdir", MJSON_STRING,
"Create folder experiment_directory/userfiles/subdir");
4180 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
4181 doc->
R(
"path", MJSON_STRING,
"Search path");
4185 MJsonNode* error = NULL;
4187 std::string subdir =
mjsonrpc_get_param(params,
"subdir", &error)->GetString();
if (error)
return error;
4190 if (subdir.find(
"..") != std::string::npos) {
4207 path +=
"userfiles";
4210 if (access(path.c_str(), F_OK) != 0) {
4212 if (mkdir(path.c_str(), 0777) != 0) {
4218 if (subdir.length() > 0) {
4225 if (access(path.c_str(), F_OK) != 0) {
4227 if (mkdir(path.c_str(), 0777) != 0) {
4233 MJsonNode* r = MJsonNode::MakeObject();
4234 r->AddToObject(
"status", MJsonNode::MakeInt(
SUCCESS));
4236 r->AddToObject(
"path", MJsonNode::MakeString(path.c_str()));
4244 doc->
D(
"js_ext_list_files");
4245 doc->
P(
"subdir", MJSON_STRING,
"List files in experiment_directory/userfiles/subdir");
4246 doc->
P(
"fileext", MJSON_STRING,
"Filename extension");
4247 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
4248 doc->
R(
"path", MJSON_STRING,
"Search path");
4249 doc->
R(
"subdirs[]", MJSON_STRING,
"list of subdirectories");
4250 doc->
R(
"files[].filename", MJSON_STRING,
"script filename");
4251 doc->
R(
"files[].description", MJSON_STRING,
"script description");
4255 MJsonNode* error = NULL;
4256 std::string subdir =
mjsonrpc_get_param(params,
"subdir", &error)->GetString();
if (error)
return error;
4257 std::string fileext =
mjsonrpc_get_param(params,
"fileext", &error)->GetString();
if (error)
return error;
4260 if (subdir.find(
"..") != std::string::npos) {
4265 if (fileext.find(
"..") != std::string::npos) {
4293 path +=
"userfiles";
4296 if (access(path.c_str(), F_OK) != 0) {
4298 if (mkdir(path.c_str(), 0777) != 0) {
4303 if (subdir.length() > 0) {
4311 MJsonNode* s = MJsonNode::MakeArray();
4316 for (
int i=0 ;
i<
n ;
i++) {
4324 MJsonNode* f = MJsonNode::MakeArray();
4325 time_t modtime = time(NULL);
4335 for (
int i=0 ;
i<
n ;
i++) {
4337 MJsonNode* o = MJsonNode::MakeObject();
4341 std::string full_name = path;
4346 o->AddToObject(
"description", MJsonNode::MakeString(
"description"));
4348 o->AddToObject(
"modtime", MJsonNode::MakeInt(modtime));
4350 o->AddToObject(
"size", MJsonNode::MakeInt(fsize));
4357 MJsonNode* r = MJsonNode::MakeObject();
4358 r->AddToObject(
"status", MJsonNode::MakeInt(
SUCCESS));
4360 r->AddToObject(
"path", MJsonNode::MakeString(path.c_str()));
4361 r->AddToObject(
"subdirs", s);
4362 r->AddToObject(
"files", f);
4372 doc->
D(
"js_ext_save_file");
4373 doc->
P(
"filename", MJSON_STRING,
"File name, save in experiment_directory/userfiles/filename");
4374 doc->
P(
"script", MJSON_STRING,
"ASCII content");
4375 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
4376 doc->
R(
"error", MJSON_STRING,
"error text");
4382 MJsonNode* error = NULL;
4383 std::string filename =
mjsonrpc_get_param(params,
"filename", &error)->GetString();
if (error)
return error;
4384 std::string script =
mjsonrpc_get_param(params,
"script", &error)->GetString();
if (error)
return error;
4387 if (filename.find(
"..") != std::string::npos ) {
4406 return mjsonrpc_make_result(
"status", MJsonNode::MakeInt(
status),
"error", MJsonNode::MakeString(
"cm_get_experiment_database() error"));
4410 path +=
"userfiles";
4413 if (access(path.c_str(), F_OK) != 0) {
4415 if (mkdir(path.c_str(), 0777) != 0) {
4423 FILE*
fp = fopen(path.c_str(),
"w");
4427 sprintf(errstr,
"fopen() errno %d (%s)", errno, strerror(errno));
4432 fwrite(script.c_str(), script.length(), 1,
fp);
4438 std::string errstr =
"no error";
4448 doc->
D(
"js_ext_read_script");
4449 doc->
P(
"filename", MJSON_STRING,
"File name, read from experiment_directory/userfiles/filename");
4450 doc->
R(
"content", MJSON_STRING,
"ASCII file content");
4451 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
4452 doc->
R(
"error", MJSON_STRING,
"error text");
4456 MJsonNode* error = NULL;
4457 std::string filename =
mjsonrpc_get_param(params,
"filename", &error)->GetString();
if (error)
return error;
4460 if (filename.find(
"..") != std::string::npos ||
4461 filename.find(
"*") != std::string::npos) {
4471 return mjsonrpc_make_result(
"status", MJsonNode::MakeInt(
status),
"error", MJsonNode::MakeString(
"cm_get_experiment_database() error"));
4478 path +=
"userfiles";
4481 if (access(path.c_str(), F_OK) != 0) {
4483 if (mkdir(path.c_str(), 0777) != 0) {
4491 FILE*
fp = fopen(path.c_str(),
"r");
4495 sprintf(errstr,
"fopen() errno %d (%s)", errno, strerror(errno));
4500 fseek(
fp, 0, SEEK_END);
4501 size_t file_size = ftell(
fp);
4504 char* buffer =
new char[file_size+1];
4505 fread(buffer, file_size, 1,
fp);
4507 buffer[file_size] =
'\0';
4515 std::string errstr =
"no error";
4517 return mjsonrpc_make_result(
"content", MJsonNode::MakeString(
content.c_str()),
"status", MJsonNode::MakeInt(
status),
"error", MJsonNode::MakeString(errstr.c_str()));
4529 doc->
D(
"js_read_binary_file");
4530 doc->
P(
"filename", MJSON_STRING,
"File name, read from experiment_directory/userfiles/filename");
4531 doc->
R(
"binary data", MJSON_ARRAYBUFFER,
"Binary file content");
4532 doc->
R(
"status", MJSON_INT,
"Return status of midas library calls");
4533 doc->
R(
"error", MJSON_STRING,
"Error text");
4537 MJsonNode* error = NULL;
4539 if (error)
return error;
4542 if (filename.find(
"..") != std::string::npos ||
4543 filename.find(
"*") != std::string::npos) {
4553 return mjsonrpc_make_result(
"status", MJsonNode::MakeInt(
status),
"error", MJsonNode::MakeString(
"cm_get_experiment_database() error"));
4560 path +=
"userfiles";
4563 if (access(path.c_str(), F_OK) != 0) {
4565 if (mkdir(path.c_str(), 0777) != 0) {
4573 FILE*
fp = fopen(path.c_str(),
"rb");
4577 sprintf(errstr,
"fopen() errno %d (%s)", errno, strerror(errno));
4582 fseek(
fp, 0, SEEK_END);
4583 size_t file_size = ftell(
fp);
4586 char* buffer =
new char[file_size];
4587 fread(buffer, file_size, 1,
fp);
4593 std::string errstr =
"no error";
4595 MJsonNode* result = MJsonNode::MakeArrayBuffer(buffer, file_size);
4610 doc->
D(
"get current value of mjsonrpc_debug");
4611 doc->
P(NULL, 0,
"there are no input parameters");
4612 doc->
R(NULL, MJSON_INT,
"current value of mjsonrpc_debug");
4623 doc->
D(
"set new value of mjsonrpc_debug");
4624 doc->
P(NULL, MJSON_INT,
"new value of mjsonrpc_debug");
4625 doc->
R(NULL, MJSON_INT,
"new value of mjsonrpc_debug");
4637 doc->
D(
"get current value of mjsonrpc_sleep");
4638 doc->
P(NULL, 0,
"there are no input parameters");
4639 doc->
R(NULL, MJSON_INT,
"current value of mjsonrpc_sleep");
4650 doc->
D(
"set new value of mjsonrpc_sleep");
4651 doc->
P(NULL, MJSON_INT,
"new value of mjsonrpc_sleep");
4652 doc->
R(NULL, MJSON_INT,
"new value of mjsonrpc_sleep");
4664 doc->
D(
"get current value of mjsonrpc_time");
4665 doc->
P(NULL, 0,
"there are no input parameters");
4666 doc->
R(NULL, MJSON_INT,
"current value of mjsonrpc_time");
4677 doc->
D(
"set new value of mjsonrpc_time");
4678 doc->
P(NULL, MJSON_INT,
"new value of mjsonrpc_time");
4679 doc->
R(NULL, MJSON_INT,
"new value of mjsonrpc_time");
4691 doc->
D(
"Get the MIDAS JSON-RPC schema JSON object");
4692 doc->
P(NULL, 0,
"there are no input parameters");
4693 doc->
R(NULL, MJSON_OBJECT,
"returns the MIDAS JSON-RPC schema JSON object");
4704 doc->
D(
"get current server timezone offset in seconds");
4705 doc->
P(NULL, 0,
"there are no input parameters");
4706 doc->
R(NULL, MJSON_INT,
"offset in seconds");
4711 time_t rawtime = time(NULL);
4713 gmtime_r(&rawtime, &gmt_tms);
4716 localtime_r(&rawtime, &tms);
4717 time_t
offset = rawtime - gmt + (tms.tm_isdst ? 3600 : 0);
4745 e.fNeedsLocking = needs_locking;
4751 gMutex = (std::mutex*)mutex;
4757 printf(
"mjsonrpc_init!\n");
4845 printf(
"mjsonrpc_exit!\n");
4854 MJsonNode* s = MJsonNode::MakeObject();
4856 s->AddToObject(
"$schema", MJsonNode::MakeString(
"http://json-schema.org/schema#"));
4857 s->AddToObject(
"id", MJsonNode::MakeString(
"MIDAS JSON-RPC autogenerated schema"));
4858 s->AddToObject(
"title", MJsonNode::MakeString(
"MIDAS JSON-RPC schema"));
4859 s->AddToObject(
"description", MJsonNode::MakeString(
"Autogenerated schema for all MIDAS JSON-RPC methods"));
4860 s->AddToObject(
"type", MJsonNode::MakeString(
"object"));
4862 MJsonNode* m = MJsonNode::MakeObject();
4868 MJsonNode* doc = iterator->second.fHandler(NULL);
4870 doc = MJsonNode::MakeObject();
4871 m->AddToObject(iterator->first.c_str(), doc);
4874 s->AddToObject(
"properties", m);
4875 s->AddToObject(
"required", MJsonNode::MakeArray());
4886static void mjsonrpc_print_schema()
4890 std::string
str = s->Stringify(1);
4891 printf(
"MJSON-RPC schema:\n");
4892 printf(
"%s\n",
str.c_str());
4897static std::string
indent(
int x,
const char* p =
" ")
4902 for (
int i=0;
i<x;
i++)
4923 void Output(
int nest,
bool span, std::string text)
4925 if (text.length() < 1)
4937 std::vector<int> tablen;
4938 std::vector<std::string> tab;
4939 std::vector<std::string> tabx;
4941 tablen.push_back(0);
4945 std::string xtab =
"";
4947 for (
int n=0; ;
n++) {
4949 for (
unsigned i=0;
i<
fLines.size();
i++) {
4956 int l =
fLines[
i].text.length();
4963 tablen.push_back(len);
4964 tab.push_back(
indent(len,
" ") +
" | ");
4965 xtab +=
indent(len,
" ") +
" | ";
4966 tabx.push_back(xtab);
4973 for (
unsigned i=0;
i<
fLines.size();
i++) {
4980 int ipad = tablen[
n+1] -
fLines[
i].text.length();
4984 std::string hr =
indent(maxlen-tabx[
n].length(),
"-");
4987 s += std::string(
" | ") +
fLines[
i].text + pad;
4988 else if (
n == nest) {
4990 if (
n == 0 ||
n == 1)
4991 s += tabx[
n] + hr +
"\n";
4992 s += tabx[
n] +
fLines[
i].text + pad;
4995 if (
n == 0 ||
n == 1)
4996 s += tabx[
n] + hr +
"\n";
4997 s += tabx[
n] +
fLines[
i].text + pad;
5011 const MJsonNode*
d = schema->FindObjectNode(
"description");
5016 std::string xshort =
"object";
5020 const MJsonNode* properties = schema->FindObjectNode(
"properties");
5022 const MJsonNodeVector* required_list = NULL;
5023 const MJsonNode* r = schema->FindObjectNode(
"required");
5025 required_list = r->GetArray();
5028 o->
Output(nest_level,
false,
"object");
5033 const MJsonStringVector *names = properties->GetObjectNames();
5034 const MJsonNodeVector *nodes = properties->GetObjectNodes();
5036 if (!names || !nodes) {
5037 o->
Output(nest_level,
false,
"object");
5042 std::string nest =
indent(nest_level * 4);
5046 s += nest +
"<table border=1>\n";
5049 s += nest +
"<tr>\n";
5050 s += nest +
" <td colspan=3>" +
description +
"</td>\n";
5051 s += nest +
"</tr>\n";
5056 for (
unsigned i=0;
i<names->size();
i++) {
5057 std::string
name = (*names)[
i];
5058 const MJsonNode* node = (*nodes)[
i];
5060 bool required =
false;
5062 for (
unsigned j=0;
j<required_list->size();
j++)
5063 if ((*required_list)[
j])
5064 if ((*required_list)[
j]->GetString() ==
name) {
5069 bool is_array =
false;
5070 const MJsonNode*
type = node->FindObjectNode(
"type");
5071 if (
type &&
type->GetString() ==
"array")
5082 s += nest +
"<tr>\n";
5083 s += nest +
" <td>" +
name +
"</td>\n";
5084 s += nest +
" <td>";
5087 s += nest +
"</tr>\n";
5090 s += nest +
"</table>\n";
5097 const MJsonNode*
d = schema->FindObjectNode(
"description");
5102 std::string xshort =
"array";
5106 const MJsonNode* items = schema->FindObjectNode(
"items");
5109 o->
Output(nest_level,
false,
"array");
5114 const MJsonNodeVector *nodes = items->GetArray();
5117 o->
Output(nest_level,
false,
"array");
5122 std::string nest =
indent(nest_level * 4);
5128 s += nest +
"<table border=1>\n";
5131 s += nest +
"<tr>\n";
5133 s += nest +
"</tr>\n";
5138 for (
unsigned i=0;
i<nodes->size();
i++) {
5139 o->
Output(nest_level,
false,
"array of");
5141 s += nest +
"<tr>\n";
5143 s += nest +
"</tr>\n";
5146 s += nest +
"</table>\n";
5157 const MJsonNode* t = schema->FindObjectNode(
"type");
5159 type = t->GetString();
5163 const MJsonNode*
d = schema->FindObjectNode(
"description");
5171 if (
type ==
"object") {
5173 }
else if (
type ==
"array") {
5203static void add(std::string* s,
const char* text)
5206 if (s->length() > 0)
5214 const MJsonNode* version =
request->FindObjectNode(
"jsonrpc");
5215 const MJsonNode* method =
request->FindObjectNode(
"method");
5216 const MJsonNode* params =
request->FindObjectNode(
"params");
5217 const MJsonNode*
id =
request->FindObjectNode(
"id");
5219 std::string bad =
"";
5222 add(&bad,
"jsonrpc version is missing");
5224 add(&bad,
"method is missing");
5226 add(&bad,
"params is missing");
5228 add(&bad,
"id is missing");
5230 if (version && (version->GetType() != MJSON_STRING))
5231 add(&bad,
"jsonrpc version is not a string");
5232 if (version && (version->GetString() !=
"2.0"))
5233 add(&bad,
"jsonrpc version is not 2.0");
5235 if (method && (method->GetType() != MJSON_STRING))
5236 add(&bad,
"method is not a string");
5238 if (!method || bad.length() > 0) {
5240 response->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5242 response->AddToObject(
"id", id->Copy());
5244 response->AddToObject(
"id", MJsonNode::MakeNull());
5248 printf(
"mjsonrpc: invalid request: reply:\n");
5249 printf(
"%s\n",
response->Stringify().c_str());
5256 double start_time = 0;
5262 const std::string ms = method->GetString();
5263 const char* m = ms.c_str();
5265 MJsonNode* result = NULL;
5269 if (strcmp(m,
"echo") == 0) {
5271 }
else if (strcmp(m,
"error") == 0) {
5273 }
else if (strcmp(m,
"invalid_json") == 0) {
5275 printf(
"mjsonrpc: reply with invalid json\n");
5277 return MJsonNode::MakeJSON(
"this is invalid json data");
5278 }
else if (strcmp(m,
"test_nan_inf") == 0) {
5281 double nan = zero/zero;
5282 double plusinf = one/zero;
5283 double minusinf = -one/zero;
5284 MJsonNode*
n = MJsonNode::MakeArray();
5285 n->AddToArray(MJsonNode::MakeNumber(nan));
5286 n->AddToArray(MJsonNode::MakeNumber(plusinf));
5287 n->AddToArray(MJsonNode::MakeNumber(minusinf));
5289 }
else if (strcmp(m,
"test_arraybuffer") == 0) {
5291 printf(
"mjsonrpc: reply with test arraybuffer data\n");
5294 char* ptr = (
char*)malloc(size);
5295 assert(ptr != NULL);
5296 for (
size_t i=0;
i<size;
i++) {
5299 *((
short*)(ptr+4*2*1)) = 111;
5300 *((
int*)(ptr+4*2*2)) = 1234;
5301 *((
double*)(ptr+4*2*3)) = 3.14;
5302 return MJsonNode::MakeArrayBuffer(ptr, size);
5306 bool lock = s->second.fNeedsLocking;
5309 result = s->second.fHandler(params);
5313 result =
mjsonrpc_make_error(-32601,
"Method not found", (std::string(
"unknown method: ") + ms).c_str());
5318 printf(
"mjsonrpc: handler reply:\n");
5323 double end_time = 0;
5324 double elapsed_time = 0;
5327 elapsed_time = end_time - start_time;
5329 printf(
"request took %.3f seconds, method [%s]\n", elapsed_time, m);
5333 if (result->GetType() == MJSON_ARRAYBUFFER) {
5337 const MJsonNode *nerror = result->FindObjectNode(
"error");
5338 const MJsonNode *nresult = result->FindObjectNode(
"result");
5341 result->DeleteObjectNode(
"result");
5342 }
else if (nresult) {
5343 result->DeleteObjectNode(
"error");
5346 result =
mjsonrpc_make_error(-32603,
"Internal error",
"bad dispatcher reply: no result and no error");
5349 result->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5352 result->AddToObject(
"id", id->Copy());
5354 result->AddToObject(
"id", MJsonNode::MakeNull());
5358 result->AddToObject(
"elapsed_time", MJsonNode::MakeNumber(elapsed_time));
5361 assert(result != NULL);
5369 MJsonNode *
request = MJsonNode::Parse(post_data);
5374 printf(
"mjsonrpc: request:\n");
5388 if (
request->GetType() == MJSON_ERROR) {
5390 reply->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5391 reply->AddToObject(
"id", MJsonNode::MakeNull());
5394 printf(
"mjsonrpc: invalid json: reply:\n");
5395 printf(
"%s\n", reply->Stringify().c_str());
5401 }
else if (
request->GetType() == MJSON_OBJECT) {
5405 }
else if (
request->GetType() == MJSON_ARRAY) {
5406 const MJsonNodeVector* a =
request->GetArray();
5408 if (a->size() < 1) {
5409 MJsonNode* reply =
mjsonrpc_make_error(-32600,
"Invalid request",
"batch request array has less than 1 element");
5410 reply->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5411 reply->AddToObject(
"id", MJsonNode::MakeNull());
5414 printf(
"mjsonrpc: invalid json: reply:\n");
5415 printf(
"%s\n", reply->Stringify().c_str());
5423 MJsonNode* reply = MJsonNode::MakeArray();
5425 for (
unsigned i=0;
i<a->size();
i++) {
5427 reply->AddToArray(r);
5428 if (r->GetType() == MJSON_ARRAYBUFFER) {
5431 reply =
mjsonrpc_make_error(-32600,
"Invalid request",
"MJSON_ARRAYBUFFER return is not permitted for batch requests");
5432 reply->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5433 reply->AddToObject(
"id", MJsonNode::MakeNull());
5441 MJsonNode* reply =
mjsonrpc_make_error(-32600,
"Invalid request",
"request is not a JSON object or JSON array");
5442 reply->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5443 reply->AddToObject(
"id", MJsonNode::MakeNull());
5446 printf(
"mjsonrpc: invalid json: reply:\n");
5447 printf(
"%s\n", reply->Stringify().c_str());
void Add(time_t t, double v)
std::vector< double > fValues
std::vector< double > fTimes
void Add(time_t t, double v)
virtual int hs_get_events(time_t time_from, std::vector< std::string > *pevents)=0
get list of events that exist(ed) at given time and later (value 0 means "return all events from begi...
virtual int hs_get_tags(const char *event_name, time_t time_from, std::vector< TAG > *ptags)=0
get list of history variables for given event (use event names returned by hs_get_events()) that exis...
virtual int hs_read_buffer(time_t start_time, time_t end_time, int num_var, const char *const event_name[], const char *const tag_name[], const int var_index[], MidasHistoryBufferInterface *buffer[], int status[])=0
returns HS_SUCCESS
virtual int hs_get_last_written(time_t start_time, int num_var, const char *const event_name[], const char *const tag_name[], const int var_index[], time_t last_written[])=0
virtual int hs_clear_cache()=0
clear internal cache, returns HS_SUCCESS
virtual int hs_read_binned(time_t start_time, time_t end_time, int num_bins, int num_var, const char *const event_name[], const char *const tag_name[], const int var_index[], int num_entries[], int *count_bins[], double *mean_bins[], double *rms_bins[], double *min_bins[], double *max_bins[], time_t *bins_first_time[], double *bins_first_value[], time_t *bins_last_time[], double *bins_last_value[], time_t last_time[], double last_value[], int status[])=0
returns HS_SUCCESS
void Output(int nest, bool span, std::string text)
std::vector< NestedLine > fLines
INT transition(INT run_number, char *error)
INT al_trigger_class(const char *alarm_class, const char *alarm_message, BOOL first)
BOOL al_evaluate_condition(const char *alarm_name, const char *condition, std::string *pvalue)
INT al_reset_alarm(const char *alarm_name)
INT al_trigger_alarm(const char *alarm_name, const char *alarm_message, const char *default_class, const char *cond_str, INT type)
INT bm_open_buffer(const char *buffer_name, INT buffer_size, INT *buffer_handle)
INT bm_request_event(HNDLE buffer_handle, short int event_id, short int trigger_mask, INT sampling_type, HNDLE *request_id, EVENT_HANDLER *func)
INT bm_set_cache_size(INT buffer_handle, size_t read_size, size_t write_size)
INT bm_match_event(short int event_id, short int trigger_mask, const EVENT_HEADER *pevent)
INT bm_get_buffer_handle(const char *buffer_name, INT *buffer_handle)
INT bm_receive_event_alloc(INT buffer_handle, EVENT_HEADER **ppevent, int timeout_msec)
INT cm_shutdown(const char *name, BOOL bUnique)
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_connect_client(const char *client_name, HNDLE *hConn)
INT cm_transition(INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag)
std::string cm_expand_env(const char *str)
int cm_exec_script(const char *odb_path_to_script)
std::string cm_get_path()
INT cm_exist(const char *name, BOOL bUnique)
INT el_search_run(int run, char *return_tag)
INT el_retrieve(char *tag, char *date, int *run, char *author, char *type, char *syst, char *subject, char *text, int *textsize, char *orig_tag, char *reply_tag, char *attachment1, char *attachment2, char *attachment3, char *encoding)
INT el_delete_message(const char *tag)
#define DB_NO_MORE_SUBKEYS
MJSO * AddArray(const char *name, const char *description)
void D(const char *description)
MJsonNode * mjsonrpc_decode_post_data(const char *post_data)
void P(const char *name, int mjson_type, const char *description)
MJsonNode * mjsonrpc_make_result(MJsonNode *node)
MJSO * AddObject(const char *name, const char *description)
static MJSO * MakeArraySchema(const char *description)
MJSO * RA(const char *description)
MJsonNode *() mjsonrpc_handler_t(const MJsonNode *params)
void Add(const char *name, int mjson_type, const char *description)
void mjsonrpc_user_init()
void AddToSchema(MJsonNode *s, const char *name)
MJsonNode * mjsonrpc_make_error(int code, const char *message, const char *data)
MJsonNode * mjsonrpc_get_schema()
static MJSO * MakeObjectSchema(const char *description)
void mjsonrpc_set_std_mutex(void *mutex)
const MJsonNode * mjsonrpc_get_param(const MJsonNode *params, const char *name, MJsonNode **error)
std::string mjsonrpc_schema_to_text(const MJsonNode *schema)
void mjsonrpc_add_handler(const char *method, mjsonrpc_handler_t *handler, bool needs_locking)
void R(const char *name, int mjson_type, const char *description)
MJSO * PA(const char *description)
#define MAX_STRING_LENGTH
time_t ss_mktime(struct tm *tms)
INT ss_dirlink_find(const char *path, const char *pattern, char **plist)
time_t ss_file_time(const char *path)
double ss_file_size(const char *path)
INT ss_sleep(INT millisec)
bool ss_repair_utf8(char *string)
INT ss_system(const char *command)
INT ss_file_find(const char *path, const char *pattern, char **plist)
INT cm_msg1(INT message_type, const char *filename, INT line, const char *facility, const char *routine, const char *format,...)
INT EXPRT cm_msg_facilities(STRING_LIST *list)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
INT cm_msg_retrieve2(const char *facility, time_t t, INT n_message, char **messages, int *num_messages)
BOOL equal_ustring(const char *str1, const char *str2)
INT db_find_link(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
INT db_reorder_key(HNDLE hDB, HNDLE hKey, INT idx)
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
INT db_copy_json_save(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end)
MJsonNode * db_scl(HNDLE hDB)
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
INT db_copy_json_index(HNDLE hDB, HNDLE hKey, int index, char **buffer, int *buffer_size, int *buffer_end)
INT db_set_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
INT db_enum_link(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
INT db_copy_json_ls(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end)
INT db_delete(HNDLE hDB, HNDLE hKeyRoot, const char *odb_path)
INT db_copy_json_values(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end, int omit_names, int omit_last_written, time_t omit_old_timestamp, int preserve_case)
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
MJsonNode * db_sor(HNDLE hDB, const char *root_path)
INT db_rename_key(HNDLE hDB, HNDLE hKey, const char *name)
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
INT EXPRT db_resize_string(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, int num_values, int max_string_length)
INT db_set_num_values(HNDLE hDB, HNDLE hKey, INT num_values)
INT db_create_link(HNDLE hDB, HNDLE hKey, const char *link_name, const char *destination)
INT EXPRT db_paste_json_node(HNDLE hDB, HNDLE hKeyRoot, int index, const MJsonNode *node)
INT rpc_client_call(HNDLE hConn, DWORD routine_id,...)
int hs_read_event_list(std::vector< std::string > *pevents)
int hs_find_reader_channel(HNDLE hDB, HNDLE *hKeyOut, int debug_flag)
int hs_get_history(HNDLE hDB, HNDLE hKey, int flags, int debug_flag, MidasHistoryInterface **mh)
int hs_image_retrieve(std::string image_name, time_t start_time, time_t stop_time, std::vector< time_t > &vtime, std::vector< std::string > &vfilename)
char buffer_name[NAME_LENGTH]
std::string msprintf(const char *format,...)
#define DIR_SEPARATOR_STR
std::vector< std::string > STRING_LIST
MidasHistoryInterface * mh
#define message(type, str)
static MJsonNode * js_cm_transition(const MJsonNode *params)
static MJsonNode * set_sleep(const MJsonNode *params)
const MJsonNodeVector * mjsonrpc_get_param_array(const MJsonNode *params, const char *name, MJsonNode **error)
static MJsonNode * js_cm_msg1(const MJsonNode *params)
static MJsonNode * get_sleep(const MJsonNode *params)
static MJsonNode * js_al_trigger_class(const MJsonNode *params)
std::map< std::string, MethodsTableEntry > MethodsTable
static MJsonNode * js_el_delete(const MJsonNode *params)
static MJsonNode * js_hs_read_arraybuffer(const MJsonNode *params)
static MJsonNode * js_db_paste(const MJsonNode *params)
static MhiMap gHistoryChannels
static MJsonNode * js_ext_save_file(const MJsonNode *params)
static std::string mjsonrpc_schema_to_html_array(const MJsonNode *schema, int nest_level, NestedOutput *o)
static MJsonNode * js_get_timezone(const MJsonNode *params)
static MJsonNode * jrpc_old(const MJsonNode *params)
static MJsonNode * js_ext_list_files(const MJsonNode *params)
static void StashEvent(const std::string buffer_name, int event_id, int trigger_mask, const EVENT_HEADER *pevent)
static int parse_array_index_list(const char *method, const char *path, std::vector< unsigned > *list)
static MJsonNode * js_hs_read_binned(const MJsonNode *params)
static MJsonNode * js_ext_read_file(const MJsonNode *params)
static MJsonNode * start_program(const MJsonNode *params)
static MJsonNode * js_hs_get_last_written(const MJsonNode *params)
static MJsonNode * jrpc_cxx(const MJsonNode *params)
static MJsonNode * js_bm_receive_event(const MJsonNode *params)
static MJsonNode * js_hs_get_active_events(const MJsonNode *params)
static std::string mjsonrpc_schema_to_html_anything(const MJsonNode *schema, int nest_level, NestedOutput *o)
static MJsonNode * js_db_ls(const MJsonNode *params)
static MJsonNode * js_db_sor(const MJsonNode *params)
static std::string remove(const std::string s, char c)
static MJsonNode * js_db_copy(const MJsonNode *params)
static MJsonNode * js_db_scl(const MJsonNode *params)
static MJsonNode * js_cm_msg_retrieve(const MJsonNode *params)
static void DeleteEventStash()
static MJsonNode * xnull(const MJsonNode *params)
static MJsonNode * js_ss_millitime(const MJsonNode *params)
static MJsonNode * js_db_delete(const MJsonNode *params)
static const EVENT_HEADER * CopyEvent(const EVENT_HEADER *pevent)
MethodsTable::iterator MethodsTableIterator
static MJsonNode * js_read_binary_file(const MJsonNode *params)
static MJsonNode * js_db_rename(const MJsonNode *params)
static MJsonNode * js_cm_msg_facilities(const MJsonNode *params)
static int mjsonrpc_sleep
static MJsonNode * js_db_key(const MJsonNode *params)
static MJsonNode * js_cm_exist(const MJsonNode *params)
static MJsonNode * js_db_reorder(const MJsonNode *params)
static MidasHistoryInterface * GetHistory(const char *name)
std::map< std::string, MidasHistoryInterface * > MhiMap
static MJsonNode * js_db_resize_string(const MJsonNode *params)
static MJsonNode * mjsonrpc_handle_request(const MJsonNode *request)
static MJsonNode * js_hs_get_tags(const MJsonNode *params)
static std::string mjsonrpc_schema_to_html_object(const MJsonNode *schema, int nest_level, NestedOutput *o)
static std::mutex * gMutex
static MJsonNode * js_el_retrieve(const MJsonNode *params)
static MJsonNode * get_alarms(const MJsonNode *params)
static MJsonNode * js_el_query(const MJsonNode *params)
static MJsonNode * js_db_link(const MJsonNode *params)
static MJsonNode * exec_script(const MJsonNode *params)
static MJsonNode * get_schema(const MJsonNode *params)
static std::vector< EventStashEntry * > gEventStash
static std::string indent(int x, const char *p=" ")
static MJsonNode * js_al_reset_alarm(const MJsonNode *params)
static MJsonNode * brpc_cxx(const MJsonNode *params)
static double GetTimeSec()
static MJsonNode * set_time(const MJsonNode *params)
static MJsonNode * set_debug(const MJsonNode *params)
static MJsonNode * js_db_resize(const MJsonNode *params)
static MJsonNode * js_hs_get_events(const MJsonNode *params)
static MJsonNode * gNullNode
static MJsonNode * js_hs_read(const MJsonNode *params)
static MJsonNode * js_make_subdir(const MJsonNode *params)
static std::mutex gEventStashMutex
static MJsonNode * js_hs_image_retrieve(const MJsonNode *params)
static const EVENT_HEADER * FindEvent(const std::string buffer_name, int event_id, int trigger_mask, int last_event_id, int last_trigger_mask, DWORD last_serial_number, DWORD last_time_stamp)
static MJsonNode * get_debug(const MJsonNode *params)
static MJsonNode * js_cm_shutdown(const MJsonNode *params)
static MethodsTable gMethodsTable
static MJsonNode * js_db_get_values(const MJsonNode *params)
static MJsonNode * js_al_trigger_alarm(const MJsonNode *params)
static MJsonNode * js_db_create(const MJsonNode *params)
static MJsonNode * mjsonrpc_make_schema(MethodsTable *h)
static MJsonNode * js_hs_read_binned_arraybuffer(const MJsonNode *params)
static MJsonNode * js_hs_get_channels(const MJsonNode *params)
static void MatchEvent(const std::string buffer_name, const EVENT_HEADER *pevent)
static MJsonNode * js_hs_reopen(const MJsonNode *params)
static MJsonNode * brpc_old(const MJsonNode *params)
int gettimeofday(struct timeval *tp, void *tzp)
const EVENT_HEADER * pevent
void ReplaceEvent(const EVENT_HEADER *xpevent)
mjsonrpc_handler_t * fHandler
static te_expr * list(state *s)