API for cloud communication 12/188712/14
authorMichal Kolodziejski <m.kolodziejs@samsung.com>
Fri, 7 Sep 2018 14:42:07 +0000 (16:42 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 14 Sep 2018 12:50:37 +0000 (12:50 +0000)
Change-Id: Ib265510e34b1b120865e20a35879ed8adbc051a2
Signed-off-by: Michal Kolodziejski <m.kolodziejs@samsung.com>
.gitignore
inc/cloud/car_info.h [new file with mode: 0644]
inc/cloud/car_info_serializer.h [new file with mode: 0644]
inc/cloud/cloud_request.h [new file with mode: 0644]
inc/cloud/http_request.h [new file with mode: 0644]

index 2a82bf0..ab20527 100644 (file)
@@ -4,3 +4,5 @@
 crash-info/
 .sign/
 /SA_Report/
+.settings/
+.vscode/
diff --git a/inc/cloud/car_info.h b/inc/cloud/car_info.h
new file mode 100644 (file)
index 0000000..2daeb0c
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CAR_INFO_H_
+#define __CAR_INFO_H_
+
+#include <stdbool.h>
+
+/**
+ * @brief The car info structure template.
+ */
+typedef struct car_info car_info_t;
+
+/**
+ * @brief Creates new instance of car_info_t.
+ * @return new car_info_t object, or NULL on error.
+ */
+car_info_t *car_info_create();
+
+/**
+ * @brief Releases car_info_t.
+ * @param[in] car_info Car info struct.
+ */
+void car_info_destroy(car_info_t *car_info);
+
+/**
+ * @brief Checks if car_info_t structure core fields are set.
+ * @param[in] car_info Car info struct.
+ * @returns Returns true if object is valid, otherwise false.
+ */
+bool car_info_is_valid(car_info_t *car_info);
+
+/**
+ * @brief Gets car id.
+ * @param[in] car_info Car info struct.
+ * @param[out] car_id The car id.
+ * @return Returns car id or NULL on error.
+ * @remark This value is valid only during car_info life.
+ */
+const char *car_info_get_car_id(car_info_t *car_info);
+
+/**
+ * @brief Sets car id.
+ * @param[in] car_info Car info struct.
+ * @param[in] car_id The car id.
+ * @return Returns 0 on success, -1 otherwise.
+ */
+int car_info_set_car_id(car_info_t *car_info, const char *car_id);
+
+/**
+ * @brief Gets car name.
+ * @param[in] car_info Car info struct.
+ * @param[out] car_id The car id.
+ * @return Returns car name or NULL on error.
+ * @remark This value is valid only during car_info life.
+ */
+const char *car_info_get_car_name(car_info_t *car_info);
+
+/**
+ * @brief Sets car name.
+ * @param[in] car_info Car info struct.
+ * @param[in] car_name The car name.
+ * @return Returns 0 on success, -1 otherwise.
+ */
+int car_info_set_car_name(car_info_t *car_info, const char *car_name);
+
+/**
+ * @brief Gets car ip.
+ * @param[in] car_info Car info struct.
+ * @param[out] car_ip The car ip.
+ * @return Returns car ip or NULL on error.
+ * @remark This value is valid only during car_info life.
+ */
+const char *car_info_get_car_ip(car_info_t *car_info);
+
+/**
+ * @brief Sets car ip.
+ * @param[in] car_info Car info struct.
+ * @param[in] car_ip The car ip.
+ * @return Returns 0 on success, -1 otherwise.
+ * @remarks Param car_ip should be valid ip address.
+ */
+int car_info_set_car_ip(car_info_t *car_info, const char *car_ip);
+
+/**
+ * @brief Gets access point mac.
+ * @param[in] car_info Car info struct.
+ * @param[out] ap_mac The access point mac address.
+ * @return Returns access po id or NULL on error.
+ * @remark This value is valid only during car_info life.
+ */
+const char *car_info_get_ap_mac(car_info_t *car_info);
+
+/**
+ * @brief Sets access point mac.
+ * @param[in] car_info Car info struct.
+ * @param[in] ap_mac The access point mac address.
+ * @return Returns 0 on success, -1 otherwise.
+ * @remarks Param ap_max should be valid mac address.
+ */
+int car_info_set_car_ap_mac(car_info_t *car_info, const char *ap_mac);
+
+/**
+ * @brief Gets access point ssid.
+ * @param[in] car_info Car info struct.
+ * @param[out] ap_ssid The access point ssid.
+ * @return Returns -1 if any error occurred, 0 otherwise.
+ */
+const char *car_info_get_ap_ssid(car_info_t *car_info);
+
+/**
+ * @brief Sets access point ssid.
+ * @param[out] ap_ssid The access point ssid.
+ * @param[in] car_id The car id.
+ * @return Returns 0 on success, -1 otherwise.
+ */
+int car_info_set_ap_ssid(car_info_t *car_info, const char *ap_ssid);
+
+#endif
\ No newline at end of file
diff --git a/inc/cloud/car_info_serializer.h b/inc/cloud/car_info_serializer.h
new file mode 100644 (file)
index 0000000..ef7885d
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CAR_INFO_SERIALIZER_H_
+#define __CAR_INFO_SERIALIZER_H_
+
+#include "car_info.h"
+
+/**
+ * @brief Serializes car_info_t struct into json string.
+ * @param[in] car_info The struct with car data.
+ * @return Json with car data.
+ * @remarks Returned value should be freed.
+ */
+char *car_info_serializer_serialize(car_info_t *car_info);
+
+/**
+ * @brief Deserializes json string to array of car_info_t structs.
+ * @param[in] json_data Json string with config.
+ * @param[out] size Length of car_info_t array.
+ * @return Dynamically allocated car_info_t array or NULL on error.
+ * @remarks Returned array should be released with @free and its every element with @car_info_destroy.
+ */
+car_info_t **car_info_serializer_deserialize_array(const char *json_data, int *size);
+
+#endif
\ No newline at end of file
diff --git a/inc/cloud/cloud_request.h b/inc/cloud/cloud_request.h
new file mode 100644 (file)
index 0000000..f266d04
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CLOUD_REQUEST_H_
+#define __CLOUD_REQUEST_H_
+
+#include "car_info.h"
+
+/**
+ * @brief Called when data from HTTP /api/racing request was obtained.
+ * @param[in] car_info The array of car_info struct.
+ * @param[in] size Length of the car_info array
+ */
+typedef void(*cloud_request_car_info_data_cb)(car_info_t *car_info, int size);
+
+/**
+ * @brief Sends cloud request that obtains list of registered cars.
+ * @param[in] ap_mac Mac address of access point that device is connected to.
+ * @return Returns 0 on success, -1 otherwise.
+ */
+int cloud_request_api_racing_get(const char *ap_mac);
+
+/**
+ * @brief Sends cloud request registering the car.
+ * @param[in] car_info The car_info object with car data.
+ * @return Returns 0 on success, -1 otherwise.
+ */
+int cloud_request_api_racing_post(car_info_t *car_info);
+
+/**
+ * @brief Sets callback that will be called when data from request will be obtained.
+ * @param[in] callback Callback function.
+ */
+void cloud_request_data_cb_set(cloud_request_car_info_data_cb callback);
+
+#endif
\ No newline at end of file
diff --git a/inc/cloud/http_request.h b/inc/cloud/http_request.h
new file mode 100644 (file)
index 0000000..3f59ad7
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CLOUD_REQUEST_H_
+#define __CLOUD_REQUEST_H_
+
+/**
+ * @brief Called when data from HTTP request was obtained.
+ * @param[in] json String containing json data from cloud.
+ */
+typedef void(*request_get_data_cb)(const char *json);
+
+/**
+ * @brief Sends cloud request that obtains list of registered cars.
+ * @param[in] ap_mac Mac address of access point that device is connected to.
+ * @param[in] callback Callback function that will be invoked when data from HTTP request was obtained.
+ * @return Returns 0 on success, -1 otherwise.
+ */
+int http_request_api_racing_get(const char *ap_mac, request_get_data_cb callback);
+
+/**
+ * @brief Sends cloud request that register the car.
+ * @param[in] json Data that is about to be sent to cloud.
+ * @return Returns 0 on success, -1 otherwise.
+ */
+int http_request_api_racing_post(const char *json);
+
+#endif
\ No newline at end of file