celix_status_t wiringAdmin_stop(wiring_admin_pt admin) {
    celix_status_t status = CELIX_SUCCESS;

    celixThreadMutex_lock(&admin->exportedWiringEndpointLock);

    // stop tracker
    hash_map_iterator_pt iter = hashMapIterator_create(admin->wiringReceiveTracker);

    while (hashMapIterator_hasNext(iter)) {
        service_tracker_pt wiringReceiveTracker = (service_tracker_pt) hashMapIterator_nextValue(iter);

        if (serviceTracker_close(wiringReceiveTracker) == CELIX_SUCCESS) {
            serviceTracker_destroy(wiringReceiveTracker);
        }
    }
    hashMapIterator_destroy(iter);

    hashMap_clear(admin->wiringReceiveTracker, false, false);

    wiringAdmin_stopWebserver(admin);

    iter = hashMapIterator_create(admin->wiringReceiveServices);

    while (hashMapIterator_hasNext(iter)) {
        array_list_pt wiringReceiveServiceList = hashMapIterator_nextValue(iter);
        arrayList_destroy(wiringReceiveServiceList);
    }

    hashMapIterator_destroy(iter);
    hashMap_clear(admin->wiringReceiveServices, false, false);

    celixThreadMutex_unlock(&admin->exportedWiringEndpointLock);

    return status;
}
Example #2
0
void test_hashMap_clear(void) {
    char * key = "key";
    char * value = "value";
    char * key2 = "key2";
    char * value2 = "value2";
    char * key3 = NULL;
    char * value3 = "value3";
    char * key4 = "key4";
    char * value4 = NULL;

    hashMap_clear(map, false, false);
    // Add one entry
    hashMap_put(map, key, value);

    // Add second entry
    hashMap_put(map, key2, value2);

    // Add third entry with NULL key
    hashMap_put(map, key3, value3);

    // Add fourth entry with NULL value
    hashMap_put(map, key4, value4);

    hashMap_clear(map, false, false);
    CU_ASSERT_EQUAL(map->size, 0);
}
Example #3
0
void test_hashMap_size(void) {
    char * key = "key";
    char * value = "value";
    char * key2 = "key2";
    char * value2 = "value2";
    char * key3 = strdup("key2");
    char * value3 = "value3";

    CU_ASSERT_EQUAL(map->size, 0);

    // Add one entry
    hashMap_put(map, key, value);
    CU_ASSERT_EQUAL(map->size, 1);

    // Add second entry
    hashMap_put(map, key2, value2);
    CU_ASSERT_EQUAL(map->size, 2);

    // Add entry using the same key, this does not overwrite an existing entry
    hashMap_put(map, key3, value3);
    CU_ASSERT_EQUAL(map->size, 3);

    // Clear map
    hashMap_clear(map, false, false);
    CU_ASSERT_EQUAL(map->size, 0);
}
Example #4
0
void test_hashMap_containsValue(void) {
    char * key = "key";
    char * value = "value";
    char * key2 = "key2";
    char * value2 = "value2";
    char * neValue = "notExisting";
    char * key3 = "key3";
    char * value3 = NULL;

    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_containsValue(map, value));
    CU_ASSERT_TRUE(hashMap_containsValue(map, value2));
    CU_ASSERT_FALSE(hashMap_containsValue(map, neValue));
    CU_ASSERT_FALSE(hashMap_containsValue(map, NULL));

    // Add third entry with NULL value
    hashMap_put(map, key3, value3);

    CU_ASSERT_TRUE(hashMap_containsValue(map, value3));
}
Example #5
0
void test_hashMap_remove(void) {
    char * key = "key";
    char * value = "value";
    char * key2 = NULL;
    char * value2 = "value2";
    char * removeKey;

    hashMap_clear(map, false, false);

    // Add one entry
    hashMap_put(map, key, value);

    // Add second entry with null key
    hashMap_put(map, key2, value2);

    // Remove unexisting entry for map
    removeKey = "unexisting";
    hashMap_remove(map, removeKey);
    CU_ASSERT_EQUAL(map->size, 2);
    CU_ASSERT_FALSE(hashMap_isEmpty(map));

    hashMap_remove(map, key);
    CU_ASSERT_EQUAL(map->size, 1);

    hashMap_remove(map, key2);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));

    // Remove unexisting entry for empty map
    removeKey = "unexisting";
    hashMap_remove(map, removeKey);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));
}
Example #6
0
void test_hashMap_resize(void) {
    int i;
    char * k;
    char key[6];

    hashMap_clear(map, false, false);

    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_EQUAL(map->tablelength, 16);
    CU_ASSERT_EQUAL(map->treshold, 12);
    for (i = 0; i < 12; i++) {
        char key[6];
        sprintf(key, "key%d", i);
        k = strdup(key);
        hashMap_put(map, k, k);
    }
    CU_ASSERT_EQUAL(map->size, 12);
    CU_ASSERT_EQUAL(map->tablelength, 16);
    CU_ASSERT_EQUAL(map->treshold, 12);

    sprintf(key, "key%d", i);
    hashMap_put(map, strdup(key), strdup(key));
    CU_ASSERT_EQUAL(map->size, 13);
    CU_ASSERT_EQUAL(map->tablelength, 32);
    CU_ASSERT_EQUAL(map->treshold, 24);
}
Example #7
0
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);
}
Example #8
0
void test_hashMap_isEmpty(void) {
    char * key = "key";
    char * value = "value";

    hashMap_clear(map, false, false);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));

    // Add one entry
    hashMap_put(map, key, value);
    CU_ASSERT_EQUAL(map->size, 1);
    CU_ASSERT_FALSE(hashMap_isEmpty(map));

    // Remove entry
    hashMap_remove(map, key);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));
}
Example #9
0
void test_hashMap_getEntry(void) {
    char * key = "key";
    char * value = "value";
    char * key2 = "key2";
    char * value2 = "value2";
    char * neKey = "notExisting";
    char * key3 = NULL;
    char * value3 = "value3";
    hash_map_entry_pt entry;

    hashMap_clear(map, false, false);

    // Add one entry
    hashMap_put(map, key, value);

    // Add second entry
    hashMap_put(map, key2, value2);
    entry = hashMap_getEntry(map, key);
    CU_ASSERT_STRING_EQUAL(entry->key, key);
    CU_ASSERT_STRING_EQUAL(entry->value, value);

    entry = hashMap_getEntry(map, key2);
    CU_ASSERT_STRING_EQUAL(entry->key, key2);
    CU_ASSERT_STRING_EQUAL(entry->value, value2);

    entry = hashMap_getEntry(map, neKey);
    CU_ASSERT_EQUAL(entry, NULL);

    entry = hashMap_getEntry(map, NULL);
    CU_ASSERT_EQUAL(entry, NULL);

    // Add third entry with NULL key
    hashMap_put(map, key3, value3);

    entry = hashMap_getEntry(map, key3);
    CU_ASSERT_EQUAL(entry->key, key3);
    CU_ASSERT_STRING_EQUAL(entry->value, value3);
}
Example #10
0
void test_hashMapValues_toArray(void) {
    char * key = "key";
    char * value = "value";
    char * key2 = "key2";
    char * value2 = "value2";
    char **array;
    unsigned int size;
    hash_map_values_pt values;

    hashMap_clear(map, false, false);

    // Add one entry
    hashMap_put(map, key, value);

    // Add second entry
    hashMap_put(map, key2, value2);

    values = hashMapValues_create(map);
    hashMapValues_toArray(values, (void*)&array, &size);
    CU_ASSERT_EQUAL(size, 2);
    CU_ASSERT_TRUE(hashMapValues_contains(values, array[0]));
    CU_ASSERT_TRUE(hashMapValues_contains(values, array[1]));
}
Example #11
0
void test_hashMap_removeMapping(void) {
    char * key = "key";
    char * value = "value";
    char * key2 = NULL;
    char * value2 = "value2";
    hash_map_entry_pt entry1;
    hash_map_entry_pt entry2;
    hash_map_entry_pt removed;

    hashMap_clear(map, false, false);

    // Add one entry
    hashMap_put(map, key, value);

    // Add second entry with null key
    hashMap_put(map, key2, value2);

    entry1 = hashMap_getEntry(map, key);
    entry2 = hashMap_getEntry(map, key2);

    CU_ASSERT_PTR_NOT_NULL_FATAL(entry1);
    CU_ASSERT_PTR_NOT_NULL_FATAL(entry2);

    removed = hashMap_removeMapping(map, entry1);
    CU_ASSERT_PTR_EQUAL(entry1, removed);
    CU_ASSERT_EQUAL(map->size, 1);

    removed = hashMap_removeMapping(map, entry2);
    CU_ASSERT_PTR_EQUAL(entry2, removed);
    CU_ASSERT_EQUAL(map->size, 0);

    // Remove unexisting entry for empty map
    hashMap_removeMapping(map, NULL);
    CU_ASSERT_EQUAL(map->size, 0);
    CU_ASSERT_TRUE(hashMap_isEmpty(map));
}
Example #12
0
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);
}
Example #13
0
celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts){
	celix_status_t status = CELIX_SUCCESS;
	struct epoll_event ev;
	memset(&ev, 0, sizeof(ev));

	ts->running = false;

	pthread_kill(ts->recv_thread.thread,SIGUSR1);

	celixThread_join(ts->recv_thread,NULL);

	status = serviceTracker_close(ts->tracker);

	celixThreadMutex_lock(&ts->socketMap_lock);
	hash_map_iterator_pt it = hashMapIterator_create(ts->socketMap);
	while(hashMapIterator_hasNext(it)) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(it);
		char *url = hashMapEntry_getKey(entry);
		int *s = hashMapEntry_getValue(entry);
		memset(&ev, 0, sizeof(ev));
		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);
		free(url);
		//hashMapIterator_remove(it);
	}
	hashMapIterator_destroy(it);
	hashMap_clear(ts->socketMap, false, false);
	celixThreadMutex_unlock(&ts->socketMap_lock);


	return status;
}