+static void aws_send_event(struct afb_ws_json *aws, const char *event, struct json_object *object)
+{
+ json_object *root, *reply;
+ const char *message;
+
+ /* builds the answering structure */
+ root = json_object_new_object();
+ json_object_object_add(root, "jtype", json_object_new_string("afb-event"));
+ json_object_object_add(root, "event", json_object_new_string(event));
+ if (object)
+ json_object_object_add(root, "data", object);
+
+ /* make the reply */
+ reply = json_object_new_array();
+ json_object_array_add(reply, json_object_new_int(EVENT));
+ json_object_array_add(reply, json_object_new_string(event));
+ json_object_array_add(reply, root);
+ json_object_array_add(reply, json_object_new_string(aws->context->token));
+
+ /* emits the reply */
+ message = json_object_to_json_string(reply);
+ afb_ws_text(aws->ws, message, strlen(message));
+ json_object_put(reply);
+}
+