diff --git a/include/edgex/edgex-base.h b/include/edgex/edgex-base.h index 96c0cad0..5c284719 100644 --- a/include/edgex/edgex-base.h +++ b/include/edgex/edgex-base.h @@ -28,7 +28,7 @@ typedef struct devsdk_nvpairs struct devsdk_nvpairs *next; } devsdk_nvpairs; -/** +/** * @brief Creates a new string list, optionally adding to an existing list * @param str The string to be added * @param list A list that will be extended, or NULL diff --git a/src/c/devman.c b/src/c/devman.c index 7a517e51..871961cd 100644 --- a/src/c/devman.c +++ b/src/c/devman.c @@ -89,6 +89,7 @@ void edgex_add_device if (result) { + devsdk_add_new_device (svc->add_device_new, name); iot_log_info (svc->logger, "Device %s added with id %s", name, result); free (result); } diff --git a/src/c/devmap.c b/src/c/devmap.c index b8677e31..e5f17fd3 100644 --- a/src/c/devmap.c +++ b/src/c/devmap.c @@ -88,6 +88,7 @@ static void add_locked (edgex_devmap_t *map, const edgex_device *newdev) edgex_device *dup = edgex_device_dup (newdev); atomic_store (&dup->refs, 1); dup->ownprofile = false; + bool result = false; edgex_deviceprofile **pp = edgex_map_get (&map->profiles, dup->profile->name); if (pp) { @@ -99,7 +100,11 @@ static void add_locked (edgex_devmap_t *map, const edgex_device *newdev) edgex_map_set (&map->profiles, dup->profile->name, dup->profile); } edgex_map_set (&map->devices, dup->name, dup); - edgex_device_autoevent_start (map->svc, dup); + result = search_devsdk_new_device (map->svc->add_device_new, dup->name); + if (result) + { + edgex_device_autoevent_start (map->svc, dup); + } } void edgex_devmap_populate_devices diff --git a/src/c/edgex-rest.c b/src/c/edgex-rest.c index 396d8346..9b8c7e32 100644 --- a/src/c/edgex-rest.c +++ b/src/c/edgex-rest.c @@ -75,6 +75,37 @@ static JSON_Value *strings_to_array (const devsdk_strings *s) return result; } +void devsdk_add_new_device (iot_data_t *devices, const char *name) +{ + if(devices == NULL) + { + devices = iot_data_alloc_map (IOT_DATA_STRING); + } + /*Check if memory got allocated or already allocated*/ + if(devices) + { + iot_data_map_add (devices, iot_data_alloc_string (name, IOT_DATA_COPY), iot_data_alloc_null ()); + } +} + +void devsdk_clean_new_device (iot_data_t *devices) +{ + if(devices) + { + iot_data_free (devices); + devices = NULL; + } +} + +bool search_devsdk_new_device (iot_data_t *devices, char *name) +{ + if (devices && iot_data_string_map_get (devices, name)) + { + return true; + } + return false; +} + devsdk_strings *devsdk_strings_dup (const devsdk_strings *strs) { devsdk_strings *result = NULL; diff --git a/src/c/edgex-rest.h b/src/c/edgex-rest.h index 5b1f97c6..02ee1db9 100644 --- a/src/c/edgex-rest.h +++ b/src/c/edgex-rest.h @@ -13,6 +13,9 @@ #include "edgex2.h" #include "rest-server.h" +void devsdk_add_new_device (iot_data_t *devices, const char *name); +void devsdk_clean_new_device (iot_data_t *devices); +bool search_devsdk_new_device (iot_data_t *devices, char *name); devsdk_strings *devsdk_strings_dup (const devsdk_strings *strs); void devsdk_strings_free (devsdk_strings *strs); char *devsdk_nvpairs_write (const devsdk_nvpairs *e); diff --git a/src/c/service.c b/src/c/service.c index 59ffa490..14dcf8b5 100644 --- a/src/c/service.c +++ b/src/c/service.c @@ -678,6 +678,7 @@ static void startConfigured (devsdk_service_t *svc, const devsdk_timeout *deadli } edgex_devmap_populate_devices (svc->devices, devs); + devsdk_clean_new_device(svc->add_device_new); edgex_device_free (svc, devs); /* Start REST server now so that we get the callbacks on device addition */ @@ -801,6 +802,7 @@ void devsdk_service_start (devsdk_service_t *svc, iot_data_t *driverdfls, devsdk toml_table_t *configtoml = NULL; bool uploadConfig = false; iot_data_t *configmap; + svc->add_device_new = NULL; if (svc->starttime) { diff --git a/src/c/service.h b/src/c/service.h index afa52107..8b3a5b1b 100644 --- a/src/c/service.h +++ b/src/c/service.h @@ -72,6 +72,7 @@ struct devsdk_service_t iot_threadpool_t *thpool; iot_threadpool_t *eventq; iot_scheduler_t *scheduler; + iot_data_t *add_device_new; }; extern void devsdk_schedule_metrics (devsdk_service_t *svc);