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_create(bundle_context_pt context, void **out) { celix_status_t status = CELIX_SUCCESS; struct activator *act = calloc(1, sizeof(*act)); if (act != NULL) { act->context = context; act->serv.handle = act; act->serv.test = test; status = serviceTrackerCustomizer_create(act, NULL, addCalc, NULL, removeCalc, &act->cust); status = CELIX_DO_IF(status, serviceTracker_create(context, CALCULATOR2_SERVICE, act->cust, &act->tracker)); } else { status = CELIX_ENOMEM; } if (status == CELIX_SUCCESS) { *out = act; } else if (act != NULL) { if (act->cust != NULL) { free(act->cust); act->cust = NULL; } if (act->tracker != NULL) { serviceTracker_destroy(act->tracker); act->tracker = NULL; } free(act); } return CELIX_SUCCESS; }
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 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 managedServiceTracker_createCustomized(bundle_context_pt context, managed_service_tracker_pt trackerHandle, service_tracker_pt *tracker) { celix_status_t status; service_tracker_customizer_pt customizer = NULL; service_tracker_pt managedServiceTracker = NULL; status = serviceTrackerCustomizer_create(trackerHandle, managedServiceTracker_addingService, managedServiceTracker_addedService, managedServiceTracker_modifiedService, managedServiceTracker_removedService, &customizer); if (status != CELIX_SUCCESS) { printf("[ ERROR ]: TrackerCustomized - Not initialized(ENOMEM) \n"); *tracker = NULL; return CELIX_ENOMEM; } serviceTracker_create(context, (char *) MANAGED_SERVICE_SERVICE_NAME, customizer, &managedServiceTracker); if (status != CELIX_SUCCESS) { printf("[ ERROR ]: TrackerCustomized - Not created \n"); *tracker = NULL; return status; } *tracker = managedServiceTracker; return CELIX_SUCCESS; }
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; }
static celix_status_t bundleActivator_createRSATracker(struct activator *activator, service_tracker_pt *tracker) { celix_status_t status; service_tracker_customizer_pt customizer = NULL; status = serviceTrackerCustomizer_create(activator->manager, topologyManager_rsaAdding, topologyManager_rsaAdded, topologyManager_rsaModified, topologyManager_rsaRemoved, &customizer); if (status == CELIX_SUCCESS) { status = serviceTracker_create(activator->context, OSGI_RSA_REMOTE_SERVICE_ADMIN, customizer, tracker); } return status; }
celix_status_t wiringTopologyManager_createWaTracker(wiring_topology_manager_pt manager, service_tracker_pt *tracker) { celix_status_t status = CELIX_SUCCESS; service_tracker_customizer_pt customizer = NULL; status = serviceTrackerCustomizer_create(manager, wiringTopologyManager_waAdding, wiringTopologyManager_waAdded, wiringTopologyManager_waModified, wiringTopologyManager_waRemoved, &customizer); if (status == CELIX_SUCCESS) { status = serviceTracker_create(manager->context, (char*) INAETICS_WIRING_ADMIN, customizer, tracker); } 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; }
static celix_status_t bundleActivator_createEPLTracker(struct activator *activator, service_tracker_pt *tracker) { celix_status_t status; service_tracker_customizer_pt customizer = NULL; status = serviceTrackerCustomizer_create(activator->manager, topologyManager_endpointListenerAdding, topologyManager_endpointListenerAdded, topologyManager_endpointListenerModified, topologyManager_endpointListenerRemoved, &customizer); if (status == CELIX_SUCCESS) { status = serviceTracker_create(activator->context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, customizer, tracker); } return status; }
celix_status_t wiringTopologyManager_createWiringEndpointListenerTracker(wiring_topology_manager_pt manager, service_tracker_pt *tracker) { celix_status_t status; service_tracker_customizer_pt customizer = NULL; status = serviceTrackerCustomizer_create(manager, wiringTopologyManager_wiringEndpointListenerAdding, wiringTopologyManager_wiringEndpointListenerAdded, wiringTopologyManager_wiringEndpointListenerModified, wiringTopologyManager_wiringEndpointListenerRemoved, &customizer); if (status == CELIX_SUCCESS) { status = serviceTracker_create(manager->context, (char *) INAETICS_WIRING_ENDPOINT_LISTENER_SERVICE, customizer, tracker); } return status; }
static celix_status_t wiringAdmin_createWiringReceiveTracker(wiring_admin_pt admin, service_tracker_pt *tracker, char* wireId) { celix_status_t status; service_tracker_customizer_pt customizer = NULL; status = serviceTrackerCustomizer_create(admin, wiringAdmin_wiringReceiveAdding, wiringAdmin_wiringReceiveAdded, wiringAdmin_wiringReceiveModified, wiringAdmin_wiringReceiveRemoved, &customizer); if (status == CELIX_SUCCESS) { char filter[512]; snprintf(filter, 512, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) INAETICS_WIRING_RECEIVE_SERVICE, (char*) INAETICS_WIRING_WIRE_ID, wireId); status = serviceTracker_createWithFilter(admin->context, filter, customizer, tracker); } 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_create(bundle_context_pt context, void **userData) { celix_status_t status = CELIX_SUCCESS; struct activator *activator; activator = calloc(1, sizeof(*activator)); if (!activator) { status = CELIX_ENOMEM; } else{ *userData = activator; status = pubsubAdmin_create(context, &(activator->admin)); if(status == CELIX_SUCCESS){ service_tracker_customizer_pt customizer = NULL; status = serviceTrackerCustomizer_create(activator->admin, NULL, pubsubAdmin_serializerAdded, NULL, pubsubAdmin_serializerRemoved, &customizer); if(status == CELIX_SUCCESS){ status = serviceTracker_create(context, PUBSUB_SERIALIZER_SERVICE, customizer, &(activator->serializerTracker)); if(status != CELIX_SUCCESS){ serviceTrackerCustomizer_destroy(customizer); pubsubAdmin_destroy(activator->admin); } } else{ pubsubAdmin_destroy(activator->admin); } } } return status; }
celix_status_t pubsub_topicSubscriptionCreate(bundle_context_pt bundle_context, char* ifIp,char* scope, char* topic ,pubsub_serializer_service_t *best_serializer, topic_subscription_pt* out){ celix_status_t status = CELIX_SUCCESS; topic_subscription_pt ts = (topic_subscription_pt) calloc(1,sizeof(*ts)); ts->context = bundle_context; ts->ifIpAddress = strdup(ifIp); #if defined(__APPLE__) && defined(__MACH__) //TODO: Use kqueue for OSX #else ts->topicEpollFd = epoll_create1(0); #endif if(ts->topicEpollFd == -1) { status += CELIX_SERVICE_EXCEPTION; } ts->running = false; ts->nrSubscribers = 0; ts->serializer = best_serializer; celixThreadMutex_create(&ts->ts_lock,NULL); arrayList_create(&ts->sub_ep_list); ts->servicesMap = hashMap_create(NULL, NULL, NULL, NULL); ts->socketMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); arrayList_create(&ts->pendingConnections); arrayList_create(&ts->pendingDisconnections); celixThreadMutex_create(&ts->pendingConnections_lock, NULL); celixThreadMutex_create(&ts->pendingDisconnections_lock, NULL); celixThreadMutex_create(&ts->socketMap_lock, NULL); ts->largeUdpHandle = largeUdp_create(MAX_UDP_SESSIONS); char filter[128]; memset(filter,0,128); if(strncmp(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, scope, strlen(PUBSUB_SUBSCRIBER_SCOPE_DEFAULT)) == 0) { // default scope, means that subscriber has not defined a scope property snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME, PUBSUB_SUBSCRIBER_TOPIC,topic); } else { snprintf(filter, 128, "(&(%s=%s)(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_SUBSCRIBER_SERVICE_NAME, PUBSUB_SUBSCRIBER_TOPIC,topic, PUBSUB_SUBSCRIBER_SCOPE,scope); } service_tracker_customizer_pt customizer = NULL; status += serviceTrackerCustomizer_create(ts,NULL,topicsub_subscriberTracked,NULL,topicsub_subscriberUntracked,&customizer); status += serviceTracker_createWithFilter(bundle_context, filter, customizer, &ts->tracker); struct sigaction actions; memset(&actions, 0, sizeof(actions)); sigemptyset(&actions.sa_mask); actions.sa_flags = 0; actions.sa_handler = sigusr1_sighandler; sigaction(SIGUSR1,&actions,NULL); if (status == CELIX_SUCCESS) { *out=ts; } return status; }