fdev: Introduce fdev for file event handling
[src/app-framework-binder.git] / src / afb-proto-ws.h
1 /*
2  * Copyright (C) 2016, 2017 "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
19 #pragma once
20
21 struct fdev;
22 struct afb_proto_ws;
23 struct afb_proto_ws_call;
24 struct afb_proto_ws_subcall;
25 struct afb_proto_ws_describe;
26
27 struct afb_proto_ws_client_itf
28 {
29         /* can't be NULL */
30         void (*on_reply_success)(void *closure, void *request, struct json_object *result, const char *info);
31         void (*on_reply_fail)(void *closure, void *request, const char *status, const char *info);
32
33         /* can be NULL */
34         void (*on_event_create)(void *closure, const char *event_name, int event_id);
35         void (*on_event_remove)(void *closure, const char *event_name, int event_id);
36         void (*on_event_subscribe)(void *closure, void *request, const char *event_name, int event_id);
37         void (*on_event_unsubscribe)(void *closure, void *request, const char *event_name, int event_id);
38         void (*on_event_push)(void *closure, const char *event_name, int event_id, struct json_object *data);
39         void (*on_event_broadcast)(void *closure, const char *event_name, struct json_object *data);
40
41         void (*on_subcall)(void *closure, struct afb_proto_ws_subcall *subcall, void *request, const char *api, const char *verb, struct json_object *args);
42 };
43
44 struct afb_proto_ws_server_itf
45 {
46         void (*on_call)(void *closure, struct afb_proto_ws_call *call, const char *verb, struct json_object *args, const char *sessionid);
47         void (*on_describe)(void *closure, struct afb_proto_ws_describe *describe);
48 };
49
50 extern struct afb_proto_ws *afb_proto_ws_create_client(struct fdev *fdev, const struct afb_proto_ws_client_itf *itf, void *closure);
51 extern struct afb_proto_ws *afb_proto_ws_create_server(struct fdev *fdev, const struct afb_proto_ws_server_itf *itf, void *closure);
52
53 extern void afb_proto_ws_unref(struct afb_proto_ws *protows);
54 extern void afb_proto_ws_addref(struct afb_proto_ws *protows);
55
56 extern int afb_proto_ws_is_client(struct afb_proto_ws *protows);
57 extern int afb_proto_ws_is_server(struct afb_proto_ws *protows);
58
59 extern void afb_proto_ws_hangup(struct afb_proto_ws *protows);
60 extern void afb_proto_ws_on_hangup(struct afb_proto_ws *protows, void (*on_hangup)(void *closure));
61
62
63
64 extern int afb_proto_ws_client_call(struct afb_proto_ws *protows, const char *verb, struct json_object *args, const char *sessionid, void *request);
65 extern int afb_proto_ws_client_describe(struct afb_proto_ws *protows, void (*callback)(void*, struct json_object*), void *closure);
66
67 extern int afb_proto_ws_server_event_create(struct afb_proto_ws *protows, const char *event_name, int event_id);
68 extern int afb_proto_ws_server_event_remove(struct afb_proto_ws *protows, const char *event_name, int event_id);
69 extern int afb_proto_ws_server_event_push(struct afb_proto_ws *protows, const char *event_name, int event_id, struct json_object *data);
70 extern int afb_proto_ws_server_event_broadcast(struct afb_proto_ws *protows, const char *event_name, struct json_object *data);
71
72 extern void afb_proto_ws_call_addref(struct afb_proto_ws_call *call);
73 extern void afb_proto_ws_call_unref(struct afb_proto_ws_call *call);
74
75 extern int afb_proto_ws_call_success(struct afb_proto_ws_call *call, struct json_object *obj, const char *info);
76 extern int afb_proto_ws_call_fail(struct afb_proto_ws_call *call, const char *status, const char *info);
77
78 extern int afb_proto_ws_call_subcall(struct afb_proto_ws_call *call, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure);
79 extern int afb_proto_ws_call_subscribe(struct afb_proto_ws_call *call, const char *event_name, int event_id);
80 extern int afb_proto_ws_call_unsubscribe(struct afb_proto_ws_call *call, const char *event_name, int event_id);
81
82 extern int afb_proto_ws_subcall_reply(struct afb_proto_ws_subcall *subcall, int status, struct json_object *result);
83
84 extern int afb_proto_ws_describe_put(struct afb_proto_ws_describe *describe, struct json_object *description);
85