CELIX-265: refactored discovery_shm to set non-default configuration
diff --git a/remote_services/discovery/private/include/endpoint_discovery_poller.h b/remote_services/discovery/private/include/endpoint_discovery_poller.h
index 1bb6679..c362973 100644
--- a/remote_services/discovery/private/include/endpoint_discovery_poller.h
+++ b/remote_services/discovery/private/include/endpoint_discovery_poller.h
@@ -50,6 +50,6 @@
 
 celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
 celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
-
+celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls);
 
 #endif /* ENDPOINT_DISCOVERY_POLLER_H_ */
diff --git a/remote_services/discovery_shm/private/include/shm_watcher.h b/remote_services/discovery_shm/private/include/shm_watcher.h
index f99007f..59c32e5 100644
--- a/remote_services/discovery_shm/private/include/shm_watcher.h
+++ b/remote_services/discovery_shm/private/include/shm_watcher.h
@@ -33,7 +33,8 @@
 
 typedef struct shm_watcher *shm_watcher_pt;
 
-celix_status_t shmWatcher_create(endpoint_discovery_poller_pt poller, bundle_context_pt context, shm_watcher_pt *watcher);
+
+celix_status_t shmWatcher_create(discovery_pt discovery, bundle_context_pt context, shm_watcher_pt *watcher);
 celix_status_t shmWatcher_destroy(shm_watcher_pt watcher);
 
 
diff --git a/remote_services/discovery_shm/private/src/discovery_impl.c b/remote_services/discovery_shm/private/src/discovery_impl.c
index 1fb5330..5159edc 100644
--- a/remote_services/discovery_shm/private/src/discovery_impl.c
+++ b/remote_services/discovery_shm/private/src/discovery_impl.c
@@ -109,35 +109,22 @@
 
 celix_status_t discovery_start(discovery_pt discovery) {
     celix_status_t status = CELIX_SUCCESS;
-	char *port = NULL;
-	char *path = NULL;
-
-
-	bundleContext_getProperty(discovery->context, DISCOVERY_SERVER_PORT, &port);
-	if (port == NULL) {
-		port = DEFAULT_SERVER_PORT;
-	}
-
-	bundleContext_getProperty(discovery->context, DISCOVERY_SERVER_PATH, &path);
-	if (path == NULL) {
-		path = DEFAULT_SERVER_PATH;
-	}
 
     status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
     if (status != CELIX_SUCCESS) {
     	return CELIX_BUNDLE_EXCEPTION;
     }
 
-    status = shmWatcher_create(discovery->poller, discovery->context, &discovery->watcher);
-    if (status != CELIX_SUCCESS) {
-    	return CELIX_BUNDLE_EXCEPTION;
-    }
-
     status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
     if (status != CELIX_SUCCESS) {
     	return CELIX_BUNDLE_EXCEPTION;
     }
 
+    status = shmWatcher_create(discovery, discovery->context, &discovery->watcher);
+    if (status != CELIX_SUCCESS) {
+        return CELIX_BUNDLE_EXCEPTION;
+    }
+
     return status;
 }
 
