Exemplo n.º 1
0
celix_status_t serviceRegistry_unregisterServices(service_registry_pt registry, bundle_pt bundle) {
	array_list_pt regs = NULL;
	unsigned int i;
	celixThreadMutex_lock(&registry->mutex);
	regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
	celixThreadMutex_unlock(&registry->mutex);
	
	for (i = 0; (regs != NULL) && i < arrayList_size(regs); i++) {
		service_registration_pt reg = arrayList_get(regs, i);
		if (serviceRegistration_isValid(reg)) {
			serviceRegistration_unregister(reg);
		}
	}

	if (regs != NULL && arrayList_isEmpty(regs)) {
	    celixThreadMutex_lock(&registry->mutex);
		array_list_pt removed = hashMap_remove(registry->serviceRegistrations, bundle);
		celixThreadMutex_unlock(&registry->mutex);
		arrayList_destroy(removed);
		removed = NULL;
	}

	celixThreadMutex_lock(&registry->mutex);
	hashMap_remove(registry->serviceRegistrations, bundle);
	celixThreadMutex_unlock(&registry->mutex);

	return CELIX_SUCCESS;
}
Exemplo n.º 2
0
void test_hashMap_remove(void) {
    char * key = "key";
    char * value = "value";
    char * key2 = NULL;
    char * value2 = "value2";
    char * removeKey;

    hashMap_clear(map, false, false);

    // Add one entry
    hashMap_put(map, key, value);

    // Add second entry with null key
    hashMap_put(map, key2, value2);

    // Remove unexisting entry for map
    removeKey = "unexisting";
    hashMap_remove(map, removeKey);
    CU_ASSERT_EQUAL(map->size, 2);
    CU_ASSERT_FALSE(hashMap_isEmpty(map));

    hashMap_remove(map, key);
    CU_ASSERT_EQUAL(map->size, 1);

    hashMap_remove(map, key2);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));

    // Remove unexisting entry for empty map
    removeKey = "unexisting";
    hashMap_remove(map, removeKey);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));
}
Exemplo n.º 3
0
celix_status_t managedServiceTracker_untrackManagedService(managed_service_tracker_pt tracker, char *pid, service_reference_pt reference){
    managedServiceTracker_lockManagedServicesReferences(tracker);

    if ( hashMap_containsKey(tracker->managedServicesReferences, pid) ){
	hashMap_remove(tracker->managedServicesReferences, pid);
	hashMap_remove(tracker->managedServices, pid);
    }
    managedServiceTracker_unlockManagedServicesReferences(tracker);
    return CELIX_SUCCESS;

}
Exemplo n.º 4
0
celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char* scope,char* topic){
	celix_status_t status = CELIX_SUCCESS;

	printf("PSA_ZMQ: Closing all subscriptions\n");

	celixThreadMutex_lock(&admin->subscriptionsLock);
	char *scope_topic = createScopeTopicKey(scope, topic);
	hash_map_entry_pt sub_entry = (hash_map_entry_pt)hashMap_getEntry(admin->subscriptions,scope_topic);
	if(sub_entry!=NULL){
		char* topic = (char*)hashMapEntry_getKey(sub_entry);

		topic_subscription_pt ts = (topic_subscription_pt)hashMapEntry_getValue(sub_entry);
		status += pubsub_topicSubscriptionStop(ts);
		disconnectTopicPubSubFromSerializer(admin, ts, false);
		status += pubsub_topicSubscriptionDestroy(ts);
		hashMap_remove(admin->subscriptions,scope_topic);
		free(topic);

	}
	free(scope_topic);
	celixThreadMutex_unlock(&admin->subscriptionsLock);

	return status;

}
Exemplo n.º 5
0
celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin, char *scope, char* topic){
	celix_status_t status = CELIX_SUCCESS;

	printf("PSA_ZMQ: Closing all publications\n");

	celixThreadMutex_lock(&admin->localPublicationsLock);
	char *scope_topic = createScopeTopicKey(scope, topic);
	hash_map_entry_pt pubsvc_entry = (hash_map_entry_pt)hashMap_getEntry(admin->localPublications,scope_topic);
	if(pubsvc_entry!=NULL){
		char* key = (char*)hashMapEntry_getKey(pubsvc_entry);
		service_factory_pt factory= (service_factory_pt)hashMapEntry_getValue(pubsvc_entry);
		topic_publication_pt pub = (topic_publication_pt)factory->handle;
		status += pubsub_topicPublicationStop(pub);
		disconnectTopicPubSubFromSerializer(admin, pub, true);
		status += pubsub_topicPublicationDestroy(pub);
		hashMap_remove(admin->localPublications,scope_topic);
		free(key);
		free(factory);
	}
	free(scope_topic);
	celixThreadMutex_unlock(&admin->localPublicationsLock);

	return status;

}
Exemplo n.º 6
0
static celix_status_t etcdWatcher_removeEntry(etcd_watcher_pt watcher, char* key, char* value) {
    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
    endpoint_discovery_poller_pt poller = watcher->discovery->poller;

    hash_map_entry_pt entry = hashMap_getEntry(watcher->entries, key);

    if (entry != NULL) {
        void* origKey = hashMapEntry_getKey(entry);
        void* value = hashMap_remove(watcher->entries, key);

        free(origKey);

        // check if there is another entry with the same value
        hash_map_iterator_pt iter = hashMapIterator_create(watcher->entries);
        unsigned int valueFound = 0;

        while (hashMapIterator_hasNext(iter) && valueFound <= 1) {
            if (strcmp(value, hashMapIterator_nextValue(iter)) == 0)
                valueFound++;
        }

        hashMapIterator_destroy(iter);

        if (valueFound == 0)
            status = endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, value);

        free(value);

    }

    return status;

}
Exemplo n.º 7
0
celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL){
	printf("pubsub_topicSubscriptionDisconnectPublisher : pubURL = %s\n", pubURL);
	celix_status_t status = CELIX_SUCCESS;
	struct epoll_event ev;
	memset(&ev, 0, sizeof(ev));

	celixThreadMutex_lock(&ts->socketMap_lock);

	if (hashMap_containsKey(ts->socketMap, pubURL)){

#if defined(__APPLE__) && defined(__MACH__)
		//TODO: Use kqueue for OSX
#else
		int *s = hashMap_remove(ts->socketMap, pubURL);
		if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_DEL, *s, &ev) == -1) {
			printf("in if error()\n");
			perror("epoll_ctl() EPOLL_CTL_DEL");
			status = CELIX_SERVICE_EXCEPTION;
		}
		free(s);
