celix_status_t serviceTracker_open(service_tracker_pt tracker) { service_listener_pt listener; array_list_pt initial = NULL; celix_status_t status = CELIX_SUCCESS; listener = (service_listener_pt) malloc(sizeof(*listener)); status = bundleContext_getServiceReferences(tracker->context, NULL, tracker->filter, &initial); if (status == CELIX_SUCCESS) { service_reference_pt initial_reference; unsigned int i; listener->handle = tracker; listener->serviceChanged = (void *) serviceTracker_serviceChanged; status = bundleContext_addServiceListener(tracker->context, listener, tracker->filter); if (status == CELIX_SUCCESS) { tracker->listener = listener; for (i = 0; i < arrayList_size(initial); i++) { initial_reference = (service_reference_pt) arrayList_get(initial, i); serviceTracker_track(tracker, initial_reference, NULL); } arrayList_clear(initial); arrayList_destroy(initial); initial = NULL; } } framework_logIfError(logger, status, NULL, "Cannot open tracker"); return status; }
celix_status_t deploymentAdmin_processDeploymentPackageResources(deployment_admin_pt admin, deployment_package_pt source) { celix_status_t status = CELIX_SUCCESS; array_list_pt infos = NULL; deploymentPackage_getResourceInfos(source, &infos); int i; for (i = 0; i < arrayList_size(infos); i++) { resource_info_pt info = arrayList_get(infos, i); apr_pool_t *tmpPool = NULL; array_list_pt services = NULL; char *filter = NULL; apr_pool_create(&tmpPool, admin->pool); filter = apr_pstrcat(tmpPool, "(", OSGI_FRAMEWORK_SERVICE_PID, "=", info->resourceProcessor, ")", NULL); status = bundleContext_getServiceReferences(admin->context, DEPLOYMENTADMIN_RESOURCE_PROCESSOR_SERVICE, filter, &services); if (status == CELIX_SUCCESS) { if (services != NULL && arrayList_size(services) > 0) { service_reference_pt ref = arrayList_get(services, 0); // In Felix a check is done to assure the processor belongs to the deployment package // Is this according to spec? void *processorP = NULL; status = bundleContext_getService(admin->context, ref, &processorP); if (status == CELIX_SUCCESS) { bundle_pt bundle = NULL; char *entry = NULL; char *name = NULL; char *packageName = NULL; resource_processor_service_pt processor = processorP; bundleContext_getBundle(admin->context, &bundle); bundle_getEntry(bundle, "/", &entry); deploymentPackage_getName(source, &name); char *resourcePath = apr_pstrcat(admin->pool, entry, "repo/", name, "/", info->path, NULL); deploymentPackage_getName(source, &packageName); processor->begin(processor->processor, packageName); processor->process(processor->processor, info->path, resourcePath); } } } if(services!=NULL){ arrayList_destroy(services); } } return status; }
celix_status_t bundleContext_getServiceReference(bundle_context_pt context, char * serviceName, service_reference_pt *service_reference) { service_reference_pt reference = NULL; array_list_pt services = NULL; celix_status_t status = CELIX_SUCCESS; if (serviceName != NULL) { if (bundleContext_getServiceReferences(context, serviceName, NULL, &services) == CELIX_SUCCESS) { reference = (arrayList_size(services) > 0) ? arrayList_get(services, 0) : NULL; arrayList_destroy(services); *service_reference = reference; } else { status = CELIX_ILLEGAL_ARGUMENT; } } else { status = CELIX_ILLEGAL_ARGUMENT; } framework_logIfError(logger, status, NULL, "Failed to get service reference"); return status; }
void dmListCommand_execute(bundle_context_pt context, char * line, FILE *out, FILE *err) { array_list_pt servRefs = NULL; int i; bundleContext_getServiceReferences(context, DM_INFO_SERVICE_NAME ,NULL, &servRefs); char *term = getenv("TERM"); bool colors = false; if (strcmp("xterm-256color", term) == 0) { colors = true; } for(i = 0; i < arrayList_size(servRefs); i++) { dm_dependency_manager_info_pt info = NULL; dm_info_service_pt infoServ = NULL; service_reference_pt servRef = NULL; servRef = arrayList_get(servRefs, i); bundleContext_getService(context, servRef, (void**)&infoServ); infoServ->getInfo(infoServ->handle, &info); int cmpCnt; for (cmpCnt = 0; cmpCnt < arrayList_size(info->components); cmpCnt++) { dm_component_info_pt compInfo = arrayList_get(info->components, cmpCnt); const char *startColors = ""; const char *endColors = ""; if (colors) { startColors = compInfo->active ? OK_COLOR : NOK_COLOR; endColors = END_COLOR; } fprintf(out, "Component: Name=%s\n|- ID=%s, %sActive=%s%s, State=%s\n", compInfo->name, compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state); int interfCnt; fprintf(out, "|- Interfaces (%d):\n", arrayList_size(compInfo->interfaces)); for(interfCnt = 0 ;interfCnt < arrayList_size(compInfo->interfaces); interfCnt++) { char * interface; interface = arrayList_get(compInfo->interfaces, interfCnt); fprintf(out, " |- Interface: %s\n", interface); } int depCnt; fprintf(out, "|- Dependencies (%d):\n", arrayList_size(compInfo->dependency_list)); for(depCnt = 0 ;depCnt < arrayList_size(compInfo->dependency_list); depCnt++) { dm_service_dependency_info_pt dependency; dependency = arrayList_get(compInfo->dependency_list, depCnt); const char *startColors = ""; const char *endColors = ""; if (colors) { if (dependency->required) { startColors = dependency->available ? OK_COLOR : NOK_COLOR; } else { startColors = dependency->available ? OK_COLOR : WARNING_COLOR; } endColors = END_COLOR; } fprintf(out, " |- Dependency: %sAvailable = %s%s, Required = %s, Filter = %s\n", startColors, dependency->available ? "true " : "false" , endColors, dependency->required ? "true " : "false", dependency->filter ); } fprintf(out, "\n"); infoServ->destroyInfo(infoServ->handle, info); } } }
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; }