diff --git a/remote_services/discovery_shm/private/src/shm_watcher.c b/remote_services/discovery_shm/private/src/shm_watcher.c
index 2152345..cd21344 100644
--- a/remote_services/discovery_shm/private/src/shm_watcher.c
+++ b/remote_services/discovery_shm/private/src/shm_watcher.c
@@ -39,7 +39,7 @@
 #include "endpoint_discovery_poller.h"
 
 struct shm_watcher {
-    endpoint_discovery_poller_pt poller;
+    discovery_pt discovery;
     bundle_context_pt context;
 
     shmData_pt shmData;
@@ -79,6 +79,7 @@
 /* retrieves all endpoints from shm and syncs them with the ones already available */
 static celix_status_t shmWatcher_syncEndpoints(shm_watcher_pt watcher) {
     celix_status_t status = CELIX_SUCCESS;
+    endpoint_discovery_poller_pt poller = watcher->discovery->poller;
     char** shmKeyArr = calloc(SHM_DATA_MAX_ENTRIES, sizeof(*shmKeyArr));
     array_list_pt registeredKeyArr = NULL; //calloc(SHM_DATA_MAX_ENTRIES, sizeof(*registeredKeyArr));
 
@@ -94,7 +95,7 @@
     discovery_shmGetKeys(watcher->shmData, shmKeyArr, &shmSize);
 
     // get all locally registered endpoints
-    endpointDiscoveryPoller_getDiscoveryEndpoints(watcher->poller, registeredKeyArr);
+    endpointDiscoveryPoller_getDiscoveryEndpoints(poller, registeredKeyArr);
 
     // add discovery points which are in shm, but not local yet
     for (i = 0; i < shmSize; i++) {
@@ -111,7 +112,7 @@
             }
 
             if (elementFound == false) {
-                endpointDiscoveryPoller_addDiscoveryEndpoint(watcher->poller, url);
+                endpointDiscoveryPoller_addDiscoveryEndpoint(poller, url);
             }
         }
     }
@@ -121,7 +122,7 @@
         char* regUrl = arrayList_get(registeredKeyArr, i);
 
         if (regUrl != NULL) {
-            endpointDiscoveryPoller_removeDiscoveryEndpoint(watcher->poller, regUrl);
+            endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, regUrl);
         }
     }
 
@@ -142,20 +143,23 @@
 
 static void* shmWatcher_run(void* data) {
     shm_watcher_pt watcher = (shm_watcher_pt) data;
+    endpoint_discovery_server_pt server = watcher->discovery->server;
+
     char localNodePath[MAX_LOCALNODE_LENGTH];
-    char* endpoints = NULL;
+    char url[SHM_ENTRY_MAX_VALUE_LENGTH];
 
     if (shmWatcher_getLocalNodePath(watcher->context, &localNodePath[0]) != CELIX_SUCCESS) {
         fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "Cannot register local discovery");
     }
 
-    if ((bundleContext_getProperty(watcher->context, DISCOVERY_POLL_ENDPOINTS, &endpoints) != CELIX_SUCCESS) || !endpoints) {
-        endpoints = DEFAULT_POLL_ENDPOINTS;
+
+    if (endpointDiscoveryServer_getUrl(server, &url[0]) != CELIX_SUCCESS) {
+        snprintf(url, SHM_ENTRY_MAX_VALUE_LENGTH, "http://%s:%s/%s", DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT, DEFAULT_SERVER_PATH);
     }
 
     while (watcher->running) {
         // register own framework
-        if (discovery_shmSet(watcher->shmData, localNodePath, endpoints) != CELIX_SUCCESS) {
+        if (discovery_shmSet(watcher->shmData, localNodePath, url) != CELIX_SUCCESS) {
             fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "Cannot register local discovery");
         }
 
@@ -166,10 +170,11 @@
     return NULL;
 }
 
-celix_status_t shmWatcher_create(endpoint_discovery_poller_pt poller, bundle_context_pt context, shm_watcher_pt *watcher) {
+celix_status_t shmWatcher_create(discovery_pt discovery, bundle_context_pt context, shm_watcher_pt *watcher) {
     celix_status_t status = CELIX_SUCCESS;
 
-    if (poller == NULL) {
+
+    if (discovery == NULL) {
         return CELIX_BUNDLE_EXCEPTION;
     }
 
@@ -177,7 +182,7 @@
     if (!*watcher) {
         return CELIX_ENOMEM;
     } else {
-        (*watcher)->poller = poller;
+        (*watcher)->discovery = discovery;
         (*watcher)->context = context;
         if (discovery_shmAttach(&((*watcher)->shmData)) != CELIX_SUCCESS)
             discovery_shmCreate(&((*watcher)->shmData));