- memory leak and etc.
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
return TRUE;
}
+void _free_device(gpointer data)
+{
+ companion_device_information_destroy(data);
+}
+
int main(int arg, char **argv)
{
GMainLoop *mainloop = NULL;
OUT:
if (found_group_list)
- g_list_free(found_group_list);
+ g_list_free_full(found_group_list, _free_device);
if (found_device_list)
- g_list_free(found_device_list);
+ g_list_free_full(found_device_list, _free_device);
companion_deinitialize();
} comp_error_e;
typedef enum {
- COMPANION_GROUP_TYPE_MINE = 0, /**< My own group */
- COMPANION_GROUP_TYPE_REMOTE, /**< Groups in remote devices */
+ COMPANION_GROUP_TYPE_ERROR = 0, /**< Error */
+ COMPANION_GROUP_TYPE_MINE = 1, /**< Local type */
+ COMPANION_GROUP_TYPE_REMOTE = 2, /**< Remote type */
} companion_group_type_e;
typedef void *companion_group_h;
#define LOG_TAG "COMP_MANAGER_CAPI"
#define _ERR(fmt, ...) \
- do { \
- LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__); \
- } while (0)
+ do { \
+ LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__); \
+ } while (0)
#define _INFO(fmt, ...) \
- do { \
- LOGI(COLOR_GREEN fmt COLOR_END, ##__VA_ARGS__); \
- } while (0)
+ do { \
+ LOGI(COLOR_GREEN fmt COLOR_END, ##__VA_ARGS__); \
+ } while (0)
#define _WARN(fmt, ...) \
- do { \
- LOGI(COLOR_BROWN fmt COLOR_END, ##__VA_ARGS__); \
- } while (0)
+ do { \
+ LOGI(COLOR_BROWN fmt COLOR_END, ##__VA_ARGS__); \
+ } while (0)
#define _DBG(fmt, ...) \
- do { \
- LOGD(fmt, ##__VA_ARGS__); \
- } while (0)
+ do { \
+ LOGD(fmt, ##__VA_ARGS__); \
+ } while (0)
#define _BEGIN() \
- do { \
- LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END); \
- } while (0)
+ do { \
+ LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END); \
+ } while (0)
#define _END() \
- do { \
- LOGD(COLOR_BLUE "END <<<<" COLOR_END); \
- } while (0)
+ do { \
+ LOGD(COLOR_BLUE "END <<<<" COLOR_END); \
+ } while (0)
#define cond_expr_ret(expr, val) \
- do { \
- if (expr) { \
- _ERR("[precond fail] expr : %s, ret : %d\n", #expr, val); \
- return (val); \
- } \
- } while (0)
+ do { \
+ if (expr) { \
+ _ERR("[precond fail] expr : %s, ret : %d\n", #expr, val); \
+ return (val); \
+ } \
+ } while (0)
#define cond_ret(val) \
- do { \
- if (val) { \
- _ERR("[precond fail] ret : %d\n", val); \
- return (val); \
- } \
- } while (0)
+ do { \
+ if (val) { \
+ _ERR("[precond fail] ret : %d\n", val); \
+ return (val); \
+ } \
+ } while (0)
+
+#define companion_check_null_ret_error(name, value, error) do { \
+ /* LCOV_EXCL_START */ \
+ if (G_UNLIKELY(NULL == (value))) { \
+ LOGE("%s is NULL", name); \
+ return error; \
+ } \
+ /* LCOV_EXCL_STOP */ \
+} while (FALSE)
+
+#define companion_check_null_ret(name, value) do { \
+ /* LCOV_EXCL_START */ \
+ if (G_UNLIKELY(NULL == (value))) { \
+ LOGE("%s is NULL", name); \
+ return; \
+ } \
+ /* LCOV_EXCL_STOP */ \
+} while (FALSE)
+
#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
#define TC_PRT(format, args...) PRT(format"\n", ##args)
return group;
}
-static companion_device_t *_create_device_handle(char *device_id, char *ip, char *device_type, int port)
+static companion_device_t *_create_device_handle(char *device_id, char *ip,
+ char *device_type, int port)
{
companion_device_t *device = g_new0(companion_device_t, 1);
{
GVariantIter *iter = NULL;
const gchar *key;
- GVariant *key_value;
+ GVariant *key_value= NULL;
companion_group_t *group = NULL;
- char *uri_path;
- char *device_id;
- char *group_name;
- char *host_addr;
- char *resource_type;
- companion_group_type_e type;
+ char *uri_path = NULL;
+ char *device_id = NULL;
+ char *group_name = NULL;
+ char *host_addr = NULL;
+ char *resource_type = NULL;
+ companion_group_type_e type = COMPANION_GROUP_TYPE_ERROR;
g_variant_get(va, "a{sv}", &iter);
while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
g_variant_get(va, "aa{sv}", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
- char *device_id;
- char *ip;
- char *device_type;
- int port;
+ char *device_id = NULL;
+ char *ip = NULL;
+ char *device_type = NULL;
+ int port = -1;
while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
if (g_strcmp0(key, "DeviceID") == 0) {
g_variant_get(va, "aa{sv}", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
- char *device_id;
- char *ip;
- char *device_type;
- int port;
+ char *device_id = NULL;
+ char *ip = NULL;
+ char *device_type = NULL;
+ int port = -1;
while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
if (g_strcmp0(key, "DeviceID") == 0) {
return ret;
}
-int companion_group_find(int timeout, companion_group_found_cb found_cb, companion_group_find_finish_cb finish_cb, void *user_data)
+void companion_group_destroy(companion_group_t *group)
+{
+ companion_check_null_ret("group", group);
+
+ if (group->uri_path) {
+ g_free(group->uri_path);
+ group->uri_path = NULL;
+ }
+ if (group->device_id) {
+ g_free(group->device_id);
+ group->device_id = NULL;
+ }
+ if (group->group_name) {
+ g_free(group->group_name);
+ group->group_name = NULL;
+ }
+ if (group->host_addr) {
+ g_free(group->host_addr);
+ group->host_addr = NULL;
+ }
+ if (group->resource_type) {
+ g_free(group->resource_type);
+ group->resource_type = NULL;
+ }
+ g_free(group);
+ group = NULL;
+}
+
+int companion_group_find(int timeout, companion_group_found_cb found_cb,
+ companion_group_find_finish_cb finish_cb, void *user_data)
{
int ret = 0;
GError *error = NULL;
g_variant_get(va, "aa{sv}", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+
+ char *uri_path = NULL;
+ char *device_id = NULL;
+ char *group_name = NULL;
+ char *host_addr = NULL;
+ char *resource_type = NULL;
+
companion_group_t *group = NULL;
- companion_group_type_e type;
- char *uri_path;
- char *device_id;
- char *group_name;
- char *host_addr;
- char *resource_type;
+ companion_group_type_e type = COMPANION_GROUP_TYPE_ERROR;
while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
if (g_strcmp0(key, "URI") == 0) {
GVariant *va = NULL;
GVariantIter *iter = NULL;
const gchar *key;
- GVariant *key_value;
- char *deviceid;
- char *addr;
- char *ver;
- int port;
+ GVariant *key_value = NULL;
+ char *deviceid = NULL;
+ char *addr = NULL;
+ char *ver = NULL;
+ int port = -1;
group_call_get_my_mowned_device_sync(group_proxy, &va, NULL, &error);
return ret;
}
+
+static void companion_device_destroy(companion_device_t *device)
+{
+ companion_check_null_ret("device", device);
+
+ if (device->device_id) {
+ g_free(device->device_id);
+ device->device_id = NULL;
+ }
+ if (device->ip) {
+ g_free(device->ip);
+ device->ip = NULL;
+ }
+ if (device->device_type) {
+ g_free(device->device_type);
+ device->device_type = NULL;
+ }
+ g_free(device);
+ device = NULL;
+}
+
int companion_device_get_my_uuid(char **uuid)
{
int ret = 0;
/* resource type enum */
typedef enum {
- COMP_RESOURCE_TYPE_GROUP = 0,
- COMP_RESOURCE_TYPE_DEVICE,
- COMP_RESOURCE_TYPE_OPERATION,
- COMP_RESOURCE_TYPE_DATA,
+ COMP_RESOURCE_TYPE_GROUP = 0, /**< Group resource type */
+ COMP_RESOURCE_TYPE_DEVICE, /**< Device resource type */
+ COMP_RESOURCE_TYPE_OPERATION, /**< Operation resource type */
+ COMP_RESOURCE_TYPE_DATA, /**< Data resource type */
COMP_RESOURCE_TYPE_MAX
} comp_resource_type_e;
/* group type enum */
typedef enum {
- COMP_GROUP_DEVICE = 0,
- COMP_GROUP_REMOTE_DEVICE,
+ COMP_GROUP_GROUP_ERROR = 0, /**< Group type error */
+ COMP_GROUP_GROUP_LOCAL = 1, /**< Local group type */
+ COMP_GROUP_GROUP_REMOTE = 2, /**< Remote group type */
} comp_group_type_e;
/**
int comp_group_get_groups(comp_group_t ***handles, int *count); //Get all of group in my daemon
int comp_group_get_remote_devices(/* callback */); //Get all of device in network (Async)
-void comp_group_add_new_mot_device(comp_mot_device_t *device);
+int comp_group_add_new_mot_device(comp_mot_device_t *device);
void comp_group_notify_mot_enable_device_done();
int comp_group_find_mot_enabled_devices(int timeout);
GVariant *comp_group_get_remote_mot_enabled_devices();
int comp_group_get_mot_device_count();
-void comp_group_add_new_mowned_device(comp_mot_device_t *device);
+int comp_group_add_new_mowned_device(comp_mot_device_t *device);
void comp_group_notify_mowned_device_find_done();
int comp_group_find_mowned_devices();
GVariant *comp_group_get_mowned_devices();
{
#endif
-#define SVR_PATH "/tmp/.svr.dat"
+#define SVR_PATH "/tmp/.svr.dat" /**< For Temp */
typedef struct _iot_discovery_t {
- gchar *uuid;
- gchar *data;
- gchar *host;
+ gchar *uuid; /**< Device Id */
+ gchar *data; /**< Data to send */
+ gchar *host; /**< Target host IP address + Port */
} iot_discovery_t;
typedef struct _comp_command_t {
- int tid;
- int resource_type;
- comp_request_type_e command;
- gchar *uuid;
- gchar *host;
- gchar *arg1;
+ int tid; /**< Timer ID */
+ int resource_type; /**< OCF resource type */
+ comp_request_type_e command; /**< Comments set for group management */
+ gchar *uuid; /**< Device UUID */
+ gchar *host; /**< Host address + Port */
+ gchar *arg1; /**< Arguement #1 */
#ifdef SUPPORT_BASE64_ENCODING
- int arg1_len;
+ int arg1_len; /**< Arguement #1 length */
#endif
- gchar *arg2;
- gchar *arg3;
- gchar *arg4;
+ gchar *arg2; /**< Arguement #2 */
+ gchar *arg3; /**< Arguement #3 */
+ gchar *arg4; /**< Arguement #4 */
} comp_command_t;
int comp_iot_initialize();
LOGD(COLOR_BLUE "END <<<<"COLOR_END); \
} while (0)
+#define NOTUSED(var) (var = var)
+
+#define comp_check_null_ret_error(name, value, error) do { \
+ /* LCOV_EXCL_START */ \
+ if (G_UNLIKELY(NULL == (value))) { \
+ LOGE("%s is NULL", name); \
+ return error; \
+ } \
+ /* LCOV_EXCL_STOP */ \
+} while (FALSE)
+
+#define comp_check_null_ret(name, value) do { \
+ /* LCOV_EXCL_START */ \
+ if (G_UNLIKELY(NULL == (value))) { \
+ LOGE("%s is NULL", name); \
+ return; \
+ } \
+ /* LCOV_EXCL_STOP */ \
+} while (FALSE)
+
const char *comp_log_get_error_string(int result);
#endif
LOG_DEBUG("disable called using dbus successful");
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, TRUE);
enabler_complete_disable(enabler, invocation, 0);
}
typedef struct {
- char *name; //group name
- GList *device_list; //remote device UUIDs. char* type
+ char *name; /**< Group name */
+ GList *device_list; /**< Remote device UUIDs. (char* type) */
} comp_grp_t;
void __print_foreach_device(gpointer data, gpointer user_data)
void __print_groups_information()
{
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret("comp_ctx", comp_ctx);
+
LOG_DEBUG("-------------------------------------------");
g_list_foreach(comp_ctx->grp_list, __print_foreach_grp, NULL);
LOG_DEBUG("-------------------------------------------");
LOG_BEGIN();
-
ret = comp_iot_add_resource(COMP_RESOURCE_TYPE_GROUP, name);
if (ret != COMP_ERROR_NONE) {
LOG_ERR("Add resource is failed : %s", comp_log_get_error_string(ret));
}
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, COMP_ERROR_INVALID_PARAMETER);
GList *list = comp_ctx->grp_list;
GList *l;
return ret;
}
-void _free_func (gpointer data)
+static void _free_device_func(gpointer data)
{
- comp_group_t *group = (comp_group_t *)data;
+ comp_check_null_ret("data", data);
+ g_free(data);
+ data = NULL;
+}
- if (group != NULL) {
- if (group->uri_path != NULL)
- g_free(group->uri_path);
- if (group->device_id != NULL)
- g_free(group->device_id);
- if (group->group_name != NULL)
- g_free(group->group_name);
- if (group->host_addr != NULL)
- g_free(group->host_addr);
- if (group->resource_type != NULL)
- g_free(group->resource_type);
+static void _free_group_func(gpointer data)
+{
+ comp_group_t *group = (comp_group_t *)data;
+ comp_check_null_ret("group", group);
- g_free(group);
+ if (group->uri_path != NULL) {
+ g_free(group->uri_path);
+ group->uri_path = NULL;
}
+ if (group->device_id != NULL) {
+ g_free(group->device_id);
+ group->device_id = NULL;
+ }
+ if (group->group_name != NULL) {
+ g_free(group->group_name);
+ group->group_name = NULL;
+ }
+ if (group->host_addr != NULL) {
+ g_free(group->host_addr);
+ group->host_addr = NULL;
+ }
+ if (group->resource_type != NULL) {
+ g_free(group->resource_type);
+ group->resource_type = NULL;
+ }
+ g_free(group);
+ group = NULL;
}
-void _mot_enb_dev_list_free_func(gpointer data)
+static void _mot_enb_dev_list_free_func(gpointer data)
{
comp_mot_device_t *device = (comp_mot_device_t *)data;
+ comp_check_null_ret("device", device);
- if (device != NULL) {
- if (device->device_id != NULL)
- g_free(device->device_id);
- if (device->addr != NULL)
- g_free(device->addr);
- if (device->route_data != NULL)
- g_free(device->route_data);
- if (device->remote_id != NULL)
- g_free(device->remote_id);
- if (device->sec_ver != NULL)
- g_free(device->sec_ver);
-
- g_free(device);
+ if (device->device_id != NULL) {
+ g_free(device->device_id);
+ device->device_id = NULL;
}
+ if (device->addr != NULL) {
+ g_free(device->addr);
+ device->addr = NULL;
+ }
+ if (device->route_data != NULL) {
+ g_free(device->route_data);
+ device->route_data = NULL;
+ }
+ if (device->remote_id != NULL) {
+ g_free(device->remote_id);
+ device->remote_id = NULL;
+ }
+ if (device->sec_ver != NULL) {
+ g_free(device->sec_ver);
+ device->sec_ver = NULL;
+ }
+ g_free(device);
+ device = NULL;
}
int comp_group_find(int timeout)
LOG_BEGIN();
/* list freeing */
- g_list_free_full (found_group_list, _free_func);
+ g_list_free_full(found_group_list, _free_group_func);
found_group_list = NULL;
comp_command_t *cmd = g_new0(comp_command_t, 1);
-
+ comp_check_null_ret_error("cmd", cmd, COMP_ERROR_INVALID_PARAMETER);
ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_GROUP, timeout, cmd);
if (ret != COMP_ERROR_NONE) {
- LOG_ERR("Failed to discover resource : %s",
- comp_log_get_error_string(ret));
+ LOG_ERR("Failed to discover resource : %s", comp_log_get_error_string(ret));
}
LOG_END();
- return COMP_ERROR_NONE;
+ return ret;
}
GVariant *comp_group_get_found_groups()
}
group_data = g_variant_builder_end(&builder);
+ g_variant_builder_unref(&builder);
return group_data;
}
notify_group_found(group_data);
+ g_variant_builder_unref(&builder);
+
LOG_END();
return COMP_ERROR_NONE;
/* Join the remote devices in my daemon */
// Find MOT enabled devices
-void comp_group_add_new_mot_device(comp_mot_device_t *device)
+int comp_group_add_new_mot_device(comp_mot_device_t *device)
{
GList *iter = NULL;
gboolean is_exist = FALSE;
}
LOG_END();
+
+ return is_exist;
}
GVariant *comp_group_get_remote_mot_enabled_devices()
}
group_data = g_variant_builder_end(&builder);
+ g_variant_builder_unref(&builder);
return group_data;
}
int _is_pairwise_uuid(char *uuid)
{
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, -1);
GList *iter = NULL;
int comp_group_add_device_in_group(char *group_name, char *uuid)
{
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, -1);
GList *iter = NULL;
LOG_BEGIN();
comp_context_t *comp_ctx = comp_context_get_context();
-
+ comp_check_null_ret_error("comp_ctx", comp_ctx, COMP_ERROR_INVALID_PARAMETER);
#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
/*
notify_group_device_eject_result(result);
}
+int comp_group_remove_device_in_group(char *uuid)
+{
+ comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, -1);
+
+ GList *iter = NULL;
+
+ /* Find the device at every group in list */
+ iter = comp_ctx->grp_list;
+ while (iter != NULL) {
+ comp_grp_t *group = (comp_grp_t *)iter->data;
+
+ /* Find the device in devices list */
+ GList *device_iter = group->device_list;
+ while (device_iter != NULL) {
+ char *device_uuid = (char *)device_iter->data;
+ /* Lastly, we find the device in the group */
+ if (strcmp(device_uuid, uuid) == 0) {
+ /* Remove device id in devices list */
+ g_list_free_full(group->device_list, _free_device_func);
+ }
+ device_iter = g_list_next(device_iter);
+ }
+ iter = g_list_next(iter);
+ }
+ __print_groups_information();
+
+ return 0;
+}
+
//dismiss from group (async)
int comp_group_dismiss(gchar *uuid_dev1, gchar *uuid_dev2)
{
#else
ret = agent_unpair(uuid_dev1, uuid_dev2);
#endif
+ comp_group_remove_device_in_group(uuid_dev2);
LOG_END();
return ret;
}
-void comp_group_add_new_mowned_device(comp_mot_device_t *device)
+int comp_group_add_new_mowned_device(comp_mot_device_t *device)
{
GList *iter = NULL;
gboolean is_exist = FALSE;
}
LOG_END();
+
+ return is_exist;
}
GVariant *comp_group_get_mowned_devices()
}
group_data = g_variant_builder_end(&builder);
+ g_variant_builder_unref(&builder);
return group_data;
}
}
group_data = g_variant_builder_end(&builder);
+ g_variant_builder_unref(&builder);
return group_data;
}
return 0;
}
+static void _clean_platform_info(OCPlatformInfo *platform_info)
+{
+ comp_check_null_ret("platform_info", platform_info);
+
+ if (platform_info->platformID) {
+ free(platform_info->platformID);
+ platform_info->platformID = NULL;
+ }
+ if (platform_info->manufacturerName) {
+ free(platform_info->manufacturerName);
+ platform_info->manufacturerName = NULL;
+ }
+ if (platform_info->modelNumber) {
+ free(platform_info->modelNumber);
+ platform_info->modelNumber = NULL;
+ }
+ if (platform_info->platformVersion) {
+ free(platform_info->platformVersion);
+ platform_info->platformVersion = NULL;
+ }
+ if (platform_info->firmwareVersion) {
+ free(platform_info->firmwareVersion);
+ platform_info->firmwareVersion = NULL;
+ }
+}
+
int comp_iot_initialize()
{
char *device_id = NULL;
OCPlatform::Configure(cfg);
ret = __comp_iot_get_platform_info(&platform_info);
+ _clean_platform_info(&platform_info);
if (ret != 0) {
LOG_ERR("Failed to get platform info %d", ret);
return COMP_ERROR_NONE;
}
- free(platform_info.platformID);
- free(platform_info.manufacturerName);
- free(platform_info.modelNumber);
- free(platform_info.platformVersion);
- free(platform_info.firmwareVersion);
-
ret = OCPlatform::registerPlatformInfo(platform_info);
if (ret != OC_STACK_OK)
LOG_DEBUG("device_id : %s", device_id);
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, COMP_ERROR_INVALID_PARAMETER);
+
comp_ctx->device_uuid = g_strdup(device_id);
/* Do Self-Ownership Transfer */
if (g_strcmp0(resource_type, "core.comp.group") == 0) {
comp_context_t *comp_ctx = comp_context_get_context();
if (g_strcmp0(resource_device_id, comp_ctx->device_uuid) == 0)
- group_type = COMP_GROUP_DEVICE;
+ group_type = COMP_GROUP_GROUP_LOCAL;
else
- group_type = COMP_GROUP_REMOTE_DEVICE;
+ group_type = COMP_GROUP_GROUP_REMOTE;
char *temp = g_strdup(resource_uri_path);
char *ptr = strtok(temp, "/");
char *resource_device_id;
char *resource_host;
char *resource_type;
- comp_group_type_e group_type;
+ comp_group_type_e group_type = COMP_GROUP_GROUP_ERROR;
/* Callback: When no more resource available.
As timeout is configured by IOTCON Library*/
if (strcmp(resource_type, "core.comp.group") == 0) {
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, IOTCON_FUNC_CONTINUE);
+
if (strcmp(resource_device_id, comp_ctx->device_uuid) == 0)
- group_type = COMP_GROUP_DEVICE;
+ group_type = COMP_GROUP_GROUP_LOCAL;
else
- group_type = COMP_GROUP_REMOTE_DEVICE;
+ group_type = COMP_GROUP_GROUP_REMOTE;
+ char *sp = NULL;
char *temp = strdup(resource_uri_path);
- char *ptr = strtok(temp, "/");
- ptr = strtok(NULL, "/");
- ptr = strtok(NULL, "/");
+ char *ptr = strtok_r(temp, "/", &sp);
+ ptr = strtok_r(NULL, "/", &sp);
+ ptr = strtok_r(NULL, "/", &sp);
LOG_DEBUG("group name is %s", ptr);
comp_group_add_new(resource_uri_path, resource_device_id,
found_group_count++;
g_free(resource_type);
+ if (temp) {
+ free(temp);
+ temp = NULL;
+ }
return IOTCON_FUNC_CONTINUE;
} else if (strcmp(resource_type, "core.comp.data") == 0) {
}
int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout,
- void *user_data)
+ void *user_data)
{
int ret;
iotcon_query_h query;
- comp_command_t *cmd = (comp_command_t *) user_data;
std::ostringstream requestURI;
+ comp_command_t *cmd = (comp_command_t *) user_data;
+ comp_check_null_ret_error("cmd", cmd, COMP_ERROR_INVALID_PARAMETER);
found_group_count = 0;
LOG_ERR("iotcon_set_timeout: Failed %s", get_error_message(ret));
}
- if (cmd && (cmd->command == COMP_REQ_SEND_DATA_ALL))
+ if (cmd->command == COMP_REQ_SEND_DATA_ALL)
ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS,
IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
query, _found_resource, user_data);
//8. g main loop run
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, COMP_ERROR_INVALID_PARAMETER);
+
comp_ctx->main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(comp_ctx->main_loop);
{
int ret;
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret_error("comp_ctx", comp_ctx, FALSE);
+
ret = agent_mot(comp_ctx->device_uuid, "12341234");
if (ret != COMP_ERROR_NONE) {
LOG_ERR("agent_mot(%s) Failed", comp_ctx->device_uuid);
return FALSE;
}
+static void _free_device_info(comp_mot_device_t *device) {
+
+ if (!device)
+ return;
+
+ if (device->device_id != NULL) {
+ g_free(device->device_id);
+ device->device_id = NULL;
+ }
+ if (device->addr != NULL) {
+ g_free(device->addr);
+ device->addr = NULL;
+ }
+ if (device->route_data != NULL) {
+ g_free(device->route_data);
+ device->route_data = NULL;
+ }
+ if (device->remote_id != NULL) {
+ g_free(device->remote_id);
+ device->remote_id = NULL;
+ }
+ if (device->sec_ver != NULL) {
+ g_free(device->sec_ver);
+ device->sec_ver = NULL;
+ }
+ g_free(device);
+ device = NULL;
+}
+
static void _agent_signal_handler(GDBusConnection *connection,
const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
const gchar *signal_name, GVariant *parameters, gpointer userdata)
gsize len = 0;
int mot_enb_devs_cnt = 0;
comp_mot_device_t *device;
+
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret("comp_ctx", comp_ctx);
if (NULL == parameters) {
LOG_ERR("No MOT enabled devices found");
return;
}
+
g_variant_get(parameters, "(aa{sv})", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
device = g_try_malloc0(sizeof(comp_mot_device_t));
g_variant_iter_free(iter_row);
if (strcmp(device->device_id, comp_ctx->device_uuid) != 0) {
- mot_enb_devs_cnt += 1;
- comp_group_add_new_mot_device(device);
- } else {
- LOG_DEBUG("It is my mowned device. Store the mowned device"
- " in daemon");
- comp_group_change_mowned_device(device);
+
+ /* Is new device */
+ if (FALSE == comp_group_add_new_mot_device(device)) {
+ mot_enb_devs_cnt += 1;
+ } else {
+ /* We have this device already */
+ _free_device_info(device);
}
+ } else {
+ LOG_DEBUG("It is my mowned device. Store the mowned device in daemon");
+ comp_group_change_mowned_device(device);
+ }
}
g_variant_iter_free(iter);
GVariant *val;
gsize len = 0;
int mowned_devs_cnt = 0;
- comp_mot_device_t *device;
+ comp_mot_device_t *device = NULL;
if (NULL == parameters) {
LOG_ERR("No Multiple Owned devices found");
g_variant_get(parameters, "(aa{sv})", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+
device = g_try_malloc0(sizeof(comp_mot_device_t));
+ comp_check_null_ret("device", device);
while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) {
if (strcasecmp(key, "deviceId") == 0) {
g_variant_iter_free(iter_row);
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret("comp_ctx", comp_ctx);
+
if (strcmp(device->device_id, comp_ctx->device_uuid) != 0) {
- mowned_devs_cnt += 1;
- comp_group_add_new_mowned_device(device);
+
+ /* Is new device */
+ if (FALSE == comp_group_add_new_mowned_device(device)) {
+ mowned_devs_cnt += 1;
+ } else {
+ /* We have this device already */
+ _free_device_info(device);
+ }
} else {
LOG_DEBUG("It is my mowned device. Store the mowned device in daemon");
comp_group_change_mowned_device(device);
#ifdef INVITE_EJECT_DEVICE_BY_MULTI_RUN
comp_mot_device_t *device;
comp_context_t *comp_ctx = comp_context_get_context();
+ comp_check_null_ret("comp_ctx", comp_ctx);
g_variant_get(parameters, "(i)", &result);
LOG_DEBUG("Result : %d", result);
LOG_DEBUG("-------------------Print resource list-----------------------");
for (int i = 0; i < COMP_RESOURCE_TYPE_MAX; i++) {
- LOG_DEBUG("Resource type %d list length : %d", i,
- g_list_length(comp_ctx->resource_list[i]));
- g_list_foreach(comp_ctx->resource_list[i], __print_foreach_resource,
- NULL);
+ LOG_DEBUG("Resource type %d list length : %d",
+ i, g_list_length(comp_ctx->resource_list[i]));
+ g_list_foreach(comp_ctx->resource_list[i], __print_foreach_resource, NULL);
}
LOG_DEBUG("-------------------Print resource list end-------------------");
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * 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.
- *
+/*\r
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
*/\r
\r
#ifndef __MA_LOG_H__\r
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * 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.
- *
+/*\r
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
*/\r
#include <glib.h>\r
\r
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * 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.
- *
+/*\r
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
*/\r
\r
#ifndef __MA_SERVICE_INTERFACE_H__\r
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * 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.
- *
+/*\r
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
*/\r
\r
#include <glib.h>\r
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * 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.
- *
+/*\r
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
*/\r
\r
#ifndef __MA_SERVICE_H__\r
} while (FALSE)
const char* ma_ocf_error_to_string(OCStackResult err);
-
const char* ma_wifi_error_to_string(wifi_manager_error_e err);
OicUuid_t* ma_convert_uuid(gchar *device_id);
-
char * ma_get_readable_uuid(const OicUuid_t* uuid);
#ifdef TEST
OCProvisionDev_t* ma_get_dev_by_id(const OCProvisionDev_t* dev_lst, const int dev_num);
#endif
-
OCProvisionDev_t* ma_get_dev_by_uuid(const OCProvisionDev_t* dev_lst,
const OicUuid_t* uuid);
-
int ma_print_dev_list(const OCProvisionDev_t* dev_lst);
-
int ma_print_result_list(const OCProvisionResult_t* rslt_lst, const int rslt_cnt);
-
int ma_set_device_id_seed(void);
#if 0
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * 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.
- *
+/*\r
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
*/\r
\r
#ifndef __MA_AGENT_H__\r