Adding/Fix classes constructors to make them correspond
[apps/agl-service-can-low-level.git] / src / utils / openxc-utils.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 <string>
22 #include <json-c/json.h>
23 #include <sys/timeb.h>
24
25 #include "openxc.pb.h"
26 #include "../obd2/active-diagnostic-request.hpp"
27
28 /**
29  * @brief Build a specific VehicleMessage containing a SimpleMessage.
30  *
31  * @param[in] message - simple message to include into openxc_VehicleMessage
32  *
33  * @return a vehicle message including simple message that will be convert into 
34  * a JSON object before being pushed to the subscribers
35  */
36 openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value);
37 openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message);
38
39 /**
40  * @fn openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value);
41  *
42  * @brief Build an openxc_SimpleMessage associating a name to an openxc_DynamicField
43  *
44  * @param[in] name - const string reference name to assign to the created SimpleMessage
45  *  this will set has_name member to true and assign name to the name member. Maximum size for name is 
46  *  set to 100 char.
47  * @param[in] value - const reference with DynamicField to assign to SimpleMessage
48  *  value.
49  *
50  * @return an openxc_SimpleMessage struct initialized with name and value provided.
51  */
52 openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value);
53
54 /**
55  * @fn openxc_DynamicField build_DynamicField(const std::string& value);
56  *
57  * @brief Build an openxc_DynamicField with a string value
58  *
59  * @param[in] value - const string reference value to assign to builded
60  *  openxc_DynamicField.
61  *
62  * @return openxc_DynamicField initialized with a string value.
63  */
64 openxc_DynamicField build_DynamicField(const std::string& value);
65
66 /**
67  * @fn openxc_DynamicField build_DynamicField(double value);
68  *
69  * @brief Build an openxc_DynamicField with a double value
70  *
71  * @param[in] value - double value to assign to builded openxc_DynamicField.
72  *
73  * @return openxc_DynamicField initialized with a double value.
74  */
75 openxc_DynamicField build_DynamicField(double value);
76
77 /**
78  * @fn openxc_DynamicField build_DynamicField(bool value);
79  *
80  * @brief Build an openxc_DynamicField with a boolean value
81  *
82  * @param[in] value - boolean value to assign to builded openxc_DynamicField.
83  *
84  * @return openxc_DynamicField initialized with a boolean value.
85  */
86 openxc_DynamicField build_DynamicField(bool value);
87
88 /**
89  * @fn void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value);
90  *
91  * @brief Make a JSON object from a DynamicField
92  *
93  * @param[in] field - openxc_DynamicField struct to convert into
94  *  a json object.
95  * @param[out] value - pointer to the object to set up.
96  */
97 void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value);
98
99 /**
100  * @fn openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg);
101  *
102  * @brief Extract the simple message value from an openxc_VehicleMessage
103  *  and return it. If there isn't SimpleMessage in the VehicleMessage then
104  *  returned value will be a SimpleMessage with all field set at false.
105  *  DynamicField from SimpleMessage will be boolean DynamicField set to false too.
106  *
107  * @param[in] v_msg - const reference to openxc_VehicleMessage
108  *
109  * @return A simpleMessage from the provided VehicleMessage.
110  */
111 openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg);
112
113 /**
114  * @fn json_object* jsonify_simple(const openxc_SimpleMessage& s_msg);
115  *
116  * @brief Make a JSON object from a SimpleMessage
117  *
118  * @param[in] s_msg - const reference to an openxc_SimpleMessage 
119  * struct to convert into a json object.
120  * @param[out] json - pointer with the DynamicField converted into json object
121  * 
122  * @return True if SimpleMessage has been transformed into json object
123  *  and false if not. In such case, a json object is returned { "error": "error msg"}
124  */
125 bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json);