2 * Copyright (C) 2015-2020 "IoT.bzh"
3 * Author: José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <json-c/json.h>
22 #include "afb-msg-json.h"
23 #include "afb-context.h"
25 static const char _success_[] = "success";
27 struct json_object *afb_msg_json_reply(struct json_object *resp, const char *error, const char *info, struct afb_context *context)
29 json_object *msg, *request;
30 json_object *type_reply = NULL;
32 msg = json_object_new_object();
34 json_object_object_add(msg, "response", resp);
36 type_reply = json_object_new_string("afb-reply");
37 json_object_object_add(msg, "jtype", type_reply);
39 request = json_object_new_object();
40 json_object_object_add(msg, "request", request);
41 json_object_object_add(request, "status", json_object_new_string(error ?: _success_));
44 json_object_object_add(request, "info", json_object_new_string(info));
49 struct json_object *afb_msg_json_event(const char *event, struct json_object *object)
52 json_object *type_event = NULL;
54 msg = json_object_new_object();
56 json_object_object_add(msg, "event", json_object_new_string(event));
59 json_object_object_add(msg, "data", object);
61 type_event = json_object_new_string("afb-event");
62 json_object_object_add(msg, "jtype", type_event);