Simplify starting of services
[src/app-framework-binder.git] / src / afb-export.h
1 /*
2  * Copyright (C) 2016, 2017, 2018 "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 json_object;
21
22 struct afb_export;
23 struct afb_apiset;
24 struct afb_context;
25 struct afb_xreq;
26
27 struct afb_binding_v2;
28 struct afb_binding_data_v2;
29 struct afb_api_v3;
30 struct afb_api_x3;
31 struct afb_event_x2;
32
33 extern struct afb_export *afb_export_create_none_for_path(
34                                 struct afb_apiset *declare_set,
35                                 struct afb_apiset *call_set,
36                                 const char *path,
37                                 int (*creator)(void*, struct afb_api_x3*),
38                                 void *closure);
39
40 extern struct afb_export *afb_export_create_v2(
41                                 struct afb_apiset *declare_set,
42                                 struct afb_apiset *call_set,
43                                 const char *apiname,
44                                 const struct afb_binding_v2 *binding,
45                                 struct afb_binding_data_v2 *data,
46                                 int (*init)(),
47                                 void (*onevent)(const char*, struct json_object*));
48
49 extern struct afb_export *afb_export_create_v3(struct afb_apiset *declare_set,
50                                 struct afb_apiset *call_set,
51                                 const char *apiname,
52                                 struct afb_api_v3 *api);
53
54 extern struct afb_export *afb_export_addref(struct afb_export *export);
55 extern void afb_export_unref(struct afb_export *export);
56
57 extern void afb_export_destroy(struct afb_export *export);
58
59 extern int afb_export_declare(struct afb_export *export, int noconcurrency);
60 extern void afb_export_undeclare(struct afb_export *export);
61
62 extern const char *afb_export_apiname(const struct afb_export *export);
63 extern int afb_export_add_alias(struct afb_export *export, const char *apiname, const char *aliasname);
64 extern int afb_export_rename(struct afb_export *export, const char *apiname);
65 extern void afb_export_update_hooks(struct afb_export *export);
66
67 extern int afb_export_unshare_session(struct afb_export *export);
68
69 extern int afb_export_preinit_x3(
70                                 struct afb_export *export,
71                                 int (*preinit)(void *,struct afb_api_x3*),
72                                 void *closure);
73
74 extern int afb_export_handle_events_v12(
75                                 struct afb_export *export,
76                                 void (*on_event)(const char *event, struct json_object *object));
77
78
79 extern int afb_export_handle_events_v3(
80                                 struct afb_export *export,
81                                 void (*on_event)(struct afb_api_x3 *api, const char *event, struct json_object *object));
82
83
84 extern int afb_export_handle_init_v3(
85                                 struct afb_export *export,
86                                 int (*oninit)(struct afb_api_x3 *api));
87
88 extern int afb_export_start(struct afb_export *export);
89
90 extern int afb_export_logmask_get(const struct afb_export *export);
91 extern void afb_export_logmask_set(struct afb_export *export, int mask);
92
93 extern void *afb_export_userdata_get(const struct afb_export *export);
94 extern void afb_export_userdata_set(struct afb_export *export, void *data);
95
96 extern int afb_export_event_handler_add(
97                         struct afb_export *export,
98                         const char *pattern,
99                         void (*callback)(void *, const char*, struct json_object*, struct afb_api_x3*),
100                         void *closure);
101
102 extern int afb_export_event_handler_del(
103                         struct afb_export *export,
104                         const char *pattern,
105                         void **closure);
106
107 extern int afb_export_subscribe(struct afb_export *export, struct afb_event_x2 *event);
108 extern int afb_export_unsubscribe(struct afb_export *export, struct afb_event_x2 *event);
109 extern void afb_export_process_xreq(struct afb_export *export, struct afb_xreq *xreq);
110 extern void afb_export_context_init(struct afb_export *export, struct afb_context *context);
111 extern struct afb_export *afb_export_from_api_x3(struct afb_api_x3 *api);
112 extern struct afb_api_x3 *afb_export_to_api_x3(struct afb_export *export);
113
114 #if defined(WITH_LEGACY_BINDING_V1)
115
116 struct afb_service_x1;
117 struct afb_binding_interface_v1;
118
119 extern struct afb_export *afb_export_create_v1(
120                                 struct afb_apiset *declare_set,
121                                 struct afb_apiset *call_set,
122                                 const char *apiname,
123                                 int (*init)(struct afb_service_x1),
124                                 void (*onevent)(const char*, struct json_object*));
125
126 extern struct afb_binding_v1 *afb_export_register_v1(
127                                 struct afb_export *export,
128                                 struct afb_binding_v1 *(*regfun)(const struct afb_binding_interface_v1*));
129
130 #endif
131