static celix_status_t serviceTracker_addingService(service_tracker_pt tracker, service_reference_pt reference, void **service) { celix_status_t status = CELIX_SUCCESS; if (tracker->customizer != NULL) { void *handle = NULL; adding_callback_pt function = NULL; status = serviceTrackerCustomizer_getHandle(tracker->customizer, &handle); if (status == CELIX_SUCCESS) { status = serviceTrackerCustomizer_getAddingFunction(tracker->customizer, &function); if (status == CELIX_SUCCESS) { if (function != NULL) { status = function(handle, reference, service); } else { status = bundleContext_getService(tracker->context, reference, service); } } } } else { status = bundleContext_getService(tracker->context, reference, service); } framework_logIfError(logger, status, NULL, "Cannot handle addingService"); return status; }
static void setupFm(void) { int rc = 0; rc = celixLauncher_launch("config.properties", &framework); CHECK_EQUAL(CELIX_SUCCESS, rc); bundle_pt bundle = NULL; rc = framework_getFrameworkBundle(framework, &bundle); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundle_getContext(bundle, &context); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(rsaRef != NULL); rc = bundleContext_getService(context, rsaRef, (void **)&rsa); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &calcRef); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(calcRef != NULL); rc = bundleContext_getService(context, calcRef, (void **)&calc); CHECK_EQUAL(CELIX_SUCCESS, rc); }
static celix_status_t benchmarkRunner_addingService(void * handle, service_reference_pt reference, void **service) { celix_status_t status; struct activator * activator = handle; status = bundleContext_getService(activator->context, reference, service); return status; }
/* Callback to the pubsub_topology_manager */ celix_status_t pubsub_discovery_informPublishersListeners(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP, bool epAdded) { celix_status_t status = CELIX_SUCCESS; // Inform listeners of new publisher endpoint celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex); if (pubsub_discovery->listenerReferences != NULL) { hash_map_iterator_pt iter = hashMapIterator_create(pubsub_discovery->listenerReferences); while (hashMapIterator_hasNext(iter)) { service_reference_pt reference = hashMapIterator_nextKey(iter); publisher_endpoint_announce_pt listener = NULL; bundleContext_getService(pubsub_discovery->context, reference, (void**) &listener); if (epAdded) { listener->announcePublisher(listener->handle, pubEP); } else { listener->removePublisher(listener->handle, pubEP); } bundleContext_ungetService(pubsub_discovery->context, reference, NULL); } hashMapIterator_destroy(iter); } celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex); return status; }
static void test1(void) { celix_status_t status; service_reference_pt ref = NULL; calculator_service_pt calcService = NULL; int retries = 4; while (ref == NULL && retries > 0) { printf("Waiting for service .. %d\n", retries); status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref); usleep(1000000); --retries; } CHECK_EQUAL(CELIX_SUCCESS, status); CHECK(ref != NULL); status = bundleContext_getService(clientContext, ref, (void **) &calcService); CHECK_EQUAL(CELIX_SUCCESS, status); CHECK(calcService != NULL); double result = 0; status = calcService->add(calcService->calculator, 2.0, 5.0, &result); CHECK_EQUAL(CELIX_SUCCESS, status); CHECK_EQUAL(7.0, result); bundleContext_ungetService(clientContext, ref, NULL); bundleContext_ungetServiceReference(clientContext, ref); }
celix_status_t driverMatcher_getBestMatch(driver_matcher_pt matcher, apr_pool_t *pool, service_reference_pt reference, match_pt *match) { celix_status_t status = CELIX_SUCCESS; if (*match != NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { service_reference_pt selectorRef = NULL; status = bundleContext_getServiceReference(matcher->context, OSGI_DEVICEACCESS_DRIVER_SELECTOR_SERVICE_NAME, &selectorRef); if (status == CELIX_SUCCESS) { int index = -1; if (selectorRef != NULL) { driver_selector_service_pt selector = NULL; status = bundleContext_getService(matcher->context, selectorRef, (void **) &selector); if (status == CELIX_SUCCESS) { if (selector != NULL) { int size = -1; status = selector->driverSelector_select(selector->selector, reference, matcher->matches, &index); if (status == CELIX_SUCCESS) { size = arrayList_size(matcher->matches); if (index != -1 && index >= 0 && index < size) { *match = arrayList_get(matcher->matches, index); } } } } } if (status == CELIX_SUCCESS && *match == NULL) { status = driverMatcher_getBestMatchInternal(matcher, pool, match); } } } return status; }
celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service) { celix_status_t status = CELIX_SUCCESS; import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle; bundleContext_getService(registration_factory->context, reference, service); return status; }
celix_status_t wiringTopologyManager_wiringEndpointListenerAdding(void* handle, service_reference_pt reference, void** service) { celix_status_t status = CELIX_SUCCESS; wiring_topology_manager_pt manager = handle; bundleContext_getService(manager->context, reference, service); return status; }
static celix_status_t wiringAdmin_wiringReceiveAdding(void * handle, service_reference_pt reference, void **service) { celix_status_t status; wiring_admin_pt admin = handle; status = bundleContext_getService(admin->context, reference, service); return status; }
void shellTui_initializeService(shell_tui_activator_pt activator) { if (activator->shell == NULL) { bundleContext_getServiceReference(activator->context, (char *) OSGI_SHELL_SERVICE_NAME, &activator->reference); if (activator->reference != NULL) { void *shell_svc = NULL; bundleContext_getService(activator->context, activator->reference, &shell_svc); activator->shell = (shell_service_pt) shell_svc; } } }
static void setupFmImport(void) { int rc = 0; rc = celixLauncher_launch("config_import.properties", &framework); CHECK_EQUAL(CELIX_SUCCESS, rc); bundle_pt bundle = NULL; rc = framework_getFrameworkBundle(framework, &bundle); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundle_getContext(bundle, &context); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(rsaRef != NULL); rc = bundleContext_getService(context, rsaRef, (void **)&rsa); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_getServiceReference(context, (char *)TOPOLOGYMANAGER_SCOPE_SERVICE, &scopeServiceRef); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(scopeServiceRef != NULL); rc = bundleContext_getService(context, scopeServiceRef, (void **)&tmScopeService); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_getServiceReference(context, (char *)TST_SERVICE_NAME, &testRef); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(testRef != NULL); rc = bundleContext_getService(context, testRef, (void **)&testImport); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_getServiceReference(context, (char*)OSGI_ENDPOINT_LISTENER_SERVICE, &eplRef); CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(eplRef != NULL); rc = bundleContext_getService(context, eplRef, (void **)&eplService); CHECK_EQUAL(CELIX_SUCCESS, rc); }
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; }
void subCommand_execute(command_pt command, char *line, void (*out)(char *), void (*err)(char *)) { celix_status_t status = CELIX_SUCCESS; service_reference_pt calculatorService = NULL; apr_pool_t *memory_pool = NULL; apr_pool_t *bundle_memory_pool = NULL; status = bundleContext_getServiceReference(command->bundleContext, (char *) CALCULATOR_SERVICE, &calculatorService); if (status == CELIX_SUCCESS) { char *token; char *commandStr = apr_strtok(line, " ", &token); char *aStr = apr_strtok(NULL, " ", &token); bool numeric; subCommand_isNumeric(command, aStr, &numeric); if (aStr != NULL && numeric) { char *bStr = apr_strtok(NULL, " ", &token); subCommand_isNumeric(command, bStr, &numeric); if (bStr != NULL && numeric) { calculator_service_pt calculator = NULL; status = bundleContext_getService(command->bundleContext, calculatorService, (void *) &calculator); if (status == CELIX_SUCCESS) { double a = atof(aStr); double b = atof(bStr); double result = 0; status = calculator->sub(calculator->calculator, a, b, &result); if (status == CELIX_SUCCESS) { char line[256]; sprintf(line, "CALCULATOR_SHELL: Sub: %f - %f = %f\n", a, b, result); out(line); } else { out("SUB: Unexpected exception in Calc service\n"); } } else { out("No calc service available\n"); } } else { out("SUB: Requires 2 numerical parameter\n"); } } else { out("SUB: Requires 2 numerical parameter\n"); status = CELIX_ILLEGAL_ARGUMENT; } double a; double b; } else { out("No calc service available\n"); } //return status; }
celix_status_t refiningDriver_attach(void * driverHandler, service_reference_pt reference, char **result) { printf("REFINING_DRIVER: attached called\n"); celix_status_t status = CELIX_SUCCESS; refining_driver_pt driver = driverHandler; (*result) = NULL; base_driver_device_service_pt device_service = NULL; status = bundleContext_getService(driver->context, reference, (void **)&device_service); if (status == CELIX_SUCCESS) { refining_driver_device_pt refiningDevice = NULL; status = refiningDriver_createDevice(driver, reference, device_service, &refiningDevice); if (status == CELIX_SUCCESS) { driver->deviceCount+=1; char serial[5]; sprintf(serial, "%4i", driver->deviceCount); status = refiningDriver_registerDevice(driver, refiningDevice, serial); } } return status; }
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; }
void logCommand_execute(bundle_context_pt context, char *line, FILE *outStream, FILE *errStream) { service_reference_pt readerService = NULL; bundleContext_getServiceReference(context, (char *) OSGI_LOGSERVICE_READER_SERVICE_NAME, &readerService); if (readerService != NULL) { linked_list_pt list = NULL; linked_list_iterator_pt iter = NULL; log_reader_service_pt reader = NULL; bundleContext_getService(context, readerService, (void **) &reader); reader->getLog(reader->reader, &list); iter = linkedListIterator_create(list, 0); while (linkedListIterator_hasNext(iter)) { log_entry_pt entry = linkedListIterator_next(iter); char time[20]; char *level = NULL; char errorString[256]; strftime(time, 20, "%Y-%m-%d %H:%M:%S", localtime(&entry->time)); logCommand_levelAsString(context, entry->level, &level); if (entry->errorCode > 0) { celix_strerror(entry->errorCode, errorString, 256); fprintf(outStream, "%s - Bundle: %s - %s - %d %s\n", time, entry->bundleSymbolicName, entry->message, entry->errorCode, errorString); } else { fprintf(outStream, "%s - Bundle: %s - %s\n", time, entry->bundleSymbolicName, entry->message); } } linkedListIterator_destroy(iter); linkedList_destroy(list); bool result = true; bundleContext_ungetService(context, readerService, &result); bundleContext_ungetServiceReference(context, readerService); } else { fprintf(outStream, "No log reader available\n"); } }
celix_status_t consumingDriver_attach(void * driverHandler, service_reference_pt reference, char **result) { printf("CONSUMING_DRIVER: attached called\n"); celix_status_t status = CELIX_SUCCESS; consuming_driver_pt driver = driverHandler; (*result) = NULL; refining_driver_device_service_pt device_service = NULL; status = bundleContext_getService(driver->context, reference, (void **)&device_service); if (status == CELIX_SUCCESS) { arrayList_add(driver->references, reference); //consume the device apr_pool_t *strpool = NULL; apr_status_t aprStatus = apr_pool_create(&strpool, driver->pool); if (aprStatus == APR_SUCCESS) { for (int i=0; i<15; i++) { char *str = NULL; device_service->getNextWord(device_service->refiningDriverDevice, strpool, &str); printf("CONSUMING_DEVICE: Word Device result is %s\n", str); } apr_pool_destroy(strpool); } } return status; }
celix_status_t helpCommand_execute(void *_ptr, char *line_str, FILE *out_ptr, FILE *err_ptr) { celix_status_t status = CELIX_SUCCESS; bundle_context_pt context_ptr = _ptr; service_reference_pt shell_service_reference_ptr = NULL; shell_service_pt shell_ptr = NULL; if (!context_ptr || !line_str || !out_ptr || !err_ptr) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { status = bundleContext_getServiceReference(context_ptr, (char *) OSGI_SHELL_SERVICE_NAME, &shell_service_reference_ptr); } if (status == CELIX_SUCCESS) { status = bundleContext_getService(context_ptr, shell_service_reference_ptr, (void **) &shell_ptr); } if (status == CELIX_SUCCESS) { uint32_t out_len = 256; char *sub = NULL; char *save_ptr = NULL; char out_str[out_len]; memset(out_str, 0, sizeof(out_str)); strtok_r(line_str, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); sub = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); if (sub == NULL) { unsigned int i; array_list_pt commands = NULL; status = shell_ptr->getCommands(shell_ptr->shell, &commands); for (i = 0; i < arrayList_size(commands); i++) { char *name = arrayList_get(commands, i); fprintf(out_ptr, "%s\n", name); } fprintf(out_ptr, "\nUse 'help <command-name>' for more information.\n"); } else { celix_status_t sub_status_desc; celix_status_t sub_status_usage; int i; array_list_pt commands = NULL; shell_ptr->getCommands(shell_ptr->shell, &commands); for (i = 0; i < arrayList_size(commands); i++) { char *name = arrayList_get(commands, i); if (strcmp(sub, name) == 0) { char *usage_str = NULL; char *desc_str = NULL; sub_status_desc = shell_ptr->getCommandDescription(shell_ptr->shell, name, &desc_str); sub_status_usage = shell_ptr->getCommandUsage(shell_ptr->shell, name, &usage_str); if (sub_status_usage == CELIX_SUCCESS && sub_status_desc == CELIX_SUCCESS) { fprintf(out_ptr, "Command : %s\n", name); fprintf(out_ptr, "Usage : %s\n", usage_str == NULL ? "" : usage_str); fprintf(out_ptr, "Description : %s\n", desc_str == NULL ? "" : desc_str); } else { fprintf(err_ptr, "Error retreiving help info for command '%s'\n", sub); } if (sub_status_desc != CELIX_SUCCESS && status == CELIX_SUCCESS) { status = sub_status_desc; } if (sub_status_usage != CELIX_SUCCESS && status == CELIX_SUCCESS) { status = sub_status_usage; } } } arrayList_destroy(commands); } } return status; }
static celix_status_t shellMediator_addingService(void *handler, service_reference_pt reference, void **service) { celix_status_t status = CELIX_SUCCESS; shell_mediator_pt instance = (shell_mediator_pt) handler; bundleContext_getService(instance->context, reference, service); 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 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, ®istration); 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; }
celix_status_t eventHandlerAddingService(void * handle, service_reference_pt ref, void **service) { celix_status_t status = CELIX_SUCCESS; event_handler_pt event_handler = handle; status = bundleContext_getService(event_handler->context, ref, service); return status; }