+PUBLIC void ucs2_subscriberx (afb_req_t request) {
+
+ if (!eventDataRx) {
+
+ eventDataRx = malloc(sizeof(EventDataRx_t));
+ if (eventDataRx) {
+ eventDataRx->rx_event = afb_api_make_event(afbBindingRoot, "rx-message");
+ }
+
+ if (!eventDataRx || !afb_event_is_valid(eventDataRx->rx_event)) {
+ afb_req_reply(request, NULL, "create-event", "Cannot create or register event");
+ goto OnExitError;
+ }
+ }
+
+ if (afb_req_subscribe(request, eventDataRx->rx_event) != 0) {
+
+ afb_req_reply (request, NULL, "subscribe-event", "Cannot subscribe to event");
+ goto OnExitError;
+ }
+
+ afb_req_reply(request,NULL, NULL,"event subscription successful");
+
+OnExitError:
+ return;
+}
+
+static json_object * ucs2_validate_command (afb_req_t request,
+ const char* func_name) {
+
+ struct json_object *j_obj = NULL;
+
+ if (!ucsContextS) { /* check UNICENS is initialized */
+ afb_req_reply_f(request, NULL, "unicens-init",
+ "Load a configuration before calling %s.",
+ func_name);
+ goto OnErrorExit;
+ }
+
+ j_obj = afb_req_json(request);
+ if (!j_obj) {
+ afb_req_reply_f(request, NULL,
+ "query-notjson","query=%s not a valid json entry",
+ afb_req_value(request,""));
+ goto OnErrorExit;
+ }
+
+ AFB_API_DEBUG(afbBindingRoot, "request: %s", json_object_to_json_string(j_obj));
+
+ if (json_object_get_type(j_obj)==json_type_array) {
+ int len = json_object_array_length(j_obj);
+
+ if (len == 1) { /* only support 1 command in array */
+ j_obj = json_object_array_get_idx(j_obj, 0);
+ }
+ else {
+ afb_req_reply_f(request, NULL,
+ "query-array",
+ "query of multiple %s commands is not supported",
+ func_name);
+ j_obj = NULL;
+ goto OnErrorExit;
+ }
+ }
+
+ OnErrorExit:
+ return j_obj;
+}
+