celix_status_t requirement_create(hash_map_pt directives, hash_map_pt attributes, requirement_pt *requirement) { celix_status_t status = CELIX_SUCCESS; *requirement = (requirement_pt) malloc(sizeof(**requirement)); if (!*requirement) { status = CELIX_ENOMEM; } else { attribute_pt serviceAttribute = NULL; attribute_pt versionAttribute = NULL; (*requirement)->attributes = attributes; (*requirement)->directives = directives; serviceAttribute = (attribute_pt) hashMap_get(attributes, "service"); status = attribute_getValue(serviceAttribute, &(*requirement)->targetName); if (status == CELIX_SUCCESS) { (*requirement)->versionRange = NULL; status = versionRange_createInfiniteVersionRange(&(*requirement)->versionRange); if (status == CELIX_SUCCESS) { versionAttribute = (attribute_pt) hashMap_get(attributes, "version"); if (versionAttribute != NULL) { char *versionStr = NULL; attribute_getValue(versionAttribute, &versionStr); (*requirement)->versionRange = NULL; status = versionRange_parse(versionStr, &(*requirement)->versionRange); } } } } framework_logIfError(logger, status, NULL, "Cannot create requirement"); return status; }
celix_status_t shell_executeCommand(shell_pt shell_ptr, char *command_line_str, FILE *out, FILE *err) { celix_status_t status = CELIX_SUCCESS; command_service_pt command_ptr = NULL; if (!shell_ptr || !command_line_str || !out || !err) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { size_t pos = strcspn(command_line_str, " "); char *command_name_str = (pos != strlen(command_line_str)) ? strndup(command_line_str, pos) : strdup(command_line_str); command_ptr = hashMap_get(shell_ptr->command_name_map_ptr, command_name_str); free(command_name_str); if (!command_ptr) { fprintf(err, "No such command\n"); status = CELIX_BUNDLE_EXCEPTION; } } if (status == CELIX_SUCCESS) { status = command_ptr->executeCommand(command_ptr->handle, command_line_str, out, err); } return status; }
celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) { celix_status_t status = CELIX_SUCCESS; /* module_pt module = NULL; char *name = NULL; bundle_getCurrentModule(bundle, &module); module_getSymbolicName(module, &name); printf("getting service for bundle '%s'\n", name); */ pthread_mutex_lock(&import->proxiesMutex); struct service_proxy *proxy = hashMap_get(import->proxies, bundle); if (proxy == NULL) { status = importRegistration_createProxy(import, bundle, &proxy); if (status == CELIX_SUCCESS) { hashMap_put(import->proxies, bundle, proxy); } } if (status == CELIX_SUCCESS) { proxy->count += 1; *out = proxy->service; } pthread_mutex_unlock(&import->proxiesMutex); return status; }
celix_status_t serviceRegistry_registerServiceInternal(service_registry_pt registry, bundle_pt bundle, char * serviceName, void * serviceObject, properties_pt dictionary, bool isFactory, service_registration_pt *registration) { array_list_pt regs; celixThreadMutex_lock(®istry->mutex); if (isFactory) { *registration = serviceRegistration_createServiceFactory(registry, bundle, serviceName, ++registry->currentServiceId, serviceObject, dictionary); } else { *registration = serviceRegistration_create(registry, bundle, serviceName, ++registry->currentServiceId, serviceObject, dictionary); } serviceRegistry_addHooks(registry, serviceName, serviceObject, *registration); regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle); if (regs == NULL) { regs = NULL; arrayList_create(®s); } arrayList_add(regs, *registration); hashMap_put(registry->serviceRegistrations, bundle, regs); celixThreadMutex_unlock(®istry->mutex); if (registry->serviceChanged != NULL) { // service_event_pt event = (service_event_pt) malloc(sizeof(*event)); // event->type = REGISTERED; // event->reference = (*registration)->reference; registry->serviceChanged(registry->framework, OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED, *registration, NULL); // free(event); // event = NULL; } return CELIX_SUCCESS; }
celix_status_t serviceRegistry_getRegisteredServices(service_registry_pt registry, bundle_pt bundle, array_list_pt *services) { celix_status_t status = CELIX_SUCCESS; celixThreadMutex_lock(®istry->mutex); array_list_pt regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle); if (regs != NULL) { unsigned int i; arrayList_create(services); for (i = 0; i < arrayList_size(regs); i++) { service_registration_pt reg = arrayList_get(regs, i); if (serviceRegistration_isValid(reg)) { service_reference_pt reference = NULL; status = serviceRegistry_createServiceReference(registry, bundle, reg, &reference); if (status == CELIX_SUCCESS) { arrayList_add(*services, reference); } } } } celixThreadMutex_unlock(®istry->mutex); framework_logIfError(logger, status, NULL, "Cannot get registered services"); return status; }
celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){ celix_status_t status = CELIX_SUCCESS; printf("PSA_ZMQ: Removing subscription [FWUUID=%s bundleID=%ld topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->topic); char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic); celixThreadMutex_lock(&admin->subscriptionsLock); topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic); if(sub!=NULL){ pubsub_topicDecreaseNrSubscribers(sub); if(pubsub_topicGetNrSubscribers(sub) == 0) { status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP); } } celixThreadMutex_unlock(&admin->subscriptionsLock); if(sub==NULL){ /* Maybe the endpoint was pending */ celixThreadMutex_lock(&admin->noSerializerPendingsLock); if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){ status = CELIX_ILLEGAL_STATE; } celixThreadMutex_unlock(&admin->noSerializerPendingsLock); } free(scope_topic); return status; }
celix_status_t serviceRegistry_unregisterServices(service_registry_pt registry, bundle_pt bundle) { array_list_pt regs = NULL; unsigned int i; celixThreadMutex_lock(®istry->mutex); regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle); celixThreadMutex_unlock(®istry->mutex); for (i = 0; (regs != NULL) && i < arrayList_size(regs); i++) { service_registration_pt reg = arrayList_get(regs, i); if (serviceRegistration_isValid(reg)) { serviceRegistration_unregister(reg); } } if (regs != NULL && arrayList_isEmpty(regs)) { celixThreadMutex_lock(®istry->mutex); array_list_pt removed = hashMap_remove(registry->serviceRegistrations, bundle); celixThreadMutex_unlock(®istry->mutex); arrayList_destroy(removed); removed = NULL; } celixThreadMutex_lock(®istry->mutex); hashMap_remove(registry->serviceRegistrations, bundle); celixThreadMutex_unlock(®istry->mutex); return CELIX_SUCCESS; }
celix_status_t serviceRegistry_ungetServiceReference(service_registry_pt registry, bundle_pt owner, service_reference_pt reference) { celix_status_t status = CELIX_SUCCESS; bool valid = false; serviceRefernce_isValid(reference, &valid); if (valid) { bool ungetResult = true; while (ungetResult) { serviceRegistry_ungetService(registry, owner, reference, &ungetResult); } } celixThreadMutex_lock(®istry->referencesMapMutex); array_list_pt references = hashMap_get(registry->serviceReferences, owner); if (references != NULL) { arrayList_removeElement(references, reference); serviceReference_destroy(&reference); if (arrayList_size(references) > 0) { hashMap_put(registry->serviceReferences, owner, references); } else { array_list_pt removed = hashMap_remove(registry->serviceReferences, owner); arrayList_destroy(removed); } } celixThreadMutex_unlock(®istry->referencesMapMutex); return status; }
void serviceRegistry_ungetServices(service_registry_pt registry, bundle_pt bundle) { array_list_pt fusages; array_list_pt usages; unsigned int i; celixThreadMutex_lock(®istry->mutex); usages = hashMap_get(registry->inUseMap, bundle); celixThreadMutex_unlock(®istry->mutex); if (usages == NULL || arrayList_isEmpty(usages)) { return; } // usage arrays? fusages = arrayList_clone(usages); for (i = 0; i < arrayList_size(fusages); i++) { usage_count_pt usage = arrayList_get(fusages, i); service_reference_pt reference = usage->reference; bool ungetResult = true; while (ungetResult) { serviceRegistry_ungetService(registry, bundle, reference, &ungetResult); } } arrayList_destroy(fusages); }
/* Service's functions implementation */ celix_status_t pubsub_discovery_announcePublisher(void *handle, pubsub_endpoint_pt pubEP) { celix_status_t status = CELIX_SUCCESS; printf("pubsub_discovery_announcePublisher : %s / %s\n", pubEP->topic, pubEP->endpoint); pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle; celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex); char *pub_key = createScopeTopicKey(pubEP->scope,pubEP->topic); array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pub_key); if(pubEP_list==NULL){ arrayList_create(&pubEP_list); hashMap_put(pubsub_discovery->discoveredPubs,strdup(pub_key),pubEP_list); } free(pub_key); pubsub_endpoint_pt p = NULL; pubsubEndpoint_clone(pubEP, &p); arrayList_add(pubEP_list,p); status = etcdWriter_addPublisherEndpoint(pubsub_discovery->writer,p,true); celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex); return status; }
celix_status_t pubsub_discovery_removeNode(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP) { celix_status_t status = CELIX_SUCCESS; pubsub_endpoint_pt p = NULL; bool found = false; celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex); char *pubs_key = createScopeTopicKey(pubEP->scope, pubEP->topic); array_list_pt pubEP_list = (array_list_pt) hashMap_get(pubsub_discovery->discoveredPubs, pubs_key); free(pubs_key); if (pubEP_list == NULL) { printf("PSD: Cannot find any registered publisher for topic %s. Something is not consistent.\n", pubEP->topic); status = CELIX_ILLEGAL_STATE; } else { int i; for (i = 0; !found && i < arrayList_size(pubEP_list); i++) { p = arrayList_get(pubEP_list, i); found = pubsubEndpoint_equals(pubEP, p); if (found) { arrayList_remove(pubEP_list, i); pubsubEndpoint_destroy(p); } } } celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex); if (found) { status = pubsub_discovery_informPublishersListeners(pubsub_discovery, pubEP, false); } pubsubEndpoint_destroy(pubEP); return status; }
celix_status_t deviceManager_driverRemoved(void * handle, service_reference_pt ref, void * service) { celix_status_t status = CELIX_SUCCESS; device_manager_pt manager = handle; logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove driver"); hashMap_remove(manager->drivers, ref); array_list_pt idleDevices = NULL; status = deviceManager_getIdleDevices(manager, &idleDevices); if (status == CELIX_SUCCESS) { int i; for (i = 0; i < arrayList_size(idleDevices); i++) { celix_status_t forStatus = CELIX_SUCCESS; service_reference_pt ref = arrayList_get(idleDevices, i); const char *bsn = NULL; bundle_pt bundle = NULL; forStatus = serviceReference_getBundle(ref, &bundle); if (forStatus == CELIX_SUCCESS) { module_pt module = NULL; forStatus = bundle_getCurrentModule(bundle, &module); if (forStatus == CELIX_SUCCESS) { forStatus = module_getSymbolicName(module, &bsn); if (forStatus == CELIX_SUCCESS) { logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: IDLE: %s", bsn); // #TODO attachDriver (idle device) // #TODO this can result in a loop? // Locate and install a driver // Let the match fail, the device is idle // The driver is removed, idle check is performed // Attach is tried again // .. loop .. void *device = hashMap_get(manager->devices, ref); forStatus = deviceManager_attachAlgorithm(manager, ref, device); } } } if (forStatus != CELIX_SUCCESS) { break; //Got error, stop loop and return status } } hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers); while (hashMapIterator_hasNext(iter)) { hashMapIterator_nextValue(iter); // driver_attributes_pt da = hashMapIterator_nextValue(iter); // driverAttributes_tryUninstall(da); } hashMapIterator_destroy(iter); } if (idleDevices != NULL) { arrayList_destroy(idleDevices); } return status; }
celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, bundle_pt bundle, service_registration_pt registration) { // array_list_t clients; unsigned int i; array_list_pt regs; array_list_pt references = NULL; celixThreadMutex_lock(®istry->mutex); serviceRegistry_removeHook(registry, registration); regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle); if (regs != NULL) { arrayList_removeElement(regs, registration); hashMap_put(registry->serviceRegistrations, bundle, regs); } celixThreadMutex_unlock(®istry->mutex); if (registry->serviceChanged != NULL) { registry->serviceChanged(registry->framework, OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING, registration, NULL); } celixThreadMutex_lock(®istry->mutex); // unget service serviceRegistration_getServiceReferences(registration, &references); for (i = 0; i < arrayList_size(references); i++) { service_reference_pt reference = (service_reference_pt) arrayList_get(references, i); array_list_pt clients = NULL; unsigned int j; clients = serviceRegistry_getUsingBundles(registry, reference); for (j = 0; (clients != NULL) && (j < arrayList_size(clients)); j++) { bundle_pt client = (bundle_pt) arrayList_get(clients, j); bool ungetResult = true; while (ungetResult) { serviceRegistry_ungetService(registry, client, reference, &ungetResult); } } arrayList_destroy(clients); serviceReference_invalidate(reference); } arrayList_destroy(references); //TODO not needed, the registration is destroyed, any reference to the registration is invalid and will result in a segfault serviceRegistration_invalidate(registration); // serviceRegistration_destroy(registration); celixThreadMutex_unlock(®istry->mutex); return CELIX_SUCCESS; }
static celix_status_t pubsubAdmin_addSubscriptionToPendingList(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){ celix_status_t status = CELIX_SUCCESS; char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic); array_list_pt pendingListPerTopic = hashMap_get(admin->pendingSubscriptions,scope_topic); if(pendingListPerTopic==NULL){ arrayList_create(&pendingListPerTopic); hashMap_put(admin->pendingSubscriptions,strdup(scope_topic),pendingListPerTopic); } arrayList_add(pendingListPerTopic,subEP); free(scope_topic); return status; }
static void process_msg(topic_subscription_pt sub,pubsub_udp_msg_t *msg){ celixThreadMutex_lock(&sub->ts_lock); hash_map_iterator_pt iter = hashMapIterator_create(sub->servicesMap); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); pubsub_subscriber_pt subsvc = hashMapEntry_getKey(entry); hash_map_pt msgTypes = hashMapEntry_getValue(entry); pubsub_msg_serializer_t *msgSer = hashMap_get(msgTypes,(void*)(uintptr_t )msg->header.type); if (msgSer == NULL) { printf("PSA_UDP_MC_TS: Serializer not available for message %d.\n",msg->header.type); } else{ void *msgInst = NULL; bool validVersion = checkVersion(msgSer->msgVersion,&msg->header); if(validVersion){ celix_status_t status = msgSer->deserialize(msgSer, (const void *) msg->payload, 0, &msgInst); if (status == CELIX_SUCCESS) { bool release = true; pubsub_multipart_callbacks_t mp_callbacks; mp_callbacks.handle = sub; mp_callbacks.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForMsgType; mp_callbacks.getMultipart = NULL; subsvc->receive(subsvc->handle, msgSer->msgName, msg->header.type, msgInst, &mp_callbacks, &release); if(release){ msgSer->freeMsg(msgSer,msgInst); } } else{ printf("PSA_UDP_MC_TS: Cannot deserialize msgType %s.\n",msgSer->msgName); } } else{ int major=0,minor=0; version_getMajor(msgSer->msgVersion,&major); version_getMinor(msgSer->msgVersion,&minor); printf("PSA_UDP_MC_TS: Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n", msgSer->msgName,major,minor,msg->header.major,msg->header.minor); } } } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&sub->ts_lock); }
celix_status_t calculatorProxy_unregisterProxyService(void* proxyFactoryService, endpoint_description_pt endpointDescription) { celix_status_t status = CELIX_SUCCESS; remote_proxy_factory_service_pt calculatorProxyFactoryService = (remote_proxy_factory_service_pt) proxyFactoryService; service_registration_pt proxyReg = hashMap_get(calculatorProxyFactoryService->proxy_registrations, endpointDescription); if (proxyReg != NULL) { serviceRegistration_unregister(proxyReg); } return status; }
static celix_status_t serviceRegistry_getUsageCount(service_registry_pt registry, bundle_pt bundle, service_reference_pt reference, usage_count_pt *usageCount) { array_list_pt usages = (array_list_pt) hashMap_get(registry->inUseMap, bundle); *usageCount = NULL; unsigned int i; for (i = 0; (usages != NULL) && (i < arrayList_size(usages)); i++) { usage_count_pt usage = (usage_count_pt) arrayList_get(usages, i); bool equals = false; serviceReference_equals(usage->reference, reference, &equals); if (equals) { *usageCount = usage; break; } } return CELIX_SUCCESS; }
celix_status_t serviceRegistry_getServicesInUse(service_registry_pt registry, bundle_pt bundle, array_list_pt *services) { celixThreadMutex_lock(®istry->mutex); array_list_pt usages = hashMap_get(registry->inUseMap, bundle); if (usages != NULL) { unsigned int i; arrayList_create(services); for (i = 0; i < arrayList_size(usages); i++) { usage_count_pt usage = arrayList_get(usages, i); arrayList_add(*services, usage->reference); } } celixThreadMutex_unlock(®istry->mutex); return CELIX_SUCCESS; }
static celix_status_t serviceRegistry_addUsageCount(service_registry_pt registry, bundle_pt bundle, service_reference_pt reference, usage_count_pt *usageCount) { array_list_pt usages = hashMap_get(registry->inUseMap, bundle); usage_count_pt usage = malloc(sizeof(*usage)); usage->reference = reference; usage->count = 0; usage->service = NULL; if (usages == NULL) { arrayList_create(&usages); } arrayList_add(usages, usage); hashMap_put(registry->inUseMap, bundle, usages); *usageCount = usage; return CELIX_SUCCESS; }
static void connectTopicPubSubToSerializer(pubsub_admin_pt admin,pubsub_serializer_service_t *serializer,void *topicPubSub,bool isPublication){ celixThreadMutex_lock(&admin->usedSerializersLock); hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer; array_list_pt list = (array_list_pt)hashMap_get(map,serializer); if(list==NULL){ arrayList_create(&list); hashMap_put(map,serializer,list); } arrayList_add(list,topicPubSub); celixThreadMutex_unlock(&admin->usedSerializersLock); }
void test_hashMap_get(void) { char * key = "key"; char * value = "value"; char * key2 = "key2"; char * value2 = "value2"; char * neKey = "notExisting"; char * key3 = NULL; char * value3 = "value3"; char * get; hashMap_clear(map, false, false); // Add one entry hashMap_put(map, key, value); // Add second entry hashMap_put(map, key2, value2); get = hashMap_get(map, key); CU_ASSERT_STRING_EQUAL(get, value); get = hashMap_get(map, key2); CU_ASSERT_STRING_EQUAL(get, value2); get = hashMap_get(map, neKey); CU_ASSERT_EQUAL(get, NULL); get = hashMap_get(map, NULL); CU_ASSERT_EQUAL(get, NULL); // Add third entry with NULL key hashMap_put(map, key3, value3); get = hashMap_get(map, NULL); CU_ASSERT_STRING_EQUAL(get, value3); }
void* statPoller(void* handle) { statistic_tracker_pt statTracker = (statistic_tracker_pt) handle; celix_status_t status = CELIX_SUCCESS; statTracker->running = true; while (statTracker->running && status == CELIX_SUCCESS) { struct stats_provider_service* statService = NULL; char* name = NULL; char* type = NULL; double statVal = 0.0f; char* mUnit = NULL; pthread_rwlock_rdlock(&statTracker->statLock); pthread_t self = pthread_self(); statService = (struct stats_provider_service*) hashMap_get(statTracker->statServices, &self); if (statService != NULL) { statService->getName(statService->statsProvider, &name); statService->getType(statService->statsProvider, &type); statService->getValue(statService->statsProvider, &statVal); statService->getMeasurementUnit(statService->statsProvider, &mUnit); msg(1, "STAT_TRACKER: Statistic for %s (type %s): %f %s ", name, type, statVal, mUnit); } else { status = CELIX_BUNDLE_EXCEPTION; } pthread_rwlock_unlock(&statTracker->statLock); if (mUnit != NULL) { free(mUnit); } if (type != NULL) { free(type); } if (name != NULL) { free(name); } sleep(WAIT_TIME_SECONDS); } return NULL; }
celix_status_t driverMatcher_get(driver_matcher_pt matcher, int key, array_list_pt *attributes) { celix_status_t status = CELIX_SUCCESS; match_key_t matchKeyS = calloc(1, sizeof(*matchKeyS)); matchKeyS->matchValue = key; *attributes = hashMap_get(matcher->attributes, matchKeyS); if (*attributes == NULL) { arrayList_create(attributes); match_key_t matchKey = calloc(1, sizeof(*matchKey)); matchKey->matchValue = key; hashMap_put(matcher->attributes, matchKey, *attributes); } return status; }
static celix_status_t wiringAdmin_wiringReceiveAdded(void * handle, service_reference_pt reference, void * service) { celix_status_t status = CELIX_SUCCESS; wiring_admin_pt admin = handle; wiring_receive_service_pt wiringReceiveService = (wiring_receive_service_pt) service; array_list_pt wiringReceiveServiceList = hashMap_get(admin->wiringReceiveServices, wiringReceiveService->wireId); printf("%s: wiringAdmin_wiringReceiveAdded, service w/ wireId %s added\n", TAG, wiringReceiveService->wireId); if (wiringReceiveServiceList == NULL) { arrayList_create(&wiringReceiveServiceList); hashMap_put(admin->wiringReceiveServices, wiringReceiveService->wireId, wiringReceiveServiceList); } arrayList_add(wiringReceiveServiceList, wiringReceiveService); return status; }
void test_hashMap_put(void) { char * key = "key"; char * value = "value"; char * key2 = "key2"; char * value2 = "value2"; char * nkey2 = strdup("key2"); char * nvalue2 = "value3"; char * key3 = NULL; char * value3 = "value3"; char * key4 = "key4"; char * value4 = NULL; char * old; char * get; hashMap_clear(map, false, false); // Add one entry hashMap_put(map, key, value); // Add second entry hashMap_put(map, key2, value2); get = hashMap_get(map, key); CU_ASSERT_STRING_EQUAL(get, value); get = hashMap_get(map, key2); CU_ASSERT_STRING_EQUAL(get, value2); // Try to add an entry with the same key, since no explicit hash function is used, // this will not overwrite an existing entry. old = (char *) hashMap_put(map, nkey2, nvalue2); CU_ASSERT_PTR_NULL_FATAL(old); // Retrieving the values will return the correct values get = hashMap_get(map, key2); CU_ASSERT_STRING_EQUAL(get, value2); get = hashMap_get(map, nkey2); CU_ASSERT_STRING_EQUAL(get, nvalue2); // Add third entry with NULL key hashMap_put(map, key3, value3); get = hashMap_get(map, key3); CU_ASSERT_STRING_EQUAL(get, value3); // Add fourth entry with NULL value hashMap_put(map, key4, value4); get = hashMap_get(map, key4); CU_ASSERT_EQUAL(get, value4); }
celix_status_t pubsub_discovery_removePublisher(void *handle, pubsub_endpoint_pt pubEP) { celix_status_t status = CELIX_SUCCESS; pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle; celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex); char *pub_key = createScopeTopicKey(pubEP->scope,pubEP->topic); array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pub_key); free(pub_key); if(pubEP_list==NULL){ printf("PSD: Cannot find any registered publisher for topic %s. Something is not consistent.\n",pubEP->topic); status = CELIX_ILLEGAL_STATE; } else{ int i; bool found = false; pubsub_endpoint_pt p = NULL; for(i=0;!found && i<arrayList_size(pubEP_list);i++){ p = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i); found = pubsubEndpoint_equals(pubEP,p); } if(!found){ printf("PSD: Trying to remove a not existing endpoint. Something is not consistent.\n"); status = CELIX_ILLEGAL_STATE; } else{ arrayList_removeElement(pubEP_list,p); status = etcdWriter_deletePublisherEndpoint(pubsub_discovery->writer,p); pubsubEndpoint_destroy(p); } } celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex); return status; }
celix_status_t serviceRegistry_ungetServiceReferences(service_registry_pt registry, bundle_pt owner) { celix_status_t status = CELIX_SUCCESS; celixThreadMutex_lock(®istry->referencesMapMutex); array_list_pt references = hashMap_get(registry->serviceReferences, owner); celixThreadMutex_unlock(®istry->referencesMapMutex); if (references != NULL) { array_list_pt referencesClone = arrayList_clone(references); int refIdx = 0; for (refIdx = 0; refIdx < arrayList_size(referencesClone); refIdx++) { service_reference_pt reference = arrayList_get(referencesClone, refIdx); serviceRegistry_ungetServiceReference(registry, owner, reference); } arrayList_destroy(referencesClone); } return status; }
celix_status_t managedServiceTracker_getManagedServiceReference(managed_service_tracker_pt tracker, char *pid, service_reference_pt *reference) { celix_status_t status; service_reference_pt ref = NULL; managedServiceTracker_lockManagedServicesReferences(tracker); ref = hashMap_get(tracker->managedServicesReferences, pid); if (ref == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { status = CELIX_SUCCESS; } managedServiceTracker_unlockManagedServicesReferences(tracker); *reference = ref; return status; }
celix_status_t pubsub_discovery_interestedInTopic(void *handle, const char* scope, const char* topic) { pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle; char *scope_topic_key = createScopeTopicKey(scope, topic); celixThreadMutex_lock(&pubsub_discovery->watchersMutex); struct watcher_info * wi = hashMap_get(pubsub_discovery->watchers, scope_topic_key); if(wi) { wi->nr_references++; free(scope_topic_key); } else { wi = calloc(1, sizeof(*wi)); etcdWatcher_create(pubsub_discovery, pubsub_discovery->context, scope, topic, &wi->watcher); wi->nr_references = 1; hashMap_put(pubsub_discovery->watchers, scope_topic_key, wi); } celixThreadMutex_unlock(&pubsub_discovery->watchersMutex); return CELIX_SUCCESS; }
celix_status_t driverMatcher_get(driver_matcher_pt matcher, int key, array_list_pt *attributes) { celix_status_t status = CELIX_SUCCESS; apr_pool_t *spool = NULL; apr_pool_create(&spool, matcher->pool); match_key_t matchKeyS = apr_palloc(spool, sizeof(*matchKeyS)); matchKeyS->matchValue = key; *attributes = hashMap_get(matcher->attributes, matchKeyS); if (*attributes == NULL) { arrayList_create(attributes); match_key_t matchKey = apr_palloc(matcher->pool, sizeof(*matchKey)); matchKey->matchValue = key; hashMap_put(matcher->attributes, matchKey, *attributes); } apr_pool_destroy(spool); return status; }