Mjsonrpc: Difference between revisions
Line 12: | Line 12: | ||
Note that the JSON standard is incompatible with [https://en.wikipedia.org/wiki/IEEE_floating_point IEEE Standard for Floating-Point Arithmetic (IEEE 754)], specifically, there is no standard way to encode the special numerical values +Infinity, -Infinity and NaN ("-0.0" is ok). | Note that the JSON standard is incompatible with [https://en.wikipedia.org/wiki/IEEE_floating_point IEEE Standard for Floating-Point Arithmetic (IEEE 754)], specifically, there is no standard way to encode the special numerical values +Infinity, -Infinity and NaN ("-0.0" is ok). | ||
In MIDAS, JSON support is provided by an ODB data encoder (in odb.c), an ODB "JSON paste" decoder (in json_paste.cxx) and a general purpose JSON encoder/decoder (mjson.h, mjson.cxx). | In MIDAS, JSON support is provided by an ODB data encoder (in odb.c), an ODB "JSON paste" decoder (in json_paste.cxx) and a general purpose JSON encoder/decoder (mjson.h, mjson.cxx, see https://daq.triumf.ca/~daqweb/doc/midas-devel/html/mjson_8h.html). | ||
MIDAS JSON implementation has following variances from the JSON standard: | MIDAS JSON implementation has following variances from the JSON standard: |
Revision as of 08:46, 20 November 2015
MIDAS JSON-RPC interface
JSON general information
JSON is a lightweight data-interchange format usually associated with Javascript and web programming. It is a popular choice as replacement for older general purpose data formats such as XML. JSON is defined by RFC-7159 (read more at http://www.json.org/). When necessary, the overhead of text encoded JSON is reduced by compressing JSON documents (using gzip), or by using binary-encoded JSON.
JSON documents look like this:
{ "Runinfo" : { "State" : 1, "Online Mode" : 1, "Run number" : 13585 } }
Note that the JSON standard is incompatible with IEEE Standard for Floating-Point Arithmetic (IEEE 754), specifically, there is no standard way to encode the special numerical values +Infinity, -Infinity and NaN ("-0.0" is ok).
In MIDAS, JSON support is provided by an ODB data encoder (in odb.c), an ODB "JSON paste" decoder (in json_paste.cxx) and a general purpose JSON encoder/decoder (mjson.h, mjson.cxx, see https://daq.triumf.ca/~daqweb/doc/midas-devel/html/mjson_8h.html).
MIDAS JSON implementation has following variances from the JSON standard:
- numerical values +Infinity, -Infinity and NaN are encoded and decoded as JSON strings "Infinity", "-Infinity" and "NaN". This is compatible with most in-browser JSON implementations. See also http://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript and similar.
JSON-RPC general information
This page is a placeholder for the documentation of the MIDAS JSON RPC interface.
test
Javascript client library
MIDAS provides a simple client library: https://daq.triumf.ca/~daqweb/doc/midas-devel/resources/mhttpd.js https://daq.triumf.ca/~daqweb/doc/midas-devel/html/
Examples
$ curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","id":null,"method":"db_get_values","params":{"paths":["/runinfo/run number"]}}' 'http://localhost:8080?mjsonrpc' {"jsonrpc": "2.0","result":{"data":[324],"status":[1],"last_written":[1443570804]},"id":null} $
Schema (List of all RPC methods)
------------------------------------------------------------------------ Autogenerated schema for all MIDAS JSON-RPC methods ------------------------------------------------------------------------ cm_exist? | calls MIDAS cm_exist() to check if given MIDAS program is running | ------------------------------------------------------- | params | name | string | name of the program, corresponding to ODB /Programs/name | | unique? | bool | bUnique argument to cm_exist() | ------------------------------------------------------- | result | status | integer | return status of cm_exist() ------------------------------------------------------------------------ cm_shutdown? | calls MIDAS cm_shutdown() to stop given MIDAS program | ------------------------------------------------------- | params | name | string | name of the program, corresponding to ODB /Programs/name | | unique? | bool | bUnique argument to cm_shutdown() | ------------------------------------------------------- | result | status | integer | return status of cm_shutdown() ------------------------------------------------------------------------ db_copy? | get copies of given ODB subtrees in the "save" json encoding | ------------------------------------------------------- | params | paths[] | array of ODB subtree paths, see note on array indices | | | array of | string | ------------------------------------------------------- | result | data[] | copy of ODB data for each path | | | array of | object | | status[] | return status of db_copy_json() for each path | | | array of | integer | | last_written[] | last_written value of the ODB subtree for each path | | | array of | number ------------------------------------------------------------------------ db_create? | get copies of given ODB subtrees in the "save" json encoding | ------------------------------------------------------- | params[] | array of ODB paths to be created | | array of | arguments to db_create() and db_resize() | | | path | string | ODB path | | | type | integer | MIDAS TID_xxx type | | | array_length? | integer | optional array length, default is 1 | | | string_length? | integer | for TID_STRING, optional string length, default is NAME_LENGTH | ------------------------------------------------------- | result | status[] | return status of db_create() for each path | | | array of | integer ------------------------------------------------------------------------ db_get_values? | get values of ODB data from given subtrees | ------------------------------------------------------- | params | paths[] | array of ODB subtree paths, see note on array indices | | | array of | string | ------------------------------------------------------- | result | data[] | values of ODB data for each path, all key names are in lower case, all symlinks are followed | | | array of | any | | status[] | return status of db_copy_json() for each path | | | array of | integer | | last_written[] | last_written value of the ODB subtree for each path | | | array of | number ------------------------------------------------------------------------ db_paste? | write data into ODB | ------------------------------------------------------- | params | paths[] | array of ODB subtree paths, see note on array indices | | | array of | string | | values[] | data to be written using db_paste_json() | | | array of | any | ------------------------------------------------------- | result | status[] | return status of db_paste_json() for each path | | | array of | integer ------------------------------------------------------------------------ get_debug? | get current value of mjsonrpc_debug | ------------------------------------------------------- | params | any | there are no input parameters | ------------------------------------------------------- | result | integer | current value of mjsonrpc_debug ------------------------------------------------------------------------ get_schema? | Get the MIDAS JSON-RPC schema JSON object | ------------------------------------------------------- | params | any | there are no input parameters | ------------------------------------------------------- | result | object | returns the MIDAS JSON-RPC schema JSON object ------------------------------------------------------------------------ null? | RPC method always returns null | ------------------------------------------------------- | params | any | method parameters are ignored | ------------------------------------------------------- | result | null | always returns null ------------------------------------------------------------------------ set_debug? | set new value of mjsonrpc_debug | ------------------------------------------------------- | params | integer | new value of mjsonrpc_debug | ------------------------------------------------------- | result | integer | new value of mjsonrpc_debug ------------------------------------------------------------------------ start_program? | start MIDAS program defined in ODB /Programs/name | ------------------------------------------------------- | params | name | string | name of the program, corresponding to ODB /Programs/name | ------------------------------------------------------- | result | status | integer | return status of ss_system() ------------------------------------------------------------------------ user_example1? | example of user defined RPC method that returns up to 3 results | ------------------------------------------------------- | params | arg | string | example string argment | | optional_arg? | integer | optional example integer argument | ------------------------------------------------------- | result | string | string | returns the value of "arg" parameter | | integer | integer | returns the value of "optional_arg" parameter ------------------------------------------------------------------------ user_example2? | example of user defined RPC method that returns more than 3 results | ------------------------------------------------------- | params | arg | string | example string argment | | optional_arg? | integer | optional example integer argument | ------------------------------------------------------- | result | string1 | string | returns the value of "arg" parameter | | string2 | string | returns "hello" | | string3 | string | returns "world!" | | value1 | integer | returns the value of "optional_arg" parameter | | value2 | number | returns 3.14 ------------------------------------------------------------------------ user_example3? | example of user defined RPC method that returns an error | ------------------------------------------------------- | params | arg | integer | integer value, if zero, throws a JSON-RPC error | ------------------------------------------------------- | result | status | integer | returns the value of "arg" parameter