2 * Copyright (C) 2015, 2016 "IoT.bzh"
3 * Author "Romain Forlot" <romain.forlot@iot.bzh>
4 * Author "Loic Collignon" <loic.collignon@iot.bzh>
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <json-c/json.h>
23 #include <sys/timeb.h>
25 #include "openxc.pb.h"
28 * @fn openxc_VehicleMessage build_VehicleMessage_with_SimpleMessage(openxc_DynamicField_Type type, const openxc_SimpleMessage& message);
30 * @brief Build a specific VehicleMessage containing a SimpleMessage.
32 * @param[in] openxc_DynamicField_Type type - The type of message to build
33 * @param[in] openxc_SimpleMessage& message - simple message to include into openxc_VehicleMessage
35 * @return openxc_VehicleMessage - a vehicle message including simple message that will be convert into
36 * a JSON object before being pushed to the subscribers
38 openxc_VehicleMessage build_VehicleMessage_with_SimpleMessage(openxc_DynamicField_Type type, const openxc_SimpleMessage& message);
41 * @fn openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value);
43 * @brief Build an openxc_SimpleMessage associating a name to an openxc_DynamicField
45 * @param[in] std::string name - const string reference name to assign to the created SimpleMessage
46 * this will set has_name member to true and assign name to the name member. Maximum size for name is
48 * @param[in] openxc_DynamicField value - const reference with DynamicField to assign to SimpleMessage
51 * @return an openxc_SimpleMessage struct initialized with name and value provided.
53 openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value);
56 * @fn openxc_DynamicField build_DynamicField(const std::string& value);
58 * @brief Build an openxc_DynamicField with a string value
60 * @param std::string value - const string reference value to assign to builded
61 * openxc_DynamicField.
63 * @return openxc_DynamicField initialized with a string value.
65 openxc_DynamicField build_DynamicField(const std::string& value);
68 * @fn openxc_DynamicField build_DynamicField(double value);
70 * @brief Build an openxc_DynamicField with a double value
72 * @param double value - double value to assign to builded openxc_DynamicField.
74 * @return openxc_DynamicField initialized with a double value.
76 openxc_DynamicField build_DynamicField(double value);
79 * @fn openxc_DynamicField build_DynamicField(bool value);
81 * @brief Build an openxc_DynamicField with a boolean value
83 * @param bool value - boolean value to assign to builded openxc_DynamicField.
85 * @return openxc_DynamicField initialized with a boolean value.
87 openxc_DynamicField build_DynamicField(bool value);
90 * @fn void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value);
92 * @brief Make a JSON object from a DynamicField
94 * @param[in] openxc_DynamicField field - openxc_DynamicField struct to convert into
96 * @param[out] json_object pointer with the DynamicField converted
98 void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value);
101 * @fn openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg);
103 * @brief Extract the simple message value from an openxc_VehicleMessage
104 * and return it. If there isn't SimpleMessage in the VehicleMessage then
105 * returned value will be a SimpleMessage with all field set at false.
106 * DynamicField from SimpleMessage will be boolean DynamicField set to false too.
108 * @param[in] openxc_VehicleMessage - const reference to openxc_VehicleMessage
110 * @return openxc_SimpleMessage - SimpleMessage from the provided VehicleMessage.
112 openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg);
115 * @fn json_object* jsonify_simple(const openxc_SimpleMessage& s_msg);
117 * @brief Make a JSON object from a SimpleMessage
119 * @param[in] openxc_SimpleMessage s_msg - const reference to an openxc_SimpleMessage
120 * struct to convert into a json object.
121 * @param[out] json_object pointer with the DynamicField converted
123 * @return boolean value - true if SimpleMessage has been transformed into json object
124 * and false if not. In such case, a json object is returned { "error": "error msg"}
126 bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json);