/* 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); }
static void teardownFmImport(void) { int rc = 0; rc = bundleContext_ungetService(context, rsaRef, NULL); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_ungetServiceReference(context,rsaRef); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_ungetService(context, scopeServiceRef, NULL); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_ungetServiceReference(context,scopeServiceRef); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_ungetService(context, testRef, NULL); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_ungetServiceReference(context,testRef); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_ungetService(context, eplRef, NULL); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_ungetServiceReference(context,eplRef); CHECK_EQUAL(CELIX_SUCCESS, rc); celixLauncher_stop(framework); celixLauncher_waitForShutdown(framework); celixLauncher_destroy(framework); scopeServiceRef = NULL; tmScopeService = NULL; calcRef = NULL; calc = NULL; rsaRef = NULL; rsa = NULL; discRef = NULL; discMock = NULL; testRef = NULL; testImport = NULL; eplRef = NULL; eplService = NULL; context = NULL; framework = NULL; }
static void teardownFm(void) { int rc = 0; rc = bundleContext_ungetService(context, rsaRef, NULL); CHECK_EQUAL(CELIX_SUCCESS, rc); rc = bundleContext_ungetService(context, calcRef, NULL); CHECK_EQUAL(CELIX_SUCCESS, rc); celixLauncher_stop(framework); celixLauncher_waitForShutdown(framework); celixLauncher_destroy(framework); rsaRef = NULL; rsa = NULL; calcRef = NULL; calc = NULL; context = NULL; framework = NULL; }
static celix_status_t serviceTracker_untrack(service_tracker_pt tracker, service_reference_pt reference, service_event_pt event) { celix_status_t status = CELIX_SUCCESS; tracked_pt tracked = NULL; unsigned int i; bool result = false; for (i = 0; i < arrayList_size(tracker->tracked); i++) { bool equals; tracked = (tracked_pt) arrayList_get(tracker->tracked, i); serviceReference_equals(reference, tracked->reference, &equals); if (equals) { arrayList_remove(tracker->tracked, i); if (status == CELIX_SUCCESS) { if (tracker->customizer != NULL) { void *handle = NULL; removed_callback_pt function = NULL; serviceTrackerCustomizer_getHandle(tracker->customizer, &handle); serviceTrackerCustomizer_getRemovedFunction(tracker->customizer, &function); if (function != NULL) { status = function(handle, reference, tracked->service); } else { status = bundleContext_ungetService(tracker->context, reference, &result); } } else { status = bundleContext_ungetService(tracker->context, reference, &result); } // ungetServiceReference bundleContext_ungetServiceReference(tracker->context, reference); //break; } free(tracked); } } framework_logIfError(logger, status, NULL, "Cannot untrack reference"); return status; }
void shellTui_serviceChanged(service_listener_pt listener, service_event_pt event) { bool result = false; shell_tui_activator_pt act = (shell_tui_activator_pt) listener->handle; if ((event->type == OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED) && (act->reference == NULL)) { shellTui_initializeService(act); } else if ((event->type == OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING) && (act->reference == event->reference)) { bundleContext_ungetService(act->context, act->reference, &result); act->reference = NULL; act->shell = NULL; shellTui_initializeService(act); } }
static apr_status_t consumingDriver_cleanup(void *handler) { printf("CONSUMING_DRIVER: cleanup\n"); consuming_driver_pt driver = handler; if (driver->references != NULL) { array_list_iterator_pt iterator = arrayListIterator_create(driver->references); while (arrayListIterator_hasNext(iterator)) { service_reference_pt reference = arrayListIterator_next(iterator); bool result; bundleContext_ungetService(driver->context, reference, &result); } arrayListIterator_destroy(iterator); arrayList_destroy(driver->references); driver->references=NULL; } return APR_SUCCESS; }
celix_status_t shell_removeCommand(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) { command_ptr = hashMap_remove(shell_ptr->command_reference_map_ptr, reference_ptr); if (!command_ptr) { status = CELIX_ILLEGAL_ARGUMENT; } } if (status == CELIX_SUCCESS) { status = serviceReference_getProperty(reference_ptr, "command.name", &name_str); if (!name_str) { status = CELIX_BUNDLE_EXCEPTION; } } if (status == CELIX_SUCCESS) { hashMap_remove(shell_ptr->command_name_map_ptr, name_str); } celix_status_t sub_status = bundleContext_ungetService(shell_ptr->bundle_context_ptr, reference_ptr, NULL); if (sub_status != CELIX_SUCCESS && status == CELIX_SUCCESS) { status = sub_status; } sub_status = bundleContext_ungetServiceReference(shell_ptr->bundle_context_ptr, reference_ptr); if (sub_status != CELIX_SUCCESS && status == CELIX_SUCCESS) { status = sub_status; } 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 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; }