celix_status_t discovery_start(discovery_pt discovery) { celix_status_t status = CELIX_SUCCESS; char *port = NULL; char *path = NULL; logHelper_start(discovery->loghelper); 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 = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } status = etcdWatcher_create(discovery, discovery->context, &discovery->watcher); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } return status; }
celix_status_t pubsub_discovery_interestedInTopic(void *handle, const char* scope, const char* topic) { pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle; char *scope_topic_key = createScopeTopicKey(scope, topic); celixThreadMutex_lock(&pubsub_discovery->watchersMutex); struct watcher_info * wi = hashMap_get(pubsub_discovery->watchers, scope_topic_key); if(wi) { wi->nr_references++; free(scope_topic_key); } else { wi = calloc(1, sizeof(*wi)); etcdWatcher_create(pubsub_discovery, pubsub_discovery->context, scope, topic, &wi->watcher); wi->nr_references = 1; hashMap_put(pubsub_discovery->watchers, scope_topic_key, wi); } celixThreadMutex_unlock(&pubsub_discovery->watchersMutex); return CELIX_SUCCESS; }