Merge branch 'master' of https://github.com/iotbzh/afb-daemon
[src/app-framework-binder.git] / src / afb-wsj1.h
1 /*
2  * Copyright (C) 2016 "IoT.bzh"
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
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
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #pragma once
19
20 struct afb_wsj1;
21 struct afb_wsj1_msg;
22
23 struct json_object;
24
25 struct afb_wsj1_itf {
26         void (*on_hangup)(void *closure, struct afb_wsj1 *wsj1);
27         void (*on_call)(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
28         void (*on_event)(void *closure, const char *event, struct afb_wsj1_msg *msg);
29 };
30
31 extern struct afb_wsj1 *afb_wsj1_create(int fd, struct afb_wsj1_itf *itf, void *closure);
32
33 extern void afb_wsj1_addref(struct afb_wsj1 *wsj1);
34 extern void afb_wsj1_unref(struct afb_wsj1 *wsj1);
35
36 extern int afb_wsj1_send_event_s(struct afb_wsj1 *wsj1, const char *event, const char *object);
37 extern int afb_wsj1_send_event_j(struct afb_wsj1 *wsj1, const char *event, struct json_object *object);
38
39 extern int afb_wsj1_call_s(struct afb_wsj1 *wsj1, const char *api, const char *verb, const char *object, void (*on_reply)(void *closure, struct afb_wsj1_msg *msg), void *closure);
40 extern int afb_wsj1_call_j(struct afb_wsj1 *wsj1, const char *api, const char *verb, struct json_object *object, void (*on_reply)(void *closure, struct afb_wsj1_msg *msg), void *closure);
41
42 extern int afb_wsj1_reply_ok_s(struct afb_wsj1_msg *msg, const char *object, const char *token);
43 extern int afb_wsj1_reply_ok_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token);
44
45 extern int afb_wsj1_reply_error_s(struct afb_wsj1_msg *msg, const char *object, const char *token);
46 extern int afb_wsj1_reply_error_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token);
47
48 extern void afb_wsj1_msg_addref(struct afb_wsj1_msg *msg);
49 extern void afb_wsj1_msg_unref(struct afb_wsj1_msg *msg);
50
51 extern int afb_wsj1_msg_is_call(struct afb_wsj1_msg *msg);
52 extern int afb_wsj1_msg_is_reply(struct afb_wsj1_msg *msg);
53 extern int afb_wsj1_msg_is_reply_ok(struct afb_wsj1_msg *msg);
54 extern int afb_wsj1_msg_is_reply_error(struct afb_wsj1_msg *msg);
55 extern int afb_wsj1_msg_is_event(struct afb_wsj1_msg *msg);
56
57 extern const char *afb_wsj1_msg_api(struct afb_wsj1_msg *msg);
58 extern const char *afb_wsj1_msg_verb(struct afb_wsj1_msg *msg);
59 extern const char *afb_wsj1_msg_event(struct afb_wsj1_msg *msg);
60 extern const char *afb_wsj1_msg_token(struct afb_wsj1_msg *msg);
61 extern struct afb_wsj1 *afb_wsj1_msg_wsj1(struct afb_wsj1_msg *msg);
62
63 extern const char *afb_wsj1_msg_object_s(struct afb_wsj1_msg *msg);
64 extern struct json_object *afb_wsj1_msg_object_j(struct afb_wsj1_msg *msg);
65