diff options
author | johnny nam <johnny@dignsys.com> | 2018-08-08 15:41:57 +0900 |
---|---|---|
committer | scott park <scott.park@dignsys.com> | 2018-09-12 14:24:05 +0900 |
commit | d470a55c031dded45d245b7ee84575d8ff9f2d89 (patch) | |
tree | e7118d4f865baeb10455b8e2ec8e68407ec46b69 /inc | |
parent | 80395833451d4f9396aab36ee0d5cc606fa548b9 (diff) | |
download | co2-meter-d470a55c031dded45d245b7ee84575d8ff9f2d89.tar.gz co2-meter-d470a55c031dded45d245b7ee84575d8ff9f2d89.tar.bz2 co2-meter-d470a55c031dded45d245b7ee84575d8ff9f2d89.zip |
initial import(release): DevPlugin
Change-Id: I03dbdc59a07f2f736208ffca0f2c41b82ed42e21
Signed-off-by: scott park <scott.park@dignsys.com>
Diffstat (limited to 'inc')
-rw-r--r-- | inc/log.h | 43 | ||||
-rw-r--r-- | inc/resource/resource_co2_sensor.h | 42 | ||||
-rw-r--r-- | inc/st_things.h | 297 | ||||
-rw-r--r-- | inc/st_things_types.h | 317 | ||||
-rw-r--r-- | inc/thing.h | 25 |
5 files changed, 724 insertions, 0 deletions
diff --git a/inc/log.h b/inc/log.h new file mode 100644 index 0000000..f7178df --- /dev/null +++ b/inc/log.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 __LOG_H__ +#define __LOG_H__ + +#include <dlog.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "co2" + +#define ERR(fmt, args...) dlog_print(DLOG_ERROR, LOG_TAG, "%s : %s(%d) > "fmt"\n", rindex(__FILE__, '/') + 1, __func__, __LINE__, ##args) +#define WARN(fmt, args...) dlog_print(DLOG_WARN, LOG_TAG, "%s : %s(%d) > "fmt"\n", rindex(__FILE__, '/') + 1, __func__, __LINE__, ##args) +#define INFO(fmt, args...) dlog_print(DLOG_INFO, LOG_TAG, "%s : %s(%d) > "fmt"\n", rindex(__FILE__, '/') + 1, __func__, __LINE__, ##args) +#define DBG(fmt, args...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s : %s(%d) > "fmt"\n", rindex(__FILE__, '/') + 1, __func__, __LINE__, ##args) + +#define FN_CALL dlog_print(DLOG_DEBUG, LOG_TAG, ">>>>>>>> called") +#define FN_END dlog_print(DLOG_DEBUG, LOG_TAG, "<<<<<<<< ended") + +#ifdef __cplusplus +} +#endif + +#endif /* __LOG_H__ */ diff --git a/inc/resource/resource_co2_sensor.h b/inc/resource/resource_co2_sensor.h new file mode 100644 index 0000000..bc5a8c2 --- /dev/null +++ b/inc/resource/resource_co2_sensor.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 _RESOURCE_CO2_SENSOR_H_ +#define _RESOURCE_CO2_SENSOR_H_ + +#include <pthread.h> + +extern pthread_mutex_t mutex; + +#define UNUSED(x) (void)(x) // unused argument +#define MUTEX_LOCK pthread_mutex_lock(&mutex) +#define MUTEX_UNLOCK pthread_mutex_unlock(&mutex) +#define ADC_MAX_SIZE 1024 // adc max array size + +typedef struct __co2_sensor_data__ { // common adc variable structure + int index; + int count; // adc read count per one secound + int bsize; // sensor_value buffer size (up to ADC_MAX_SIZE) + short sensor_value[ADC_MAX_SIZE]; // save adc buffer in round-robin method + float co2_sensor_average; // co2 average value(ppm) per one secound +} co2_sensor_data_t; + +typedef struct sensor_mg811__ { + float zero_point_volts; // refer to datasheet, start co2 valtage + float max_point_volts; // refer to datasheet, max co2 voltage +} sensor_mg811_t; + +#endif /* _RESOURCE_CO2_SENSOR_H_ */ diff --git a/inc/st_things.h b/inc/st_things.h new file mode 100644 index 0000000..11b3267 --- /dev/null +++ b/inc/st_things.h @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 __ST_THINGS_H__ +#define __ST_THINGS_H__ + +#include <stdint.h> +#include <stdbool.h> + +#ifdef __ST_THINGS_RTOS__ +#include <st_things/st_things_types.h> +#else +#include "st_things_types.h" +#endif // __ST_THINGS_RTOS__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Set prefix paths (ReadOnly and ReadWrite) for configuration files for the device. + * This is Optional API, and should be used if relative location is used in + * filePath variable in JSON Configuration file. + * @param[in] ro_path Prefix Path for Read Only directory location. + * @param[in] rw_path Prefix Path for Read Write directory location. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter(both ro_path and rw_path are NULL). + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + * @retval #ST_THINGS_ERROR_STACK_ALREADY_INITIALIZED Stack already initialized. + * To set Prefix Paths, stack should be deinitilized first by calling st_things_deinitialize(). + * @retval #ST_THINGS_ERROR_STACK_RUNNING Stack is currently running. + * To set Prefix Paths, stack should be stopped first by calling st_things_stop() + * and then deinitialized by calling st_things_deinitialize(). + */ +int st_things_set_configuration_prefix_path(const char* ro_path, const char* rw_path); + +/** + * @brief Initializes things stack and returns whether easy-setup is completed or not. + * Easy-setup enable users to acquire the ownership of things and to connect the things with the cloud. + * After performing easy-setup, users can access things from anywhere through the cloud. + * In things stack, easy-setup is a primary and the first operation to be performed on the thing. + * Application running on the thing can know whether easy-setup is done already or not. + * If easy-setup is done, app can start the things stack by calling st_things_start(). + * If easy-setup is not done, app can either wait for the user interaction before starting the things stack or + * start the things stack directly without waiting for any events(This case is for those things which doesn't + * support input capability and for all other unknown cases). + * To use a new json file after initialization, stack should be deinitialized + * and stopped(if its started already). + * @param[in] json_path Path to Json file which defines a thing. Definition includes the device information, + * resources and their properties, configuration info for connectivity and easy-setup, etc. + * @param[out] easysetup_complete Indicates whether easysetup is completed already or not. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + * @retval #ST_THINGS_ERROR_STACK_ALREADY_INITIALIZED Stack already initialized. + * To initialize again, stack should be deinitilized first by calling st_things_deinitialize(). + * @retval #ST_THINGS_ERROR_STACK_RUNNING Stack is currently running. + * To initialize again, stack should be stopped first by calling st_things_stop() + * and then deinitialized by calling st_things_deinitialize(). + */ +int st_things_initialize(const char *json_path, bool *easysetup_complete); + +/** + * @brief Deinitializes things stack. + * Stack should have been initialized before calling this API. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not initialized. + * Initialize the stack by calling st_things_initialize(). + * @retval #ST_THINGS_ERROR_STACK_RUNNING Stack is currently running. + * Before deinitialize, stack needs to be stopped by calling st_things_stop(). + */ +int st_things_deinitialize(void); + +/** + * @brief Callback for handling GET request. + * @param[in] req_msg GET request message. + * @param[out] resp_rep Representation that will be set to payload of response. + * @return @c true in case of success, otherwise @c false + */ +typedef bool (*st_things_get_request_cb)(st_things_get_request_message_s *req_msg, st_things_representation_s *resp_rep); + +/** + * @brief Callback for handling SET(POST) request. + * @param[in] req_msg SET request message. + * @param[out] resp_rep Representation that will be set to payload of response. + * @return @c true in case of success, otherwise @c false + */ +typedef bool (*st_things_set_request_cb)(st_things_set_request_message_s *req_msg, st_things_representation_s *resp_rep); + +/** + * @brief Callback registration function for handling request messages. + * @details The callbacks ensure that a request message will be carried with one of the resource uris from json file of st_things_start(). + * @remarks Only one callback function can be set with this API.\n + * If multiple callbacks are set, the last one is registered only.\n + * And the callbacks are called in the internal thread, which is not detached,\n + * so application should return it to get the next callbacks. + * @param[in] get_cb Reference of the callback function to handle GET request. + * @param[in] set_cb Reference of the callback function to handle SET(POST) request. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + */ +int st_things_register_request_cb(st_things_get_request_cb get_cb, st_things_set_request_cb set_cb); + +/** + * @brief Starts things stack. + * Parses the thing definition(whose path is passed to st_things_initialize(), configures the thing, + * creates the resources and prepares it for easy-setup. + * If easy-setup is not done yet, onboarding will be started using either SoftAP or BLE connection. + * Onboarding creates an ad-hoc network between the thing and the client for performing easy-setup. + * If easy-setup is already done, thing will be connected with the cloud. + * Application can know whether easy-setup is done or not through st_things_initialize API. + * Stack should have been initialized before calling this API. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful. + * It is also used for the case that the stack is started already. + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not initialized. + * Initialize the stack by calling st_things_initialize(). + */ +int st_things_start(void); + +/** + * @brief Stops things stack. + * Removes all the data being used internally and releases all the memory allocated for the stack. + * Stack should have been initialized and started before calling this API. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not initialized. + * Initialize the stack by calling st_things_initialize(). + * @retval #ST_THINGS_ERROR_STACK_NOT_STARTED Stack is not started. + * Start the stack by calling st_things_start(). + */ +int st_things_stop(void); + +/** + * @brief Callback for getting user's opinion regarding device reset. + * @return @c true to confirm, otherwise @c to deny + */ +typedef bool (*st_things_reset_confirm_cb)(void); + +/** + * @brief Callback for carrying the result of reset. + * @param[in] is_success Result of Stack-reset. (true : success, false : failure) + */ +typedef void (*st_things_reset_result_cb)(bool is_success); + +/** + * @brief Callback registration function for Reset-Confirmation and Reset-Result functions. + * @remarks Only one callback function can be set with this API.\n + * If multiple callbacks are set, the last one is registered only.\n + And the callbacks are called in the internal thread, which is not detached,\n + * so application should return it to get the next callbacks. + * @param[in] confirm_cb Callback function that will be called to get the user's input when reset is triggered. + * @param[in] result_cb Callback function that will be called after the reset process is done. + * This parameter can be NULL if notification for result of reset is not needed. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + */ +int st_things_register_reset_cb(st_things_reset_confirm_cb confirm_cb, st_things_reset_result_cb result_cb); + +/** + * @brief Reset all the data related to security and cloud being used in the stack. + * Stack should have been initialized and started before calling this API. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not intialized. + * Initialize the stack by calling st_things_initialize(). + * @retval #ST_THINGS_ERROR_STACK_NOT_STARTED Stack is not started. + * Start the stack by calling st_things_start(). + */ +int st_things_reset(void); + +/** + * @brief Callback for carrying the randomly generated PIN info. + * @details Device should show the PIN on display. + * @param[in] pin_data PIN data in string format. + * @param[in] pin_size Length of the PIN String. + */ +typedef void (*st_things_pin_generated_cb)(const char *pin_data, const size_t pin_size); + +/** + * @brief Callback for informing the application to close the PIN display. + */ +typedef void (*st_things_pin_display_close_cb)(void); + +/** + * @brief Callback registration function for getting randomly generated PIN for the PIN-Based Ownership Transfer Request. + * @remarks Only one callback function can be set with this API.\n + * If multiple callbacks are set, the last one is registered only.\n + * And the callbacks are called in the internal thread, which is not detached,\n + * so application should return it to get the next callbacks. + * @param[in] generated_cb Callback function that will be called when device receives a Ownership Transfer request from client. + * @param[in] close_cb Callback function that will be called when Ownership Transfer is done so device can stop showing PIN on display. + * This parameter can be NULL if stop triggering is not needed. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + */ +int st_things_register_pin_handling_cb(st_things_pin_generated_cb generated_cb, st_things_pin_display_close_cb close_cb); + +/** + * @brief Callback for getting user's input regarding mutual verification. + * @return @c true true in cse of confirmed, otherwise @c false + */ +typedef bool (*st_things_user_confirm_cb)(void); + +/** + * @brief Callback registration function for getting user confirmation for MUTUAL VERIFICATION BASED JUST WORK Ownership transfer. + * @remarks Only one callback function can be set with this API.\n + * If multiple callbacks are set, the last one is registered only.\n + * And the callbacks are called in the internal thread, which is not detached,\n + * so application should return it to get the next callbacks. + * @param[in] confirm_cb Callback function that will be called when device receives a confirm request from client. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + */ +int st_things_register_user_confirm_cb(st_things_user_confirm_cb confirm_cb); + +/** + * @brief Callback for getting the current state of ST Things. + * @param[in] things_status ST Things State + */ +typedef void (*st_things_status_change_cb)(st_things_status_e things_status); + +/** + * @brief Callback registration function for getting notified when ST Things state changes. + * @remarks Only one callback function can be set with this API.\n + * If multiple callbacks are set, the last one is registered only.\n + * And the callbacks are called in the internal thread, which is not detached,\n + * so application should return it to get the next callbacks. + * @param[in] status_cb Refernce of the callback function to get ST Things status + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + */ +int st_things_register_things_status_change_cb(st_things_status_change_cb status_cb); + +/** + * @brief Notify the observers of a specific resource. + * Stack should have been initialized and started before calling this API. + * @param[in] resource_uri Resource URI of the resource which will be notified to observers. + * @return @c 0 on success, otherwise a negative error value + * @retval #ST_THINGS_ERROR_NONE Successful + * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed + * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not intialized. + * Initialize the stack by calling st_things_initialize(). + * @retval #ST_THINGS_ERROR_STACK_NOT_STARTED Stack is not started. + * Start the stack by calling st_things_start(). + */ +int st_things_notify_observers(const char *resource_uri); + +/** + * @brief Create an instance of representation. + * @remarks To destroy an instance, st_things_destroy_representation_inst() should be used. + * @return a pointer of the created representation, otherwise a null pointer if the memory is insufficient. + */ +st_things_representation_s *st_things_create_representation_inst(void); + +/** + * @brief Destroy an instance of representation. + * @param[in] rep Representation that will be destroyed. + */ +void st_things_destroy_representation_inst(st_things_representation_s *rep); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __ST_THINGS_H__ */ diff --git a/inc/st_things_types.h b/inc/st_things_types.h new file mode 100644 index 0000000..344f4b8 --- /dev/null +++ b/inc/st_things_types.h @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 __ST_THINGS_TYPES_H__ +#define __ST_THINGS_TYPES_H__ + +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +/** + * @brief Enumeration for ST Things error code. + */ +typedef enum { + ST_THINGS_ERROR_NONE = 0, /**< Successful */ + ST_THINGS_ERROR_INVALID_PARAMETER = -1, /**< Invalid parameter (If parameter is null or empty)*/ + ST_THINGS_ERROR_OPERATION_FAILED = -2, /**< Operation Failed */ + ST_THINGS_ERROR_STACK_NOT_INITIALIZED = -3, /**< Stack is not yet initialized*/ + ST_THINGS_ERROR_STACK_ALREADY_INITIALIZED = -4, /**< Stack is already initialized*/ + ST_THINGS_ERROR_STACK_NOT_STARTED = -5, /**< Stack is not yet started*/ + ST_THINGS_ERROR_STACK_RUNNING = -6, /**< Stack is currently running*/ +} st_things_error_e; + +/** + * @brief Enumeration for ST Things status. + */ +typedef enum { + ST_THINGS_STATUS_INIT = 0, /**< Initial state of ST Things */ + ST_THINGS_STATUS_ES_STARTED, /**< Easy-setup is started */ + ST_THINGS_STATUS_ES_DONE, /**< Easy-setup is done */ + ST_THINGS_STATUS_ES_FAILED_ON_OWNERSHIP_TRANSFER, /**< Easy-setup failed due to Ownership-Transfer failure */ + ST_THINGS_STATUS_CONNECTING_TO_AP, /**< Connecting to target Wi-Fi access point */ + ST_THINGS_STATUS_CONNECTED_TO_AP, /**< Connected to target Wi-Fi access point */ + ST_THINGS_STATUS_CONNECTING_TO_AP_FAILED, /**< Failed to connect to target Wi-Fi access point */ + ST_THINGS_STATUS_REGISTERING_TO_CLOUD, /**< Trying to Sign-up/Sign-in/Publish-Resource(s) to Cloud */ + ST_THINGS_STATUS_REGISTERED_TO_CLOUD, /**< Publish resource(s) to cloud is complete. Now the Thing is ready to be controlled via Cloud */ + ST_THINGS_STATUS_REGISTERING_FAILED_ON_SIGN_IN, /**< Failed to sign-in to Cloud */ + ST_THINGS_STATUS_REGISTERING_FAILED_ON_PUB_RES /**< Failed to publish resources to Cloud */ +} st_things_status_e; + +/** + * @brief Structure for Representation. + */ +typedef struct _st_things_representation +{ + void* payload; /**< Payload of representation */ + + /** + * @brief API for getting the value of string type property with a key. + * @remarks This API will return deep-copied string value as out parameter, so application must free it after use. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[out] value String value + * @return @c true if value exist, otherwise @c false + */ + bool (*get_str_value) (struct _st_things_representation* rep, const char* key, char** value); + + /** + * @brief API for getting the value of boolean type property with a key. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[out] value Bool value + * @return @c true if value exist, otherwise @c false + */ + bool (*get_bool_value) (struct _st_things_representation* rep, const char* key, bool* value); + + /** + * @brief API for getting the value of integer type property with a key. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[out] value Integer value + * @return @c true if value exist, otherwise @c false + */ + bool (*get_int_value) (struct _st_things_representation* rep, const char* key, int64_t* value); + + /** + * @brief API for getting the value of double type property with a key. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[out] value Double value + * @return @c true if value exist, otherwise @c false + */ + bool (*get_double_value) (struct _st_things_representation* rep, const char* key, double* value); + + /** + * @brief API for getting the value of byte array type property with a key. + * @remarks This API will return deep-copied byte value as out parameter, so application must free it after use. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[out] value Byte value + * @param[out] size Size of Byte value + * @return @c true if value exist, otherwise @c false + */ + bool (*get_byte_value) (struct _st_things_representation* rep, const char* key, uint8_t** value, size_t* size); + + /** + * @brief API for getting the value of object type property with a key. + * @remarks This API will return deep-copied object value as out parameter, so application must free it after use.\n + * To free an object, st_things_destroy_representation_inst() in st_things.h should be used. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[out] value Object value + * @return @c true if value exist, otherwise @c false + */ + bool (*get_object_value) (struct _st_things_representation* rep, const char* key, struct _st_things_representation** value); + + /** + * @brief API for setting the value of string type property with a key. + * @remarks This API will deep-copy the string value inside, so application still has an ownership of memory for the string value. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the value. + * @param[in] value String value. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_str_value) (struct _st_things_representation* rep, const char* key, const char* value); + + /** + * @brief API for setting the value of boolean type property with a key. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the value. + * @param[in] value Bool value. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_bool_value) (struct _st_things_representation* rep, const char* key, bool value); + + /** + * @brief API for setting the value of integer type property with a key. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the value. + * @param[in] value Integer value. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_int_value) (struct _st_things_representation* rep, const char* key, int64_t value); + + /** + * @brief API for setting the value of double type property with a key. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the value. + * @param[in] value Double value. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_double_value) (struct _st_things_representation* rep, const char* key, double value); + + /** + * @brief API for setting the value of byte array type property with a key. + * @remarks This API will deep-copy the byte value inside, so application still has an ownership of memory for the byte value. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the value. + * @param[in] value Byte value. + * @param[in] size Size of Byte value. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_byte_value) (struct _st_things_representation* rep, const char* key, const uint8_t* value, size_t size); + + /** + * @brief API for setting the value of object type property with a key. + * @remarks This API will deep-copy the object value inside, so application still has an ownership of memory for the object value. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the value. + * @param[in] value Object value. + * @return @c true if value exist, otherwise @c false + */ + bool (*set_object_value) (struct _st_things_representation* rep, const char* key, const struct _st_things_representation* value); + + /** + * @brief API for getting the value of string array type property with a key. + * @remarks This API will return deep-copied array value as out parameter, so application must free it after use. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the array type of value. + * @param[out] array Reference of the string array to where the value will be copied. + * @param[out] length Total number of elements in the array. + * @return @c true if value exist, otherwise @c false + */ + bool (*get_str_array_value) (struct _st_things_representation* rep, const char* key, char*** array, size_t* length); + + /** + * @brief API for getting the value of integer array type property with a key. + * @remarks This API will return deep-copied array value as out parameter, so application must free it after use. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the array type of value. + * @param[out] array Reference of the integer array where the value will be copied. + * @param[out] length Total number of elements in the array. + * @return @c true if value exist, otherwise @c false + */ + bool (*get_int_array_value) (struct _st_things_representation* rep, const char* key, int64_t** array, size_t* length); + + /** + * @brief API for getting the value of double array type property with a key. + * @remarks This API will return deep-copied array value as out parameter, so application must free it after use. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which will represent the array type of value. + * @param[out] array Reference of the double array where the value will be copied. + * @param[out] length Total number of elements in the array. + * @return @c true if value exist, otherwise @c false + */ + bool (*get_double_array_value) (struct _st_things_representation* rep, const char* key, double** array, size_t* length); + + /** + * @brief API for getting the value of object array type property with a key. + * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.\n + * To free each object in array, st_things_destroy_representation_inst() in st_things.h should be used. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the array type of value. + * @param[out] array Reference of the object array where the value will be copied. + * @param[out] length Total number of elements in the array. + * @return @c true if value exist, otherwise @c false + */ + bool (*get_object_array_value) (struct _st_things_representation* rep, const char* key, struct _st_things_representation*** array, size_t* length); + + /** + * @brief API for setting the value of string array type property with a key. + * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[in] array String array type value. + * @param[in] length Total number of elements in the array. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_str_array_value) (struct _st_things_representation* rep, const char* key, const char** array, size_t length); + + /** + * @brief API for setting the value of integer array type property with a key. + * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[in] array Integer array type value. + * @param[in] length Total number of elements in the array. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_int_array_value) (struct _st_things_representation* rep, const char* key, const int64_t* array, size_t length); + + /** + * @brief API for setting the value of double array type property with a key. + * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[in] array Double array type value. + * @param[in] length Total number of elements in the array. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_double_array_value) (struct _st_things_representation* rep, const char* key, const double* array, size_t length); + + /** + * @brief API for setting the value of object array type property with a key. + * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value. + * @param[in] rep Instance of Representation. + * @param[in] key Property Name which represents the value. + * @param[in] array Object array type value. + * @param[in] length Total number of elements in the array. + * @return @c true if setting value is successful, otherwise @c false + */ + bool (*set_object_array_value) (struct _st_things_representation* rep, const char* key, const struct _st_things_representation** array, size_t length); + +} st_things_representation_s; + +/** + * @brief Structure for representing the Get Request Message. + */ +typedef struct _st_things_get_request_message +{ + char* resource_uri; /**< Resource URI */ + char* query; /**< One or more query parameters of the request message. Ex: key1=value1;key2=value2;... */ + char* property_key; /**< One or more property key that application needs to set a value for response. Ex: key1;key2;... */ + + /** + * @brief API for getting the value of a specific query from the query parameters of the request. + * @param[in] req_msg Instance of get request message. + * @param[in] key Name of the query.(ex: key1, key2, etc) + * @param[out] value Value of the query.(value1, value2, etc) + * @return @c true if query exist, otherwise @c false + */ + bool (*get_query_value) (struct _st_things_get_request_message* req_msg, const char* key, char** value); + + /** + * @brief API for checking whether the request has a specific property key or not. + * @param[in] req_msg Instance of get request message. + * @param[in] key Name of the property. + * @return @c true if the property key exists, otherwise @c false + */ + bool (*has_property_key) (struct _st_things_get_request_message* req_msg, const char* key); + +} st_things_get_request_message_s; + +/** + * @brief Structure for representing the Set Request Message. + */ +typedef struct _st_things_set_request_message +{ + char* resource_uri; /**< Resource URI */ + char* query; /**< One or more query parameters of the request message. Ex: key1=value1?key2=value2?... */ + struct _st_things_representation* rep; /**< Representation of the set request message */ + + /** + * @brief API for getting the value of a specific query from the query parameters of the request. + * @param[in] req_msg Instance of request message. + * @param[in] key Name of the query.(ex: key1, key2, etc) + * @param[out] value Value of the query.(value1, value2, etc) + * @return @c true if query exist, otherwise @c false + */ + bool (*get_query_value) (struct _st_things_set_request_message* req_msg, const char* key, char** value); + +} st_things_set_request_message_s; + +#endif /* __ST_THINGS_TYPES_H__ */ diff --git a/inc/thing.h b/inc/thing.h new file mode 100644 index 0000000..e91b2d0 --- /dev/null +++ b/inc/thing.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void init_thing(); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ |