예제 #1
0
celix_status_t driverAttributes_isInUse(driver_attributes_pt driverAttributes, bool *inUse) {
	celix_status_t status = CELIX_SUCCESS;

	array_list_pt references = NULL;
	status = bundle_getServicesInUse(driverAttributes->bundle, &references);
	if (status == CELIX_SUCCESS) {
		if (references == NULL || arrayList_size(references) == 0) {
			*inUse = false;
		} else {
			int i;
			for (i = 0; i < arrayList_size(references); i++) {
				service_reference_pt ref = arrayList_get(references, i);
				char *object = NULL;
				status = serviceReference_getProperty(ref, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &object);

				if (status == CELIX_SUCCESS) {
					char *category = NULL;
					status = serviceReference_getProperty(ref, "DEVICE_CATEGORY", &category);

					if (status == CELIX_SUCCESS) {
						if ((object != NULL && strcmp(object, OSGI_DEVICEACCESS_DEVICE_SERVICE_NAME) == 0) || (category != NULL)) {
							*inUse = true;
						}
					}
				}
			}
		}
	}

	return status;
}
예제 #2
0
파일: dm_event.c 프로젝트: leckie711/celix
celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle_context_pt context, service_reference_pt reference, void *service, dm_event_pt *event) {
	celix_status_t status = CELIX_SUCCESS;

	*event = calloc(1, sizeof(**event));
	if (!*event) {
		status = CELIX_ENOMEM;
	}

	char *serviceIdStr = NULL;
	serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_ID, &serviceIdStr);
	long servId = atol(serviceIdStr);

	//FIXME service ranking can dynamicly change, but service reference can be removed at any time.
	char *rankingStr = NULL;
	serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_RANKING, &rankingStr);
	long ranking = rankingStr == NULL ? 0 : atol(rankingStr);

	if (status == CELIX_SUCCESS) {
		(*event)->bundle = bundle;
		(*event)->event_type = event_type;
		(*event)->context = context;
		(*event)->reference = reference;
		(*event)->service = service;
		(*event)->serviceId = servId;
		(*event)->ranking = ranking;
	}

	return status;
}
celix_status_t wiringTopologyManager_wiringEndpointListenerAdded(void* handle, service_reference_pt reference, void* service) {
    celix_status_t status = CELIX_SUCCESS;
    wiring_topology_manager_pt manager = handle;
    char *scope = NULL;
    char* wtm = NULL;

    serviceReference_getProperty(reference, (char *) INAETICS_WIRING_ENDPOINT_LISTENER_SCOPE, &scope);
    serviceReference_getProperty(reference, "WTM", &wtm);

    if (wtm != NULL && strcmp(wtm, "true") == 0) {
        printf("WTM: Ignoring own ENDPOINT_LISTENER\n");
    }
    else {
        status = celixThreadMutex_lock(&manager->listenerListLock);

        if (status == CELIX_SUCCESS) {
            hashMap_put(manager->listenerList, reference, NULL);
            celixThreadMutex_unlock(&manager->listenerListLock);
        }

        filter_pt filter = filter_create(scope);
        status = celixThreadMutex_lock(&manager->exportedWiringEndpointsLock);

        if (status == CELIX_SUCCESS) {
            hash_map_iterator_pt propIter = hashMapIterator_create(manager->exportedWiringEndpoints);

            while (hashMapIterator_hasNext(propIter)) {
                hash_map_pt wiringAdminList = hashMapIterator_nextValue(propIter);
                hash_map_iterator_pt waIter = hashMapIterator_create(wiringAdminList);

                while (hashMapIterator_hasNext(waIter)) {
                    wiring_endpoint_description_pt wEndpoint = hashMapIterator_nextValue(waIter);

                    bool matchResult = false;
                    filter_match(filter, wEndpoint->properties, &matchResult);

                    if (matchResult) {
                        wiring_endpoint_listener_pt listener = (wiring_endpoint_listener_pt) service;
                        status = listener->wiringEndpointAdded(listener->handle, wEndpoint, scope);
                    }
                }
                hashMapIterator_destroy(waIter);
            }
            hashMapIterator_destroy(propIter);

            celixThreadMutex_unlock(&manager->exportedWiringEndpointsLock);
        }
        filter_destroy(filter);

    }


    return status;
}
예제 #4
0
파일: shell.c 프로젝트: leckie711/celix
celix_status_t shell_getCommandReference(shell_pt shell_ptr, char *command_name_str, service_reference_pt *command_reference_ptr) {
	celix_status_t status = CELIX_SUCCESS;

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

	if (status == CELIX_SUCCESS) {
		*command_reference_ptr = NULL;
		hash_map_iterator_pt iter = hashMapIterator_create(shell_ptr->command_reference_map_ptr);
		while (hashMapIterator_hasNext(iter)) {
			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
			service_reference_pt reference = hashMapEntry_getKey(entry);
			char *name_str = NULL;
			serviceReference_getProperty(reference, "command.name", &name_str);
			if (strcmp(name_str, command_name_str) == 0) {
				*command_reference_ptr = (service_reference_pt) hashMapEntry_getKey(entry);
				break;
			}
		}
		hashMapIterator_destroy(iter);
	}

	return status;
}
예제 #5
0
celix_status_t deviceManager_noDriverFound(device_manager_pt manager, void *service, service_reference_pt reference) {
	celix_status_t status = CELIX_SUCCESS;
    const char* objectClass = NULL;
    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &objectClass);
    if (strcmp(objectClass, OSGI_DEVICEACCESS_DRIVER_SERVICE_NAME) == 0) {
        device_service_pt device = service;
        status = device->noDriverFound(device->device);
    }
	return status;
}
예제 #6
0
celix_status_t refiningDriver_match(void *driverHandler, service_reference_pt reference, int *value) {
	printf("REFINING_DRIVER: match called\n");
	int match = 0;
	celix_status_t status = CELIX_SUCCESS;

    char *category = NULL;
    status = serviceReference_getProperty(reference, OSGI_DEVICEACCESS_DEVICE_CATEGORY, &category);
    if (status == CELIX_SUCCESS) {
        if (strcmp(category, BASE_DRIVER_DEVICE_CATEGORY) == 0) {
            match = 10;
        }
    }

	(*value) = match;
	return status;
}
예제 #7
0
    static void testExportService(void) {
        int rc = 0;
        char *calcId = NULL;
        array_list_pt regs = NULL;

        rc = arrayList_create(&regs);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = serviceReference_getProperty(calcRef, (char *)"service.id", &calcId);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        rc = rsa->exportService(rsa->admin, calcId, NULL, &regs);
        CHECK_EQUAL(CELIX_SUCCESS, rc);

        CHECK_EQUAL(1, arrayList_size(regs));
    }
