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->
R(
"status", MJSON_INT,
"return status of cm_shutdown()");
469 MJsonNode* error = NULL;
478 printf(
"cm_shutdown(%s) -> %d\n",
name.c_str(),
status);
487 doc->
D(
"start MIDAS program defined in ODB /Programs/name");
488 doc->
P(
"name", MJSON_STRING,
"name of the program, corresponding to ODB /Programs/name");
489 doc->
R(
"status", MJSON_INT,
"return status of ss_system()");
493 MJsonNode* error = NULL;
497 std::string path =
"";
498 path +=
"/Programs/";
500 path +=
"/Start command";
520 doc->
D(
"execute custom script defined in ODB /Script (scripts show in the menu) or /CustomScript (scripts from custom pages)");
521 doc->
P(
"script?", MJSON_STRING,
"Execute ODB /Script/xxx");
522 doc->
P(
"customscript?", MJSON_STRING,
"Execute ODB /CustomScript/xxx");
523 doc->
R(
"status", MJSON_INT,
"return status of cm_exec_script()");
528 std::string customscript =
mjsonrpc_get_param(params,
"customscript", NULL)->GetString();
532 if (script.length() > 0) {
536 }
else if (customscript.length() > 0) {
537 path +=
"/CustomScript";
539 path += customscript;
544 if (path.length() > 0) {
565 const char*s = strchr(path,
'[');
568 cm_msg(
MERROR, method,
"expected an array index character \'[\' in \"%s\"", path);
574 while (s && (*s != 0)) {
578 cm_msg(
MERROR, method,
"expected a number in array index in \"%s\" at \"%s\"", path, s);
582 unsigned value1 = strtoul(s, (
char**)&s, 10);
589 cm_msg(
MERROR, method,
"expected a number in array index in \"%s\" at \"%s\"", path, s);
593 unsigned value2 = strtoul(s, (
char**)&s, 10);
595 if (value2 >= value1)
596 for (
unsigned i=value1;
i<=value2;
i++)
604 for (
unsigned i=value1;
i!=value2;
i--)
606 list->push_back(value2);
609 list->push_back(value1);
623 cm_msg(
MERROR, method,
"invalid char in array index in \"%s\" at \"%s\"", path, s);
628 printf(
"parsed array indices for \"%s\" size is %d: ", path, (
int)
list->size());
629 for (
unsigned i=0;
i<
list->size();
i++)
630 printf(
" %d", (*
list)[
i]);
641 doc->
D(
"get values of ODB data from given subtrees");
642 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB subtree paths, see note on array indices");
643 doc->
P(
"omit_names?", MJSON_BOOL,
"omit the /name entries");
644 doc->
P(
"omit_last_written?", MJSON_BOOL,
"omit the /last_written entries and the last_written[] result");
645 doc->
P(
"omit_tid?", MJSON_BOOL,
"omit the tid[] result");
646 doc->
P(
"omit_old_timestamp?", MJSON_NUMBER,
"omit data older than given ODB timestamp");
647 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");
648 doc->
R(
"data[]", 0,
"values of ODB data for each path, all key names are in lower case, all symlinks are followed");
649 doc->
R(
"status[]", MJSON_INT,
"return status of db_copy_json_values() or db_copy_json_index() for each path");
650 doc->
R(
"tid?[]", MJSON_INT,
"odb type id for each path, absent if omit_tid is true");
651 doc->
R(
"last_written?[]", MJSON_NUMBER,
"last_written value of the ODB subtree for each path, absent if omit_last_written is true");
655 MJsonNode* error = NULL;
660 bool omit_last_written =
mjsonrpc_get_param(params,
"omit_last_written", NULL)->GetBool();
662 double xomit_old_timestamp =
mjsonrpc_get_param(params,
"omit_old_timestamp", NULL)->GetDouble();
663 time_t omit_old_timestamp = (time_t)xomit_old_timestamp;
666 MJsonNode* dresult = MJsonNode::MakeArray();
667 MJsonNode* sresult = MJsonNode::MakeArray();
668 MJsonNode* tresult = MJsonNode::MakeArray();
669 MJsonNode* lwresult = MJsonNode::MakeArray();
674 for (
unsigned i=0;
i<paths->size();
i++) {
678 std::string path = (*paths)[
i]->GetString();
682 dresult->AddToArray(MJsonNode::MakeNull());
683 sresult->AddToArray(MJsonNode::MakeInt(
status));
684 tresult->AddToArray(MJsonNode::MakeNull());
685 lwresult->AddToArray(MJsonNode::MakeNull());
691 dresult->AddToArray(MJsonNode::MakeNull());
692 sresult->AddToArray(MJsonNode::MakeInt(
status));
693 tresult->AddToArray(MJsonNode::MakeNull());
694 lwresult->AddToArray(MJsonNode::MakeNull());
698 if (path.find(
"[") != std::string::npos) {
699 std::vector<unsigned>
list;
703 dresult->AddToArray(MJsonNode::MakeNull());
704 sresult->AddToArray(MJsonNode::MakeInt(
status));
705 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
710 if (
list.size() > 1) {
711 MJsonNode *ddresult = MJsonNode::MakeArray();
712 MJsonNode *ssresult = MJsonNode::MakeArray();
714 for (
unsigned i=0;
i<
list.size();
i++) {
722 ddresult->AddToArray(MJsonNode::MakeJSON(buf));
723 ssresult->AddToArray(MJsonNode::MakeInt(
status));
725 ddresult->AddToArray(MJsonNode::MakeNull());
726 ssresult->AddToArray(MJsonNode::MakeInt(
status));
733 dresult->AddToArray(ddresult);
734 sresult->AddToArray(ssresult);
735 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
746 dresult->AddToArray(MJsonNode::MakeJSON(buf));
747 sresult->AddToArray(MJsonNode::MakeInt(
status));
748 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
751 dresult->AddToArray(MJsonNode::MakeNull());
752 sresult->AddToArray(MJsonNode::MakeInt(
status));
753 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
766 omit_last_written, omit_old_timestamp, preserve_case);
770 dresult->AddToArray(MJsonNode::MakeJSON(buf));
771 sresult->AddToArray(MJsonNode::MakeInt(
status));
772 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
775 dresult->AddToArray(MJsonNode::MakeNull());
776 sresult->AddToArray(MJsonNode::MakeInt(
status));
777 tresult->AddToArray(MJsonNode::MakeInt(
key.
type));
786 MJsonNode* result = MJsonNode::MakeObject();
788 result->AddToObject(
"data", dresult);
789 result->AddToObject(
"status", sresult);
791 result->AddToObject(
"tid", tresult);
794 if (!omit_last_written)
795 result->AddToObject(
"last_written", lwresult);
806 doc->
D(
"get contents of given ODB subdirectory in the \"ls\" json encoding - similar to odbedit command \"ls -l\"");
807 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB subtree paths");
808 doc->
R(
"data[]", MJSON_OBJECT,
"keys and values of ODB data for each path");
809 doc->
R(
"status[]", MJSON_INT,
"return status of db_copy_json_ls() for each path");
813 MJsonNode* error = NULL;
817 MJsonNode* dresult = MJsonNode::MakeArray();
818 MJsonNode* sresult = MJsonNode::MakeArray();
823 for (
unsigned i=0;
i<paths->size();
i++) {
826 std::string path = (*paths)[
i]->GetString();
830 dresult->AddToArray(MJsonNode::MakeNull());
831 sresult->AddToArray(MJsonNode::MakeInt(
status));
843 dresult->AddToArray(MJsonNode::MakeJSON(buf));
844 sresult->AddToArray(MJsonNode::MakeInt(
status));
846 dresult->AddToArray(MJsonNode::MakeNull());
847 sresult->AddToArray(MJsonNode::MakeInt(
status));
861 doc->
D(
"get complete ODB data in the \"save\" json encoding, suitable for reloading with odbedit command \"load\"");
862 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB subtree paths");
863 doc->
R(
"data[]", MJSON_OBJECT,
"keys and values of ODB data for each path");
864 doc->
R(
"status[]", MJSON_INT,
"return status of db_copy_json_save() for each path");
868 MJsonNode* error = NULL;
872 MJsonNode* dresult = MJsonNode::MakeArray();
873 MJsonNode* sresult = MJsonNode::MakeArray();
878 for (
unsigned i=0;
i<paths->size();
i++) {
881 std::string path = (*paths)[
i]->GetString();
885 dresult->AddToArray(MJsonNode::MakeNull());
886 sresult->AddToArray(MJsonNode::MakeInt(
status));
898 dresult->AddToArray(MJsonNode::MakeJSON(buf));
899 sresult->AddToArray(MJsonNode::MakeInt(
status));
901 dresult->AddToArray(MJsonNode::MakeNull());
902 sresult->AddToArray(MJsonNode::MakeInt(
status));
916 doc->
D(
"write data into ODB");
917 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB subtree paths, see note on array indices");
918 doc->
P(
"values[]", 0,
"array of data values written to ODB via db_paste_json() for each path");
919 doc->
R(
"status[]", MJSON_INT,
"array of return status of db_paste_json() for each path");
923 MJsonNode* error = NULL;
928 if (paths->size() != values->size()) {
929 return mjsonrpc_make_error(-32602,
"Invalid params",
"paths and values should have the same length");
932 MJsonNode* sresult = MJsonNode::MakeArray();
937 for (
unsigned i=0;
i<paths->size();
i++) {
940 std::string path = (*paths)[
i]->GetString();
944 sresult->AddToArray(MJsonNode::MakeInt(
status));
948 const MJsonNode* v = (*values)[
i];
951 if (path.find(
"[*]") != std::string::npos) {
958 }
else if (path.find(
"[") != std::string::npos) {
959 std::vector<unsigned>
list;
963 sresult->AddToArray(MJsonNode::MakeInt(
status));
972 if (
list.size() < 1) {
973 cm_msg(
MERROR,
"js_db_paste",
"invalid array indices for array path \"%s\"", path.c_str());
976 }
else if (
list.size() == 1) {
977 if (v->GetType() == MJSON_ARRAY) {
978 cm_msg(
MERROR,
"js_db_paste",
"unexpected array of values for array path \"%s\"", path.c_str());
984 sresult->AddToArray(MJsonNode::MakeInt(
status));
985 }
else if ((
list.size() > 1) && (v->GetType() == MJSON_ARRAY)) {
986 const MJsonNodeVector* vvalues = v->GetArray();
988 if (
list.size() != vvalues->size()) {
989 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());
994 MJsonNode *ssresult = MJsonNode::MakeArray();
996 for (
unsigned j =0;
j <
list.size();
j++) {
997 const MJsonNode* vv = (*vvalues)[
j];
1000 cm_msg(
MERROR,
"js_db_paste",
"internal error: NULL array value at index %d for array path \"%s\"",
j, path.c_str());
1006 ssresult->AddToArray(MJsonNode::MakeInt(
status));
1009 sresult->AddToArray(ssresult);
1011 MJsonNode *ssresult = MJsonNode::MakeArray();
1012 for (
unsigned j =0;
j <
list.size();
j++) {
1014 ssresult->AddToArray(MJsonNode::MakeInt(
status));
1016 sresult->AddToArray(ssresult);
1020 sresult->AddToArray(MJsonNode::MakeInt(
status));
1031 doc->
D(
"Create new ODB entries");
1032 MJSO* o = doc->
PA(
"array of ODB paths to be created")->
AddObject(
"",
"arguments to db_create_key() and db_set_num_values()");
1033 o->
Add(
"path", MJSON_STRING,
"ODB path to be created");
1034 o->
Add(
"type", MJSON_INT,
"MIDAS TID_xxx type");
1035 o->
Add(
"array_length?", MJSON_INT,
"optional array length, default is 1");
1036 o->
Add(
"string_length?", MJSON_INT,
"for TID_STRING, optional string length, default is NAME_LENGTH");
1037 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");
1041 MJsonNode* sresult = MJsonNode::MakeArray();
1043 const MJsonNodeVector* pp = params->GetArray();
1047 return mjsonrpc_make_error(-32602,
"Invalid params",
"parameters must be an array of objects");
1053 for (
unsigned i=0;
i<pp->size();
i++) {
1054 const MJsonNode* p = (*pp)[
i];
1062 if (string_length == 0)
1071 char* buf = (
char*)calloc(1, string_length);
1072 assert(buf != NULL);
1073 int size = string_length;
1086 sresult->AddToArray(MJsonNode::MakeInt(
status));
1096 doc->
D(
"delete ODB keys");
1097 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths to delete");
1098 doc->
R(
"status[]", MJSON_INT,
"return status of db_delete() for each path");
1102 MJsonNode* error = NULL;
1106 MJsonNode* sresult = MJsonNode::MakeArray();
1111 for (
unsigned i=0;
i<paths->size();
i++) {
1112 std::string path = (*paths)[
i]->GetString();
1114 sresult->AddToArray(MJsonNode::MakeInt(
status));
1124 doc->
D(
"Change size of ODB arrays");
1125 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths to resize");
1126 doc->
P(
"new_lengths[]", MJSON_INT,
"array of new lengths for each ODB path");
1127 doc->
R(
"status[]", MJSON_INT,
"return status of db_set_num_values() for each path");
1131 MJsonNode* error = NULL;
1136 if (paths->size() != lengths->size()) {
1137 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"new_lengths\" should have the same length");
1140 MJsonNode* sresult = MJsonNode::MakeArray();
1145 for (
unsigned i=0;
i<paths->size();
i++) {
1148 std::string path = (*paths)[
i]->GetString();
1152 sresult->AddToArray(MJsonNode::MakeInt(
status));
1156 int length = (*lengths)[
i]->GetInt();
1163 sresult->AddToArray(MJsonNode::MakeInt(
status));
1173 doc->
D(
"Change size of ODB string arrays");
1174 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths to resize");
1175 doc->
P(
"new_lengths[]", MJSON_INT,
"array of new lengths for each ODB path");
1176 doc->
P(
"new_string_lengths[]", MJSON_INT,
"array of new string lengths for each ODB path");
1177 doc->
R(
"status[]", MJSON_INT,
"return status of db_resize_string() for each path");
1181 MJsonNode* error = NULL;
1185 const MJsonNodeVector* string_lengths =
mjsonrpc_get_param_array(params,
"new_string_lengths", &error);
if (error)
return error;
1187 if (paths->size() != lengths->size()) {
1188 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"new_lengths\" should have the same length");
1191 if (paths->size() != string_lengths->size()) {
1192 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"new_string_lengths\" should have the same length");
1195 MJsonNode* sresult = MJsonNode::MakeArray();
1200 for (
unsigned i=0;
i<paths->size();
i++) {
1201 std::string path = (*paths)[
i]->GetString();
1203 int length = (*lengths)[
i]->GetInt();
1209 int string_length = (*string_lengths)[
i]->GetInt();
1216 sresult->AddToArray(MJsonNode::MakeInt(
status));
1226 doc->
D(
"get ODB keys");
1227 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths");
1228 doc->
R(
"status[]", MJSON_INT,
"return status of db_key() for each path");
1229 doc->
R(
"keys[]", MJSON_OBJECT,
"key data for each path");
1230 doc->
R(
"keys[].type", MJSON_INT,
"key type TID_xxx");
1231 doc->
R(
"keys[].num_values", MJSON_INT,
"array length, 1 for normal entries");
1232 doc->
R(
"keys[].name", MJSON_STRING,
"key name");
1233 doc->
R(
"keys[].total_size", MJSON_INT,
"data total size in bytes");
1234 doc->
R(
"keys[].item_size", MJSON_INT,
"array element size, string length for TID_STRING");
1235 doc->
R(
"keys[].access_mode", MJSON_INT,
"access mode bitmap of MODE_xxx");
1236 doc->
R(
"keys[].notify_count", MJSON_INT,
"number of hotlinks attached to this key");
1237 doc->
R(
"keys[].last_written", MJSON_INT,
"timestamp when data was last updated");
1241 MJsonNode* error = NULL;
1245 MJsonNode* kresult = MJsonNode::MakeArray();
1246 MJsonNode* sresult = MJsonNode::MakeArray();
1251 for (
unsigned i=0;
i<paths->size();
i++) {
1255 std::string path = (*paths)[
i]->GetString();
1259 kresult->AddToArray(MJsonNode::MakeNull());
1260 sresult->AddToArray(MJsonNode::MakeInt(
status));
1266 kresult->AddToArray(MJsonNode::MakeNull());
1267 sresult->AddToArray(MJsonNode::MakeInt(
status));
1271 MJsonNode* jkey = MJsonNode::MakeObject();
1273 jkey->AddToObject(
"type", MJsonNode::MakeInt(
key.
type));
1274 jkey->AddToObject(
"num_values", MJsonNode::MakeInt(
key.
num_values));
1276 jkey->AddToObject(
"name", MJsonNode::MakeString(
key.
name));
1277 jkey->AddToObject(
"total_size", MJsonNode::MakeInt(
key.
total_size));
1278 jkey->AddToObject(
"item_size", MJsonNode::MakeInt(
key.
item_size));
1279 jkey->AddToObject(
"access_mode", MJsonNode::MakeInt(
key.
access_mode));
1280 jkey->AddToObject(
"notify_count", MJsonNode::MakeInt(
key.
notify_count));
1281 jkey->AddToObject(
"last_written", MJsonNode::MakeInt(
key.
last_written));
1283 kresult->AddToArray(jkey);
1284 sresult->AddToArray(MJsonNode::MakeInt(
status));
1294 doc->
D(
"Change size of ODB arrays");
1295 doc->
P(
"paths[]", MJSON_STRING,
"array of ODB paths to rename");
1296 doc->
P(
"new_names[]", MJSON_STRING,
"array of new names for each ODB path");
1297 doc->
R(
"status[]", MJSON_INT,
"return status of db_rename_key() for each path");
1301 MJsonNode* error = NULL;
1306 if (paths->size() != names->size()) {
1307 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"new_names\" should have the same length");
1310 MJsonNode* sresult = MJsonNode::MakeArray();
1315 for (
unsigned i=0;
i<paths->size();
i++) {
1318 std::string path = (*paths)[
i]->GetString();
1322 sresult->AddToArray(MJsonNode::MakeInt(
status));
1326 std::string new_name = (*names)[
i]->GetString();
1327 if (new_name.length() < 1) {
1334 sresult->AddToArray(MJsonNode::MakeInt(
status));
1344 doc->
D(
"Create ODB symlinks");
1345 doc->
P(
"new_links[]", MJSON_STRING,
"array of new symlinks to be created");
1346 doc->
P(
"target_paths[]", MJSON_STRING,
"array of existing ODB paths for each link");
1347 doc->
R(
"status[]", MJSON_INT,
"return status of db_create_link() for each path");
1351 MJsonNode* error = NULL;
1353 const MJsonNodeVector* target_paths =
mjsonrpc_get_param_array(params,
"target_paths", &error);
if (error)
return error;
1356 if (target_paths->size() != new_links->size()) {
1357 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"target_paths\" and \"new_links\" should have the same length");
1360 MJsonNode* sresult = MJsonNode::MakeArray();
1365 for (
unsigned i=0;
i<new_links->size();
i++) {
1367 std::string target_path = (*target_paths)[
i]->GetString();
1368 std::string new_link = (*new_links)[
i]->GetString();
1369 if (new_link.length() < 1) {
1376 sresult->AddToArray(MJsonNode::MakeInt(
status));
1386 doc->
D(
"Change order of ODB keys in a subdirectory");
1387 doc->
P(
"paths[]", MJSON_STRING,
"array of new symlinks to be created");
1388 doc->
P(
"indices[]", MJSON_INT,
"array of existing ODB paths for each link");
1389 doc->
R(
"status[]", MJSON_INT,
"return status of db_reorder_key() for each path");
1393 MJsonNode* error = NULL;
1398 if (paths->size() != indices->size()) {
1399 return mjsonrpc_make_error(-32602,
"Invalid params",
"arrays \"paths\" and \"indices\" should have the same length");
1402 MJsonNode* sresult = MJsonNode::MakeArray();
1407 for (
unsigned i=0;
i<paths->size();
i++) {
1410 std::string path = (*paths)[
i]->GetString();
1411 int index = (*indices)[
i]->GetInt();
1415 sresult->AddToArray(MJsonNode::MakeInt(
status));
1421 sresult->AddToArray(MJsonNode::MakeInt(
status));
1431 doc->
D(
"Show ODB open records starting from given ODB path");
1432 doc->
P(
"path?", MJSON_STRING,
"ODB path");
1433 doc->
R(
"sor", MJSON_JSON,
"return value of db_sor()");
1437 MJsonNode* error = NULL;
1439 std::string path =
mjsonrpc_get_param(params,
"path", NULL)->GetString();
if (error)
return error;
1444 MJsonNode* sor =
db_sor(
hDB, path.c_str());
1453 doc->
D(
"Show ODB clients");
1454 doc->
R(
"scl", MJSON_JSON,
"return value of db_scl()");
1476 doc->
D(
"get message facilities using cm_msg_facilities()");
1477 doc->
R(
"status", MJSON_INT,
"return status of cm_msg_facilities()");
1478 doc->
R(
"facilities[]", MJSON_STRING,
"array of facility names");
1486 MJsonNode* facilities = MJsonNode::MakeArray();
1488 for (
unsigned i=0;
i<
list.size();
i++) {
1490 facilities->AddToArray(MJsonNode::MakeString(
list[
i].c_str()));
1494 "facilities", facilities);
1501 doc->
D(
"Generate a midas message using cm_msg1()");
1502 doc->
P(
"facility?", MJSON_STRING,
"message facility, default is \"midas\"");
1503 doc->
P(
"user?", MJSON_STRING,
"message user, default is \"javascript_commands\"");
1504 doc->
P(
"type?", MJSON_INT,
"message type, MT_xxx from midas.h, default is MT_INFO");
1505 doc->
P(
"message", MJSON_STRING,
"message text");
1506 doc->
R(
"status", MJSON_INT,
"return status of cm_msg1()");
1510 MJsonNode* error = NULL;
1517 if (facility.size() <1)
1520 user =
"javascript_commands";
1533 doc->
D(
"Retrieve midas messages using cm_msg_retrieve2()");
1534 doc->
P(
"facility?", MJSON_STRING,
"message facility, default is \"midas\"");
1535 doc->
P(
"min_messages?", MJSON_INT,
"get at least this many messages, default is 1");
1536 doc->
P(
"time?", MJSON_NUMBER,
"start from given timestamp, value 0 means give me newest messages, default is 0");
1537 doc->
R(
"num_messages", MJSON_INT,
"number of messages returned");
1538 doc->
R(
"messages", MJSON_STRING,
"messages separated by \\n");
1539 doc->
R(
"status", MJSON_INT,
"return status of cm_msg_retrieve2()");
1547 if (facility.size() < 1)
1550 int num_messages = 0;
1551 char* messages = NULL;
1555 MJsonNode* result = MJsonNode::MakeObject();
1557 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
1558 result->AddToObject(
"num_messages", MJsonNode::MakeInt(num_messages));
1562 result->AddToObject(
"messages", MJsonNode::MakeString(messages));
1580 doc->
D(
"reset alarms");
1581 doc->
P(
"alarms[]", MJSON_STRING,
"array of alarm names");
1582 doc->
R(
"status[]", MJSON_INT,
"return status of al_reset_alarm() for each alarm");
1586 MJsonNode* error = NULL;
1590 MJsonNode* sresult = MJsonNode::MakeArray();
1592 for (
unsigned i=0;
i<alarms->size();
i++) {
1594 sresult->AddToArray(MJsonNode::MakeInt(
status));
1604 doc->
D(
"trigger an alarm");
1605 doc->
P(
"name", MJSON_STRING,
"alarm name");
1606 doc->
P(
"message", MJSON_STRING,
"alarm message");
1607 doc->
P(
"class", MJSON_STRING,
"alarm class");
1608 doc->
P(
"condition", MJSON_STRING,
"alarm condition");
1609 doc->
P(
"type", MJSON_INT,
"alarm type (AT_xxx)");
1610 doc->
R(
"status", MJSON_INT,
"return status of al_trigger_alarm()");
1614 MJsonNode* error = NULL;
1618 std::string xclass =
mjsonrpc_get_param(params,
"class", &error)->GetString();
if (error)
return error;
1619 std::string condition =
mjsonrpc_get_param(params,
"condition", &error)->GetString();
if (error)
return error;
1631 doc->
D(
"trigger an alarm");
1632 doc->
P(
"class", MJSON_STRING,
"alarm class");
1633 doc->
P(
"message", MJSON_STRING,
"alarm message");
1634 doc->
P(
"first?", MJSON_BOOL,
"see al_trigger_class() in midas.c");
1635 doc->
R(
"status", MJSON_INT,
"return status of al_trigger_class()");
1639 MJsonNode* error = NULL;
1641 std::string xclass =
mjsonrpc_get_param(params,
"class", &error)->GetString();
if (error)
return error;
1662 doc->
D(
"get list of active history events using hs_read_event_list()");
1663 doc->
R(
"status", MJSON_INT,
"return status of hs_read_event_list()");
1664 doc->
R(
"events[]", MJSON_STRING,
"array of history event names");
1672 MJsonNode* events = MJsonNode::MakeArray();
1674 for (
unsigned i=0;
i<
list.size();
i++) {
1676 events->AddToArray(MJsonNode::MakeString(
list[
i].c_str()));
1682typedef std::map<std::string,MidasHistoryInterface*>
MhiMap;
1702 if (strlen(
name) < 1) {
1723 cm_msg(
MERROR,
"GetHistory",
"Cannot configure history, hs_get_history() status %d",
status);
1749 doc->
D(
"get list of history channels in /Logger/History");
1750 doc->
R(
"status", MJSON_INT,
"return success or failure status");
1751 doc->
R(
"default_channel", MJSON_STRING,
"name of the default logger history channel");
1752 doc->
R(
"channels[]", MJSON_STRING,
"all logger history channel names");
1753 doc->
R(
"active_channels[]", MJSON_STRING,
"active logger history channel names");
1757 MJsonNode* channels = MJsonNode::MakeArray();
1758 MJsonNode* active_channels = MJsonNode::MakeArray();
1773 for (
int ichan=0; ; ichan++) {
1789 channels->AddToArray(MJsonNode::MakeString(
key.
name));
1792 INT size =
sizeof(active);
1796 active_channels->AddToArray(MJsonNode::MakeString(
key.
name));
1803 std::string default_channel;
1817 "default_channel", MJsonNode::MakeString(default_channel.c_str()),
1818 "active_channels", active_channels,
1819 "channels", channels);
1826 doc->
D(
"get list of history events that existed at give time using hs_get_events()");
1827 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
1828 doc->
P(
"time?", MJSON_NUMBER,
"timestamp, value 0 means current time, default is 0");
1829 doc->
R(
"status", MJSON_INT,
"return status of hs_get_events()");
1830 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
1831 doc->
R(
"events[]", MJSON_STRING,
"array of history event names");
1840 MJsonNode* events = MJsonNode::MakeArray();
1848 time = ::time(NULL);
1855 for (
unsigned i=0;
i<
list.size();
i++) {
1857 events->AddToArray(MJsonNode::MakeString(
list[
i].c_str()));
1867 doc->
D(
"reopen the history channel to make sure we see the latest list of events using hs_clear_cache()");
1868 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
1869 doc->
R(
"status", MJSON_INT,
"return status of hs_get_events()");
1870 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
1892 doc->
D(
"get list of history tags for given history events that existed at give time using hs_get_tags()");
1893 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
1894 doc->
P(
"time?", MJSON_NUMBER,
"timestamp, value 0 means current time, default is 0");
1895 doc->
P(
"events[]?", MJSON_STRING,
"array of history event names, default is get all events using hs_get_events()");
1896 doc->
R(
"status", MJSON_INT,
"return status");
1897 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
1898 doc->
R(
"events[].name", MJSON_STRING,
"array of history event names for each history event");
1899 doc->
R(
"events[].status", MJSON_INT,
"array of status ohistory tags for each history event");
1900 doc->
R(
"events[].tags[]", MJSON_STRING,
"array of history tags for each history event");
1901 doc->
R(
"events[].tags[].name", MJSON_STRING,
"history tag name");
1902 doc->
R(
"events[].tags[].type", MJSON_INT,
"history tag midas data type");
1903 doc->
R(
"events[].tags[].n_data?", MJSON_INT,
"history tag number of array elements, omitted if 1");
1912 time = ::time(NULL);
1917 MJsonNode* events = MJsonNode::MakeArray();
1924 std::vector<std::string> event_names;
1926 if (events_array && events_array->size() > 0) {
1927 for (
unsigned i=0;
i<events_array->size();
i++) {
1928 event_names.push_back((*events_array)[
i]->GetString());
1932 if (event_names.size() < 1) {
1939 for (
unsigned i=0;
i<event_names.size();
i++) {
1940 MJsonNode* o = MJsonNode::MakeObject();
1941 const char* event_name = event_names[
i].c_str();
1942 std::vector<TAG> tags;
1945 o->AddToObject(
"name", MJsonNode::MakeString(event_name));
1946 o->AddToObject(
"status", MJsonNode::MakeInt(
status));
1947 MJsonNode *ta = MJsonNode::MakeArray();
1948 for (
unsigned j=0;
j<tags.size();
j++) {
1949 MJsonNode* to = MJsonNode::MakeObject();
1951 to->AddToObject(
"name", MJsonNode::MakeString(tags[
j].
name));
1952 to->AddToObject(
"type", MJsonNode::MakeInt(tags[
j].
type));
1953 if (tags[
j].n_data != 1) {
1954 to->AddToObject(
"n_data", MJsonNode::MakeInt(tags[
j].n_data));
1958 o->AddToObject(
"tags", ta);
1959 events->AddToArray(o);
1970 doc->
D(
"get list of history tags for given history events that existed at give time using hs_get_last_written()");
1971 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
1972 doc->
P(
"time?", MJSON_NUMBER,
"timestamp, value 0 means current time, default is 0");
1973 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
1974 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
1975 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
1976 doc->
R(
"status", MJSON_INT,
"return status");
1977 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
1978 doc->
R(
"last_written[]", MJSON_NUMBER,
"array of last-written times for each history event");
1991 MJsonNode* lw = MJsonNode::MakeArray();
1998 unsigned num_var = events_array->size();
2000 if (tags_array->size() != num_var) {
2001 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2004 if (index_array->size() != num_var) {
2005 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2008 std::vector<std::string> event_names(num_var);
2009 std::vector<std::string> tag_names(num_var);
2012 int* var_index =
new int[num_var];
2013 time_t* last_written =
new time_t[num_var];
2015 for (
unsigned i=0;
i<num_var;
i++) {
2018 event_names[
i] = (*events_array)[
i]->GetString();
2019 tag_names[
i] = (*tags_array)[
i]->GetString();
2020 var_index[
i] = (*index_array)[
i]->GetInt();
2024 printf(
"time %f, num_vars %d:\n", time, num_var);
2025 for (
unsigned i=0;
i<num_var;
i++) {
2026 printf(
"%d: [%s] [%s] [%d]\n",
i, event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2031 time = ::time(NULL);
2035 const char** event_name =
new const char*[num_var];
2036 const char** tag_name =
new const char*[num_var];
2037 for (
unsigned i=0;
i<num_var;
i++) {
2038 event_name[
i] = event_names[
i].c_str();
2039 tag_name[
i] = tag_names[
i].c_str();
2043 for (
unsigned i=0;
i<num_var;
i++) {
2045 printf(
"%d: last_written %d\n",
i, (
int)last_written[
i]);
2047 lw->AddToArray(MJsonNode::MakeNumber(last_written[
i]));
2050 delete[] event_name;
2053 delete[] last_written;
2084 fTimeJson += MJsonNode::EncodeDouble(t);
2099 doc->
D(
"get history data for given history events that existed at give time using hs_read_buffer()");
2100 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
2101 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2102 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2103 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
2104 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
2105 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
2106 doc->
R(
"status", MJSON_INT,
"return status");
2107 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
2108 doc->
R(
"data[]", MJSON_ARRAY,
"array of history data");
2109 doc->
R(
"data[].status", MJSON_INT,
"status for each event");
2110 doc->
R(
"data[].count", MJSON_INT,
"number of data for each event");
2111 doc->
R(
"data[].time[]", MJSON_NUMBER,
"time data");
2112 doc->
R(
"data[].value[]", MJSON_NUMBER,
"value data");
2116 MJsonNode* error = NULL;
2119 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2120 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2128 MJsonNode*
data = MJsonNode::MakeArray();
2135 unsigned num_var = events_array->size();
2137 if (tags_array->size() != num_var) {
2138 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2141 if (index_array->size() != num_var) {
2142 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2145 std::vector<std::string> event_names(num_var);
2146 std::vector<std::string> tag_names(num_var);
2147 int* var_index =
new int[num_var];
2150 int* hs_status =
new int[num_var];
2152 for (
unsigned i=0;
i<num_var;
i++) {
2155 event_names[
i] = (*events_array)[
i]->GetString();
2156 tag_names[
i] = (*tags_array)[
i]->GetString();
2157 var_index[
i] = (*index_array)[
i]->GetInt();
2164 printf(
"time %f %f, num_vars %d:\n", start_time, end_time, num_var);
2165 for (
unsigned i=0;
i<num_var;
i++) {
2166 printf(
"%d: [%s] [%s] [%d]\n",
i, event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2170 const char** event_name =
new const char*[num_var];
2171 const char** tag_name =
new const char*[num_var];
2172 for (
unsigned i=0;
i<num_var;
i++) {
2173 event_name[
i] = event_names[
i].c_str();
2174 tag_name[
i] = tag_names[
i].c_str();
2177 int status =
mh->
hs_read_buffer(start_time, end_time, num_var, event_name, tag_name, var_index, buf, hs_status);
2179 for (
unsigned i=0;
i<num_var;
i++) {
2182 MJsonNode* obj = MJsonNode::MakeObject();
2183 obj->AddToObject(
"status", MJsonNode::MakeInt(hs_status[
i]));
2184 obj->AddToObject(
"count", MJsonNode::MakeInt(jbuf[
i]->fCount));
2185 obj->AddToObject(
"time", MJsonNode::MakeJSON(jbuf[
i]->fTimeJson.c_str()));
2186 obj->AddToObject(
"value", MJsonNode::MakeJSON(jbuf[
i]->fValueJson.c_str()));
2187 data->AddToArray(obj);
2194 delete[] event_name;
2208 doc->
D(
"get history data for given history events that existed at give time using hs_read_buffer()");
2209 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
2210 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2211 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2212 doc->
P(
"num_bins", MJSON_INT,
"number of time bins");
2213 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
2214 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
2215 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
2216 doc->
R(
"status", MJSON_INT,
"return status");
2217 doc->
R(
"channel", MJSON_STRING,
"logger history channel name");
2218 doc->
R(
"data[]", MJSON_ARRAY,
"array of history data");
2219 doc->
R(
"data[].status", MJSON_INT,
"status for each event");
2220 doc->
R(
"data[].num_entries", MJSON_INT,
"number of data points for each event");
2221 doc->
R(
"data[].count[]", MJSON_INT,
"number of data points for each bin");
2222 doc->
R(
"data[].mean[]", MJSON_NUMBER,
"mean for each bin");
2223 doc->
R(
"data[].rms[]", MJSON_NUMBER,
"rms for each bin");
2224 doc->
R(
"data[].min[]", MJSON_NUMBER,
"minimum value for each bin");
2225 doc->
R(
"data[].max[]", MJSON_NUMBER,
"maximum value for each bin");
2226 doc->
R(
"data[].bins_first_time[]", MJSON_NUMBER,
"first data point in each bin");
2227 doc->
R(
"data[].bins_first_value[]", MJSON_NUMBER,
"first data point in each bin");
2228 doc->
R(
"data[].bins_last_time[]", MJSON_NUMBER,
"last data point in each bin");
2229 doc->
R(
"data[].bins_last_value[]", MJSON_NUMBER,
"last data point in each bin");
2230 doc->
R(
"data[].last_time", MJSON_NUMBER,
"time of last data entry");
2231 doc->
R(
"data[].last_value", MJSON_NUMBER,
"value of last data entry");
2235 MJsonNode* error = NULL;
2238 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2239 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2240 int num_bins =
mjsonrpc_get_param(params,
"num_bins", &error)->GetInt();
if (error)
return error;
2243 return mjsonrpc_make_error(-32602,
"Invalid params",
"Value of num_bins should be 1 or more");
2252 MJsonNode*
data = MJsonNode::MakeArray();
2259 unsigned num_var = events_array->size();
2262 return mjsonrpc_make_error(-32602,
"Invalid params",
"Array of events should have 1 or more elements");
2265 if (tags_array->size() != num_var) {
2266 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2269 if (index_array->size() != num_var) {
2270 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2273 std::vector<std::string> event_names(num_var);
2274 std::vector<std::string> tag_names(num_var);
2277 int* var_index =
new int[num_var];
2279 int* num_entries =
new int[num_var];
2280 time_t*
last_time =
new time_t[num_var];
2281 double* last_value =
new double[num_var];
2282 int* hs_status =
new int[num_var];
2284 int** count_bins =
new int*[num_var];
2285 double** mean_bins =
new double*[num_var];
2286 double** rms_bins =
new double*[num_var];
2287 double** min_bins =
new double*[num_var];
2288 double** max_bins =
new double*[num_var];
2290 time_t** bins_first_time =
new time_t*[num_var];
2291 time_t** bins_last_time =
new time_t*[num_var];
2293 double** bins_first_value =
new double*[num_var];
2294 double** bins_last_value =
new double*[num_var];
2296 for (
unsigned i=0;
i<num_var;
i++) {
2299 event_names[
i] = (*events_array)[
i]->GetString();
2300 tag_names[
i] = (*tags_array)[
i]->GetString();
2301 var_index[
i] = (*index_array)[
i]->GetInt();
2306 count_bins[
i] =
new int[num_bins];
2307 mean_bins[
i] =
new double[num_bins];
2308 rms_bins[
i] =
new double[num_bins];
2309 min_bins[
i] =
new double[num_bins];
2310 max_bins[
i] =
new double[num_bins];
2312 bins_first_time[
i] =
new time_t[num_bins];
2313 bins_last_time[
i] =
new time_t[num_bins];
2315 bins_first_value[
i] =
new double[num_bins];
2316 bins_last_value[
i] =
new double[num_bins];
2320 printf(
"time %f %f, num_vars %d:\n", start_time, end_time, num_var);
2321 for (
unsigned i=0;
i<num_var;
i++) {
2322 printf(
"%d: [%s] [%s] [%d]\n",
i, event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2326 const char** event_name =
new const char*[num_var];
2327 const char** tag_name =
new const char*[num_var];
2328 for (
unsigned i=0;
i<num_var;
i++) {
2329 event_name[
i] = event_names[
i].c_str();
2330 tag_name[
i] = tag_names[
i].c_str();
2333 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);
2335 for (
unsigned i=0;
i<num_var;
i++) {
2336 MJsonNode* obj = MJsonNode::MakeObject();
2337 obj->AddToObject(
"status", MJsonNode::MakeInt(hs_status[
i]));
2338 obj->AddToObject(
"num_entries", MJsonNode::MakeInt(num_entries[
i]));
2340 MJsonNode* a1 = MJsonNode::MakeArray();
2341 MJsonNode* a2 = MJsonNode::MakeArray();
2342 MJsonNode* a3 = MJsonNode::MakeArray();
2343 MJsonNode* a4 = MJsonNode::MakeArray();
2344 MJsonNode* a5 = MJsonNode::MakeArray();
2346 MJsonNode* b1 = MJsonNode::MakeArray();
2347 MJsonNode* b2 = MJsonNode::MakeArray();
2348 MJsonNode* b3 = MJsonNode::MakeArray();
2349 MJsonNode* b4 = MJsonNode::MakeArray();
2351 for (
int j=0;
j<num_bins;
j++) {
2352 a1->AddToArray(MJsonNode::MakeInt(count_bins[
i][
j]));
2353 a2->AddToArray(MJsonNode::MakeNumber(mean_bins[
i][
j]));
2354 a3->AddToArray(MJsonNode::MakeNumber(rms_bins[
i][
j]));
2355 a4->AddToArray(MJsonNode::MakeNumber(min_bins[
i][
j]));
2356 a5->AddToArray(MJsonNode::MakeNumber(max_bins[
i][
j]));
2358 b1->AddToArray(MJsonNode::MakeNumber(bins_first_time[
i][
j]));
2359 b2->AddToArray(MJsonNode::MakeNumber(bins_first_value[
i][
j]));
2360 b3->AddToArray(MJsonNode::MakeNumber(bins_last_time[
i][
j]));
2361 b4->AddToArray(MJsonNode::MakeNumber(bins_last_value[
i][
j]));
2364 obj->AddToObject(
"count", a1);
2365 obj->AddToObject(
"mean", a2);
2366 obj->AddToObject(
"rms", a3);
2367 obj->AddToObject(
"min", a4);
2368 obj->AddToObject(
"max", a5);
2369 obj->AddToObject(
"bins_first_time", b1);
2370 obj->AddToObject(
"bins_first_value", b2);
2371 obj->AddToObject(
"bins_last_time", b3);
2372 obj->AddToObject(
"bins_last_value", b4);
2373 obj->AddToObject(
"last_time", MJsonNode::MakeNumber(
last_time[
i]));
2374 obj->AddToObject(
"last_value", MJsonNode::MakeNumber(last_value[
i]));
2375 data->AddToArray(obj);
2377 delete count_bins[
i];
2378 delete mean_bins[
i];
2383 delete bins_first_time[
i];
2384 delete bins_first_value[
i];
2385 delete bins_last_time[
i];
2386 delete bins_last_value[
i];
2389 delete[] count_bins;
2395 delete[] bins_first_time;
2396 delete[] bins_first_value;
2397 delete[] bins_last_time;
2398 delete[] bins_last_value;
2400 delete[] event_name;
2404 delete[] num_entries;
2406 delete[] last_value;
2442 doc->
D(
"get history data for given history events that existed at give time using hs_read_buffer()");
2443 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
2444 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2445 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2446 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
2447 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
2448 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
2449 doc->
R(
"binary data", MJSON_ARRAYBUFFER,
"binary data, see documentation");
2453 MJsonNode* error = NULL;
2456 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2457 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2470 size_t num_var = events_array->size();
2472 if (tags_array->size() != num_var) {
2473 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2476 if (index_array->size() != num_var) {
2477 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2480 std::vector<std::string> event_names(num_var);
2481 std::vector<std::string> tag_names(num_var);
2482 int* var_index =
new int[num_var];
2485 int* hs_status =
new int[num_var];
2487 for (
size_t i=0;
i<num_var;
i++) {
2490 event_names[
i] = (*events_array)[
i]->GetString();
2491 tag_names[
i] = (*tags_array)[
i]->GetString();
2492 var_index[
i] = (*index_array)[
i]->GetInt();
2499 printf(
"time %f %f, num_vars %d:\n", start_time, end_time,
int(num_var));
2500 for (
size_t i=0;
i<num_var;
i++) {
2501 printf(
"%d: [%s] [%s] [%d]\n",
int(
i), event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2505 const char** event_name =
new const char*[num_var];
2506 const char** tag_name =
new const char*[num_var];
2507 for (
unsigned i=0;
i<num_var;
i++) {
2508 event_name[
i] = event_names[
i].c_str();
2509 tag_name[
i] = tag_names[
i].c_str();
2512 int status =
mh->
hs_read_buffer(start_time, end_time, num_var, event_name, tag_name, var_index, buf, hs_status);
2514 size_t num_values = 0;
2516 for (
unsigned i=0;
i<num_var;
i++) {
2518 num_values += jbuf[
i]->
fValues.size();
2522 size_t p0_size =
sizeof(double)*(2+2*num_var+2*num_values);
2524 size_t size_limit = 1000*1024*1024;
2526 if (p0_size > size_limit) {
2527 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);
2529 for (
size_t i=0;
i<num_var;
i++) {
2535 delete[] event_name;
2545 double* p0 = (
double*)malloc(p0_size);
2548 cm_msg(
MERROR,
"js_hs_read_binned_arraybuffer",
"Cannot allocate return buffer %d bytes\n",
int(p0_size));
2550 for (
size_t i=0;
i<num_var;
i++) {
2556 delete[] event_name;
2563 return mjsonrpc_make_error(-32603,
"Internal error",
"Cannot allocate buffer, too much data");
2587 for (
size_t i=0;
i<num_var;
i++) {
2588 *pptr++ = hs_status[
i];
2591 for (
size_t i=0;
i<num_var;
i++) {
2595 for (
size_t i=0;
i<num_var;
i++) {
2596 size_t nv = jbuf[
i]->
fValues.size();
2597 for (
size_t j=0;
j<nv;
j++) {
2609 assert(p0_size == ((pptr-p0)*
sizeof(
double)));
2611 delete[] event_name;
2618 MJsonNode* result = MJsonNode::MakeArrayBuffer((
char*)p0, p0_size);
2627 doc->
D(
"get history data for given history events that existed at give time using hs_read_buffer()");
2628 doc->
P(
"channel?", MJSON_STRING,
"midas history channel, default is the default reader channel");
2629 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2630 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2631 doc->
P(
"num_bins", MJSON_INT,
"number of time bins");
2632 doc->
P(
"events[]", MJSON_STRING,
"array of history event names");
2633 doc->
P(
"tags[]", MJSON_STRING,
"array of history event tag names");
2634 doc->
P(
"index[]", MJSON_STRING,
"array of history event tag array indices");
2635 doc->
R(
"binary data", MJSON_ARRAYBUFFER,
"binary data, see documentation");
2639 MJsonNode* error = NULL;
2642 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2643 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2644 int inum_bins =
mjsonrpc_get_param(params,
"num_bins", &error)->GetInt();
if (error)
return error;
2646 if (inum_bins < 1) {
2647 return mjsonrpc_make_error(-32602,
"Invalid params",
"Value of num_bins should be 1 or more");
2650 size_t num_bins = inum_bins;
2663 size_t num_var = events_array->size();
2666 return mjsonrpc_make_error(-32602,
"Invalid params",
"Array of events should have 1 or more elements");
2669 if (tags_array->size() != num_var) {
2670 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and tags should have the same length");
2673 if (index_array->size() != num_var) {
2674 return mjsonrpc_make_error(-32602,
"Invalid params",
"Arrays events and index should have the same length");
2677 std::vector<std::string> event_names(num_var);
2678 std::vector<std::string> tag_names(num_var);
2681 int* var_index =
new int[num_var];
2683 int* num_entries =
new int[num_var];
2684 time_t*
last_time =
new time_t[num_var];
2685 double* last_value =
new double[num_var];
2686 int* hs_status =
new int[num_var];
2688 int** count_bins =
new int*[num_var];
2689 double** mean_bins =
new double*[num_var];
2690 double** rms_bins =
new double*[num_var];
2691 double** min_bins =
new double*[num_var];
2692 double** max_bins =
new double*[num_var];
2694 time_t** bins_first_time =
new time_t*[num_var];
2695 time_t** bins_last_time =
new time_t*[num_var];
2697 double** bins_first_value =
new double*[num_var];
2698 double** bins_last_value =
new double*[num_var];
2700 for (
unsigned i=0;
i<num_var;
i++) {
2703 event_names[
i] = (*events_array)[
i]->GetString();
2704 tag_names[
i] = (*tags_array)[
i]->GetString();
2705 var_index[
i] = (*index_array)[
i]->GetInt();
2710 count_bins[
i] =
new int[num_bins];
2711 mean_bins[
i] =
new double[num_bins];
2712 rms_bins[
i] =
new double[num_bins];
2713 min_bins[
i] =
new double[num_bins];
2714 max_bins[
i] =
new double[num_bins];
2715 bins_first_time[
i] =
new time_t[num_bins];
2716 bins_last_time[
i] =
new time_t[num_bins];
2717 bins_first_value[
i] =
new double[num_bins];
2718 bins_last_value[
i] =
new double[num_bins];
2722 printf(
"time %f %f, num_vars %d:\n", start_time, end_time,
int(num_var));
2723 for (
size_t i=0;
i<num_var;
i++) {
2724 printf(
"%d: [%s] [%s] [%d]\n",
int(
i), event_names[
i].c_str(), tag_names[
i].c_str(), var_index[
i]);
2728 const char** event_name =
new const char*[num_var];
2729 const char** tag_name =
new const char*[num_var];
2730 for (
size_t i=0;
i<num_var;
i++) {
2731 event_name[
i] = event_names[
i].c_str();
2732 tag_name[
i] = tag_names[
i].c_str();
2735 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);
2738 size_t p0_size =
sizeof(double)*(5+4*num_var+9*num_var*num_bins);
2740 size_t size_limit = 100*1024*1024;
2742 if (p0_size > size_limit) {
2743 cm_msg(
MERROR,
"js_hs_read_binned_arraybuffer",
"Refusing to return %d bytes. limit is %d bytes\n",
int(p0_size),
int(size_limit));
2745 for (
size_t i=0;
i<num_var;
i++) {
2746 delete count_bins[
i];
2747 delete mean_bins[
i];
2751 delete bins_first_time[
i];
2752 delete bins_first_value[
i];
2753 delete bins_last_time[
i];
2754 delete bins_last_value[
i];
2757 delete[] count_bins;
2763 delete[] bins_first_time;
2764 delete[] bins_first_value;
2765 delete[] bins_last_time;
2766 delete[] bins_last_value;
2768 delete[] event_name;
2772 delete[] num_entries;
2774 delete[] last_value;
2780 double* p0 = (
double*)malloc(p0_size);
2783 cm_msg(
MERROR,
"js_hs_read_binned_arraybuffer",
"Cannot allocate return buffer %d bytes\n",
int(p0_size));
2785 for (
size_t i=0;
i<num_var;
i++) {
2786 delete count_bins[
i];
2787 delete mean_bins[
i];
2791 delete bins_first_time[
i];
2792 delete bins_first_value[
i];
2793 delete bins_last_time[
i];
2794 delete bins_last_value[
i];
2797 delete[] count_bins;
2803 delete[] bins_first_time;
2804 delete[] bins_first_value;
2805 delete[] bins_last_time;
2806 delete[] bins_last_value;
2808 delete[] event_name;
2812 delete[] num_entries;
2814 delete[] last_value;
2817 return mjsonrpc_make_error(-32603,
"Internal error",
"Cannot allocate buffer, too much data");
2856 *pptr++ = start_time;
2861 for (
unsigned i=0;
i<num_var;
i++) {
2862 *pptr++ = hs_status[
i];
2865 for (
unsigned i=0;
i<num_var;
i++) {
2866 *pptr++ = num_entries[
i];
2869 for (
unsigned i=0;
i<num_var;
i++) {
2873 for (
unsigned i=0;
i<num_var;
i++) {
2874 *pptr++ = last_value[
i];
2877 for (
size_t i=0;
i<num_var;
i++) {
2878 for (
size_t j=0;
j<num_bins;
j++) {
2879 *pptr++ = count_bins[
i][
j];
2880 *pptr++ = mean_bins[
i][
j];
2881 *pptr++ = rms_bins[
i][
j];
2882 *pptr++ = min_bins[
i][
j];
2883 *pptr++ = max_bins[
i][
j];
2884 *pptr++ = bins_first_time[
i][
j];
2885 *pptr++ = bins_first_value[
i][
j];
2886 *pptr++ = bins_last_time[
i][
j];
2887 *pptr++ = bins_last_value[
i][
j];
2890 delete count_bins[
i];
2891 delete mean_bins[
i];
2895 delete bins_first_time[
i];
2896 delete bins_first_value[
i];
2897 delete bins_last_time[
i];
2898 delete bins_last_value[
i];
2903 assert(p0_size == ((pptr-p0)*
sizeof(
double)));
2905 delete[] count_bins;
2911 delete[] bins_first_time;
2912 delete[] bins_first_value;
2913 delete[] bins_last_time;
2914 delete[] bins_last_value;
2916 delete[] event_name;
2920 delete[] num_entries;
2922 delete[] last_value;
2925 MJsonNode* result = MJsonNode::MakeArrayBuffer((
char*)p0, p0_size);
2939 doc->
D(
"Get a list of history image files");
2940 doc->
P(
"image?", MJSON_STRING,
"image name as defined under /History/Images/<image>");
2941 doc->
P(
"start_time", MJSON_NUMBER,
"start time of the data");
2942 doc->
P(
"end_time", MJSON_NUMBER,
"end time of the data");
2943 doc->
R(
"time[]", MJSON_ARRAYBUFFER,
"array of time stamps in seconds");
2944 doc->
R(
"filename[]", MJSON_ARRAYBUFFER,
"array of file names");
2948 MJsonNode* error = NULL;
2951 double start_time =
mjsonrpc_get_param(params,
"start_time", &error)->GetDouble();
if (error)
return error;
2952 double end_time =
mjsonrpc_get_param(params,
"end_time", &error)->GetDouble();
if (error)
return error;
2954 std::vector<time_t>vtime{};
2955 std::vector<std::string>vfilename{};
2959 MJsonNode *tj = MJsonNode::MakeArray();
2960 MJsonNode *fj = MJsonNode::MakeArray();
2962 for (
int i=0 ;
i<(int)vtime.size() ;
i++) {
2963 tj->AddToArray(MJsonNode::MakeInt(vtime[
i]));
2965 fj->AddToArray(MJsonNode::MakeString(vfilename[
i].c_str()));
2967 MJsonNode*
data = MJsonNode::MakeObject();
2968 data->AddToObject(
"count", MJsonNode::MakeInt(
count));
2969 data->AddToObject(
"time", tj);
2970 data->AddToObject(
"filename", fj);
2985 doc->
D(
"Get an elog message");
2986 doc->
P(
"tag", MJSON_STRING,
"elog message tag");
2987 doc->
R(
"status", MJSON_INT,
"return status of el_retrieve");
2988 doc->
R(
"msg.tag", MJSON_STRING,
"message tag");
2992 MJsonNode* error = NULL;
2994 std::string tag =
mjsonrpc_get_param(params,
"tag", &error)->GetString();
if (error)
return error;
2997 char date[80], author[80],
type[80], system[80], subject[256], text[10000];
2998 char orig_tag[80], reply_tag[80], attachment[3][256], encoding[80];
3001 mstrlcpy(xtag, tag.c_str(),
sizeof(xtag));
3003 int size =
sizeof(text);
3006 date, &
run, author,
type, system, subject,
3007 text, &size, orig_tag, reply_tag,
3008 attachment[0], attachment[1], attachment[2], encoding);
3012 MJsonNode* msg = MJsonNode::MakeObject();
3016 msg->AddToObject(
"tag", MJsonNode::MakeString(xtag));
3018 msg->AddToObject(
"date", MJsonNode::MakeString(date));
3019 msg->AddToObject(
"run", MJsonNode::MakeInt(
run));
3021 msg->AddToObject(
"author", MJsonNode::MakeString(author));
3023 msg->AddToObject(
"type", MJsonNode::MakeString(
type));
3025 msg->AddToObject(
"system", MJsonNode::MakeString(system));
3027 msg->AddToObject(
"subject", MJsonNode::MakeString(subject));
3029 msg->AddToObject(
"text", MJsonNode::MakeString(text));
3031 msg->AddToObject(
"orig_tag", MJsonNode::MakeString(orig_tag));
3033 msg->AddToObject(
"reply_tag", MJsonNode::MakeString(reply_tag));
3035 msg->AddToObject(
"attachment0", MJsonNode::MakeString(attachment[0]));
3037 msg->AddToObject(
"attachment1", MJsonNode::MakeString(attachment[1]));
3039 msg->AddToObject(
"attachment2", MJsonNode::MakeString(attachment[2]));
3041 msg->AddToObject(
"encoding", MJsonNode::MakeString(encoding));
3051 doc->
D(
"Query elog messages");
3052 doc->
P(
"last_n_hours?", MJSON_INT,
"return messages from the last N hours");
3053 doc->
R(
"status", MJSON_INT,
"return status of el_retrieve");
3054 doc->
R(
"msg[].tag", MJSON_STRING,
"message tag");
3080 MJsonNode* msg_array = MJsonNode::MakeArray();
3083 char date[80], author[80],
type[80], system[80], subject[256], text[10000],
3084 orig_tag[80], reply_tag[80], attachment[3][256], encoding[80];
3085 char str[256], str2[10000], tag[256];
3089 extern const char *
mname[];
3105 r1 = atoi(pr1.c_str());
3108 r2 = atoi(pr2.c_str());
3110 time_t ltime_start = 0;
3111 time_t ltime_end = 0;
3116 if (py1.length() > 0)
3117 y1 = atoi(py1.c_str());
3119 if (pd1.length() > 0)
3120 d1 = atoi(pd1.c_str());
3122 mstrlcpy(
str, pm1.c_str(),
sizeof(
str));
3123 for (m1 = 0; m1 < 12; m1++)
3129 if (pd2.length() > 0) {
3130 d2 = atoi(pd2.c_str());
3133 if (py2.length() > 0) {
3136 mstrlcpy(
str, pm2.c_str(),
sizeof(
str));
3137 for (m2 = 0; m2 < 12; m2++)
3145 if (py2.length() > 0) {
3146 y2 = atoi(py2.c_str());
3149 if (y2>=0 && m2>=0 && d2>=0) {
3150 memset(&tms, 0,
sizeof(
struct tm));
3151 tms.tm_year = y2 % 100;
3156 if (tms.tm_year < 90)
3168 time_t now = time(NULL);
3169 ltime_start = now - 3600 * last_n;
3171 localtime_r(<ime_start, &tms);
3172 sprintf(tag,
"%02d%02d%02d.0", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
3173 }
else if (r1 > 0) {
3176 }
else if (y1>=0 && m1>=0 && d1>=0) {
3178 sprintf(tag,
"%02d%02d%02d.0", y1 % 100, m1 + 1, d1);
3182 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",
3193 size =
sizeof(text);
3195 text, &size, orig_tag, reply_tag,
3196 attachment[0], attachment[1], attachment[2], encoding);
3198 std::string this_tag = tag;
3202 mstrlcat(tag,
"+1",
sizeof(tag));
3205 if ((r2 > 0) && (r2 <
run)) {
3210 memset(&tms, 0,
sizeof(
struct tm));
3211 tms.tm_year = (tag[0] -
'0') * 10 + (tag[1] -
'0');
3212 tms.tm_mon = (tag[2] -
'0') * 10 + (tag[3] -
'0') - 1;
3213 tms.tm_mday = (tag[4] -
'0') * 10 + (tag[5] -
'0');
3214 tms.tm_hour = (date[11] -
'0') * 10 + (date[12] -
'0');
3215 tms.tm_min = (date[14] -
'0') * 10 + (date[15] -
'0');
3216 tms.tm_sec = (date[17] -
'0') * 10 + (date[18] -
'0');
3218 if (tms.tm_year < 90)
3226 if (ltime_start > 0)
3227 if (ltime_current < ltime_start)
3231 if (ltime_end > 0) {
3232 if (ltime_current > ltime_end)
3240 if ((psystem.length()>0) && !
equal_ustring(psystem.c_str(), system))
3243 if (pauthor.length()>0) {
3244 mstrlcpy(
str, pauthor.c_str(),
sizeof(
str));
3245 for (
i = 0;
i < (int) strlen(
str);
i++)
3248 for (
i = 0;
i < (int) strlen(author) && author[
i] !=
'@';
i++)
3249 str2[
i] = toupper(author[
i]);
3252 if (strstr(str2,
str) == NULL)
3256 if (psubject.length()>0) {
3257 mstrlcpy(
str, psubject.c_str(),
sizeof(
str));
3258 for (
i = 0;
i < (int) strlen(
str);
i++)
3261 for (
i = 0;
i < (int) strlen(subject);
i++)
3262 str2[
i] = toupper(subject[
i]);
3265 if (strstr(str2,
str) == NULL)
3269 if (psubtext.length()>0) {
3270 mstrlcpy(
str, psubtext.c_str(),
sizeof(
str));
3271 for (
i = 0;
i < (int) strlen(
str);
i++)
3274 for (
i = 0;
i < (int) strlen(text);
i++)
3275 str2[
i] = toupper(text[
i]);
3278 if (strstr(str2,
str) == NULL)
3284 MJsonNode* msg = MJsonNode::MakeObject();
3287 msg->AddToObject(
"tag", MJsonNode::MakeString(this_tag.c_str()));
3289 msg->AddToObject(
"date", MJsonNode::MakeString(date));
3290 msg->AddToObject(
"run", MJsonNode::MakeInt(
run));
3292 msg->AddToObject(
"author", MJsonNode::MakeString(author));
3294 msg->AddToObject(
"type", MJsonNode::MakeString(
type));
3296 msg->AddToObject(
"system", MJsonNode::MakeString(system));
3298 msg->AddToObject(
"subject", MJsonNode::MakeString(subject));
3300 msg->AddToObject(
"text", MJsonNode::MakeString(text));
3302 msg->AddToObject(
"orig_tag", MJsonNode::MakeString(orig_tag));
3304 msg->AddToObject(
"reply_tag", MJsonNode::MakeString(reply_tag));
3306 msg->AddToObject(
"attachment0", MJsonNode::MakeString(attachment[0]));
3308 msg->AddToObject(
"attachment1", MJsonNode::MakeString(attachment[1]));
3310 msg->AddToObject(
"attachment2", MJsonNode::MakeString(attachment[2]));
3312 msg->AddToObject(
"encoding", MJsonNode::MakeString(encoding));
3314 msg_array->AddToArray(msg);
3326 doc->
D(
"Delete elog message");
3327 doc->
P(
"tag", MJSON_STRING,
"tag of message to delete");
3328 doc->
R(
"status", MJSON_INT,
"return status of el_delete");
3332 MJsonNode* error = NULL;
3333 std::string tag =
mjsonrpc_get_param(params,
"tag", &error)->GetString();
if (error)
return error;
3349 doc->
D(
"make RPC call into frontend program via RPC_JRPC_CXX");
3350 doc->
P(
"client_name", MJSON_STRING,
"Connect to this MIDAS client, see cm_connect_client()");
3351 doc->
P(
"cmd", MJSON_STRING,
"Command passed to client");
3352 doc->
P(
"args", MJSON_STRING,
"Parameters passed to client as a string, could be JSON encoded");
3353 doc->
R(
"reply", MJSON_STRING,
"Reply from client as a string, could be JSON encoded");
3354 doc->
R(
"status", MJSON_INT,
"return status of cm_connect_client() and rpc_client_call()");
3358 MJsonNode* error = NULL;
3360 std::string
name =
mjsonrpc_get_param(params,
"client_name", &error)->GetString();
if (error)
return error;
3361 std::string cmd =
mjsonrpc_get_param(params,
"cmd", &error)->GetString();
if (error)
return error;
3362 std::string args =
mjsonrpc_get_param(params,
"args", &error)->GetString();
if (error)
return error;
3390 MJsonNode*
rn = MJsonNode::MakeString(reply.c_str());
3399 doc->
D(
"make RPC call into frontend program via RPC_JRPC");
3400 doc->
P(
"client_name", MJSON_STRING,
"Connect to this MIDAS client, see cm_connect_client()");
3401 doc->
P(
"cmd", MJSON_STRING,
"Command passed to client");
3402 doc->
P(
"args", MJSON_STRING,
"Parameters passed to client as a string, could be JSON encoded");
3403 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.");
3404 doc->
R(
"reply", MJSON_STRING,
"Reply from client as a string, could be JSON encoded");
3405 doc->
R(
"status", MJSON_INT,
"return status of cm_connect_client() and rpc_client_call()");
3409 MJsonNode* error = NULL;
3411 std::string
name =
mjsonrpc_get_param(params,
"client_name", &error)->GetString();
if (error)
return error;
3412 std::string cmd =
mjsonrpc_get_param(params,
"cmd", &error)->GetString();
if (error)
return error;
3413 std::string args =
mjsonrpc_get_param(params,
"args", &error)->GetString();
if (error)
return error;
3414 int max_reply_length =
mjsonrpc_get_param(params,
"max_reply_length", NULL)->GetInt();
3418 int buf_length = 1024;
3420 if (max_reply_length > buf_length)
3421 buf_length = max_reply_length;
3423 char* buf = (
char*)malloc(buf_length);
3426 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());
3455 MJsonNode* reply = MJsonNode::MakeString(buf);
3471 doc->
D(
"make RPC call into frontend program via RPC_BRPC_CXX");
3472 doc->
P(
"client_name", MJSON_STRING,
"Connect to this MIDAS client, see cm_connect_client()");
3473 doc->
P(
"cmd", MJSON_STRING,
"Command passed to client");
3474 doc->
P(
"args", MJSON_STRING,
"Parameters passed to client as a string, could be JSON encoded");
3475 doc->
R(
"reply", MJSON_STRING,
"Reply from client as a string, could be JSON encoded");
3476 doc->
R(
"status", MJSON_INT,
"return status of cm_connect_client() and rpc_client_call()");
3480 MJsonNode* error = NULL;
3482 std::string
name =
mjsonrpc_get_param(params,
"client_name", &error)->GetString();
if (error)
return error;
3483 std::string cmd =
mjsonrpc_get_param(params,
"cmd", &error)->GetString();
if (error)
return error;
3484 std::string args =
mjsonrpc_get_param(params,
"args", &error)->GetString();
if (error)
return error;
3496 std::vector<char> *pbuf =
new std::vector<char>;
3510 return MJsonNode::MakeArrayBuffer(pbuf);
3517 doc->
D(
"make RPC call into frontend program via RPC_BRPC");
3518 doc->
P(
"client_name", MJSON_STRING,
"Connect to this MIDAS client, see cm_connect_client()");
3519 doc->
P(
"cmd", MJSON_STRING,
"Command passed to client");
3520 doc->
P(
"args", MJSON_STRING,
"Parameters passed to client as a string, could be JSON encoded");
3521 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.");
3522 doc->
R(
"reply", MJSON_STRING,
"Reply from client as a string, could be JSON encoded");
3523 doc->
R(
"status", MJSON_INT,
"return status of cm_connect_client() and rpc_client_call()");
3527 MJsonNode* error = NULL;
3529 std::string
name =
mjsonrpc_get_param(params,
"client_name", &error)->GetString();
if (error)
return error;
3530 std::string cmd =
mjsonrpc_get_param(params,
"cmd", &error)->GetString();
if (error)
return error;
3531 std::string args =
mjsonrpc_get_param(params,
"args", &error)->GetString();
if (error)
return error;
3532 int max_reply_length =
mjsonrpc_get_param(params,
"max_reply_length", NULL)->GetInt();
3536 int buf_length = 1024;
3538 if (max_reply_length > buf_length)
3539 buf_length = max_reply_length;
3541 char* buf = (
char*)malloc(buf_length);
3544 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());
3571 return MJsonNode::MakeArrayBuffer(buf, buf_length);
3584 doc->
D(
"start and stop runs");
3585 doc->
P(
"transition", MJSON_STRING,
"requested transition: TR_START, TR_STOP, TR_PAUSE, TR_RESUME");
3586 doc->
P(
"run_number?", MJSON_INT,
"New run number, value 0 means /runinfo/run_number + 1, default is 0");
3587 doc->
P(
"async_flag?", MJSON_INT,
"Transition type. Default is multithreaded transition TR_MTHREAD");
3588 doc->
P(
"debug_flag?", MJSON_INT,
"See cm_transition(), value 1: trace to stdout, value 2: trace to midas.log");
3589 doc->
R(
"status", MJSON_INT,
"return status of cm_transition()");
3590 doc->
R(
"error_string?", MJSON_STRING,
"return error string from cm_transition()");
3594 MJsonNode* error = NULL;
3596 std::string xtransition =
mjsonrpc_get_param(params,
"transition", &error)->GetString();
if (error)
return error;
3605 if (xtransition ==
"TR_START")
3607 else if (xtransition ==
"TR_STOP")
3609 else if (xtransition ==
"TR_PAUSE")
3611 else if (xtransition ==
"TR_RESUME")
3617 if (async_flag == 0)
3620 char error_str[1024];
3624 MJsonNode* result = MJsonNode::MakeObject();
3626 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3627 if (strlen(error_str) > 0) {
3629 result->AddToObject(
"error_string", MJsonNode::MakeString(error_str));
3681 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);
3697 s->ReplaceEvent(pevent);
3699 }
else if (
bm_match_event(s->event_id, s->trigger_mask, pevent)) {
3700 s->ReplaceEvent(pevent);
3722 s->ReplaceEvent(pevent);
3746 if (s->pevent->event_id == last_event_id
3747 && s->pevent->trigger_mask == last_trigger_mask
3748 && s->pevent->serial_number == last_serial_number
3749 && s->pevent->time_stamp == last_time_stamp) {
3765 doc->
D(
"read event buffers");
3766 doc->
P(
"buffer_name", MJSON_STRING,
"name of event buffer");
3767 doc->
P(
"event_id?", MJSON_INT,
"requested event id, -1 means any event id");
3768 doc->
P(
"trigger_mask?", MJSON_INT,
"requested trigger mask, -1 means any trigger mask");
3769 doc->
P(
"get_recent?", MJSON_BOOL,
"get last available event that matches this event request");
3770 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]");
3771 doc->
P(
"timeout_millisec?", MJSON_NUMBER,
"how long to wait for an event");
3772 doc->
R(
"binary data", MJSON_ARRAYBUFFER,
"binary event data");
3773 doc->
R(
"status", MJSON_INT,
"return status of bm_open_buffer(), bm_request_event(), bm_set_cache_size(), bm_receive_alloc()");
3777 MJsonNode* error = NULL;
3783 const MJsonNodeVector* last_event_header =
mjsonrpc_get_param(params,
"last_event_header", NULL)->GetArray();
3784 int timeout_millisec =
mjsonrpc_get_param(params,
"timeout_millisec", NULL)->GetInt();
3786 int last_event_id = 0;
3787 int last_trigger_mask = 0;
3788 int last_serial_number = 0;
3789 int last_time_stamp = 0;
3791 if (last_event_header && last_event_header->size() > 0) {
3792 if (last_event_header->size() != 4) {
3793 return mjsonrpc_make_error(-32602,
"Invalid params",
"last_event_header should be an array with 4 elements");
3796 last_event_id = (*last_event_header)[0]->GetInt();
3797 last_trigger_mask = (*last_event_header)[1]->GetInt();
3798 last_serial_number = (*last_event_header)[2]->GetInt();
3799 last_time_stamp = (*last_event_header)[3]->GetInt();
3814 HNDLE buffer_handle = 0;
3822 static std::mutex
gMutex;
3823 std::lock_guard<std::mutex> lock_guard(
gMutex);
3832 MJsonNode* result = MJsonNode::MakeObject();
3833 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3838 MJsonNode* result = MJsonNode::MakeObject();
3839 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3845 MJsonNode* result = MJsonNode::MakeObject();
3846 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3852 if (timeout_millisec <= 0)
3853 timeout_millisec = 100.0;
3856 double end_time = start_time + timeout_millisec/1000.0;
3884 return MJsonNode::MakeArrayBuffer((
char*)pevent,
event_size);
3899 MJsonNode* result = MJsonNode::MakeObject();
3900 result->AddToObject(
"status", MJsonNode::MakeInt(
status));
3914 return MJsonNode::MakeArrayBuffer((
char*)pevent,
event_size);
3917 MJsonNode* result = MJsonNode::MakeObject();
3932 doc->
D(
"get current MIDAS time using ss_millitime()");
3933 doc->
P(NULL, 0,
"there are no input parameters");
3934 doc->
R(NULL, MJSON_INT,
"current value of ss_millitime()");
3951 doc->
D(
"get alarm data");
3952 doc->
P(
"get_all?", MJSON_BOOL,
"get all alarms, even in alarm system not active and alarms not triggered");
3953 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
3954 doc->
R(
"alarm_system_active", MJSON_BOOL,
"value of ODB \"/Alarms/alarm system active\"");
3955 doc->
R(
"alarms", MJSON_OBJECT,
"alarm data, keyed by alarm name");
3956 doc->
R(
"alarms[].triggered", MJSON_BOOL,
"alarm is triggered");
3957 doc->
R(
"alarms[].active", MJSON_BOOL,
"alarm is enabled");
3958 doc->
R(
"alarms[].class", MJSON_STRING,
"alarm class");
3959 doc->
R(
"alarms[].type", MJSON_INT,
"alarm type AT_xxx");
3960 doc->
R(
"alarms[].bgcolor", MJSON_STRING,
"display background color");
3961 doc->
R(
"alarms[].fgcolor", MJSON_STRING,
"display foreground color");
3962 doc->
R(
"alarms[].message", MJSON_STRING,
"alarm ODB message field");
3963 doc->
R(
"alarms[].condition", MJSON_STRING,
"alarm ODB condition field");
3964 doc->
R(
"alarms[].evaluated_value?", MJSON_STRING,
"evaluated alarm condition (AT_EVALUATED alarms only)");
3965 doc->
R(
"alarms[].periodic_next_time?", MJSON_STRING,
"next time the periodic alarm will fire (AT_PERIODIC alarms only)");
3966 doc->
R(
"alarms[].time_triggered_first", MJSON_STRING,
"time when alarm was triggered");
3967 doc->
R(
"alarms[].show_to_user", MJSON_STRING,
"final alarm text shown to user by mhttpd");
3986 int alarm_system_active = 0;
3990 size =
sizeof(flag);
3997 alarm_system_active = flag;
3999 if (!alarm_system_active)
4002 "alarm_system_active", MJsonNode::MakeBool(alarm_system_active!=0),
4003 "alarms", MJsonNode::MakeObject());
4014 MJsonNode* alarms = MJsonNode::MakeObject();
4016 for (
int i = 0;;
i++) {
4030 size =
sizeof(flag);
4038 MJsonNode* a = MJsonNode::MakeObject();
4040 a->AddToObject(
"triggered", MJsonNode::MakeBool(flag!=0));
4043 size =
sizeof(
BOOL);
4046 a->AddToObject(
"active", MJsonNode::MakeBool(flag!=0));
4048 std::string alarm_class{
"Alarm"};
4054 a->AddToObject(
"class", MJsonNode::MakeString(alarm_class.c_str()));
4057 size =
sizeof(atype);
4060 a->AddToObject(
"type", MJsonNode::MakeInt(atype));
4062 std::string bgcol{
"red"};
4064 if (alarm_class.length() > 0) {
4065 std::string path =
msprintf(
"/Alarms/Classes/%s/Display BGColor", alarm_class.c_str());
4071 a->AddToObject(
"bgcolor", MJsonNode::MakeString(bgcol.c_str()));
4073 std::string fgcol{
"black"};
4075 if (alarm_class.length() > 0) {
4076 std::string path =
msprintf(
"/Alarms/Classes/%s/Display FGColor", alarm_class.c_str());
4082 a->AddToObject(
"fgcolor", MJsonNode::MakeString(fgcol.c_str()));
4085 if (alarm_class.length() > 0) {
4086 size =
sizeof(
BOOL);
4087 std::string path =
msprintf(
"/Alarms/Classes/%s/Alarm sound", alarm_class.c_str());
4091 a->AddToObject(
"alarm_sound", MJsonNode::MakeBool(flag!=0));
4098 a->AddToObject(
"message", MJsonNode::MakeString(msg.c_str()));
4105 a->AddToObject(
"condition", MJsonNode::MakeString(cond.c_str()));
4107 std::string show_to_user;
4115 a->AddToObject(
"evaluated_value", MJsonNode::MakeString(
value.c_str()));
4121 a->AddToObject(
"show_to_user", MJsonNode::MakeString(show_to_user.c_str()));
4123 std::string triggered_first;
4128 a->AddToObject(
"time_triggered_first", MJsonNode::MakeString(triggered_first.c_str()));
4132 size =
sizeof(last);
4141 size =
sizeof(interval);
4144 time_t tnext = last + interval;
4147 ctime_r(&tnext, ctimebuf);
4151 a->AddToObject(
"periodic_next_time", MJsonNode::MakeString(ctimebuf));
4154 alarms->AddToObject(
name, a);
4158 "alarm_system_active", MJsonNode::MakeBool(alarm_system_active!=0),
4172 doc->
D(
"js_make_subdir");
4173 doc->
P(
"subdir", MJSON_STRING,
"Create folder experiment_directory/userfiles/subdir");
4174 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
4175 doc->
R(
"path", MJSON_STRING,
"Search path");
4179 MJsonNode* error = NULL;
4181 std::string subdir =
mjsonrpc_get_param(params,
"subdir", &error)->GetString();
if (error)
return error;
4184 if (subdir.find(
"..") != std::string::npos) {
4201 path +=
"userfiles";
4204 if (access(path.c_str(), F_OK) != 0) {
4206 if (mkdir(path.c_str(), 0777) != 0) {
4212 if (subdir.length() > 0) {
4219 if (access(path.c_str(), F_OK) != 0) {
4221 if (mkdir(path.c_str(), 0777) != 0) {
4227 MJsonNode* r = MJsonNode::MakeObject();
4228 r->AddToObject(
"status", MJsonNode::MakeInt(
SUCCESS));
4230 r->AddToObject(
"path", MJsonNode::MakeString(path.c_str()));
4238 doc->
D(
"js_ext_list_files");
4239 doc->
P(
"subdir", MJSON_STRING,
"List files in experiment_directory/userfiles/subdir");
4240 doc->
P(
"fileext", MJSON_STRING,
"Filename extension");
4241 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
4242 doc->
R(
"path", MJSON_STRING,
"Search path");
4243 doc->
R(
"subdirs[]", MJSON_STRING,
"list of subdirectories");
4244 doc->
R(
"files[].filename", MJSON_STRING,
"script filename");
4245 doc->
R(
"files[].description", MJSON_STRING,
"script description");
4249 MJsonNode* error = NULL;
4250 std::string subdir =
mjsonrpc_get_param(params,
"subdir", &error)->GetString();
if (error)
return error;
4251 std::string fileext =
mjsonrpc_get_param(params,
"fileext", &error)->GetString();
if (error)
return error;
4254 if (subdir.find(
"..") != std::string::npos) {
4259 if (fileext.find(
"..") != std::string::npos) {
4287 path +=
"userfiles";
4290 if (access(path.c_str(), F_OK) != 0) {
4292 if (mkdir(path.c_str(), 0777) != 0) {
4297 if (subdir.length() > 0) {
4305 MJsonNode* s = MJsonNode::MakeArray();
4310 for (
int i=0 ;
i<
n ;
i++) {
4318 MJsonNode* f = MJsonNode::MakeArray();
4319 time_t modtime = time(NULL);
4329 for (
int i=0 ;
i<
n ;
i++) {
4331 MJsonNode* o = MJsonNode::MakeObject();
4335 std::string full_name = path;
4340 o->AddToObject(
"description", MJsonNode::MakeString(
"description"));
4342 o->AddToObject(
"modtime", MJsonNode::MakeInt(modtime));
4344 o->AddToObject(
"size", MJsonNode::MakeInt(fsize));
4351 MJsonNode* r = MJsonNode::MakeObject();
4352 r->AddToObject(
"status", MJsonNode::MakeInt(
SUCCESS));
4354 r->AddToObject(
"path", MJsonNode::MakeString(path.c_str()));
4355 r->AddToObject(
"subdirs", s);
4356 r->AddToObject(
"files", f);
4366 doc->
D(
"js_ext_save_file");
4367 doc->
P(
"filename", MJSON_STRING,
"File name, save in experiment_directory/userfiles/filename");
4368 doc->
P(
"script", MJSON_STRING,
"ASCII content");
4369 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
4370 doc->
R(
"error", MJSON_STRING,
"error text");
4376 MJsonNode* error = NULL;
4377 std::string filename =
mjsonrpc_get_param(params,
"filename", &error)->GetString();
if (error)
return error;
4378 std::string script =
mjsonrpc_get_param(params,
"script", &error)->GetString();
if (error)
return error;
4381 if (filename.find(
"..") != std::string::npos ) {
4400 return mjsonrpc_make_result(
"status", MJsonNode::MakeInt(
status),
"error", MJsonNode::MakeString(
"cm_get_experiment_database() error"));
4404 path +=
"userfiles";
4407 if (access(path.c_str(), F_OK) != 0) {
4409 if (mkdir(path.c_str(), 0777) != 0) {
4417 FILE*
fp = fopen(path.c_str(),
"w");
4421 sprintf(errstr,
"fopen() errno %d (%s)", errno, strerror(errno));
4426 fwrite(script.c_str(), script.length(), 1,
fp);
4432 std::string errstr =
"no error";
4442 doc->
D(
"js_ext_read_script");
4443 doc->
P(
"filename", MJSON_STRING,
"File name, read from experiment_directory/userfiles/filename");
4444 doc->
R(
"content", MJSON_STRING,
"ASCII file content");
4445 doc->
R(
"status", MJSON_INT,
"return status of midas library calls");
4446 doc->
R(
"error", MJSON_STRING,
"error text");
4450 MJsonNode* error = NULL;
4451 std::string filename =
mjsonrpc_get_param(params,
"filename", &error)->GetString();
if (error)
return error;
4454 if (filename.find(
"..") != std::string::npos ||
4455 filename.find(
"*") != std::string::npos) {
4465 return mjsonrpc_make_result(
"status", MJsonNode::MakeInt(
status),
"error", MJsonNode::MakeString(
"cm_get_experiment_database() error"));
4472 path +=
"userfiles";
4475 if (access(path.c_str(), F_OK) != 0) {
4477 if (mkdir(path.c_str(), 0777) != 0) {
4485 FILE*
fp = fopen(path.c_str(),
"r");
4489 sprintf(errstr,
"fopen() errno %d (%s)", errno, strerror(errno));
4494 fseek(
fp, 0, SEEK_END);
4495 size_t file_size = ftell(
fp);
4498 char* buffer =
new char[file_size+1];
4499 fread(buffer, file_size, 1,
fp);
4501 buffer[file_size] =
'\0';
4509 std::string errstr =
"no error";
4511 return mjsonrpc_make_result(
"content", MJsonNode::MakeString(
content.c_str()),
"status", MJsonNode::MakeInt(
status),
"error", MJsonNode::MakeString(errstr.c_str()));
4523 doc->
D(
"js_read_binary_file");
4524 doc->
P(
"filename", MJSON_STRING,
"File name, read from experiment_directory/userfiles/filename");
4525 doc->
R(
"binary data", MJSON_ARRAYBUFFER,
"Binary file content");
4526 doc->
R(
"status", MJSON_INT,
"Return status of midas library calls");
4527 doc->
R(
"error", MJSON_STRING,
"Error text");
4531 MJsonNode* error = NULL;
4533 if (error)
return error;
4536 if (filename.find(
"..") != std::string::npos ||
4537 filename.find(
"*") != std::string::npos) {
4547 return mjsonrpc_make_result(
"status", MJsonNode::MakeInt(
status),
"error", MJsonNode::MakeString(
"cm_get_experiment_database() error"));
4554 path +=
"userfiles";
4557 if (access(path.c_str(), F_OK) != 0) {
4559 if (mkdir(path.c_str(), 0777) != 0) {
4567 FILE*
fp = fopen(path.c_str(),
"rb");
4571 sprintf(errstr,
"fopen() errno %d (%s)", errno, strerror(errno));
4576 fseek(
fp, 0, SEEK_END);
4577 size_t file_size = ftell(
fp);
4580 char* buffer =
new char[file_size];
4581 fread(buffer, file_size, 1,
fp);
4587 std::string errstr =
"no error";
4589 MJsonNode* result = MJsonNode::MakeArrayBuffer(buffer, file_size);
4604 doc->
D(
"get current value of mjsonrpc_debug");
4605 doc->
P(NULL, 0,
"there are no input parameters");
4606 doc->
R(NULL, MJSON_INT,
"current value of mjsonrpc_debug");
4617 doc->
D(
"set new value of mjsonrpc_debug");
4618 doc->
P(NULL, MJSON_INT,
"new value of mjsonrpc_debug");
4619 doc->
R(NULL, MJSON_INT,
"new value of mjsonrpc_debug");
4631 doc->
D(
"get current value of mjsonrpc_sleep");
4632 doc->
P(NULL, 0,
"there are no input parameters");
4633 doc->
R(NULL, MJSON_INT,
"current value of mjsonrpc_sleep");
4644 doc->
D(
"set new value of mjsonrpc_sleep");
4645 doc->
P(NULL, MJSON_INT,
"new value of mjsonrpc_sleep");
4646 doc->
R(NULL, MJSON_INT,
"new value of mjsonrpc_sleep");
4658 doc->
D(
"get current value of mjsonrpc_time");
4659 doc->
P(NULL, 0,
"there are no input parameters");
4660 doc->
R(NULL, MJSON_INT,
"current value of mjsonrpc_time");
4671 doc->
D(
"set new value of mjsonrpc_time");
4672 doc->
P(NULL, MJSON_INT,
"new value of mjsonrpc_time");
4673 doc->
R(NULL, MJSON_INT,
"new value of mjsonrpc_time");
4685 doc->
D(
"Get the MIDAS JSON-RPC schema JSON object");
4686 doc->
P(NULL, 0,
"there are no input parameters");
4687 doc->
R(NULL, MJSON_OBJECT,
"returns the MIDAS JSON-RPC schema JSON object");
4698 doc->
D(
"get current server timezone offset in seconds");
4699 doc->
P(NULL, 0,
"there are no input parameters");
4700 doc->
R(NULL, MJSON_INT,
"offset in seconds");
4705 time_t rawtime = time(NULL);
4707 gmtime_r(&rawtime, &gmt_tms);
4710 localtime_r(&rawtime, &tms);
4711 time_t
offset = rawtime - gmt + (tms.tm_isdst ? 3600 : 0);
4739 e.fNeedsLocking = needs_locking;
4745 gMutex = (std::mutex*)mutex;
4751 printf(
"mjsonrpc_init!\n");
4839 printf(
"mjsonrpc_exit!\n");
4848 MJsonNode* s = MJsonNode::MakeObject();
4850 s->AddToObject(
"$schema", MJsonNode::MakeString(
"http://json-schema.org/schema#"));
4851 s->AddToObject(
"id", MJsonNode::MakeString(
"MIDAS JSON-RPC autogenerated schema"));
4852 s->AddToObject(
"title", MJsonNode::MakeString(
"MIDAS JSON-RPC schema"));
4853 s->AddToObject(
"description", MJsonNode::MakeString(
"Autogenerated schema for all MIDAS JSON-RPC methods"));
4854 s->AddToObject(
"type", MJsonNode::MakeString(
"object"));
4856 MJsonNode* m = MJsonNode::MakeObject();
4862 MJsonNode* doc = iterator->second.fHandler(NULL);
4864 doc = MJsonNode::MakeObject();
4865 m->AddToObject(iterator->first.c_str(), doc);
4868 s->AddToObject(
"properties", m);
4869 s->AddToObject(
"required", MJsonNode::MakeArray());
4880static void mjsonrpc_print_schema()
4884 std::string
str = s->Stringify(1);
4885 printf(
"MJSON-RPC schema:\n");
4886 printf(
"%s\n",
str.c_str());
4891static std::string
indent(
int x,
const char* p =
" ")
4896 for (
int i=0;
i<x;
i++)
4917 void Output(
int nest,
bool span, std::string text)
4919 if (text.length() < 1)
4931 std::vector<int> tablen;
4932 std::vector<std::string> tab;
4933 std::vector<std::string> tabx;
4935 tablen.push_back(0);
4939 std::string xtab =
"";
4941 for (
int n=0; ;
n++) {
4943 for (
unsigned i=0;
i<
fLines.size();
i++) {
4950 int l =
fLines[
i].text.length();
4957 tablen.push_back(len);
4958 tab.push_back(
indent(len,
" ") +
" | ");
4959 xtab +=
indent(len,
" ") +
" | ";
4960 tabx.push_back(xtab);
4967 for (
unsigned i=0;
i<
fLines.size();
i++) {
4974 int ipad = tablen[
n+1] -
fLines[
i].text.length();
4978 std::string hr =
indent(maxlen-tabx[
n].length(),
"-");
4981 s += std::string(
" | ") +
fLines[
i].text + pad;
4982 else if (
n == nest) {
4984 if (
n == 0 ||
n == 1)
4985 s += tabx[
n] + hr +
"\n";
4986 s += tabx[
n] +
fLines[
i].text + pad;
4989 if (
n == 0 ||
n == 1)
4990 s += tabx[
n] + hr +
"\n";
4991 s += tabx[
n] +
fLines[
i].text + pad;
5005 const MJsonNode*
d = schema->FindObjectNode(
"description");
5010 std::string xshort =
"object";
5014 const MJsonNode* properties = schema->FindObjectNode(
"properties");
5016 const MJsonNodeVector* required_list = NULL;
5017 const MJsonNode* r = schema->FindObjectNode(
"required");
5019 required_list = r->GetArray();
5022 o->
Output(nest_level,
false,
"object");
5027 const MJsonStringVector *names = properties->GetObjectNames();
5028 const MJsonNodeVector *nodes = properties->GetObjectNodes();
5030 if (!names || !nodes) {
5031 o->
Output(nest_level,
false,
"object");
5036 std::string nest =
indent(nest_level * 4);
5040 s += nest +
"<table border=1>\n";
5043 s += nest +
"<tr>\n";
5044 s += nest +
" <td colspan=3>" +
description +
"</td>\n";
5045 s += nest +
"</tr>\n";
5050 for (
unsigned i=0;
i<names->size();
i++) {
5051 std::string
name = (*names)[
i];
5052 const MJsonNode* node = (*nodes)[
i];
5054 bool required =
false;
5056 for (
unsigned j=0;
j<required_list->size();
j++)
5057 if ((*required_list)[
j])
5058 if ((*required_list)[
j]->GetString() ==
name) {
5063 bool is_array =
false;
5064 const MJsonNode*
type = node->FindObjectNode(
"type");
5065 if (
type &&
type->GetString() ==
"array")
5076 s += nest +
"<tr>\n";
5077 s += nest +
" <td>" +
name +
"</td>\n";
5078 s += nest +
" <td>";
5081 s += nest +
"</tr>\n";
5084 s += nest +
"</table>\n";
5091 const MJsonNode*
d = schema->FindObjectNode(
"description");
5096 std::string xshort =
"array";
5100 const MJsonNode* items = schema->FindObjectNode(
"items");
5103 o->
Output(nest_level,
false,
"array");
5108 const MJsonNodeVector *nodes = items->GetArray();
5111 o->
Output(nest_level,
false,
"array");
5116 std::string nest =
indent(nest_level * 4);
5122 s += nest +
"<table border=1>\n";
5125 s += nest +
"<tr>\n";
5127 s += nest +
"</tr>\n";
5132 for (
unsigned i=0;
i<nodes->size();
i++) {
5133 o->
Output(nest_level,
false,
"array of");
5135 s += nest +
"<tr>\n";
5137 s += nest +
"</tr>\n";
5140 s += nest +
"</table>\n";
5151 const MJsonNode* t = schema->FindObjectNode(
"type");
5153 type = t->GetString();
5157 const MJsonNode*
d = schema->FindObjectNode(
"description");
5165 if (
type ==
"object") {
5167 }
else if (
type ==
"array") {
5197static void add(std::string* s,
const char* text)
5200 if (s->length() > 0)
5208 const MJsonNode* version =
request->FindObjectNode(
"jsonrpc");
5209 const MJsonNode* method =
request->FindObjectNode(
"method");
5210 const MJsonNode* params =
request->FindObjectNode(
"params");
5211 const MJsonNode*
id =
request->FindObjectNode(
"id");
5213 std::string bad =
"";
5216 add(&bad,
"jsonrpc version is missing");
5218 add(&bad,
"method is missing");
5220 add(&bad,
"params is missing");
5222 add(&bad,
"id is missing");
5224 if (version && (version->GetType() != MJSON_STRING))
5225 add(&bad,
"jsonrpc version is not a string");
5226 if (version && (version->GetString() !=
"2.0"))
5227 add(&bad,
"jsonrpc version is not 2.0");
5229 if (method && (method->GetType() != MJSON_STRING))
5230 add(&bad,
"method is not a string");
5232 if (!method || bad.length() > 0) {
5234 response->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5236 response->AddToObject(
"id", id->Copy());
5238 response->AddToObject(
"id", MJsonNode::MakeNull());
5242 printf(
"mjsonrpc: invalid request: reply:\n");
5243 printf(
"%s\n",
response->Stringify().c_str());
5250 double start_time = 0;
5256 const std::string ms = method->GetString();
5257 const char* m = ms.c_str();
5259 MJsonNode* result = NULL;
5263 if (strcmp(m,
"echo") == 0) {
5265 }
else if (strcmp(m,
"error") == 0) {
5267 }
else if (strcmp(m,
"invalid_json") == 0) {
5269 printf(
"mjsonrpc: reply with invalid json\n");
5271 return MJsonNode::MakeJSON(
"this is invalid json data");
5272 }
else if (strcmp(m,
"test_nan_inf") == 0) {
5275 double nan = zero/zero;
5276 double plusinf = one/zero;
5277 double minusinf = -one/zero;
5278 MJsonNode*
n = MJsonNode::MakeArray();
5279 n->AddToArray(MJsonNode::MakeNumber(nan));
5280 n->AddToArray(MJsonNode::MakeNumber(plusinf));
5281 n->AddToArray(MJsonNode::MakeNumber(minusinf));
5283 }
else if (strcmp(m,
"test_arraybuffer") == 0) {
5285 printf(
"mjsonrpc: reply with test arraybuffer data\n");
5288 char* ptr = (
char*)malloc(size);
5289 assert(ptr != NULL);
5290 for (
size_t i=0;
i<size;
i++) {
5293 *((
short*)(ptr+4*2*1)) = 111;
5294 *((
int*)(ptr+4*2*2)) = 1234;
5295 *((
double*)(ptr+4*2*3)) = 3.14;
5296 return MJsonNode::MakeArrayBuffer(ptr, size);
5300 bool lock = s->second.fNeedsLocking;
5303 result = s->second.fHandler(params);
5307 result =
mjsonrpc_make_error(-32601,
"Method not found", (std::string(
"unknown method: ") + ms).c_str());
5312 printf(
"mjsonrpc: handler reply:\n");
5317 double end_time = 0;
5318 double elapsed_time = 0;
5321 elapsed_time = end_time - start_time;
5323 printf(
"request took %.3f seconds, method [%s]\n", elapsed_time, m);
5327 if (result->GetType() == MJSON_ARRAYBUFFER) {
5331 const MJsonNode *nerror = result->FindObjectNode(
"error");
5332 const MJsonNode *nresult = result->FindObjectNode(
"result");
5335 result->DeleteObjectNode(
"result");
5336 }
else if (nresult) {
5337 result->DeleteObjectNode(
"error");
5340 result =
mjsonrpc_make_error(-32603,
"Internal error",
"bad dispatcher reply: no result and no error");
5343 result->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5346 result->AddToObject(
"id", id->Copy());
5348 result->AddToObject(
"id", MJsonNode::MakeNull());
5352 result->AddToObject(
"elapsed_time", MJsonNode::MakeNumber(elapsed_time));
5355 assert(result != NULL);
5363 MJsonNode *
request = MJsonNode::Parse(post_data);
5368 printf(
"mjsonrpc: request:\n");
5382 if (
request->GetType() == MJSON_ERROR) {
5384 reply->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5385 reply->AddToObject(
"id", MJsonNode::MakeNull());
5388 printf(
"mjsonrpc: invalid json: reply:\n");
5389 printf(
"%s\n", reply->Stringify().c_str());
5395 }
else if (
request->GetType() == MJSON_OBJECT) {
5399 }
else if (
request->GetType() == MJSON_ARRAY) {
5400 const MJsonNodeVector* a =
request->GetArray();
5402 if (a->size() < 1) {
5403 MJsonNode* reply =
mjsonrpc_make_error(-32600,
"Invalid request",
"batch request array has less than 1 element");
5404 reply->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5405 reply->AddToObject(
"id", MJsonNode::MakeNull());
5408 printf(
"mjsonrpc: invalid json: reply:\n");
5409 printf(
"%s\n", reply->Stringify().c_str());
5417 MJsonNode* reply = MJsonNode::MakeArray();
5419 for (
unsigned i=0;
i<a->size();
i++) {
5421 reply->AddToArray(r);
5422 if (r->GetType() == MJSON_ARRAYBUFFER) {
5425 reply =
mjsonrpc_make_error(-32600,
"Invalid request",
"MJSON_ARRAYBUFFER return is not permitted for batch requests");
5426 reply->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5427 reply->AddToObject(
"id", MJsonNode::MakeNull());
5435 MJsonNode* reply =
mjsonrpc_make_error(-32600,
"Invalid request",
"request is not a JSON object or JSON array");
5436 reply->AddToObject(
"jsonrpc", MJsonNode::MakeString(
"2.0"));
5437 reply->AddToObject(
"id", MJsonNode::MakeNull());
5440 printf(
"mjsonrpc: invalid json: reply:\n");
5441 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)
INT cm_exist(const char *name, BOOL bClientName)
std::string cm_expand_env(const char *str)
int cm_exec_script(const char *odb_path_to_script)
std::string cm_get_path()
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 EXPRT db_get_value_string(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, int index, std::string *s, BOOL create, int create_string_length)
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)