celix_status_t wiringAdmin_importWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt wEndpointDescription) {
    celix_status_t status = CELIX_SUCCESS;

    wiring_send_service_pt wiringSendService = calloc(1, sizeof(*wiringSendService));

    if (!wiringSendService) {
        status = CELIX_ENOMEM;
    } else {
        service_registration_pt wiringSendServiceReg = NULL;
        char* wireId = properties_get(wEndpointDescription->properties, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY);

        properties_pt props = properties_create();
        properties_set(props, (char*) INAETICS_WIRING_WIRE_ID, wireId);

        wiringSendService->wiringEndpointDescription = wEndpointDescription;
        wiringSendService->send = wiringAdmin_send;
        wiringSendService->admin = admin;
        wiringSendService->errorCount = 0;

        status = bundleContext_registerService(admin->context, (char *) INAETICS_WIRING_SEND_SERVICE, wiringSendService, props, &wiringSendServiceReg);

        if (status == CELIX_SUCCESS) {

            hashMap_put(admin->wiringSendServices, wEndpointDescription, wiringSendService);
            hashMap_put(admin->wiringSendRegistrations, wEndpointDescription, wiringSendServiceReg);

            printf("%s: SEND SERVICE sucessfully registered w/ wireId %s\n", TAG, wireId);
        } else {
            printf("%s: could not register SEND SERVICE w/ wireId %s\n", TAG, wireId);

        }
    }

    return status;
}
Example #2
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 #3
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 #4
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 #5
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 #6
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 #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
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;

}
Example #9
0
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(&registry->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(&registry->referencesMapMutex);

	return status;
}
Example #10
0
/* 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;
}
Example #11
0
celix_status_t calculatorProxy_registerProxyService(void* proxyFactoryService, endpoint_description_pt endpointDescription, void* rsa, sendToHandle sendToCallback) {
	celix_status_t status = CELIX_SUCCESS;

	remote_proxy_factory_service_pt calculatorProxyFactoryService = (remote_proxy_factory_service_pt) proxyFactoryService;
	calculator_pt calculator = NULL;
	calculator_service_pt calculatorService = NULL;

	calculatorProxy_create(calculatorProxyFactoryService->pool, calculatorProxyFactoryService->context, &calculator);
	calculatorService = apr_palloc(calculatorProxyFactoryService->pool, sizeof(*calculatorService));
	calculatorService->calculator = calculator;
	calculatorService->add = calculatorProxy_add;
	calculatorService->sub = calculatorProxy_sub;
	calculatorService->sqrt = calculatorProxy_sqrt;

	properties_pt srvcProps = properties_create();
	properties_set(srvcProps, (char *) "proxy.interface", (char *) CALCULATOR_SERVICE);
	properties_set(srvcProps, (char *) "endpoint.framework.uuid", (char *) endpointDescription->frameworkUUID);

	service_registration_pt proxyReg = NULL;

	calculatorProxy_setEndpointDescription(calculator, endpointDescription);
	calculatorProxy_setHandler(calculator, rsa);
	calculatorProxy_setCallback(calculator, sendToCallback);

	if (bundleContext_registerService(calculatorProxyFactoryService->context, CALCULATOR_SERVICE, calculatorService, srvcProps, &proxyReg) != CELIX_SUCCESS)
	{
		printf("CALCULATOR_PROXY: error while registering calculator service\n");
	}

	hashMap_put(calculatorProxyFactoryService->proxy_registrations, endpointDescription, proxyReg);


	return status;
}
Example #12
0
celix_status_t pubsub_discovery_tmPublisherAnnounceAdded(void * handle, service_reference_pt reference, void * service) {
	celix_status_t status = CELIX_SUCCESS;

	pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt)handle;
	publisher_endpoint_announce_pt listener = (publisher_endpoint_announce_pt)service;

	celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
	celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);

	/* Notify the PSTM about discovered publisher endpoints */
	hash_map_iterator_pt iter = hashMapIterator_create(pubsub_discovery->discoveredPubs);
	while(hashMapIterator_hasNext(iter)){
		array_list_pt pubEP_list = (array_list_pt)hashMapIterator_nextValue(iter);
		int i;
		for(i=0;i<arrayList_size(pubEP_list);i++){
			pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
			status += listener->announcePublisher(listener->handle, pubEP);
		}
	}

	hashMapIterator_destroy(iter);

	hashMap_put(pubsub_discovery->listenerReferences, reference, NULL);

	celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);
	celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);

	printf("PSD: pubsub_tm_announce_publisher added.\n");

	return status;
}
Example #13
0
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(&registry->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(&regs);
	}
	arrayList_add(regs, *registration);
	hashMap_put(registry->serviceRegistrations, bundle, regs);

	celixThreadMutex_unlock(&registry->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;
}
Example #14
0
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;
}
Example #15
0
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;
}
Example #16
0
void symTab_enter(JSymTab* tab, const char* name, JValue* value)
{
	JValue* old;
	char* key = strPool_save(tab->pool, name, -1);
	old = (JValue*)hashMap_put(tab->map, key, value);
	if (old) {
	}
}
Example #17
0
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(&registry->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(&registry->mutex);

	if (registry->serviceChanged != NULL) {
		registry->serviceChanged(registry->framework, OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING, registration, NULL);
	}

	celixThreadMutex_lock(&registry->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(&registry->mutex);

	return CELIX_SUCCESS;
}
celix_status_t wiringTopologyManager_wiringEndpointListenerAdded(void* handle, service_reference_pt reference, void* service) {
    celix_status_t status = CELIX_SUCCESS;
    wiring_topology_manager_pt manager = handle;
    char *scope = NULL;
    char* wtm = NULL;

    serviceReference_getProperty(reference, (char *) INAETICS_WIRING_ENDPOINT_LISTENER_SCOPE, &scope);
    serviceReference_getProperty(reference, "WTM", &wtm);

    if (wtm != NULL && strcmp(wtm, "true") == 0) {
        printf("WTM: Ignoring own ENDPOINT_LISTENER\n");
    }
    else {
        status = celixThreadMutex_lock(&manager->listenerListLock);

        if (status == CELIX_SUCCESS) {
            hashMap_put(manager->listenerList, reference, NULL);
            celixThreadMutex_unlock(&manager->listenerListLock);
        }

        filter_pt filter = filter_create(scope);
        status = celixThreadMutex_lock(&manager->exportedWiringEndpointsLock);

        if (status == CELIX_SUCCESS) {
            hash_map_iterator_pt propIter = hashMapIterator_create(manager->exportedWiringEndpoints);

            while (hashMapIterator_hasNext(propIter)) {
                hash_map_pt wiringAdminList = hashMapIterator_nextValue(propIter);
                hash_map_iterator_pt waIter = hashMapIterator_create(wiringAdminList);

                while (hashMapIterator_hasNext(waIter)) {
                    wiring_endpoint_description_pt wEndpoint = hashMapIterator_nextValue(waIter);

                    bool matchResult = false;
                    filter_match(filter, wEndpoint->properties, &matchResult);

                    if (matchResult) {
                        wiring_endpoint_listener_pt listener = (wiring_endpoint_listener_pt) service;
                        status = listener->wiringEndpointAdded(listener->handle, wEndpoint, scope);
                    }
                }
                hashMapIterator_destroy(waIter);
            }
            hashMapIterator_destroy(propIter);

            celixThreadMutex_unlock(&manager->exportedWiringEndpointsLock);
        }
        filter_destroy(filter);

    }


    return status;
}
celix_status_t wiringAdmin_exportWiringEndpoint(wiring_admin_pt admin, wiring_endpoint_description_pt* wEndpointDescription) {
    celix_status_t status = CELIX_SUCCESS;

    celixThreadMutex_lock(&admin->exportedWiringEndpointLock);

    if (hashMap_size(admin->wiringReceiveTracker) == 0) {
        status = wiringAdmin_startWebserver(admin->context, &admin);
    }

    if (status == CELIX_SUCCESS) {
        char* fwuuid = NULL;

        status = bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwuuid);

        if (status == CELIX_SUCCESS) {
            char* wireId = NULL;
            properties_pt props = properties_create();

            printf("%s: HTTP Wiring Endpoint running at %s\n", TAG, admin->url);

            status = wiringEndpointDescription_create(NULL, props, wEndpointDescription);

            properties_set(props, WIRING_ADMIN_PROPERTIES_CONFIG_KEY, WIRING_ADMIN_PROPERTIES_CONFIG_VALUE);
            properties_set(props, WIRING_ENDPOINT_DESCRIPTION_HTTP_URL_KEY, admin->url);
            properties_set(props, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, fwuuid);

            wireId = properties_get(props, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY);

            printf("%s: wiringEndpointDescription_create w/ wireId %s started\n", TAG, wireId);

            if (status == CELIX_SUCCESS) {
                service_tracker_pt tracker = NULL;
                status = wiringAdmin_createWiringReceiveTracker(admin, &tracker, wireId);

                if (status == CELIX_SUCCESS) {
                    status = serviceTracker_open(tracker);

                    if (status == CELIX_SUCCESS) {
                        hashMap_put(admin->wiringReceiveTracker, *wEndpointDescription, tracker);
                        printf("%s: WiringReceiveTracker w/ wireId %s started\n", TAG, wireId);
                    } else {
                        serviceTracker_destroy(tracker);
                    }
                }
            }
        }
    } else {
        printf("%s: Cannot export Wiring Endpoint\n", TAG);
    }

    celixThreadMutex_unlock(&admin->exportedWiringEndpointLock);

    return status;
}
Example #20
0
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;
}
Example #21
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 #22
0
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;
}
Example #23
0
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;
}
Example #24
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 #25
0
celix_status_t deploymentPackage_create(apr_pool_t *pool, bundle_context_pt context, manifest_pt manifest, deployment_package_pt *package) {
	celix_status_t status = CELIX_SUCCESS;

	*package = apr_palloc(pool, sizeof(**package));
	if (!package) {
		status = CELIX_ENOMEM;
	} else {
		(*package)->pool = pool;
		(*package)->context = context;
		(*package)->manifest = manifest;
		(*package)->bundleInfos = NULL;
		(*package)->resourceInfos = NULL;
		(*package)->nameToBundleInfo = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
		(*package)->pathToEntry = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
		status = arrayList_create(&(*package)->bundleInfos);
		if (status == CELIX_SUCCESS) {
			status = arrayList_create(&(*package)->resourceInfos);
			if (status == CELIX_SUCCESS) {
				status = deploymentPackage_processEntries(*package);
				if (status == CELIX_SUCCESS) {
					int i;
					for (i = 0; i < arrayList_size((*package)->bundleInfos); i++) {
						bundle_info_pt info = arrayList_get((*package)->bundleInfos, i);
						hashMap_put((*package)->nameToBundleInfo, info->symbolicName, info);
					}
					for (i = 0; i < arrayList_size((*package)->resourceInfos); i++) {
						resource_info_pt info = arrayList_get((*package)->resourceInfos, i);
						hashMap_put((*package)->pathToEntry, info->path, info);
					}
				}
			}
		}
	}

	return status;
}
Example #26
0
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;
}
Example #27
0
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);

}
Example #28
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 #29
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);
}
static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback) {
	celix_status_t status = CELIX_SUCCESS;
	proxy_instance_pt proxy_instance_ptr = NULL;

	if (!remote_proxy_factory_ptr || !remote_proxy_factory_ptr->create_proxy_service_ptr) {
		status = CELIX_ILLEGAL_ARGUMENT;
	}

	if (status == CELIX_SUCCESS) {
		proxy_instance_ptr = calloc(1, sizeof(*proxy_instance_ptr));
		if (!proxy_instance_ptr) {
			status = CELIX_ENOMEM;
		}
	}

	if (status == CELIX_SUCCESS) {
		proxy_instance_ptr->properties = properties_create();
		if (!proxy_instance_ptr->properties) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
	}

	if (status == CELIX_SUCCESS) {
		status = remote_proxy_factory_ptr->create_proxy_service_ptr(remote_proxy_factory_ptr->handle, endpointDescription, rsa, sendToCallback, proxy_instance_ptr->properties, &proxy_instance_ptr->service);
	}

	if (status == CELIX_SUCCESS) {
		properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);

		hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties);
		while (hashMapIterator_hasNext(iter)) {
			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
			char *key = hashMapEntry_getKey(entry);
			char *value = hashMapEntry_getValue(entry);
			properties_set(proxy_instance_ptr->properties, key, value);
		}
	}

	if (status == CELIX_SUCCESS) {
		status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, remote_proxy_factory_ptr->service, proxy_instance_ptr->service, proxy_instance_ptr->properties, &proxy_instance_ptr->registration_ptr);
	}

	if (status == CELIX_SUCCESS) {
		hashMap_put(remote_proxy_factory_ptr->proxy_instances, endpointDescription, proxy_instance_ptr);
	}

	return status;
}