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;
}
示例#2
0
void *remoteShell_connection_run(void *data) {
	celix_status_t status = CELIX_SUCCESS;
	connection_pt connection = data;
	size_t len;
	int result;
	struct timeval timeout; /* Timeout for select */

	int fd = fileno(connection->socketStream);

	connection->threadRunning = true;
	status = remoteShell_connection_print(connection, RS_WELCOME);

	while (status == CELIX_SUCCESS && connection->threadRunning == true) {
		do {
			timeout.tv_sec = CONNECTION_LISTENER_TIMEOUT_SEC;
			timeout.tv_usec = 0;

			FD_ZERO(&connection->pollset);
			FD_SET(fd, &connection->pollset);
			result = select(fd + 1, &connection->pollset, NULL, NULL, &timeout);
		} while (result == -1 && errno == EINTR && connection->threadRunning == true);

		/* The socket_fd has data available to be read */
		if (result > 0 && FD_ISSET(fd, &connection->pollset)) {
			char buff[COMMAND_BUFF_SIZE];

			len = recv(fd, buff, COMMAND_BUFF_SIZE - 1, 0);
			if (len < COMMAND_BUFF_SIZE) {
				celix_status_t commandStatus = CELIX_SUCCESS;
				buff[len] = '\0';

				commandStatus = remoteShell_connection_execute(connection, buff);

				if (commandStatus == CELIX_SUCCESS) {
					remoteShell_connection_print(connection, RS_PROMPT);
				} else if (commandStatus == CELIX_FILE_IO_EXCEPTION) {
					//exit command
					break;
				} else { //error
					remoteShell_connection_print(connection, RS_ERROR);
					remoteShell_connection_print(connection, RS_PROMPT);
				}

			} else {
				logHelper_log(*connection->parent->loghelper, OSGI_LOGSERVICE_ERROR, "REMOTE_SHELL: Error while retrieving data");
			}
		}
	}

	remoteShell_connection_print(connection, RS_GOODBYE);

	logHelper_log(*connection->parent->loghelper, OSGI_LOGSERVICE_INFO, "REMOTE_SHELL: Closing socket");
	celixThreadMutex_lock(&connection->parent->mutex);
	arrayList_removeElement(connection->parent->connections, connection);
	celixThreadMutex_unlock(&connection->parent->mutex);

	fclose(connection->socketStream);

	return NULL;
}
示例#3
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;
}
示例#4
0
celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
	celix_status_t status = CELIX_SUCCESS;

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

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

	celixThreadMutex_lock(&admin->subscriptionsLock);
	topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
	if(sub!=NULL){
		pubsub_topicDecreaseNrSubscribers(sub);
		if(pubsub_topicGetNrSubscribers(sub) == 0) {
			status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP);
		}
	}
	celixThreadMutex_unlock(&admin->subscriptionsLock);

	if(sub==NULL){
		/* Maybe the endpoint was pending */
		celixThreadMutex_lock(&admin->noSerializerPendingsLock);
		if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){
			status = CELIX_ILLEGAL_STATE;
		}
		celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
	}

	free(scope_topic);



	return status;

}
示例#5
0
celix_status_t discovery_endpointRemoved(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
    celix_status_t status  = CELIX_SUCCESS;
    struct disc_mock_activator *act = handle;
    printf("%s\n", __func__);
    arrayList_removeElement(act->endpointList, endpoint);

    return status;
}
示例#6
0
celix_status_t pubsub_topicSubscriptionRemoveSubscriber(topic_subscription_pt ts, pubsub_endpoint_pt subEP){
	celix_status_t status = CELIX_SUCCESS;

	celixThreadMutex_lock(&ts->ts_lock);
	arrayList_removeElement(ts->sub_ep_list,subEP);
	celixThreadMutex_unlock(&ts->ts_lock);

	return status;
}
示例#7
0
celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, bundle_pt bundle, service_registration_pt registration) {
	// array_list_t clients;
	unsigned int i;
	array_list_pt regs;
	array_list_pt references = NULL;

	celixThreadMutex_lock(&registry->mutex);

	serviceRegistry_removeHook(registry, registration);

	regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
	if (regs != NULL) {
		arrayList_removeElement(regs, registration);
		hashMap_put(registry->serviceRegistrations, bundle, regs);
	}

	celixThreadMutex_unlock(&registry->mutex);

	if (registry->serviceChanged != NULL) {
		registry->serviceChanged(registry->framework, OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING, registration, NULL);
	}

	celixThreadMutex_lock(&registry->mutex);
	// unget service

	serviceRegistration_getServiceReferences(registration, &references);
	for (i = 0; i < arrayList_size(references); i++) {
		service_reference_pt reference = (service_reference_pt) arrayList_get(references, i);
		array_list_pt clients = NULL;
		unsigned int j;

		clients = serviceRegistry_getUsingBundles(registry, reference);
		for (j = 0; (clients != NULL) && (j < arrayList_size(clients)); j++) {
			bundle_pt client = (bundle_pt) arrayList_get(clients, j);
			bool ungetResult = true;
			while (ungetResult) {
				serviceRegistry_ungetService(registry, client, reference, &ungetResult);
			}
		}
		arrayList_destroy(clients);

		serviceReference_invalidate(reference);
	}
	arrayList_destroy(references);

	//TODO not needed, the registration is destroyed, any reference to the registration is invalid and will result in a segfault
	serviceRegistration_invalidate(registration);

	// serviceRegistration_destroy(registration);

	celixThreadMutex_unlock(&registry->mutex);

	return CELIX_SUCCESS;
}
示例#8
0
static celix_status_t refiningDriver_stopDevice(refining_driver_device_pt device) {
	printf("REFINING_DRIVER: stopping device, parent device is unregistered\n");
	celix_status_t status =  CELIX_SUCCESS;

	if (device->deviceRegistration != NULL) {
		status = serviceRegistration_unregister(device->deviceRegistration);
		if (status == CELIX_SUCCESS) {
			printf("unregistered refining device\n");
		}
	}

	arrayList_removeElement(device->driver->devices, device);
	return status;
}
示例#9
0
celix_status_t serviceRegistry_removeHook(service_registry_pt registry, service_registration_pt registration) {
	celix_status_t status = CELIX_SUCCESS;
	char *serviceName = NULL;

	properties_pt props = NULL;
	serviceRegistration_getProperties(registration, &props);
	serviceName = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
	if (strcmp(OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, serviceName) == 0) {
	    celixThreadMutex_lock(&registry->mutex);
		arrayList_removeElement(registry->listenerHooks, registration);
		celixThreadMutex_unlock(&registry->mutex);
	}

	return status;
}
示例#10
0
static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication){

	celixThreadMutex_lock(&admin->usedSerializersLock);

	hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
	hash_map_iterator_pt iter = hashMapIterator_create(map);
	while(hashMapIterator_hasNext(iter)){
		array_list_pt list = (array_list_pt)hashMapIterator_nextValue(iter);
		if(arrayList_removeElement(list, topicPubSub)){ //Found it!
			break;
		}
	}
	hashMapIterator_destroy(iter);

	celixThreadMutex_unlock(&admin->usedSerializersLock);

}
示例#11
0
celix_status_t pubsub_discovery_removePublisher(void *handle, pubsub_endpoint_pt pubEP) {
	celix_status_t status = CELIX_SUCCESS;

	pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;

	celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);

	char *pub_key = createScopeTopicKey(pubEP->scope,pubEP->topic);
	array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pub_key);
	free(pub_key);
	if(pubEP_list==NULL){
		printf("PSD: Cannot find any registered publisher for topic %s. Something is not consistent.\n",pubEP->topic);
		status = CELIX_ILLEGAL_STATE;
	}
	else{

		int i;
		bool found = false;
		pubsub_endpoint_pt p = NULL;

		for(i=0;!found && i<arrayList_size(pubEP_list);i++){
			p = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
			found = pubsubEndpoint_equals(pubEP,p);
		}

		if(!found){
			printf("PSD: Trying to remove a not existing endpoint. Something is not consistent.\n");
			status = CELIX_ILLEGAL_STATE;
		}
		else{

			arrayList_removeElement(pubEP_list,p);

			status = etcdWriter_deletePublisherEndpoint(pubsub_discovery->writer,p);

			pubsubEndpoint_destroy(p);
		}
	}

	celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);

	return status;
}
示例#12
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;
}
示例#13
0
void test_arrayList_removeElement(void) {
	char * entry = "entry";
	char * entry2 = "entry2";
	char * entry3 = "entry3";
	char * get;

	arrayList_clear(list);

	arrayList_add(list, entry);
	arrayList_add(list, entry2);

	// Remove entry
	CU_ASSERT_TRUE(arrayList_removeElement(list, entry));

	// Check the new first element
	get = arrayList_get(list, 0);
	CU_ASSERT_EQUAL(entry2, get);

	// Add a new element
	arrayList_add(list, entry3);

	get = arrayList_get(list, 1);
	CU_ASSERT_EQUAL(entry3, get);
}
示例#14
0
celix_status_t deviceManager_matchAttachDriver(device_manager_pt manager, apr_pool_t *attachPool, driver_loader_pt loader,
		array_list_pt driverIds, array_list_pt included, array_list_pt excluded, void *service, service_reference_pt reference) {
	celix_status_t status = CELIX_SUCCESS;

	array_list_pt references = NULL;

	int i;
	for (i = 0; i < arrayList_size(excluded); i++) {
		void *exclude = arrayList_get(excluded, i);
		arrayList_removeElement(included, exclude);
	}

	for (i = 0; i < arrayList_size(driverIds); i++) {
		char *id = arrayList_get(driverIds, i);
		printf("DEVICE_MANAGER: Driver found: %s\n", id);
	}

	status = driverLoader_loadDrivers(loader, attachPool, manager->locators, driverIds, &references);
	if (status == CELIX_SUCCESS) {
		for (i = 0; i < arrayList_size(references); i++) {
			service_reference_pt reference = arrayList_get(references, i);
			driver_attributes_pt attributes = hashMap_get(manager->drivers, reference);
			if (attributes != NULL) {
				arrayList_add(included, attributes);
			}
		}

		driver_matcher_pt matcher = NULL;
		status = driverMatcher_create(attachPool, manager->context, &matcher);
		if (status == CELIX_SUCCESS) {
			for (i = 0; i < arrayList_size(included); i++) {
				driver_attributes_pt attributes = arrayList_get(included, i);

				int match = 0;
				celix_status_t substatus = driverAttributes_match(attributes, reference, &match);
				if (substatus == CELIX_SUCCESS) {
					printf("DEVICE_MANAGER: Found match: %d\n", match);
					if (match <= OSGI_DEVICEACCESS_DEVICE_MATCH_NONE) {
						continue;
					}
					driverMatcher_add(matcher, match, attributes);
				} else {
					// Ignore
				}
			}

			match_pt match = NULL;
			status = driverMatcher_getBestMatch(matcher, attachPool, reference, &match);
			if (status == CELIX_SUCCESS) {
				if (match == NULL) {
					status = deviceManager_noDriverFound(manager, service, reference);
				} else {
					service_registration_pt registration = NULL;
					status = serviceReference_getServiceRegistration(match->reference, &registration);
					if (status == CELIX_SUCCESS) {
						properties_pt properties = NULL;
						status = serviceRegistration_getProperties(registration, &properties);
						if (status == CELIX_SUCCESS) {
							char *driverId = properties_get(properties, (char *) OSGI_DEVICEACCESS_DRIVER_ID);
							driver_attributes_pt finalAttributes = hashMap_get(manager->drivers, match->reference);
							if (finalAttributes == NULL) {
								status = deviceManager_noDriverFound(manager, service, reference);
							} else {
								char *newDriverId = NULL;
								status = driverAttributes_attach(finalAttributes, reference, &newDriverId);
								if (status == CELIX_SUCCESS) {
									if (newDriverId != NULL) {
										array_list_pt ids = NULL;
										arrayList_create(&ids);
										arrayList_add(ids, newDriverId);
										arrayList_add(excluded, finalAttributes);
										status = deviceManager_matchAttachDriver(manager, attachPool, loader,
												ids, included, excluded, service, reference);
									} else {
										// Attached, unload unused drivers
										status = driverLoader_unloadDrivers(loader, finalAttributes);
									}
								}
							}
						}
					}
				}
			}
		}
	}

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

	return status;
}
示例#15
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;

}
示例#16
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;
}
示例#17
0
celix_status_t deviceManager_locatorRemoved(void * handle, service_reference_pt ref, void * service) {
	printf("DEVICE_MANAGER: Remove locator\n");
	device_manager_pt manager = handle;
	arrayList_removeElement(manager->locators, service);
	return CELIX_SUCCESS;
}
示例#18
0
celix_status_t deviceManager_matchAttachDriver(device_manager_pt manager, driver_loader_pt loader,
		array_list_pt driverIds, array_list_pt included, array_list_pt excluded, void *service, service_reference_pt reference) {
	celix_status_t status = CELIX_SUCCESS;

	array_list_pt references = NULL;

	int i;
	for (i = 0; i < arrayList_size(excluded); i++) {
		void *exclude = arrayList_get(excluded, i);
		arrayList_removeElement(included, exclude);
	}

	for (i = 0; i < arrayList_size(driverIds); i++) {
		char *id = arrayList_get(driverIds, i);
		logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "DEVICE_MANAGER: Driver found: %s", id);
	}

	status = driverLoader_loadDrivers(loader, manager->locators, driverIds, &references);
	if (status == CELIX_SUCCESS) {
		for (i = 0; i < arrayList_size(references); i++) {
			service_reference_pt reference = arrayList_get(references, i);
			driver_attributes_pt attributes = hashMap_get(manager->drivers, reference);
			if (attributes != NULL) {
				arrayList_add(included, attributes);
			}
		}

		driver_matcher_pt matcher = NULL;
		status = driverMatcher_create(manager->context, &matcher);
		if (status == CELIX_SUCCESS) {
			for (i = 0; i < arrayList_size(included); i++) {
				driver_attributes_pt attributes = arrayList_get(included, i);

				int match = 0;
				celix_status_t substatus = driverAttributes_match(attributes, reference, &match);
				if (substatus == CELIX_SUCCESS) {
					logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "DEVICE_MANAGER: Found match: %d", match);
					if (match <= OSGI_DEVICEACCESS_DEVICE_MATCH_NONE) {
						continue;
					}
					driverMatcher_add(matcher, match, attributes);
				} else {
					// Ignore
				}
			}

			match_pt match = NULL;
			status = driverMatcher_getBestMatch(matcher, reference, &match);
			if (status == CELIX_SUCCESS) {
				if (match == NULL) {
					status = deviceManager_noDriverFound(manager, service, reference);
				} else {
                    driver_attributes_pt finalAttributes = hashMap_get(manager->drivers, match->reference);
                    if (finalAttributes == NULL) {
                        status = deviceManager_noDriverFound(manager, service, reference);
                    } else {
                        char *newDriverId = NULL;
                        status = driverAttributes_attach(finalAttributes, reference, &newDriverId);
                        if (status == CELIX_SUCCESS) {
                            if (newDriverId != NULL) {
                                array_list_pt ids = NULL;
                                arrayList_create(&ids);
                                arrayList_add(ids, newDriverId);
                                arrayList_add(excluded, finalAttributes);
                                status = deviceManager_matchAttachDriver(manager, loader,
                                        ids, included, excluded, service, reference);
                            } else {
                                // Attached, unload unused drivers
                                status = driverLoader_unloadDrivers(loader, finalAttributes);
                            }
                        }
					}
				}
			}
		}

		driverMatcher_destroy(&matcher);

	}

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

	return status;
}
示例#19
0
celix_status_t deviceManager_locatorRemoved(void * handle, service_reference_pt ref, void * service) {
	device_manager_pt manager = handle;
	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove locator");
	arrayList_removeElement(manager->locators, service);
	return CELIX_SUCCESS;
}
示例#20
0
int phase3_removePhase2(phase3_cmp_t *cmp, phase2_t *phase2) {
    arrayList_removeElement(cmp->phase2Services, phase2);
    return 0;
}