celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; service_tracker_customizer_pt queueCustomizer = NULL; service_tracker_customizer_pt dataStoreCustomizer = NULL; bundle_activator_pt activator = (bundle_activator_pt) userData; char *name = NULL; char *uuid = NULL; char uuidName[128]; memset(uuidName, 0, 128); bundleContext_getProperty(context, "inaetics.demonstrator.processor.name", &name); bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid); if (name != NULL) { snprintf(uuidName, 128, "%s %s",PROCESSOR_STATS_SERVICE_NAME_PREFIX, name); } else if (name == NULL && uuid != NULL) { snprintf(uuidName, 128, "%s %.8s",PROCESSOR_STATS_SERVICE_NAME_PREFIX, uuid); } else { snprintf(uuidName, 128, "%s (unknown ID)",PROCESSOR_STATS_SERVICE_NAME_PREFIX); } printf("PROCESSOR: Starting bundle...\n"); status = processor_create(uuidName, &activator->processor); if (status == CELIX_SUCCESS) { bundleActivator_createStatsService(activator); if (activator->processorStatsService != NULL) { bundleActivator_registerStatsService(activator); } if (activator->processorStatsService == NULL || activator->processorStatsRegistration == NULL) { printf("PROCESSOR: Error creating/registering statService\n"); } else { printf("PROCESSOR: Created processor with name %s\n", uuidName); } } /*Track QueueService*/ serviceTrackerCustomizer_create(activator->processor, NULL, processor_queueServiceAdded, NULL, processor_queueServiceRemoved, &queueCustomizer); serviceTracker_create(context, INAETICS_DEMONSTRATOR_API__SAMPLE_QUEUE_SERVICE_NAME, queueCustomizer, &activator->queueTracker); serviceTracker_open(activator->queueTracker); /*Track DataStoreService*/ serviceTrackerCustomizer_create(activator->processor, NULL, processor_dataStoreServiceAdded, NULL, processor_dataStoreServiceRemoved, &dataStoreCustomizer); serviceTracker_create(context, INAETICS_DEMONSTRATOR_API__DATA_STORE_SERVICE_NAME, dataStoreCustomizer, &activator->dataStoreTracker); serviceTracker_open(activator->dataStoreTracker); return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; struct activator *activator = userData; pubsub_admin_service_pt pubsubAdminSvc = calloc(1, sizeof(*pubsubAdminSvc)); if (!pubsubAdminSvc) { status = CELIX_ENOMEM; } else{ pubsubAdminSvc->admin = activator->admin; pubsubAdminSvc->addPublication = pubsubAdmin_addPublication; pubsubAdminSvc->removePublication = pubsubAdmin_removePublication; pubsubAdminSvc->addSubscription = pubsubAdmin_addSubscription; pubsubAdminSvc->removeSubscription = pubsubAdmin_removeSubscription; pubsubAdminSvc->closeAllPublications = pubsubAdmin_closeAllPublications; pubsubAdminSvc->closeAllSubscriptions = pubsubAdmin_closeAllSubscriptions; pubsubAdminSvc->matchEndpoint = pubsubAdmin_matchEndpoint; activator->adminService = pubsubAdminSvc; status = bundleContext_registerService(context, PUBSUB_ADMIN_SERVICE, pubsubAdminSvc, NULL, &activator->registration); status += serviceTracker_open(activator->serializerTracker); } return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; struct activator * activator = userData; pthread_mutex_init(&activator->mutex, NULL); serviceTrackerCustomizer_create(activator, benchmarkRunner_addingService, benchmarkRunner_addedService, benchmarkRunner_modifiedService, benchmarkRunner_removedService, &activator->customizer); char filter[128]; sprintf(filter, "(|(%s=%s)(%s=%s))", "objectClass", BENCHMARK_SERVICE_NAME, "objectClass", FREQUENCY_SERVICE_NAME); serviceTracker_createWithFilter(context, filter, activator->customizer, &activator->tracker); serviceTracker_open(activator->tracker); activator->reg = NULL; activator->command = calloc(1, sizeof(*activator->command)); activator->command->handle = activator; activator->command->executeCommand = benchmarkRunner_execute; properties_pt props = properties_create(); properties_set(props, OSGI_SHELL_COMMAND_NAME, "benchmark"); properties_set(props, OSGI_SHELL_COMMAND_USAGE, "benchmark run"); properties_set(props, OSGI_SHELL_COMMAND_DESCRIPTION, "run the available benchmark"); bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->command, props, &activator->reg); return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; struct activator *activator = userData; event_admin_service_pt event_admin_service = NULL; apr_pool_t *pool; status = bundleContext_getMemoryPool(context, &pool); if(status == CELIX_SUCCESS) { struct activator * data = (struct activator *) userData; service_tracker_customizer_pt cust = NULL; service_tracker_pt tracker = NULL; data->context = context; serviceTrackerCustomizer_create(data->event_admin_service->eventAdmin, eventAdmin_addingService, eventAdmin_addedService, eventAdmin_modifiedService, eventAdmin_removedService, &cust); serviceTracker_create(context, (char *) EVENT_HANDLER_SERVICE, cust, &tracker); data->tracker = tracker; serviceTracker_open(tracker); properties_pt properties = NULL; properties = properties_create(); event_admin_service = activator->event_admin_service; //printf("pointer of event admin service %p\n",event_admin_service); bundleContext_registerService(context, (char *) EVENT_ADMIN_NAME, event_admin_service, properties, &activator->registration); logHelper_start(activator->loghelper); } return status; }
celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt *instance) { celix_status_t status = CELIX_SUCCESS; service_tracker_customizer_pt customizer = NULL; (*instance) = (shell_mediator_pt) calloc(1, sizeof(**instance)); if ((*instance) != NULL) { (*instance)->context = context; (*instance)->tracker = NULL; (*instance)->shellService = NULL; status = logHelper_create(context, &(*instance)->loghelper); status = CELIX_DO_IF(status, celixThreadMutex_create(&(*instance)->mutex, NULL)); status = CELIX_DO_IF(status, serviceTrackerCustomizer_create((*instance), shellMediator_addingService, shellMediator_addedService, shellMediator_modifiedService, shellMediator_removedService, &customizer)); status = CELIX_DO_IF(status, serviceTracker_create(context, (char * )OSGI_SHELL_SERVICE_NAME, customizer, &(*instance)->tracker)); if (status == CELIX_SUCCESS) { logHelper_start((*instance)->loghelper); serviceTracker_open((*instance)->tracker); } } else { status = CELIX_ENOMEM; } if (status != CELIX_SUCCESS) { logHelper_log((*instance)->loghelper, OSGI_LOGSERVICE_ERROR, "Error creating shell_mediator, error code is %i\n", status); } return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; struct activator *activator = userData; properties_pt properties = NULL; properties = properties_create(); properties_set(properties,(char*)EVENT_HANDLER_SERVICE,(char *)EVENT_HANDLER_NAME); properties_set(properties,(char*)EVENT_TOPIC, (char*) "log/error/eventpublishers/event"); event_handler_service_pt event_handler_service = activator->event_handler_service; bundleContext_registerService(context, (char *) EVENT_HANDLER_SERVICE, event_handler_service, properties, &activator->registration); apr_pool_t *pool; status = bundleContext_getMemoryPool(context, &pool); if (status == CELIX_SUCCESS) { service_tracker_customizer_pt customizer = NULL; service_tracker_pt tracker = NULL; serviceTrackerCustomizer_create(activator->event_handler_service->event_handler, eventHandlerAddingService, eventHandlerAddedService, eventHandlerModifiedService, eventHandlerRemovedService, &customizer); serviceTracker_create(context, (char *) EVENT_ADMIN_NAME, customizer, &tracker); activator->eventAdminTracker = tracker; serviceTracker_open(tracker); properties_pt properties = NULL; properties = properties_create(); } return status; }
celix_status_t wiringAdmin_exportWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt* wEndpointDescription) { celix_status_t status = CELIX_SUCCESS; celixThreadMutex_lock(&admin->exportedWiringEndpointLock); if (hashMap_size(admin->wiringReceiveTracker) == 0) { status = wiringAdmin_startWebserver(admin->context, &admin); } if (status == CELIX_SUCCESS) { char* fwuuid = NULL; status = bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwuuid); if (status == CELIX_SUCCESS) { char* wireId = NULL; properties_pt props = properties_create(); printf("%s: HTTP Wiring Endpoint running at %s\n", TAG, admin->url); status = wiringEndpointDescription_create(NULL, props, wEndpointDescription); properties_set(props, WIRING_ADMIN_PROPERTIES_CONFIG_KEY, WIRING_ADMIN_PROPERTIES_CONFIG_VALUE); properties_set(props, WIRING_ENDPOINT_DESCRIPTION_HTTP_URL_KEY, admin->url); properties_set(props, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, fwuuid); wireId = properties_get(props, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY); printf("%s: wiringEndpointDescription_create w/ wireId %s started\n", TAG, wireId); if (status == CELIX_SUCCESS) { service_tracker_pt tracker = NULL; status = wiringAdmin_createWiringReceiveTracker(admin, &tracker, wireId); if (status == CELIX_SUCCESS) { status = serviceTracker_open(tracker); if (status == CELIX_SUCCESS) { hashMap_put(admin->wiringReceiveTracker, *wEndpointDescription, tracker); printf("%s: WiringReceiveTracker w/ wireId %s started\n", TAG, wireId); } else { serviceTracker_destroy(tracker); } } } } } else { printf("%s: Cannot export Wiring Endpoint\n", TAG); } celixThreadMutex_unlock(&admin->exportedWiringEndpointLock); return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; struct activator * act = userData; act->reg = NULL; status = bundleContext_registerService(context, (char *)TST_SERVICE_NAME, &act->serv, NULL, &act->reg); status = CELIX_DO_IF(status, serviceTracker_open(act->tracker)); return status; }
celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts){ celix_status_t status = CELIX_SUCCESS; status = serviceTracker_open(ts->tracker); ts->running = true; if(status==CELIX_SUCCESS){ status=celixThread_create(&ts->recv_thread,NULL,udp_recv_thread_func,ts); } return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { struct publisherActivator * act = (struct publisherActivator *) userData; int i; array_list_pt topic_list = pubsub_getTopicsFromString(PUB_TOPIC); if(topic_list !=NULL){ char filter[128]; for(i=0; i<arrayList_size(topic_list);i++){ char* topic = arrayList_get(topic_list,i); if(strlen(topic)<MAX_TOPIC_LEN){ bundle_pt bundle = NULL; long bundleId = 0; bundleContext_getBundle(context,&bundle); bundle_getBundleId(bundle,&bundleId); service_tracker_pt tracker = NULL; memset(filter,0,128); snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC,topic); service_tracker_customizer_pt customizer = NULL; serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer); serviceTracker_createWithFilter(context, filter, customizer, &tracker); arrayList_add(act->trackerList,tracker); } else{ printf("Topic %s too long. Skipping publication.\n",topic); } free(topic); } arrayList_destroy(topic_list); } publisher_start(act->client); for(i=0;i<arrayList_size(act->trackerList);i++){ service_tracker_pt tracker = arrayList_get(act->trackerList,i); serviceTracker_open(tracker); } return CELIX_SUCCESS; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; struct activator *activator = userData; char *uuid = NULL; status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid); if (!uuid) { printf("DISCOVERY_CONFIGURED: no framework UUID defined?!\n"); return CELIX_ILLEGAL_STATE; } size_t len = 11 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid); char *scope = malloc(len); if (!scope) { return CELIX_ENOMEM; } sprintf(scope, "(&(%s=*)(%s=%s))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid); scope[len] = 0; printf("DISCOVERY_CONFIGURED: using scope %s.\n", scope); endpoint_listener_pt endpointListener = malloc(sizeof(struct endpoint_listener)); if (!endpointListener) { return CELIX_ENOMEM; } endpointListener->handle = activator->discovery; endpointListener->endpointAdded = discovery_endpointAdded; endpointListener->endpointRemoved = discovery_endpointRemoved; properties_pt props = properties_create(); properties_set(props, "DISCOVERY", "true"); properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope); status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService); if (status == CELIX_SUCCESS) { status = serviceTracker_open(activator->endpointListenerTracker); } if (status == CELIX_SUCCESS) { status = discovery_start(activator->discovery); } // We can release the scope, as properties_set makes a copy of the key & value... free(scope); return status; }
celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) { celix_status_t status = CELIX_SUCCESS; service_tracker_customizer_pt customizer = NULL; status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer); if (status == CELIX_SUCCESS) { char *filter = apr_pstrcat(registration_factory->pool, "(&(", OSGI_FRAMEWORK_OBJECTCLASS, "=", OSGI_RSA_REMOTE_PROXY_FACTORY,")(proxy.interface=", registration_factory->serviceName, "))", NULL); status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker); if (status == CELIX_SUCCESS) { serviceTracker_open(*tracker); } } return status; }
celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) { celix_status_t status; service_tracker_customizer_pt customizer = NULL; status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer); if (status == CELIX_SUCCESS) { char filter[512]; snprintf(filter, 512, "(&(%s=%s)(proxy.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_PROXY_FACTORY, registration_factory->serviceName); status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker); if (status == CELIX_SUCCESS) { serviceTracker_open(*tracker); } } return status; }
celix_status_t serviceDependency_start(dm_service_dependency_pt dependency) { celix_status_t status = CELIX_SUCCESS; bundle_context_pt context = NULL; if (!dependency || !dependency->component || (!dependency->tracked_service_name && !dependency->tracked_filter)) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { status = component_getBundleContext(dependency->component, &context); if (!context) { status = CELIX_BUNDLE_EXCEPTION; } } if (status == CELIX_SUCCESS) { dependency->tracker_customizer = NULL; status = serviceTrackerCustomizer_create(dependency, NULL, serviceDependency_addedService, serviceDependency_modifiedService, serviceDependency_removedService, &dependency->tracker_customizer); } if (status == CELIX_SUCCESS) { if (dependency->tracked_filter) { status = serviceTracker_createWithFilter(context, dependency->tracked_filter, dependency->tracker_customizer, &dependency->tracker); } else if (dependency->tracked_service_name) { status = serviceTracker_create(context, dependency->tracked_service_name, dependency->tracker_customizer, &dependency->tracker); } } if (status == CELIX_SUCCESS) { status = serviceTracker_open(dependency->tracker); } if (status == CELIX_SUCCESS) { dependency->isStarted = true; } return status; }
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; }