void test_hashMap_containsKey(void) { char * key = "key"; char * value = "value"; char * key2 = "key2"; char * value2 = "value2"; char * neKey = "notExisting"; char * key3 = NULL; char * value3 = "value3"; hashMap_clear(map, false, false); // Add one entry hashMap_put(map, key, value); // Add second entry hashMap_put(map, key2, value2); CU_ASSERT_TRUE(hashMap_containsKey(map, key)); CU_ASSERT_TRUE(hashMap_containsKey(map, key2)); CU_ASSERT_FALSE(hashMap_containsKey(map, neKey)); CU_ASSERT_FALSE(hashMap_containsKey(map, NULL)); // Add third entry with NULL key hashMap_put(map, key3, value3); CU_ASSERT_TRUE(hashMap_containsKey(map, key3)); }
static celix_status_t topicsub_subscriberTracked(void * handle, service_reference_pt reference, void * service){ celix_status_t status = CELIX_SUCCESS; topic_subscription_pt ts = handle; celixThreadMutex_lock(&ts->ts_lock); if (!hashMap_containsKey(ts->servicesMap, service)) { bundle_pt bundle = NULL; hash_map_pt msgTypes = NULL; serviceReference_getBundle(reference, &bundle); if(ts->serializer != NULL && bundle!=NULL){ ts->serializer->createSerializerMap(ts->serializer->handle,bundle,&msgTypes); if(msgTypes != NULL){ hashMap_put(ts->servicesMap, service, msgTypes); printf("PSA_UDP_MC_TS: New subscriber registered.\n"); } } else{ printf("PSA_UDP_MC_TS: Cannot register new subscriber.\n"); status = CELIX_SERVICE_EXCEPTION; } } celixThreadMutex_unlock(&ts->ts_lock); return status; }
celix_status_t pubsub_topicSubscriptionDisconnectPublisher(topic_subscription_pt ts, char* pubURL){ printf("pubsub_topicSubscriptionDisconnectPublisher : pubURL = %s\n", pubURL); celix_status_t status = CELIX_SUCCESS; struct epoll_event ev; memset(&ev, 0, sizeof(ev)); celixThreadMutex_lock(&ts->socketMap_lock); if (hashMap_containsKey(ts->socketMap, pubURL)){ #if defined(__APPLE__) && defined(__MACH__) //TODO: Use kqueue for OSX #else int *s = hashMap_remove(ts->socketMap, pubURL); if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_DEL, *s, &ev) == -1) { printf("in if error()\n"); perror("epoll_ctl() EPOLL_CTL_DEL"); status = CELIX_SERVICE_EXCEPTION; } free(s); #endif } celixThreadMutex_unlock(&ts->socketMap_lock); return status; }
celix_status_t wiringTopologyManager_waRemoved(void * handle, service_reference_pt reference, void * service) { celix_status_t status = CELIX_SUCCESS; wiring_topology_manager_pt manager = handle; wiring_admin_service_pt wiringAdminService = (wiring_admin_service_pt) service; /* check whether one of the exported Wires can be exported here via the newly available wiringAdmin*/ celixThreadMutex_lock(&manager->exportedWiringEndpointsLock); hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedWiringEndpoints); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); hash_map_pt wiringAdminMap = hashMapEntry_getValue(entry); if (hashMap_containsKey(wiringAdminMap, wiringAdminService)) { wiring_endpoint_description_pt wEndpoint = (wiring_endpoint_description_pt) hashMap_remove(wiringAdminMap, wiringAdminService); status = wiringTopologyManager_notifyListenersWiringEndpointRemoved(manager, wEndpoint); if (status == CELIX_SUCCESS) { status = wiringAdminService->removeExportedWiringEndpoint(wiringAdminService->admin, wEndpoint); } else { printf("WTM: failed while removing WiringAdmin.\n"); } } } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&manager->exportedWiringEndpointsLock); /* Check if the added WA can match one of the imported WiringEndpoints */ celixThreadMutex_lock(&manager->importedWiringEndpointsLock); iter = hashMapIterator_create(manager->importedWiringEndpoints); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); wiring_endpoint_description_pt importedWiringEndpointDesc = hashMapEntry_getKey(entry); array_list_pt wiringAdminList = hashMapEntry_getValue(entry); if (arrayList_contains(wiringAdminList, wiringAdminService)) { status = wiringAdminService->removeImportedWiringEndpoint(wiringAdminService->admin, importedWiringEndpointDesc); arrayList_removeElement(wiringAdminList, wiringAdminService); } if (status == CELIX_SUCCESS) { arrayList_add(wiringAdminList, wiringAdminService); } } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&manager->importedWiringEndpointsLock); celixThreadMutex_lock(&manager->waListLock); arrayList_removeElement(manager->waList, wiringAdminService); celixThreadMutex_unlock(&manager->waListLock); printf("WTM: Removed WA\n"); return status; }
celix_status_t managedServiceTracker_untrackManagedService(managed_service_tracker_pt tracker, char *pid, service_reference_pt reference){ managedServiceTracker_lockManagedServicesReferences(tracker); if ( hashMap_containsKey(tracker->managedServicesReferences, pid) ){ hashMap_remove(tracker->managedServicesReferences, pid); hashMap_remove(tracker->managedServices, pid); } managedServiceTracker_unlockManagedServicesReferences(tracker); return CELIX_SUCCESS; }
static celix_status_t etcdWatcher_addEntry(etcd_watcher_pt watcher, char* key, char* value) { celix_status_t status = CELIX_BUNDLE_EXCEPTION; endpoint_discovery_poller_pt poller = watcher->discovery->poller; if (!hashMap_containsKey(watcher->entries, key)) { status = endpointDiscoveryPoller_addDiscoveryEndpoint(poller, value); if (status == CELIX_SUCCESS) { hashMap_put(watcher->entries, strdup(key), strdup(value)); } } return status; }
celix_status_t managedServiceTracker_trackManagedService(managed_service_tracker_pt tracker, char *pid, service_reference_pt reference, managed_service_service_pt service) { managedServiceTracker_lockManagedServicesReferences(tracker); if (hashMap_containsKey(tracker->managedServicesReferences, pid)) { printf("[ WARNING ]: Tracker - Track ( Service{PID=%s} already registered ) ", pid); managedServiceTracker_unlockManagedServicesReferences(tracker); return CELIX_ILLEGAL_ARGUMENT; } hashMap_put(tracker->managedServicesReferences, pid, reference); hashMap_put(tracker->managedServices, pid, service); managedServiceTracker_unlockManagedServicesReferences(tracker); return CELIX_SUCCESS; }
celix_status_t deploymentPackage_getBundle(deployment_package_pt package, char *name, bundle_pt *bundle) { if (hashMap_containsKey(package->nameToBundleInfo, name)) { array_list_pt bundles = NULL; bundleContext_getBundles(package->context, &bundles); int i; for (i = 0; i < arrayList_size(bundles); i++) { bundle_pt ibundle = arrayList_get(bundles, i); module_pt module = NULL; bundle_getCurrentModule(ibundle, &module); char *bsn = NULL; module_getSymbolicName(module, &bsn); if (strcmp(bsn, name) == 0) { *bundle = ibundle; break; } } } return CELIX_SUCCESS; }
static celix_status_t topicsub_subscriberUntracked(void * handle, service_reference_pt reference, void * service){ celix_status_t status = CELIX_SUCCESS; topic_subscription_pt ts = handle; celixThreadMutex_lock(&ts->ts_lock); if (hashMap_containsKey(ts->servicesMap, service)) { hash_map_pt msgTypes = hashMap_remove(ts->servicesMap, service); if(msgTypes!=NULL && ts->serializer!=NULL){ ts->serializer->destroySerializerMap(ts->serializer->handle,msgTypes); printf("PSA_ZMQ_TS: Subscriber unregistered.\n"); } else{ printf("PSA_ZMQ_TS: Cannot unregister subscriber.\n"); status = CELIX_SERVICE_EXCEPTION; } } celixThreadMutex_unlock(&ts->ts_lock); printf("PSA_UDP_MC_TS: Subscriber unregistered.\n"); return status; }
celix_status_t pubsub_topicSubscriptionConnectPublisher(topic_subscription_pt ts, char* pubURL) { printf("pubsub_topicSubscriptionConnectPublisher : pubURL = %s\n", pubURL); celix_status_t status = CELIX_SUCCESS; celixThreadMutex_lock(&ts->socketMap_lock); if(!hashMap_containsKey(ts->socketMap, pubURL)){ int *recvSocket = calloc(sizeof(int), 1); *recvSocket = socket(AF_INET, SOCK_DGRAM, 0); if (*recvSocket < 0) { perror("pubsub_topicSubscriptionCreate:socket"); status = CELIX_SERVICE_EXCEPTION; } if (status == CELIX_SUCCESS){ int reuse = 1; if (setsockopt(*recvSocket, SOL_SOCKET, SO_REUSEADDR, (char*) &reuse, sizeof(reuse)) != 0) { perror("setsockopt() SO_REUSEADDR"); status = CELIX_SERVICE_EXCEPTION; } } if(status == CELIX_SUCCESS){ // TODO Check if there is a better way to parse the URL to IP/Portnr //replace ':' by spaces char *url = strdup(pubURL); char *pt = url; while((pt=strchr(pt, ':')) != NULL) { *pt = ' '; } char mcIp[100]; unsigned short mcPort; sscanf(url, "udp //%s %hu", mcIp, &mcPort); free(url); printf("pubsub_topicSubscriptionConnectPublisher : IP = %s, Port = %hu\n", mcIp, mcPort); struct ip_mreq mc_addr; mc_addr.imr_multiaddr.s_addr = inet_addr(mcIp); mc_addr.imr_interface.s_addr = inet_addr(ts->ifIpAddress); printf("Adding MC %s at interface %s\n", mcIp, ts->ifIpAddress); if (setsockopt(*recvSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &mc_addr, sizeof(mc_addr)) != 0) { perror("setsockopt() IP_ADD_MEMBERSHIP"); status = CELIX_SERVICE_EXCEPTION; } if (status == CELIX_SUCCESS){ struct sockaddr_in mcListenAddr; mcListenAddr.sin_family = AF_INET; mcListenAddr.sin_addr.s_addr = INADDR_ANY; mcListenAddr.sin_port = htons(mcPort); if(bind(*recvSocket, (struct sockaddr*)&mcListenAddr, sizeof(mcListenAddr)) != 0) { perror("bind()"); status = CELIX_SERVICE_EXCEPTION; } } if (status == CELIX_SUCCESS){ #if defined(__APPLE__) && defined(__MACH__) //TODO: Use kqueue for OSX #else struct epoll_event ev; memset(&ev, 0, sizeof(ev)); ev.events = EPOLLIN; ev.data.fd = *recvSocket; if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_ADD, *recvSocket, &ev) == -1) { perror("epoll_ctl() EPOLL_CTL_ADD"); status = CELIX_SERVICE_EXCEPTION; } #endif } } if (status == CELIX_SUCCESS){ hashMap_put(ts->socketMap, strdup(pubURL), (void*)recvSocket); } else{ free(recvSocket); } } celixThreadMutex_unlock(&ts->socketMap_lock); return status; }