summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJin Yoon <jinny.yoon@samsung.com>2017-10-24 12:03:35 +0000
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>2017-10-24 12:03:35 +0000
commit0ce860cd380923fa6092d41641bfe385108d74af (patch)
treef7550c0ae4c8b913b121a88d3a2bb5f9a7914369
parentd86240b21c2add18a9c90d98350658d7c9c39c11 (diff)
parent0826420d5b27bfaa663d7ba89c7cf0b44ce2fe7b (diff)
downloadposition-finder-server-0ce860cd380923fa6092d41641bfe385108d74af.tar.gz
position-finder-server-0ce860cd380923fa6092d41641bfe385108d74af.tar.bz2
position-finder-server-0ce860cd380923fa6092d41641bfe385108d74af.zip
Merge "Adds APIs related to connectivity"
-rw-r--r--inc/connectivity.h28
-rw-r--r--src/connectivity.c66
2 files changed, 84 insertions, 10 deletions
diff --git a/inc/connectivity.h b/inc/connectivity.h
index b88f83a..5165dda 100644
--- a/inc/connectivity.h
+++ b/inc/connectivity.h
@@ -50,33 +50,43 @@ extern int connectivity_set_resource(const char *path, const char *type, connect
extern void connectivity_unset_resource(connectivity_resource_s *resource);
/**
- * @brief Notifies specific clients that resource's attributes have changed with boolean value.
+ * @brief Notifies a resource's value to observed clients.
* @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A new key to be added into attributes
- * @param[in] value A boolean value to be added into attributes
+ * @param[in] key A key to be sended.
+ * @param[in] value A value to be sended.
* @return 0 on success, otherwise a negative error value
* @see If key is already exists, current value will be replaced with new value.
*/
extern int connectivity_notify_bool(connectivity_resource_s *resource_info, const char *key, bool value);
/**
- * @brief Notifies specific clients that resource's attributes have changed with int value.
+ * @brief Notifies a resource's value to observed clients.
* @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A new key to be added into attributes
- * @param[in] value A int value to be added into attributes
+ * @param[in] key A key to be sended.
+ * @param[in] value A value to be sended.
* @return 0 on success, otherwise a negative error value
* @see If key is already exists, current value will be replaced with new value.
*/
extern int connectivity_notify_int(connectivity_resource_s *resource_info, const char *key, int value);
/**
- * @brief Notifies specific clients that resource's attributes have changed with double value.
+ * @brief Notifies a resource's value to observed clients.
* @param[in] resource_info A structure containing information about connectivity resource
- * @param[in] key A new key to be added into attributes
- * @param[in] value A double value to be added into attributes
+ * @param[in] key A key to be sended.
+ * @param[in] value A value to be sended.
* @return 0 on success, otherwise a negative error value
* @see If key is already exists, current value will be replaced with new value.
*/
extern int connectivity_notify_double(connectivity_resource_s *resource_info, const char *key, double value);
+/**
+ * @brief Notifies a resource's value to observed clients.
+ * @param[in] resource_info A structure containing information about connectivity resource
+ * @param[in] key A key to be sended.
+ * @param[in] value A value to be sended.
+ * @return 0 on success, otherwise a negative error value
+ * @see If key is already exists, current value will be replaced with new value.
+ */
+extern int connectivity_notify_string(connectivity_resource_s *resource_info, const char *key, char *value);
+
#endif /* __POSITION_FINDER_CONNECTIVITY_H__ */
diff --git a/src/connectivity.c b/src/connectivity.c
index 3154e2d..cc2c547 100644
--- a/src/connectivity.c
+++ b/src/connectivity.c
@@ -186,6 +186,45 @@ error:
return NULL;
}
+static iotcon_representation_h _create_representation_with_string(connectivity_resource_s *resource_info, const char *key, char *value)
+{
+ iotcon_attributes_h attributes = NULL;
+ iotcon_representation_h representation = NULL;
+ char *uri_path = NULL;
+ int ret = -1;
+
+ ret = iotcon_resource_get_uri_path(resource_info->res, &uri_path);
+ retv_if(IOTCON_ERROR_NONE != ret, NULL);
+
+ ret = iotcon_representation_create(&representation);
+ retv_if(IOTCON_ERROR_NONE != ret, NULL);
+
+ ret = iotcon_attributes_create(&attributes);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ ret = iotcon_representation_set_uri_path(representation, uri_path);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ ret = iotcon_attributes_add_str(attributes, PATH, resource_info->path);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ ret = iotcon_attributes_add_str(attributes, key, value);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ ret = iotcon_representation_set_attributes(representation, attributes);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ iotcon_attributes_destroy(attributes);
+
+ return representation;
+
+error:
+ if (attributes) iotcon_attributes_destroy(attributes);
+ if (representation) iotcon_representation_destroy(representation);
+
+ return NULL;
+}
+
static void _print_iotcon_error(int err_no)
{
switch (err_no) {
@@ -262,7 +301,7 @@ int connectivity_notify_double(connectivity_resource_s *resource_info, const cha
retv_if(!resource_info, -1);
retv_if(!resource_info->observers, -1);
- _D("Notify the value[%f]", value);
+ _D("Notify the value [%.2lf]", value);
representation = _create_representation_with_double(resource_info, key, value);
retv_if(!representation, -1);
@@ -279,6 +318,31 @@ int connectivity_notify_double(connectivity_resource_s *resource_info, const cha
return 0;
}
+int connectivity_notify_string(connectivity_resource_s *resource_info, const char *key, char *value)
+{
+ iotcon_representation_h representation;
+ int ret = -1;
+
+ retv_if(!resource_info, -1);
+ retv_if(!resource_info->observers, -1);
+
+ _D("Notify the value [%s]", value);
+
+ representation = _create_representation_with_string(resource_info, key, value);
+ retv_if(!representation, -1);
+
+ ret = iotcon_resource_notify(resource_info->res, representation, resource_info->observers, IOTCON_QOS_LOW);
+ if (IOTCON_ERROR_NONE != ret) {
+ _I("There are some troubles for notifying value[%d]", ret);
+ _print_iotcon_error(ret);
+ return -1;
+ }
+
+ _destroy_representation(representation);
+
+ return 0;
+}
+
static bool _query_cb(const char *key, const char *value, void *user_data)
{
_D("Key : [%s], Value : [%s]", key, value);