Fix: force to pass a ref at threads launch
[apps/agl-service-can-low-level.git] / src / low-can-binding.hpp
1 /*
2  * Copyright (C) 2015, 2016 "IoT.bzh"
3  * Author "Romain Forlot" <romain.forlot@iot.bzh>
4  * Author "Loic Collignon" <loic.collignon@iot.bzh>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18  
19 #pragma once
20
21 #include <map>
22 #include <queue>
23 #include <vector>
24 #include <string>
25 #include <memory>
26 #include <thread>
27 #include <fcntl.h>
28 #include <errno.h>
29 #include <unistd.h>
30 #include <net/if.h>
31 #include <functional>
32 #include <sys/ioctl.h>
33 #include <linux/can.h>
34 #include <openxc.pb.h>
35 #include <sys/timeb.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <json-c/json.h>
39 #include <linux/can/raw.h>
40 #include <systemd/sd-event.h>
41
42 #include "timer.hpp"
43 #include "openxc.pb.h"
44 #include "can-utils.hpp"
45 #include "can-signals.hpp"
46 #include "can-decoder.hpp"
47 #include "openxc-utils.hpp"
48
49 #define MESSAGE_SET_ID 0
50
51 /*
52  *      Interface between the daemon and the binding
53  */
54 static const struct afb_binding_interface *interface;
55
56 extern "C"
57 {
58         #include <afb/afb-binding.h>
59         #include <afb/afb-service-itf.h>
60
61         static void subscribe(struct afb_req request);
62         static void unsubscribe(struct afb_req request);
63
64         /**
65         * @brief Register the binding.
66         *
67         * @desc - A binding V1 MUST have a function of this name and signature.
68         * This function is called during loading of the binding. It
69         * receives an 'interface' that should be recorded for later access to
70         * functions provided by the framework.
71         *
72         * This function MUST return the address of a structure that describes
73         * the binding and its implemented verbs.
74         *
75         * In case of initialisation error, NULL must be returned.
76         * 
77         * @param[in] const struct afb_binding_interface *itf - interface to the application framework binder.
78         * 
79         * @return pointer to the binding or NULL in case of error
80         */
81         const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *itf);
82
83         /**
84         * @brief Initialize the binding.
85         * 
86         * @param[in] service Structure which represent the Application Framework Binder.
87         * 
88         * @return Exit code, zero if success.
89         */
90         int afbBindingV1ServiceInit(struct afb_service service);
91 };
92
93 /** Can signal event map making access to afb_event
94  * external to openxc existing structure.
95  */
96 static std::map<std::string, struct afb_event> subscribed_signals;
97 static std::map<std::string, struct afb_event>::iterator subscribed_signals_i;