afb-svc: make service existing during its initialisation
[src/app-framework-binder.git] / src / afb-svc.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 struct afb_svc;
21 struct afb_service;
22 struct afb_session;
23 struct afb_apiset;
24 struct afb_evt_listener;
25 struct afb_binding_data_v2;
26
27 struct json_object;
28
29 /*
30  * Structure for recording service
31  */
32 struct afb_svc
33 {
34         /* api/prefix */
35         const char *api;
36
37         /* session of the service */
38         struct afb_session *session;
39
40         /* the apiset for the service */
41         struct afb_apiset *apiset;
42
43         /* event listener of the service or NULL */
44         struct afb_evt_listener *listener;
45
46         /* on event callback for the service */
47         void (*on_event)(const char *event, struct json_object *object);
48
49         /* hooking flags */
50         int hookflags;
51 };
52
53 extern void afb_svc_destroy(struct afb_svc *svc, struct afb_service *service);
54
55 extern struct afb_svc *afb_svc_create(
56                         const char *api,
57                         struct afb_apiset *apiset,
58                         int share_session,
59                         void (*on_event)(const char *event, struct json_object *object),
60                         struct afb_service *service);
61
62 extern int afb_svc_start_v1(struct afb_svc *svc, int (*start)(struct afb_service));
63 extern int afb_svc_start_v2(struct afb_svc *svc, int (*start)());
64
65 extern void afb_svc_update_hook(struct afb_svc *svc);
66