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; }
int main() { endpoint_descriptor_writer_pt writer = NULL; endpointDescriptorWriter_create(&writer); array_list_pt list = NULL; arrayList_create(&list); properties_pt props = properties_create(); properties_set(props, "objectClass", "com.acme.Foo"); properties_set(props, "endpoint.service.id", "3"); properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz"); properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96"); endpoint_description_pt epd = NULL; endpointDescription_create(props, &epd); arrayList_add(list, epd); properties_pt props2 = properties_create(); properties_set(props2, "objectClass", "com.acme.Bar"); properties_set(props, "endpoint.service.id", "4"); properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz"); properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96"); endpoint_description_pt epd2 = NULL; endpointDescription_create(props2, &epd2); arrayList_add(list, epd2); char *buffer = NULL; endpointDescriptorWriter_writeDocument(writer, list, &buffer); arrayList_destroy(list); endpointDescription_destroy(epd); endpointDescription_destroy(epd2); endpointDescriptorWriter_destroy(writer); printf("%s\n", buffer); }
static void manager_init(DBusGConnection *connection) { manager = dbus_g_proxy_new_for_name(connection, "net.connman", "/", "net.connman.Manager"); properties_create(manager, manager_property_changed, NULL); }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; struct activator *activator = userData; calculator_pt calculator = NULL; calculator_service_pt service = NULL; properties_pt properties = NULL; status = calculator_create(activator->pool, &calculator); if (status == CELIX_SUCCESS) { service = apr_palloc(activator->pool, sizeof(*service)); if (!service) { status = CELIX_ENOMEM; } else { service->calculator = calculator; service->add = calculator_add; service->sub = calculator_sub; service->sqrt = calculator_sqrt; properties = properties_create(); properties_set(properties, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR_SERVICE); bundleContext_registerService(context, (char *) CALCULATOR_SERVICE, service, properties, &activator->calculatorReg); } } return status; }
celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) { printf("phase3: dm_init\n"); celix_status_t status = CELIX_SUCCESS; struct phase3_activator_struct *act = (struct phase3_activator_struct *)userData; act->phase3Cmp = phase3_create(); if (act->phase3Cmp != NULL) { properties_pt props = properties_create(); properties_set(props, "id", "phase3"); dm_component_pt cmp; component_create(context, "PHASE3_PROCESSING_COMPONENT", &cmp); component_setImplementation(cmp, act->phase3Cmp); component_setCallbacksSafe(cmp, phase3_cmp_t *, phase3_init, phase3_start, phase3_stop, phase3_deinit); dm_service_dependency_pt dep; serviceDependency_create(&dep); serviceDependency_setService(dep, PHASE2_NAME, NULL); serviceDependency_setCallbacksSafe(dep, phase3_cmp_t *, phase2_t *, NULL, phase3_addPhase2, NULL, phase3_removePhase2, NULL); serviceDependency_setRequired(dep, true); component_addServiceDependency(cmp, dep); dependencyManager_add(manager, cmp); } else { status = CELIX_ENOMEM; } return status; }
celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr) { celix_status_t status = CELIX_SUCCESS; remote_proxy_factory_ptr->remote_proxy_factory_service_ptr = calloc(1, sizeof(*remote_proxy_factory_ptr->remote_proxy_factory_service_ptr)); if (!remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) { status = CELIX_ENOMEM; } if (status == CELIX_SUCCESS) { remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->factory = remote_proxy_factory_ptr; remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->registerProxyService = remoteProxyFactory_registerProxyService; remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->unregisterProxyService = remoteProxyFactory_unregisterProxyService; remote_proxy_factory_ptr->properties = properties_create(); if (!remote_proxy_factory_ptr->properties) { status = CELIX_BUNDLE_EXCEPTION; } else { properties_set(remote_proxy_factory_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service); } } if (status == CELIX_SUCCESS) { status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, OSGI_RSA_REMOTE_PROXY_FACTORY, remote_proxy_factory_ptr->remote_proxy_factory_service_ptr, remote_proxy_factory_ptr->properties, &remote_proxy_factory_ptr->registration); } return status; }
celix_status_t calculatorProxy_registerProxyService(void* proxyFactoryService, endpoint_description_pt endpointDescription, void* rsa, sendToHandle sendToCallback) { celix_status_t status = CELIX_SUCCESS; remote_proxy_factory_service_pt calculatorProxyFactoryService = (remote_proxy_factory_service_pt) proxyFactoryService; calculator_pt calculator = NULL; calculator_service_pt calculatorService = NULL; calculatorProxy_create(calculatorProxyFactoryService->pool, calculatorProxyFactoryService->context, &calculator); calculatorService = apr_palloc(calculatorProxyFactoryService->pool, sizeof(*calculatorService)); calculatorService->calculator = calculator; calculatorService->add = calculatorProxy_add; calculatorService->sub = calculatorProxy_sub; calculatorService->sqrt = calculatorProxy_sqrt; properties_pt srvcProps = properties_create(); properties_set(srvcProps, (char *) "proxy.interface", (char *) CALCULATOR_SERVICE); properties_set(srvcProps, (char *) "endpoint.framework.uuid", (char *) endpointDescription->frameworkUUID); service_registration_pt proxyReg = NULL; calculatorProxy_setEndpointDescription(calculator, endpointDescription); calculatorProxy_setHandler(calculator, rsa); calculatorProxy_setCallback(calculator, sendToCallback); if (bundleContext_registerService(calculatorProxyFactoryService->context, CALCULATOR_SERVICE, calculatorService, srvcProps, &proxyReg) != CELIX_SUCCESS) { printf("CALCULATOR_PROXY: error while registering calculator service\n"); } hashMap_put(calculatorProxyFactoryService->proxy_registrations, endpointDescription, proxyReg); return status; }
celix_status_t wiringAdmin_importWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt wEndpointDescription) { celix_status_t status = CELIX_SUCCESS; wiring_send_service_pt wiringSendService = calloc(1, sizeof(*wiringSendService)); if (!wiringSendService) { status = CELIX_ENOMEM; } else { service_registration_pt wiringSendServiceReg = NULL; char* wireId = properties_get(wEndpointDescription->properties, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY); properties_pt props = properties_create(); properties_set(props, (char*) INAETICS_WIRING_WIRE_ID, wireId); wiringSendService->wiringEndpointDescription = wEndpointDescription; wiringSendService->send = wiringAdmin_send; wiringSendService->admin = admin; wiringSendService->errorCount = 0; status = bundleContext_registerService(admin->context, (char *) INAETICS_WIRING_SEND_SERVICE, wiringSendService, props, &wiringSendServiceReg); if (status == CELIX_SUCCESS) { hashMap_put(admin->wiringSendServices, wEndpointDescription, wiringSendService); hashMap_put(admin->wiringSendRegistrations, wEndpointDescription, wiringSendServiceReg); printf("%s: SEND SERVICE sucessfully registered w/ wireId %s\n", TAG, wireId); } else { printf("%s: could not register SEND SERVICE w/ wireId %s\n", TAG, wireId); } } return status; }
TEST(filter, match_false){ char * filter_str = my_strdup("(&(test_attr1=attr1)(&(test_attr2=attr2)(test_attr3=attr3)))"); filter_pt filter = filter_create(filter_str); properties_pt props = properties_create(); char * key = my_strdup("test_attr1"); char * val = my_strdup("attr1"); char * key2 = my_strdup("test_attr2"); char * val2 = my_strdup("attr2"); properties_set(props, key, val); properties_set(props, key2, val2); bool result = true; filter_match(filter, props, &result); CHECK_FALSE(result); //cleanup properties_destroy(props); filter_destroy(filter); free(filter_str); free(key); free(key2); free(val); free(val2); mock().checkExpectations(); }
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; bundle_instance_pt bi = (bundle_instance_pt) userData; command_service_pt commandService = calloc(1, sizeof(*commandService)); if (commandService != NULL) { commandService->handle = context; commandService->executeCommand = dmListCommand_execute; properties_pt props = properties_create(); properties_set(props, OSGI_SHELL_COMMAND_NAME, "dm"); properties_set(props, OSGI_SHELL_COMMAND_USAGE, "dm"); properties_set(props, OSGI_SHELL_COMMAND_DESCRIPTION, "Gives an overview of the component managemend by a dependency manager."); bi->dmCommand = commandService; status = bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, commandService, props, &bi->reg); } else { status = CELIX_ENOMEM; free(commandService); } 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; }
static void testImportService(void) { int rc = 0; import_registration_pt reg = NULL; endpoint_description_pt endpoint = NULL; properties_pt props = properties_create(); properties_set(props, (char *)OSGI_RSA_ENDPOINT_SERVICE_ID, (char *)"42"); properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42"); properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42"); properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.Example"); rc = endpointDescription_create(props, &endpoint); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = rsa->importService(rsa->admin, endpoint, ®); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(reg != NULL); service_reference_pt ref = NULL; rc = bundleContext_getServiceReference(context, (char *)"org.apache.celix.Example", &ref); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(ref != NULL); /* Cannot test. uses requesting bundles descriptor void *service = NULL; rc = bundleContext_getService(context, ref, &service); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(service != NULL); */ }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { printf("CONSUMING_DRIVER: starting bundle\n"); celix_status_t status = CELIX_SUCCESS; consuming_driver_bundle_instance_pt bi = userData; consuming_driver_pt driver = NULL; status = consumingDriver_create(context, &driver); if (status == CELIX_SUCCESS) { driver_service_pt service = NULL; status = consumingDriver_createService(driver, &service); if (status == CELIX_SUCCESS) { properties_pt props = properties_create(); properties_set(props, "DRIVER_ID", CONSUMING_DRIVER_ID); status = bundleContext_registerService(context, OSGI_DEVICEACCESS_DRIVER_SERVICE_NAME, service, props, &bi->registration); } } if (status == CELIX_SUCCESS) { printf("CONSUMING_DRIVER: registered driver service.\n"); } else { char error[256]; printf("CONSUMING_DRIVER: Could not register driver service. Get error %s\n", celix_strerror(status, error, 256)); } return status; }
celix_status_t wiringAdmin_create(bundle_context_pt context, wiring_admin_pt *admin) { celix_status_t status = CELIX_SUCCESS; *admin = calloc(1, sizeof(**admin)); if (!*admin) { status = CELIX_ENOMEM; } else { (*admin)->context = context; (*admin)->wiringSendServices = hashMap_create(wiringEndpointDescription_hash, NULL, wiringEndpointDescription_equals, NULL); (*admin)->wiringSendRegistrations = hashMap_create(wiringEndpointDescription_hash, NULL, wiringEndpointDescription_equals, NULL); (*admin)->wiringReceiveServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); (*admin)->wiringReceiveTracker = hashMap_create(wiringEndpointDescription_hash, NULL, wiringEndpointDescription_equals, NULL); (*admin)->adminProperties = properties_create(); properties_set((*admin)->adminProperties, WIRING_ADMIN_PROPERTIES_SECURE_KEY, WIRING_ADMIN_PROPERTIES_SECURE_VALUE); properties_set((*admin)->adminProperties, WIRING_ADMIN_PROPERTIES_CONFIG_KEY, WIRING_ADMIN_PROPERTIES_CONFIG_VALUE); celixThreadMutex_create(&(*admin)->exportedWiringEndpointLock, NULL); celixThreadMutex_create(&(*admin)->importedWiringEndpointLock, NULL); } return status; }
celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) { printf("PHASE1: dm_init\n"); celix_status_t status = CELIX_SUCCESS; struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData; act->phase1Cmp = phase1_create(); if (act->phase1Cmp != NULL) { act->phase1Serv.handle = act->phase1Cmp; act->phase1Serv.getData = (void *)phase1_getData; properties_pt props = properties_create(); properties_set(props, "id", "phase1"); dm_component_pt cmp; component_create(context, "PHASE1_PROCESSING_COMPONENT", &cmp); component_setImplementation(cmp, act->phase1Cmp); component_setCallbacksSafe(cmp, phase1_cmp_t *, phase1_init, phase1_start, phase1_stop, phase1_deinit); component_addInterface(cmp, PHASE1_NAME, &act->phase1Serv, props); dependencyManager_add(manager, cmp); } else { status = CELIX_ENOMEM; } return status; }
// gets everything from provided key celix_status_t etcdWatcher_getWiringEndpointFromKey(node_discovery_pt node_discovery, char* etcdKey, char* etcdValue, node_description_pt* nodeDescription) { celix_status_t status = CELIX_SUCCESS; char rootPath[MAX_ROOTNODE_LENGTH]; char expr[MAX_LOCALNODE_LENGTH]; char zoneId[MAX_LOCALNODE_LENGTH]; char nodeId[MAX_LOCALNODE_LENGTH]; char wireId[MAX_LOCALNODE_LENGTH]; etcdWatcher_getRootPath(node_discovery->context, &rootPath[0]); snprintf(expr, MAX_LOCALNODE_LENGTH, "/%s/%%[^/]/%%[^/]/%%[^/].*", rootPath); int foundItems = sscanf(etcdKey, expr, &zoneId[0], &nodeId[0], &wireId[0]); if (foundItems != 3) { printf("NODE_DISCOVERY: Could not find zone/node/wire (key: %s) \n", etcdKey); status = CELIX_ILLEGAL_STATE; } else { properties_pt nodeDescProperties = properties_create(); status = nodeDescription_create(nodeId, zoneId, nodeDescProperties, nodeDescription); if (status == CELIX_SUCCESS) { wiring_endpoint_description_pt wiringEndpointDescription = NULL; properties_pt wiringDescProperties = properties_create(); if (etcdValue != NULL) { if (wiringEndpoint_properties_load(etcdValue, wiringDescProperties) != CELIX_SUCCESS) { printf("NODE_DISCOVERY: Error while loading wiring properties"); } } status = wiringEndpointDescription_create(wireId, wiringDescProperties, &wiringEndpointDescription); if (status == CELIX_SUCCESS) { celixThreadMutex_lock(&(*nodeDescription)->wiring_ep_desc_list_lock); arrayList_add((*nodeDescription)->wiring_ep_descriptions_list, wiringEndpointDescription); celixThreadMutex_unlock(&(*nodeDescription)->wiring_ep_desc_list_lock); } } else { printf("NODE_DISCOVERY: Could not create Node description\n"); } } return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt ctx) { struct greetingActivator * act = (struct greetingActivator *) userData; celix_status_t status = CELIX_SUCCESS; simple_shape_pt es = triangleShape_create(ctx); properties_pt props = properties_create(); properties_set(props, "name", "triangle"); status = bundleContext_registerService(ctx, SIMPLE_SHAPE_SERVICE_NAME, es, props, &act->reg); printf("Triangle activated %d\n", status); return status; }
static celix_status_t bundleActivator_registerProducerService(bundle_activator_pt act) { celix_status_t status = CELIX_SUCCESS; properties_pt props = NULL; props = properties_create(); properties_set(props, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) INAETICS_DEMONSTRATOR_API__PRODUCER_SERVICE_NAME); status = bundleContext_registerService(act->context, (char *) INAETICS_DEMONSTRATOR_API__PRODUCER_SERVICE_NAME, act->producerService, props, &act->producerRegistration); 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; }
static celix_status_t bundleActivator_registerQueueService(struct activator *act) { celix_status_t status = CELIX_SUCCESS; properties_pt props = NULL; props = properties_create(); properties_set(props, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) INAETICS_DEMONSTRATOR_API__SAMPLE_QUEUE_SERVICE_NAME); status = bundleContext_registerService(act->context, (char *)INAETICS_DEMONSTRATOR_API__SAMPLE_QUEUE_SERVICE_NAME, act->queueService, props, &act->queueRegistration); return status; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt ctx) { struct activator * act = (struct activator *) userData; celix_status_t status = CELIX_SUCCESS; simple_shape_pt es = NULL; properties_pt props = NULL; circleShape_create(ctx, &es); props = properties_create(); properties_set(props, "name", "circle"); status = bundleContext_registerService(ctx, SIMPLE_SHAPE_SERVICE_NAME, es, props, &act->reg); return status; }
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 bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status; struct disc_mock_activator * act = userData; const char *uuid = NULL; act->reg = NULL; status = bundleContext_registerService(context, DISC_MOCK_SERVICE_NAME, act->serv, NULL, &act->reg); bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid); if (!uuid) { return CELIX_ILLEGAL_STATE; } size_t len = 11 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid); char *scope = malloc(len + 1); if (!scope) { return CELIX_ENOMEM; } sprintf(scope, "(&(%s=*)(%s=%s))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid); scope[len] = 0; properties_pt props = properties_create(); properties_set(props, "DISCOVERY", "true"); properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope); if (status == CELIX_SUCCESS) { endpoint_listener_pt endpointListener = calloc(1, sizeof(struct endpoint_listener)); if (endpointListener) { endpointListener->handle = act; endpointListener->endpointAdded = discovery_endpointAdded; endpointListener->endpointRemoved = discovery_endpointRemoved; status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &act->endpointListenerService); if (status == CELIX_SUCCESS) { act->endpointListener = endpointListener; } else { free(endpointListener); } } } // We can release the scope, as properties_set makes a copy of the key & value... free(scope); return status; }
celix_status_t manifest_create(manifest_pt *manifest) { celix_status_t status = CELIX_SUCCESS; *manifest = malloc(sizeof(**manifest)); if (!*manifest) { status = CELIX_ENOMEM; } else { (*manifest)->mainAttributes = properties_create(); (*manifest)->attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); } framework_logIfError(logger, status, NULL, "Cannot create manifest"); return status; }
static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback) { celix_status_t status = CELIX_SUCCESS; proxy_instance_pt proxy_instance_ptr = NULL; if (!remote_proxy_factory_ptr || !remote_proxy_factory_ptr->create_proxy_service_ptr) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { proxy_instance_ptr = calloc(1, sizeof(*proxy_instance_ptr)); if (!proxy_instance_ptr) { status = CELIX_ENOMEM; } } if (status == CELIX_SUCCESS) { proxy_instance_ptr->properties = properties_create(); if (!proxy_instance_ptr->properties) { status = CELIX_BUNDLE_EXCEPTION; } } if (status == CELIX_SUCCESS) { status = remote_proxy_factory_ptr->create_proxy_service_ptr(remote_proxy_factory_ptr->handle, endpointDescription, rsa, sendToCallback, proxy_instance_ptr->properties, &proxy_instance_ptr->service); } if (status == CELIX_SUCCESS) { properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service); hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); char *key = hashMapEntry_getKey(entry); char *value = hashMapEntry_getValue(entry); properties_set(proxy_instance_ptr->properties, key, value); } } if (status == CELIX_SUCCESS) { status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, remote_proxy_factory_ptr->service, proxy_instance_ptr->service, proxy_instance_ptr->properties, &proxy_instance_ptr->registration_ptr); } if (status == CELIX_SUCCESS) { hashMap_put(remote_proxy_factory_ptr->proxy_instances, endpointDescription, proxy_instance_ptr); } return status; }
static celix_status_t refiningDriver_registerDevice(refining_driver_pt driver, refining_driver_device_pt device, char *serial) { celix_status_t status = CELIX_SUCCESS; refining_driver_device_service_pt service = NULL; status = refiningDriverDevice_createService(device, &service); if (status == CELIX_SUCCESS) { properties_pt props = properties_create(); properties_set(props, OSGI_DEVICEACCESS_DEVICE_CATEGORY, REFINING_DRIVER_DEVICE_CATEGORY); properties_set(props, OSGI_DEVICEACCESS_DEVICE_SERIAL, serial); status = bundleContext_registerService(driver->context, OSGI_DEVICEACCESS_DEVICE_SERVICE_NAME, service, props, &device->deviceRegistration); } if (status == CELIX_SUCCESS) { printf("REFINING_DRIVER: registered refining device with serial %s\n", serial); } return status; }
static celix_status_t serviceRegistration_initializeProperties(service_registration_pt registration, properties_pt dictionary) { char * sId = (char *)malloc(sizeof(registration->serviceId) + 1); if (dictionary == NULL) { dictionary = properties_create(); } registration->properties = dictionary; sprintf(sId, "%ld", registration->serviceId); properties_set(dictionary, (char *) OSGI_FRAMEWORK_SERVICE_ID, sId); properties_set(dictionary, (char *) OSGI_FRAMEWORK_OBJECTCLASS, registration->className); free(sId); return CELIX_SUCCESS; }
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { celix_status_t status = CELIX_SUCCESS; properties_pt props = properties_create(); struct activatorData * data = (struct activatorData *) userData; data->ps = calloc(1, sizeof(*(data->ps))); data->pub = calloc(1, sizeof(*(data->pub))); data->ps->invoke = publisher_invoke; data->ps->publisher = data->pub; data->reg = NULL; properties_set(props, "id", "B"); bundleContext_registerService(context, PUBLISHER_NAME, data->ps, props, &data->reg); return status; }
// org.eclipse.equinox.internal.cm modified to fit with org.apache.felix.cm.impl // change due to ConfigurationStore implementation celix_status_t configuration_getAllProperties(configuration_impl_pt configuration, properties_pt *properties) { celix_status_t status; properties_pt copy = NULL; // (1) configuration.lock configuration_lock(configuration); // (2) configuration.deleted ? if( configuration->deleted ) { *properties = NULL; configuration_unlock(configuration); return CELIX_SUCCESS; } // (3) configuration.getProps if( configuration_getProperties(configuration, ©) != CELIX_SUCCESS) { configuration_unlock(configuration); return CELIX_ILLEGAL_ARGUMENT; } // (4) configuration.setProperties if ( copy == NULL ) { //set all the automatic properties copy = properties_create(); status = configuration_setAutoProperties(configuration, ©, true); } else { // copy != NULL - only set service.bundleLocation status = configuration_setBundleLocationProperty(configuration, ©); } // (5) return if (status == CELIX_SUCCESS) { *properties = copy; } else { *properties = NULL; } configuration_unlock(configuration); return status; }