Add 'noconcurrency' when creating dynamic API
[src/app-framework-binder.git] / include / afb / afb-dynapi-itf.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 #pragma once
19
20 /* declared here */
21 struct afb_dynapi;
22 struct afb_dynapi_itf;
23
24 /* referenced here */
25 #include <stdarg.h>
26 struct sd_event;
27 struct sd_bus;
28 struct afb_request;
29 struct afb_eventid;
30 struct afb_auth;
31 struct afb_verb_v2;
32
33 /*
34  * structure for the dynapi
35  */
36 struct afb_dynapi
37 {
38         /* interface for the dynapi */
39         const struct afb_dynapi_itf *itf;
40
41         /* user defined data */
42         void *userdata;
43
44         /* current verbosity level */
45         int verbosity;
46
47         /* the name of the api */
48         const char *apiname;
49 };
50
51 /*
52  * Definition of the interface for the API
53  */
54 struct afb_dynapi_itf
55 {
56         /* CAUTION: respect the order, add at the end */
57
58         void (*vverbose)(
59                 void *dynapi,
60                 int level,
61                 const char *file,
62                 int line,
63                 const char * func,
64                 const char *fmt,
65                 va_list args);
66
67         /* gets the common systemd's event loop */
68         struct sd_event *(*get_event_loop)(
69                 void *dynapi);
70
71         /* gets the common systemd's user d-bus */
72         struct sd_bus *(*get_user_bus)(
73                 void *dynapi);
74
75         /* gets the common systemd's system d-bus */
76         struct sd_bus *(*get_system_bus)(
77                 void *dynapi);
78
79         int (*rootdir_get_fd)(
80                 void *dynapi);
81
82         int (*rootdir_open_locale)(
83                 void *dynapi,
84                 const char *filename,
85                 int flags,
86                 const char *locale);
87
88         int (*queue_job)(
89                 void *dynapi,
90                 void (*callback)(int signum, void *arg),
91                 void *argument,
92                 void *group,
93                 int timeout);
94
95         int (*require_api)(
96                 void *dynapi,
97                 const char *name,
98                 int initialized);
99
100         int (*rename_api)(
101                 void *dynapi,
102                 const char *name);
103
104         /* broadcasts event 'name' with 'object' */
105         int (*event_broadcast)(
106                 void *dynapi,
107                 const char *name,
108                 struct json_object *object);
109
110         /* creates an event of 'name' */
111         struct afb_eventid *(*eventid_make)(
112                 void *dynapi,
113                 const char *name);
114
115         void (*call)(
116                 struct afb_dynapi *dynapi,
117                 const char *api,
118                 const char *verb,
119                 struct json_object *args,
120                 void (*callback)(void*, int, struct json_object*, struct afb_dynapi *),
121                 void *callback_closure);
122
123         int (*call_sync)(
124                 void *dynapi,
125                 const char *api,
126                 const char *verb,
127                 struct json_object *args,
128                 struct json_object **result);
129
130         int (*api_new_api)(
131                 void *dynapi,
132                 const char *api,
133                 const char *info,
134                 int noconcurrency,
135                 int (*preinit)(void*, struct afb_dynapi *),
136                 void *closure);
137
138         int (*api_set_verbs_v2)(
139                 struct afb_dynapi *dynapi,
140                 const struct afb_verb_v2 *verbs);
141
142         int (*api_add_verb)(
143                 struct afb_dynapi *dynapi,
144                 const char *verb,
145                 const char *info,
146                 void (*callback)(struct afb_request *request),
147                 void *vcbdata,
148                 const struct afb_auth *auth,
149                 uint32_t session);
150
151         int (*api_sub_verb)(
152                 struct afb_dynapi *dynapi,
153                 const char *verb);
154
155         int (*api_set_on_event)(
156                 struct afb_dynapi *dynapi,
157                 void (*onevent)(struct afb_dynapi *dynapi, const char *event, struct json_object *object));
158
159         int (*api_set_on_init)(
160                 struct afb_dynapi *dynapi,
161                 int (*oninit)(struct afb_dynapi *dynapi));
162
163         void (*api_seal)(
164                 struct afb_dynapi *dynapi);
165 };
166