예제 #8
0
celix_status_t pubsubAdmin_serializerAdded(void * handle, service_reference_pt reference, void * service){
	/* Assumption: serializers are all available at startup.
	 * If a new (possibly better) serializer is installed and started, already created topic_publications/subscriptions will not be destroyed and recreated */

	celix_status_t status = CELIX_SUCCESS;
	int i=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;
	}

	pubsub_admin_pt admin = (pubsub_admin_pt)handle;
	celixThreadMutex_lock(&admin->serializerListLock);
	arrayList_add(admin->serializerList, reference);
	celixThreadMutex_unlock(&admin->serializerListLock);

	/* Now let's re-evaluate the pending */
	celixThreadMutex_lock(&admin->noSerializerPendingsLock);

	for(i=0;i<arrayList_size(admin->noSerializerSubscriptions);i++){
		pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerSubscriptions,i);
		pubsub_serializer_service_t *best_serializer = NULL;
		pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
		if(best_serializer != NULL){ /* Finally we have a valid serializer! */
			pubsubAdmin_addSubscription(admin, ep);
		}
	}

	for(i=0;i<arrayList_size(admin->noSerializerPublications);i++){
		pubsub_endpoint_pt ep = (pubsub_endpoint_pt)arrayList_get(admin->noSerializerPublications,i);
		pubsub_serializer_service_t *best_serializer = NULL;
		pubsubAdmin_getBestSerializer(admin, ep, &best_serializer);
		if(best_serializer != NULL){ /* Finally we have a valid serializer! */
			pubsubAdmin_addPublication(admin, ep);
		}
	}

	celixThreadMutex_unlock(&admin->noSerializerPendingsLock);

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

	return status;
}
예제 #9
0
celix_status_t managedServiceTracker_removedService(void * handle, service_reference_pt reference, void * service) {
    celix_status_t status = CELIX_SUCCESS;
    const char* pid;
    managed_service_tracker_pt managedServiceTracker_i = handle;	//instance
    bundle_context_pt context;


    status = serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_PID, &pid);
    if (status != CELIX_SUCCESS || pid == NULL){
	return CELIX_ILLEGAL_ARGUMENT;
    }
    if ( managedServiceTracker_getBundleContext(managedServiceTracker_i, &context) != CELIX_SUCCESS ){
	return CELIX_ILLEGAL_ARGUMENT;
    }
    status = managedServiceTracker_remove(managedServiceTracker_i, reference, (char*)pid);

    return status;

}
예제 #10
0
celix_status_t driverAttributes_getDriverId(driver_attributes_pt driverAttributes, char **driverId) {
	celix_status_t status = CELIX_SUCCESS;

    char *id_prop = NULL;
    status = serviceReference_getProperty(driverAttributes->reference, "DRIVER_ID", &id_prop);
    if (status == CELIX_SUCCESS) {
        if (!id_prop) {
            status = CELIX_ENOMEM;
        } else {
            *driverId = strdup(id_prop);

            if (*driverId == NULL) {
                status = CELIX_ENOMEM;
			}
		}
	}

	return status;
}
예제 #11
0
파일: shell.c 프로젝트: leckie711/celix
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;
}
예제 #12
0
파일: shell.c 프로젝트: leckie711/celix
celix_status_t shell_getCommandDescription(shell_pt shell_ptr, char *command_name_str, char **command_description_pstr) {
	celix_status_t status = CELIX_SUCCESS;

	service_reference_pt reference = NULL;

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

	if (status == CELIX_SUCCESS) {
		status = shell_getCommandReference(shell_ptr, command_name_str, &reference);
		if (!reference) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
	}

	if (status == CELIX_SUCCESS) {
		serviceReference_getProperty(reference, "command.description", command_description_pstr);
	}

	return status;
}
예제 #13
0
파일: shell.c 프로젝트: leckie711/celix
celix_status_t shell_addCommand(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) {
		status = bundleContext_getService(shell_ptr->bundle_context_ptr, reference_ptr, (void **) &command_ptr);
		if (!command_ptr) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
	}

	if (status == CELIX_SUCCESS) {
		status = serviceReference_getProperty(reference_ptr, "command.name", &name_str);
		if (!name_str) {
            logHelper_log(shell_ptr->logHelper, OSGI_LOGSERVICE_ERROR, "Command service must contain a 'command.name' property!");
			status = CELIX_BUNDLE_EXCEPTION;
		}
	}

	if (status == CELIX_SUCCESS) {
		hashMap_put(shell_ptr->command_name_map_ptr, name_str, command_ptr);
		hashMap_put(shell_ptr->command_reference_map_ptr, reference_ptr, command_ptr);
	}

	if (status != CELIX_SUCCESS) {
		shell_removeCommand(shell_ptr, reference_ptr);
        char err[32];
        celix_strerror(status, err, 32);
        logHelper_log(shell_ptr->logHelper, OSGI_LOGSERVICE_ERROR, "Could not add command, got error %s\n", err);
	}

	return status;
}
예제 #14
0
celix_status_t deviceManager_isDriverBundle(device_manager_pt manager, bundle_pt bundle, bool *isDriver) {
	celix_status_t status = CELIX_SUCCESS;
	(*isDriver) = false;

	array_list_pt refs = NULL;
		status = bundle_getRegisteredServices(bundle, &refs);
		if (status == CELIX_SUCCESS) {
			if (refs != NULL) {
				int i;
				for (i = 0; i < arrayList_size(refs); i++) {
					service_reference_pt ref = arrayList_get(refs, i);
                    const char* object = NULL;
                    serviceReference_getProperty(ref, OSGI_FRAMEWORK_OBJECTCLASS, &object);
                    if (strcmp(object, "driver") == 0) {
                        *isDriver = true;
                        break;
                    }
				}
				arrayList_destroy(refs);
			}
		}

	return status;
}
예제 #15
0
celix_status_t managedServiceTracker_addingService(void * handle, service_reference_pt reference, void **service) {


    celix_status_t status;

    const char* pid = NULL;

    bundle_context_pt context = NULL;

    managed_service_tracker_pt managedServiceTracker_i = handle;	//instance
    managed_service_service_pt managedService_s = NULL;			//service

    // (1) reference.getPid

    status = serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_PID, &pid);
    if (status != CELIX_SUCCESS || pid == NULL) {
        *service = NULL;
        printf(" [ ERROR ]: Tracker - PID is NULL \n");
        return CELIX_ILLEGAL_ARGUMENT;
    }

    // (2) context.getManagedServiceService

    // (2.1) trackerInstance.getBundleContext

    if (managedServiceTracker_getBundleContext(managedServiceTracker_i, &context) != CELIX_SUCCESS) {
        *service = NULL;
        printf(" [ ERROR ]: Tracker - NULL bundleContext \n");
        return CELIX_ILLEGAL_ARGUMENT;
    }

    // (2.2) context.getManagedServiceService

    if (bundleContext_getService(context, reference, (void*) &managedService_s) != CELIX_SUCCESS) {
        printf("[ ERROR ]: Tracker - AddingService ( BundleContext - getService{PID=%s} ) \n", pid);
        *service = NULL;
        return CELIX_ILLEGAL_ARGUMENT;
    }
    if (managedService_s == NULL) {
        printf("[ WARNING ]: Tracker - AddingService (none Service{PID=%s}) \n", pid);
        *service = NULL;
        return CELIX_ILLEGAL_ARGUMENT;
    }

    /* DEBUG CODE *

    service_registration_pt registration = NULL;
    serviceReference_getServiceRegistration(reference, &registration);
    char *serviceName = NULL;
    serviceRegistration_getServiceName(registration, &serviceName);

    printf("[ DEBUG ]: Tracker - AddingService ( SUCCESS BundleCtxt - getService{Name=%s,PID=%s}  ) \n", serviceName, pid);

    * ENF OF DEBUG CODE */

    // (3) trackerInstance.AddManagedServiceToLocalList
    configurationStore_lock(managedServiceTracker_i->configurationStore);

    status = managedServiceTracker_add(managedServiceTracker_i, reference, (char*)pid, managedService_s);
    if (status != CELIX_SUCCESS) {
        bundleContext_ungetService(context, reference, NULL);
    }
    configurationStore_unlock(managedServiceTracker_i->configurationStore);

    if (status != CELIX_SUCCESS) {
        *service = NULL;
    } else {
        *service = &managedService_s;
    }

    return status;

}
예제 #16
0
celix_status_t inspectCommand_printExportedServices(bundle_context_pt context, array_list_pt ids, FILE *outStream, FILE *errStream) {
	celix_status_t status = CELIX_SUCCESS;
	array_list_pt bundles = NULL;

	if (arrayList_isEmpty(ids)) {
		status = bundleContext_getBundles(context, &bundles);
	} else {
		unsigned int i;

		arrayList_create(&bundles);
		for (i = 0; i < arrayList_size(ids); i++) {
			char *idStr = (char *) arrayList_get(ids, i);
			long id = atol(idStr);
			bundle_pt b = NULL;
			celix_status_t st = bundleContext_getBundleById(context, id, &b);
			if (st == CELIX_SUCCESS) {
				arrayList_add(bundles, b);
			} else {
				fprintf(outStream, "INSPECT: Invalid bundle ID: %ld\n", id);
			}
		}
	}

	if (status == CELIX_SUCCESS) {
		unsigned int i = 0;
		for (i = 0; i < arrayList_size(bundles); i++) {
			bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i);

			if (i > 0) {
				fprintf(outStream, "\n");
			}

			if (bundle != NULL) {
				array_list_pt refs = NULL;

				if (bundle_getRegisteredServices(bundle, &refs) == CELIX_SUCCESS) {
					module_pt module = NULL;
					char * name = NULL;
					status = bundle_getCurrentModule(bundle, &module);
					if (status == CELIX_SUCCESS) {
						status = module_getSymbolicName(module, &name);
						if (status == CELIX_SUCCESS) {
							fprintf(outStream, "%s provides services:\n", name);
							fprintf(outStream, "==============\n");

							if (refs == NULL || arrayList_size(refs) == 0) {
								fprintf(outStream, "Nothing\n");
							} else {
								unsigned int j = 0;
								for (j = 0; j < arrayList_size(refs); j++) {
									service_reference_pt ref = (service_reference_pt) arrayList_get(refs, j);
									unsigned int size = 0;
									char **keys;

									serviceReference_getPropertyKeys(ref, &keys, &size);
									for (int k = 0; k < size; k++) {
									    char *key = keys[k];
									    char *value = NULL;
									    serviceReference_getProperty(ref, key, &value);

										fprintf(outStream, "%s = %s\n", key, value);
									}

//									objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
//									sprintf(line, "ObjectClass = %s\n", objectClass);
									if ((j + 1) < arrayList_size(refs)) {
										fprintf(outStream, "----\n");
									}
								}
							}
						}
					}
				}
			}
		}
	}

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

	return status;
}
예제 #17
0
celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_pt matcher, match_pt *match) {
    celix_status_t status = CELIX_SUCCESS;

    if (!hashMap_isEmpty(matcher->attributes)) {
        match_key_t matchKey = NULL;
        hash_map_iterator_pt iter = hashMapIterator_create(matcher->attributes);
        while (hashMapIterator_hasNext(iter)) {
            hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
            match_key_t key = hashMapEntry_getKey(entry);
            if (matchKey == NULL || matchKey->matchValue < key->matchValue) {
                matchKey = key;
            }
        }
        hashMapIterator_destroy(iter);

        array_list_pt das = hashMap_get(matcher->attributes, matchKey);
        service_reference_pt best = NULL;
        int i;
        for (i = 0; i < arrayList_size(das); i++) {
            driver_attributes_pt attributes = arrayList_get(das, i);
            service_reference_pt reference = NULL;

            celix_status_t substatus = driverAttributes_getReference(attributes, &reference);
            if (substatus == CELIX_SUCCESS) {
                if (best != NULL) {
                    char *rank1Str, *rank2Str;
                    int rank1, rank2;

                    rank1Str = "0";
                    rank2Str = "0";

                    logHelper_log(matcher->loghelper, OSGI_LOGSERVICE_DEBUG, "DRIVER_MATCHER: Compare ranking");

                    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank1Str);
                    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank2Str);

                    rank1 = atoi(rank1Str);
                    rank2 = atoi(rank2Str);

                    if (rank1 != rank2) {
                        if (rank1 > rank2) {
                            best = reference;
                        }
                    } else {
                        char *id1Str, *id2Str;
                        long id1, id2;

                        id1Str = NULL;
                        id2Str = NULL;

                        logHelper_log(matcher->loghelper, OSGI_LOGSERVICE_DEBUG, "DRIVER_MATCHER: Compare id's");

                        serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_ID, &id1Str);
                        serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_ID, &id2Str);

                        id1 = atol(id1Str);
                        id2 = atol(id2Str);

                        if (id1 < id2) {
                            best = reference;
                        }
                    }
                } else {
                    best = reference;
                }
            }

        }

        *match = calloc(1, sizeof(**match));
        if (!*match) {
            status = CELIX_ENOMEM;
        } else {
            (*match)->matchValue = matchKey->matchValue;
            (*match)->reference = best;
        }
    }

    return status;
}
예제 #18
0
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
    celix_status_t status;
    struct activator *activator = userData;

    endpoint_listener_pt endpointListener = malloc(sizeof(*endpointListener));
    endpointListener->handle = activator->manager;
    endpointListener->endpointAdded = topologyManager_addImportedService;
    endpointListener->endpointRemoved = topologyManager_removeImportedService;
    activator->endpointListener = endpointListener;

    char *uuid = NULL;
    status = bundleContext_getProperty(activator->context, (char *) OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
    if (!uuid) {
        logHelper_log(activator->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
        return CELIX_ILLEGAL_STATE;
    }

    size_t len = 14 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
    char *scope = malloc(len);
    if (!scope) {
        return CELIX_ENOMEM;
    }

    snprintf(scope, len, "(&(%s=*)(!(%s=%s)))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);

    logHelper_log(activator->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: endpoint listener scope is %s", scope);

    properties_pt props = properties_create();
    properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);

    // We can release the scope, as properties_set makes a copy of the key & value...
    free(scope);

    bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);

    listener_hook_service_pt hookService = malloc(sizeof(*hookService));
    hookService->handle = activator->manager;
    hookService->added = topologyManager_listenerAdded;
    hookService->removed = topologyManager_listenerRemoved;
    activator->hookService = hookService;

    bundleContext_registerService(context, (char *) OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hookService, NULL, &activator->hook);
    bundleContext_addServiceListener(context, activator->serviceListener, "(service.exported.interfaces=*)");

    if (status == CELIX_SUCCESS) {
        serviceTracker_open(activator->remoteServiceAdminTracker);
    }

    if (status == CELIX_SUCCESS) {
        status = serviceTracker_open(activator->endpointListenerTracker);
    }

	bundleContext_registerService(context, (char *) TOPOLOGYMANAGER_SCOPE_SERVICE, activator->scopeService, NULL, &activator->scopeReg);

    array_list_pt references = NULL;
    bundleContext_getServiceReferences(context, NULL, "(service.exported.interfaces=*)", &references);
    int i;
    for (i = 0; i < arrayList_size(references); i++) {
        service_reference_pt reference = arrayList_get(references, i);
        char *serviceId = NULL;
        status = CELIX_DO_IF(status, serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_ID, &serviceId));

        CELIX_DO_IF(status, topologyManager_addExportedService(activator->manager, reference, serviceId));
    }
    arrayList_destroy(references);

    return status;
}
예제 #19
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;
}
예제 #20
0
static celix_status_t deviceManager_attachAlgorithm(device_manager_pt manager, service_reference_pt ref, void *service) {
	celix_status_t status = CELIX_SUCCESS;

	driver_loader_pt loader = NULL;
	status = driverLoader_create(manager->context, &loader);
	if (status == CELIX_SUCCESS) {
		array_list_pt included = NULL;
		array_list_pt excluded = NULL;

		array_list_pt driverIds = NULL;

		hashMap_put(manager->devices, ref, service);

		status = arrayList_create(&included);
		if (status == CELIX_SUCCESS) {
			status = arrayList_create(&excluded);
			if (status == CELIX_SUCCESS) {
				properties_pt properties = properties_create();

				unsigned int size = 0;
				char **keys;

				serviceReference_getPropertyKeys(ref, &keys, &size);
				for (int i = 0; i < size; i++) {
					char* key = keys[i];
					const char* value = NULL;
					serviceReference_getProperty(ref, key, &value);
					properties_set(properties, key, value);
				}

				status = driverLoader_findDrivers(loader, manager->locators, properties, &driverIds);
				if (status == CELIX_SUCCESS) {
					hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers);
					while (hashMapIterator_hasNext(iter)) {
						driver_attributes_pt driverAttributes = hashMapIterator_nextValue(iter);
						arrayList_add(included, driverAttributes);

						// Each driver that already is installed can be removed from the list
						char *id = NULL;
						celix_status_t substatus = driverAttributes_getDriverId(driverAttributes, &id);
						if (substatus == CELIX_SUCCESS) {
							// arrayList_removeElement(driverIds, id);
							array_list_iterator_pt idsIter = arrayListIterator_create(driverIds);
							while (arrayListIterator_hasNext(idsIter)) {
								char *value = arrayListIterator_next(idsIter);
								if (strcmp(value, id) == 0) {
									arrayListIterator_remove(idsIter);
								}
							}
							arrayListIterator_destroy(idsIter);
						}
						if(id != NULL){
							free(id);
						}
					}
					hashMapIterator_destroy(iter);

					status = deviceManager_matchAttachDriver(manager, loader, driverIds, included, excluded, service, ref);

				}
				arrayList_destroy(driverIds);
				properties_destroy(properties);
				arrayList_destroy(excluded);
			}
			arrayList_destroy(included);
		}

	}

	driverLoader_destroy(&loader);
	return status;
}