#endif

	}

	celixThreadMutex_unlock(&ts->socketMap_lock);

	return status;
}
Exemplo n.º 8
0
celix_status_t serviceRegistry_ungetServiceReference(service_registry_pt registry, bundle_pt owner, service_reference_pt reference) {
    celix_status_t status = CELIX_SUCCESS;

    bool valid = false;
    serviceRefernce_isValid(reference, &valid);
    if (valid) {
        bool ungetResult = true;
        while (ungetResult) {
            serviceRegistry_ungetService(registry, owner, reference, &ungetResult);
        }
    }

    celixThreadMutex_lock(&registry->referencesMapMutex);
    array_list_pt references = hashMap_get(registry->serviceReferences, owner);
    if (references != NULL) {
        arrayList_removeElement(references, reference);
        serviceReference_destroy(&reference);
        if (arrayList_size(references) > 0) {
            hashMap_put(registry->serviceReferences, owner, references);
        } else {
            array_list_pt removed = hashMap_remove(registry->serviceReferences, owner);
            arrayList_destroy(removed);
        }
    }
    celixThreadMutex_unlock(&registry->referencesMapMutex);

	return status;
}
Exemplo n.º 9
0
/**
 * Removes an endpoint URL from the list of polled endpoints.
 */
celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url) {
	celix_status_t status = CELIX_SUCCESS;

	if (celixThreadMutex_lock(&poller->pollerLock) != CELIX_SUCCESS) {
		status = CELIX_BUNDLE_EXCEPTION;
	} else {
		hash_map_entry_pt entry = hashMap_getEntry(poller->entries, url);

		if (entry == NULL) {
			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: There was no entry found belonging to url %s - maybe already removed?", url);
		} else {
			char* origKey = hashMapEntry_getKey(entry);

			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: remove discovery endpoint with url %s", url);

			array_list_pt entries = hashMap_remove(poller->entries, url);

			for (unsigned int i = arrayList_size(entries); i > 0; i--) {
				endpoint_description_pt endpoint = arrayList_get(entries, i - 1);
				discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
				arrayList_remove(entries, i - 1);
				endpointDescription_destroy(endpoint);
			}

			if (entries != NULL) {
				arrayList_destroy(entries);
			}

			free(origKey);
		}
		status = celixThreadMutex_unlock(&poller->pollerLock);
	}

	return status;
}
static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription) {
	celix_status_t status = CELIX_SUCCESS;
	proxy_instance_pt proxy_instance_ptr = NULL;

	if (!remote_proxy_factory_ptr || !endpointDescription || !remote_proxy_factory_ptr->proxy_instances || !remote_proxy_factory_ptr->handle) {
		status = CELIX_ILLEGAL_ARGUMENT;
	}

	if (status == CELIX_SUCCESS) {
		proxy_instance_ptr = hashMap_remove(remote_proxy_factory_ptr->proxy_instances, endpointDescription);
		if (proxy_instance_ptr == NULL) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
	}

	if (status == CELIX_SUCCESS) {
		if (proxy_instance_ptr->registration_ptr) {
			status = serviceRegistration_unregister(proxy_instance_ptr->registration_ptr);
			proxy_instance_ptr->properties = NULL;
		}
		if (proxy_instance_ptr->service) {
			status = remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
		}
		if (proxy_instance_ptr->properties) {
			properties_destroy(proxy_instance_ptr->properties);
		}
		if (proxy_instance_ptr) {
			free(proxy_instance_ptr);
		}
	}

	return status;
}
Exemplo n.º 11
0
celix_status_t wiringAdmin_removeExportedWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt wEndpointDescription) {
    celix_status_t status = CELIX_SUCCESS;

    if (wEndpointDescription == NULL) {
        status = CELIX_ILLEGAL_ARGUMENT;
    } else {
        celixThreadMutex_lock(&admin->exportedWiringEndpointLock);
        service_tracker_pt wiringReceiveTracker = NULL;

        wiringReceiveTracker = hashMap_remove(admin->wiringReceiveTracker, wEndpointDescription);

        if (wiringReceiveTracker != NULL) {
            if (serviceTracker_close(wiringReceiveTracker) == CELIX_SUCCESS) {
                serviceTracker_destroy(wiringReceiveTracker);
            }

            if (hashMap_size(admin->wiringReceiveTracker) == 0) {
                wiringAdmin_stopWebserver(admin);
            }
        }

        wiringEndpointDescription_destroy(&wEndpointDescription);

        celixThreadMutex_unlock(&admin->exportedWiringEndpointLock);
    }

    return status;
}
Exemplo n.º 12
0
celix_status_t pubsub_discovery_uninterestedInTopic(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);

    hash_map_entry_pt entry =  hashMap_getEntry(pubsub_discovery->watchers, scope_topic_key);
    if(entry) {
        struct watcher_info * wi = hashMapEntry_getValue(entry);
        wi->nr_references--;
        if(wi->nr_references == 0) {
            char *key = hashMapEntry_getKey(entry);
            hashMap_remove(pubsub_discovery->watchers, scope_topic_key);
            free(key);
            free(scope_topic_key);
            etcdWatcher_stop(wi->watcher);
            etcdWatcher_destroy(wi->watcher);
            free(wi);
        }
    } else {
        fprintf(stderr, "[DISC] Inconsistency error: Removing unknown topic %s\n", topic);
    }
    celixThreadMutex_unlock(&pubsub_discovery->watchersMutex);
    return CELIX_SUCCESS;
}
Exemplo n.º 13
0
celix_status_t deviceManager_driverRemoved(void * handle, service_reference_pt ref, void * service) {
	celix_status_t status = CELIX_SUCCESS;

	device_manager_pt manager = handle;
	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove driver");

	hashMap_remove(manager->drivers, ref);

	array_list_pt idleDevices = NULL;
	status = deviceManager_getIdleDevices(manager, &idleDevices);
	if (status == CELIX_SUCCESS) {
		int i;
		for (i = 0; i < arrayList_size(idleDevices); i++) {
			celix_status_t forStatus = CELIX_SUCCESS;
			service_reference_pt ref = arrayList_get(idleDevices, i);
			const char *bsn = NULL;
			bundle_pt bundle = NULL;
			forStatus = serviceReference_getBundle(ref, &bundle);
			if (forStatus == CELIX_SUCCESS) {
				module_pt module = NULL;
				forStatus = bundle_getCurrentModule(bundle, &module);
				if (forStatus == CELIX_SUCCESS) {
					forStatus = module_getSymbolicName(module, &bsn);
					if (forStatus == CELIX_SUCCESS) {
						logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: IDLE: %s", bsn);
						// #TODO attachDriver (idle device)
						// #TODO this can result in a loop?
						//		Locate and install a driver
						//		Let the match fail, the device is idle
						//		The driver is removed, idle check is performed
						//		Attach is tried again
						//		.. loop ..
						void *device = hashMap_get(manager->devices, ref);
						forStatus = deviceManager_attachAlgorithm(manager, ref, device);
					}
				}
			}

			if (forStatus != CELIX_SUCCESS) {
				break; //Got error, stop loop and return status
			}
		}


		hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers);
		while (hashMapIterator_hasNext(iter)) {
			hashMapIterator_nextValue(iter);
//			driver_attributes_pt da = hashMapIterator_nextValue(iter);
//			driverAttributes_tryUninstall(da);
		}
		hashMapIterator_destroy(iter);
	}

	if (idleDevices != NULL) {
		arrayList_destroy(idleDevices);
	}

	return status;
}
Exemplo n.º 14
0
// configuration->dictionary must not contain keys reserved to ConfigAdmin (i.e. "service.pid")
celix_status_t configuration_updateDictionary(configuration_impl_pt configuration, properties_pt properties) {

    properties_pt newDictionary = NULL;

    if ( configuration->dictionary != NULL && configuration->dictionary != properties ) {
        properties_destroy(configuration->dictionary); //free
    }

    newDictionary = properties; // properties == NULL | properties != NULL

    if ( newDictionary != NULL ) {

        hashMap_remove(newDictionary, (void *) OSGI_FRAMEWORK_SERVICE_PID);
        hashMap_remove(newDictionary, (void *) SERVICE_FACTORYPID);
        hashMap_remove(newDictionary, (void *) SERVICE_BUNDLELOCATION);
    }

    configuration->dictionary = newDictionary;
    return CELIX_SUCCESS;

}
Exemplo n.º 15
0
celix_status_t wiringAdmin_removeImportedWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt wEndpointDescription) {
    celix_status_t status;

    celixThreadMutex_lock(&admin->importedWiringEndpointLock);
    char* wireId = properties_get(wEndpointDescription->properties, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY);

    printf("%s: remove Wiring Endpoint w/ wireId %s\n", TAG, wireId);

    wiring_send_service_pt wiringSendService = hashMap_remove(admin->wiringSendServices, wEndpointDescription);
    service_registration_pt wiringSendRegistration = hashMap_remove(admin->wiringSendRegistrations, wEndpointDescription);

    status = serviceRegistration_unregister(wiringSendRegistration);

    if (status == CELIX_SUCCESS) {
        free(wiringSendService);
    }

    celixThreadMutex_unlock(&admin->importedWiringEndpointLock);

    return status;
}
Exemplo n.º 16
0
celix_status_t shell_removeCommand(shell_pt shell_ptr, service_reference_pt reference_ptr) {
	celix_status_t status = CELIX_SUCCESS;

	command_service_pt command_ptr = NULL;
	char *name_str = NULL;

	if (!shell_ptr || !reference_ptr) {
		status = CELIX_ILLEGAL_ARGUMENT;
	}

	if (status == CELIX_SUCCESS) {
		command_ptr = hashMap_remove(shell_ptr->command_reference_map_ptr, reference_ptr);
		if (!command_ptr) {
			status = CELIX_ILLEGAL_ARGUMENT;
		}
	}

	if (status == CELIX_SUCCESS) {
		status = serviceReference_getProperty(reference_ptr, "command.name", &name_str);
		if (!name_str) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
	}

	if (status == CELIX_SUCCESS) {
		hashMap_remove(shell_ptr->command_name_map_ptr, name_str);
	}

	celix_status_t sub_status = bundleContext_ungetService(shell_ptr->bundle_context_ptr, reference_ptr, NULL);
	if (sub_status != CELIX_SUCCESS && status == CELIX_SUCCESS) {
		status = sub_status;
	}

	sub_status = bundleContext_ungetServiceReference(shell_ptr->bundle_context_ptr, reference_ptr);
	if (sub_status != CELIX_SUCCESS && status == CELIX_SUCCESS) {
		status = sub_status;
	}

	return status;
}
Exemplo n.º 17
0
celix_status_t pubsub_discovery_tmPublisherAnnounceRemoved(void * handle, service_reference_pt reference, void * service) {
	celix_status_t status = CELIX_SUCCESS;
	pubsub_discovery_pt pubsub_discovery = handle;

	celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);

	if (pubsub_discovery->listenerReferences != NULL) {
		if (hashMap_remove(pubsub_discovery->listenerReferences, reference)) {
			printf("PSD: pubsub_tm_announce_publisher removed.\n");
		}
	}
	celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);

	return status;
}
celix_status_t wiringTopologyManager_wiringEndpointListenerRemoved(void * handle, service_reference_pt reference, void * service) {
    celix_status_t status;
    wiring_topology_manager_pt manager = handle;

    status = celixThreadMutex_lock(&manager->listenerListLock);

    if (status == CELIX_SUCCESS) {
        if (hashMap_remove(manager->listenerList, reference)) {
            printf("WTM: EndpointListener Removed");
        }

        status = celixThreadMutex_unlock(&manager->listenerListLock);
    }

    return status;
}
Exemplo n.º 19
0
void test_hashMap_isEmpty(void) {
    char * key = "key";
    char * value = "value";

    hashMap_clear(map, false, false);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));

    // Add one entry
    hashMap_put(map, key, value);
    CU_ASSERT_EQUAL(map->size, 1);
    CU_ASSERT_FALSE(hashMap_isEmpty(map));

    // Remove entry
    hashMap_remove(map, key);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));
}
Exemplo n.º 20
0
static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service){
	celix_status_t status = CELIX_SUCCESS;
	topic_subscription_pt ts = handle;

	celixThreadMutex_lock(&ts->ts_lock);
	if (hashMap_containsKey(ts->servicesMap, service)) {
		hash_map_pt msgTypes = hashMap_remove(ts->servicesMap, service);
		if(msgTypes!=NULL && ts->serializer!=NULL){
			ts->serializer->destroySerializerMap(ts->serializer->handle,msgTypes);
			printf("PSA_ZMQ_TS: Subscriber unregistered.\n");
		}
		else{
			printf("PSA_ZMQ_TS: Cannot unregister subscriber.\n");
			status = CELIX_SERVICE_EXCEPTION;
		}
	}
	celixThreadMutex_unlock(&ts->ts_lock);

	printf("PSA_UDP_MC_TS: Subscriber unregistered.\n");
	return status;
}
Exemplo n.º 21
0
celix_status_t statistic_tracker_statServiceRemoved(void *handle, service_reference_pt reference, void *service) {

	celix_status_t status = CELIX_BUNDLE_EXCEPTION;
	statistic_tracker_pt statTracker = (statistic_tracker_pt) handle;

	pthread_t* thread_pt = NULL;

	pthread_rwlock_wrlock(&statTracker->statLock);

	hash_map_iterator_pt iter = hashMapIterator_create(statTracker->statServices);

	while (hashMapIterator_hasNext(iter) && thread_pt == NULL) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);

		if (service == hashMapEntry_getValue(entry)) {
			struct stats_provider_service* statService = (struct stats_provider_service*) service;
			char* name = NULL;

			statService->getName(statService->statsProvider, &name);

			thread_pt = hashMapEntry_getKey(entry);

			msg(1, "STAT_TRACKER: Service %s Removed. ", name);
			hashMap_remove(statTracker->statServices, thread_pt);
		}
	}

	hashMapIterator_destroy(iter);

	pthread_rwlock_unlock(&statTracker->statLock);

	if (thread_pt != NULL) {
		pthread_join(*thread_pt, NULL);
		msg(1, "STAT_TRACKER: Service Removed. Thread %lu stopped.", (unsigned long) *thread_pt);
		free(thread_pt);
		status = CELIX_SUCCESS;
	}

	return status;
}
Exemplo n.º 22
0
celix_status_t producer_queueServiceRemoved(void *handle, service_reference_pt reference, void *service)
{
    celix_status_t status = CELIX_SUCCESS;
    producer_pt producer = (producer_pt) handle;

    printf("PRODUCER: QueueService Removed.\n");

    pthread_rwlock_wrlock(&producer->queueLock);

    producer_thread_data_pt th_data = (producer_thread_data_pt) hashMap_get(producer->queueServices, service);
    th_data->running = false;
    pthread_join(th_data->thread, NULL);

    pthread_rwlock_destroy(&th_data->sampleRateLock);

    hashMap_remove(producer->queueServices, service);
    free(th_data);

    pthread_rwlock_unlock(&producer->queueLock);

    return status;
}
Exemplo n.º 23
0
static celix_status_t wiringAdmin_wiringReceiveRemoved(void * handle, service_reference_pt reference, void * service) {
    celix_status_t status = CELIX_SUCCESS;

    wiring_admin_pt admin = handle;
    wiring_receive_service_pt wiringReceiveService = (wiring_receive_service_pt) service;
    array_list_pt wiringReceiveServiceList = hashMap_get(admin->wiringReceiveServices, wiringReceiveService->wireId);

    if (wiringReceiveServiceList != NULL) {
        arrayList_removeElement(wiringReceiveServiceList, wiringReceiveService);

        printf("%s: wiringAdmin_wiringReceiveRemoved, service w/ wireId %s removed!\n", TAG, wiringReceiveService->wireId);

        if (arrayList_size(wiringReceiveServiceList) == 0) {
            arrayList_destroy(wiringReceiveServiceList);
            hashMap_remove(admin->wiringReceiveServices, wiringReceiveService->wireId);
        }
    } else {
        printf("%s: wiringAdmin_wiringReceiveRemoved, service w/ wireId %s not found!\n", TAG, wiringReceiveService->wireId);
    }

    return status;
}
Exemplo n.º 24
0
static celix_status_t serviceRegistry_flushUsageCount(service_registry_pt registry, bundle_pt bundle, service_reference_pt reference) {
	array_list_pt usages = hashMap_get(registry->inUseMap, bundle);
	if (usages != NULL) {
		array_list_iterator_pt iter = arrayListIterator_create(usages);
		while (arrayListIterator_hasNext(iter)) {
			usage_count_pt usage = arrayListIterator_next(iter);
			bool equals = false;
			serviceReference_equals(usage->reference, reference, &equals);
			if (equals) {
				arrayListIterator_remove(iter);
				free(usage);
			}
		}
		arrayListIterator_destroy(iter);
		if (arrayList_size(usages) > 0) {
			hashMap_put(registry->inUseMap, bundle, usages);
		} else {
			array_list_pt removed = hashMap_remove(registry->inUseMap, bundle);
			arrayList_destroy(removed);
		}
	}
	return CELIX_SUCCESS;
}
Exemplo n.º 25
0
celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin, pubsub_endpoint_pt pubEP) {
	celix_status_t status = CELIX_SUCCESS;

	printf("PSA_ZMQ: Received publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n", pubEP->frameworkUUID, pubEP->serviceID, pubEP->scope, pubEP->topic);

	const char* fwUUID = NULL;

	bundleContext_getProperty(admin->bundle_context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
	if (fwUUID == NULL) {
		printf("PSA_ZMQ: Cannot retrieve fwUUID.\n");
		return CELIX_INVALID_BUNDLE_CONTEXT;
	}

	char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);

	if ((strcmp(pubEP->frameworkUUID, fwUUID) == 0) && (pubEP->endpoint == NULL)) {

		celixThreadMutex_lock(&admin->localPublicationsLock);

		service_factory_pt factory = (service_factory_pt) hashMap_get(admin->localPublications, scope_topic);

		if (factory == NULL) {
			topic_publication_pt pub = NULL;
			pubsub_serializer_service_t *best_serializer = NULL;
			if( (status=pubsubAdmin_getBestSerializer(admin, pubEP, &best_serializer)) == CELIX_SUCCESS){
				status = pubsub_topicPublicationCreate(admin->bundle_context, pubEP, best_serializer, admin->ipAddress, admin->basePort, admin->maxPort, &pub);
			}
			else{
				printf("PSA_ZMQ: Cannot find a serializer for publishing topic %s. Adding it to pending list.\n", pubEP->topic);
				celixThreadMutex_lock(&admin->noSerializerPendingsLock);
				arrayList_add(admin->noSerializerPublications,pubEP);
				celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
			}

			if (status == CELIX_SUCCESS) {
				status = pubsub_topicPublicationStart(admin->bundle_context, pub, &factory);
				if (status == CELIX_SUCCESS && factory != NULL) {
					hashMap_put(admin->localPublications, strdup(scope_topic), factory);
					connectTopicPubSubToSerializer(admin, best_serializer, pub, true);
				}
			} else {
				printf("PSA_ZMQ: Cannot create a topicPublication for scope=%s, topic=%s (bundle %ld).\n", pubEP->scope, pubEP->topic, pubEP->serviceID);
			}
		} else {
			//just add the new EP to the list
			topic_publication_pt pub = (topic_publication_pt) factory->handle;
			pubsub_topicPublicationAddPublisherEP(pub, pubEP);
		}

		celixThreadMutex_unlock(&admin->localPublicationsLock);
	}
	else{

		celixThreadMutex_lock(&admin->externalPublicationsLock);
		array_list_pt ext_pub_list = (array_list_pt) hashMap_get(admin->externalPublications, scope_topic);
		if (ext_pub_list == NULL) {
			arrayList_create(&ext_pub_list);
			hashMap_put(admin->externalPublications, strdup(scope_topic), ext_pub_list);
		}

		arrayList_add(ext_pub_list, pubEP);

		celixThreadMutex_unlock(&admin->externalPublicationsLock);
	}

	/* Re-evaluate the pending subscriptions */
	celixThreadMutex_lock(&admin->pendingSubscriptionsLock);

	hash_map_entry_pt pendingSub = hashMap_getEntry(admin->pendingSubscriptions, scope_topic);
	if (pendingSub != NULL) { //There were pending subscription for the just published topic. Let's connect them.
		char* topic = (char*) hashMapEntry_getKey(pendingSub);
		array_list_pt pendingSubList = (array_list_pt) hashMapEntry_getValue(pendingSub);
		int i;
		for (i = 0; i < arrayList_size(pendingSubList); i++) {
			pubsub_endpoint_pt subEP = (pubsub_endpoint_pt) arrayList_get(pendingSubList, i);
			pubsubAdmin_addSubscription(admin, subEP);
		}
		hashMap_remove(admin->pendingSubscriptions, scope_topic);
		arrayList_clear(pendingSubList);
		arrayList_destroy(pendingSubList);
		free(topic);
	}

	celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);

	/* Connect the new publisher to the subscription for his topic, if there is any */
	celixThreadMutex_lock(&admin->subscriptionsLock);

	topic_subscription_pt sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, scope_topic);
	if (sub != NULL && pubEP->endpoint != NULL) {
		pubsub_topicSubscriptionAddConnectPublisherToPendingList(sub, pubEP->endpoint);
	}

	/* And check also for ANY subscription */
	topic_subscription_pt any_sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, PUBSUB_ANY_SUB_TOPIC);
	if (any_sub != NULL && pubEP->endpoint != NULL) {
		pubsub_topicSubscriptionAddConnectPublisherToPendingList(any_sub, pubEP->endpoint);
	}

	free(scope_topic);

	celixThreadMutex_unlock(&admin->subscriptionsLock);

	return status;

}
Exemplo n.º 26
0
celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoint_pt pubEP){
	celix_status_t status = CELIX_SUCCESS;
	int count = 0;

	printf("PSA_ZMQ: Removing publication [FWUUID=%s bundleID=%ld topic=%s]\n",pubEP->frameworkUUID,pubEP->serviceID,pubEP->topic);

	const char* fwUUID = NULL;

	bundleContext_getProperty(admin->bundle_context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
	if(fwUUID==NULL){
		printf("PSA_ZMQ: Cannot retrieve fwUUID.\n");
		return CELIX_INVALID_BUNDLE_CONTEXT;
	}
	char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic);

	if(strcmp(pubEP->frameworkUUID,fwUUID)==0){

		celixThreadMutex_lock(&admin->localPublicationsLock);
		service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
		if(factory!=NULL){
			topic_publication_pt pub = (topic_publication_pt)factory->handle;
			pubsub_topicPublicationRemovePublisherEP(pub,pubEP);
		}
		celixThreadMutex_unlock(&admin->localPublicationsLock);

		if(factory==NULL){
			/* Maybe the endpoint was pending */
			celixThreadMutex_lock(&admin->noSerializerPendingsLock);
			if(!arrayList_removeElement(admin->noSerializerPublications, pubEP)){
				status = CELIX_ILLEGAL_STATE;
			}
			celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
		}
	}
	else{

		celixThreadMutex_lock(&admin->externalPublicationsLock);
		array_list_pt ext_pub_list = (array_list_pt)hashMap_get(admin->externalPublications,scope_topic);
		if(ext_pub_list!=NULL){
			int i;
			bool found = false;
			for(i=0;!found && i<arrayList_size(ext_pub_list);i++){
				pubsub_endpoint_pt p  = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
				found = pubsubEndpoint_equals(pubEP,p);
				if (found){
					arrayList_remove(ext_pub_list,i);
				}
			}
			// Check if there are more publishers on the same endpoint (happens when 1 celix-instance with multiple bundles publish in same topic)
			for(i=0; i<arrayList_size(ext_pub_list);i++) {
				pubsub_endpoint_pt p  = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
				if (strcmp(pubEP->endpoint,p->endpoint) == 0) {
					count++;
				}
			}

			if(arrayList_size(ext_pub_list)==0){
				hash_map_entry_pt entry = hashMap_getEntry(admin->externalPublications,scope_topic);
				char* topic = (char*)hashMapEntry_getKey(entry);
				array_list_pt list = (array_list_pt)hashMapEntry_getValue(entry);
				hashMap_remove(admin->externalPublications,topic);
				arrayList_destroy(list);
				free(topic);
			}
		}

		celixThreadMutex_unlock(&admin->externalPublicationsLock);
	}

	/* Check if this publisher was connected to one of our subscribers*/
	celixThreadMutex_lock(&admin->subscriptionsLock);

	topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
	if(sub!=NULL && pubEP->endpoint!=NULL && count == 0){
		pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(sub,pubEP->endpoint);
	}

	/* And check also for ANY subscription */
	topic_subscription_pt any_sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
	if(any_sub!=NULL && pubEP->endpoint!=NULL && count == 0){
		pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(any_sub,pubEP->endpoint);
	}

	free(scope_topic);
	celixThreadMutex_unlock(&admin->subscriptionsLock);

	return status;

}
Exemplo n.º 27
0
celix_status_t wiringTopologyManager_waRemoved(void * handle, service_reference_pt reference, void * service) {
    celix_status_t status = CELIX_SUCCESS;
    wiring_topology_manager_pt manager = handle;
    wiring_admin_service_pt wiringAdminService = (wiring_admin_service_pt) service;

    /* check whether one of the exported Wires can be exported here via the newly available wiringAdmin*/
    celixThreadMutex_lock(&manager->exportedWiringEndpointsLock);
    hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedWiringEndpoints);
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        hash_map_pt wiringAdminMap = hashMapEntry_getValue(entry);

        if (hashMap_containsKey(wiringAdminMap, wiringAdminService)) {
            wiring_endpoint_description_pt wEndpoint = (wiring_endpoint_description_pt) hashMap_remove(wiringAdminMap, wiringAdminService);

            status = wiringTopologyManager_notifyListenersWiringEndpointRemoved(manager, wEndpoint);

            if (status == CELIX_SUCCESS) {
                status = wiringAdminService->removeExportedWiringEndpoint(wiringAdminService->admin, wEndpoint);
            } else {
                printf("WTM: failed while removing WiringAdmin.\n");
            }
        }
    }

    hashMapIterator_destroy(iter);

    celixThreadMutex_unlock(&manager->exportedWiringEndpointsLock);

    /* Check if the added WA can match one of the imported WiringEndpoints */
    celixThreadMutex_lock(&manager->importedWiringEndpointsLock);
    iter = hashMapIterator_create(manager->importedWiringEndpoints);
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        wiring_endpoint_description_pt importedWiringEndpointDesc = hashMapEntry_getKey(entry);
        array_list_pt wiringAdminList = hashMapEntry_getValue(entry);

        if (arrayList_contains(wiringAdminList, wiringAdminService)) {
            status = wiringAdminService->removeImportedWiringEndpoint(wiringAdminService->admin, importedWiringEndpointDesc);
            arrayList_removeElement(wiringAdminList, wiringAdminService);
        }

        if (status == CELIX_SUCCESS) {
            arrayList_add(wiringAdminList, wiringAdminService);
        }

    }
    hashMapIterator_destroy(iter);
    celixThreadMutex_unlock(&manager->importedWiringEndpointsLock);

    celixThreadMutex_lock(&manager->waListLock);
    arrayList_removeElement(manager->waList, wiringAdminService);
    celixThreadMutex_unlock(&manager->waListLock);

    printf("WTM: Removed WA\n");

    return status;
}
Exemplo n.º 28
0
celix_status_t deviceManager_deviceRemoved(void * handle, service_reference_pt ref, void * service) {
	printf("DEVICE_MANAGER: Remove device\n");
	device_manager_pt manager = handle;
	hashMap_remove(manager->devices, ref);
	return CELIX_SUCCESS;
}
Exemplo n.º 29
0
celix_status_t deviceManager_deviceRemoved(void * handle, service_reference_pt ref, void * service) {
	device_manager_pt manager = handle;
	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove device");
	hashMap_remove(manager->devices, ref);
	return CELIX_SUCCESS;
}
Exemplo n.º 30
0
celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt reference, void * service){

	pubsub_admin_pt admin = (pubsub_admin_pt)handle;
	int i=0, j=0;
	const char *serType = NULL;

	serviceReference_getProperty(reference, PUBSUB_SERIALIZER_TYPE_KEY,&serType);
	if(serType == NULL){
		printf("Serializer serviceReference %p has no pubsub_serializer.type property specified\n",reference);
		return CELIX_SERVICE_EXCEPTION;
	}

	celixThreadMutex_lock(&admin->serializerListLock);
	/* Remove the serializer from the list */
	arrayList_removeElement(admin->serializerList, reference);
	celixThreadMutex_unlock(&admin->serializerListLock);


	celixThreadMutex_lock(&admin->usedSerializersLock);
	array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer, service);
	array_list_pt topicSubList = (array_list_pt)hashMap_remove(admin->topicSubscriptionsPerSerializer, service);
	celixThreadMutex_unlock(&admin->usedSerializersLock);

	/* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the noSerializer pending list */
	if(topicPubList!=NULL){
		for(i=0;i<arrayList_size(topicPubList);i++){
			topic_publication_pt topicPub = (topic_publication_pt)arrayList_get(topicPubList,i);
			/* Stop the topic publication */
			pubsub_topicPublicationStop(topicPub);
			/* Get the endpoints that are going to be orphan */
			array_list_pt pubList = pubsub_topicPublicationGetPublisherList(topicPub);
			for(j=0;j<arrayList_size(pubList);j++){
				pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubList,j);
				/* Remove the publication */
				pubsubAdmin_removePublication(admin, pubEP);
				/* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
				if(pubEP->endpoint!=NULL){
					free(pubEP->endpoint);
					pubEP->endpoint = NULL;
				}
				/* Add the orphan endpoint to the noSerializer pending list */
				celixThreadMutex_lock(&admin->noSerializerPendingsLock);
				arrayList_add(admin->noSerializerPublications,pubEP);
				celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
			}
			arrayList_destroy(pubList);

			/* Cleanup also the localPublications hashmap*/
			celixThreadMutex_lock(&admin->localPublicationsLock);
			hash_map_iterator_pt iter = hashMapIterator_create(admin->localPublications);
			char *key = NULL;
			service_factory_pt factory = NULL;
			while(hashMapIterator_hasNext(iter)){
				hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
				factory = (service_factory_pt)hashMapEntry_getValue(entry);
				topic_publication_pt pub = (topic_publication_pt)factory->handle;
				if(pub==topicPub){
					key = (char*)hashMapEntry_getKey(entry);
					break;
				}
			}
			hashMapIterator_destroy(iter);
			if(key!=NULL){
				hashMap_remove(admin->localPublications, key);
				free(factory);
				free(key);
			}
			celixThreadMutex_unlock(&admin->localPublicationsLock);

			/* Finally destroy the topicPublication */
			pubsub_topicPublicationDestroy(topicPub);
		}
		arrayList_destroy(topicPubList);
	}

	/* Now destroy the topicSubscriptions, but first put back the pubsub_endpoints back to the noSerializer pending list */
	if(topicSubList!=NULL){
		for(i=0;i<arrayList_size(topicSubList);i++){
			topic_subscription_pt topicSub = (topic_subscription_pt)arrayList_get(topicSubList,i);
			/* Stop the topic subscription */
			pubsub_topicSubscriptionStop(topicSub);
			/* Get the endpoints that are going to be orphan */
			array_list_pt subList = pubsub_topicSubscriptionGetSubscribersList(topicSub);
			for(j=0;j<arrayList_size(subList);j++){
				pubsub_endpoint_pt subEP = (pubsub_endpoint_pt)arrayList_get(subList,j);
				/* Remove the subscription */
				pubsubAdmin_removeSubscription(admin, subEP);
				/* Reset the endpoint field, so that will be recreated from scratch when a new serializer will be found */
				if(subEP->endpoint!=NULL){
					free(subEP->endpoint);
					subEP->endpoint = NULL;
				}
				/* Add the orphan endpoint to the noSerializer pending list */
				celixThreadMutex_lock(&admin->noSerializerPendingsLock);
				arrayList_add(admin->noSerializerSubscriptions,subEP);
				celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
			}

			/* Cleanup also the subscriptions hashmap*/
			celixThreadMutex_lock(&admin->subscriptionsLock);
			hash_map_iterator_pt iter = hashMapIterator_create(admin->subscriptions);
			char *key = NULL;
			while(hashMapIterator_hasNext(iter)){
				hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
				topic_subscription_pt sub = (topic_subscription_pt)hashMapEntry_getValue(entry);
				if(sub==topicSub){
					key = (char*)hashMapEntry_getKey(entry);
					break;
				}
			}
			hashMapIterator_destroy(iter);
			if(key!=NULL){
				hashMap_remove(admin->subscriptions, key);
				free(key);
			}
			celixThreadMutex_unlock(&admin->subscriptionsLock);

			/* Finally destroy the topicSubscription */
			pubsub_topicSubscriptionDestroy(topicSub);
		}
		arrayList_destroy(topicSubList);
	}



	printf("PSA_ZMQ: %s serializer removed\n",serType);


	return CELIX_SUCCESS;
}