Skip to content

Commit

Permalink
CELIX-376: Use of serviceId as hashMap index instead of registration …
Browse files Browse the repository at this point in the history
…pointer
  • Loading branch information
gricciardi committed Oct 14, 2016
1 parent 73ffc04 commit 652741c
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 64 deletions.
2 changes: 1 addition & 1 deletion dependency_manager/private/include/dm_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef enum dm_event_type dm_event_type_e;

struct dm_event {
const void* service;
long serviceId;
unsigned long serviceId;
long ranking;
service_reference_pt reference;
bundle_context_pt context;
Expand Down
2 changes: 1 addition & 1 deletion dependency_manager/private/src/dm_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle

const char* serviceIdStr = NULL;
serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &serviceIdStr);
long servId = atol(serviceIdStr);
unsigned long servId = strtoul(serviceIdStr,NULL,10);

//FIXME service ranking can dynamicly change, but service reference can be removed at any time.
const char* rankingStr = NULL;
Expand Down
6 changes: 3 additions & 3 deletions framework/private/include/service_registration_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct serviceRegistration {
bundle_pt bundle;
properties_pt properties;
const void * svcObj;
long serviceId;
unsigned long serviceId;

bool isUnregistering;

Expand All @@ -53,8 +53,8 @@ struct serviceRegistration {
celix_thread_rwlock_t lock;
};

service_registration_pt serviceRegistration_create(registry_callback_t callback, bundle_pt bundle, const char* serviceName, long serviceId, const void * serviceObject, properties_pt dictionary);
service_registration_pt serviceRegistration_createServiceFactory(registry_callback_t callback, bundle_pt bundle, const char* serviceName, long serviceId, const void * serviceObject, properties_pt dictionary);
service_registration_pt serviceRegistration_create(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId, const void * serviceObject, properties_pt dictionary);
service_registration_pt serviceRegistration_createServiceFactory(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId, const void * serviceObject, properties_pt dictionary);

void serviceRegistration_retain(service_registration_pt registration);
void serviceRegistration_release(service_registration_pt registration);
Expand Down
4 changes: 2 additions & 2 deletions framework/private/include/service_registry_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ struct serviceRegistry {
registry_callback_t callback;

hash_map_pt serviceRegistrations; //key = bundle (reg owner), value = list ( registration )
hash_map_pt serviceReferences; //key = bundle, value = map (key = registration, value = reference)
hash_map_pt serviceReferences; //key = bundle, value = map (key = serviceId, value = reference)

bool checkDeletedReferences; //If enabled. check if provided service references are still valid
hash_map_pt deletedServiceReferences; //key = ref pointer, value = bool

serviceChanged_function_pt serviceChanged;
long currentServiceId;
unsigned long currentServiceId;

array_list_pt listenerHooks;

Expand Down
8 changes: 4 additions & 4 deletions framework/private/mock/service_registration_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@
#include "service_registration.h"
#include "service_registration_private.h"

service_registration_pt serviceRegistration_create(registry_callback_t callback, bundle_pt bundle, const char* serviceName, long serviceId, const void* serviceObject, properties_pt dictionary) {
service_registration_pt serviceRegistration_create(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId, const void* serviceObject, properties_pt dictionary) {
mock_c()->actualCall("serviceRegistration_create")
->withParameterOfType("registry_callback_t", "callback", &callback)
->withPointerParameters("bundle", bundle)
->withStringParameters("serviceName", serviceName)
->withIntParameters("serviceId", serviceId)
->withUnsignedLongIntParameters("serviceId", serviceId)
->withPointerParameters("serviceObject", (void*)serviceObject)
->withPointerParameters("dictionary", dictionary);
return mock_c()->returnValue().value.pointerValue;
}

service_registration_pt serviceRegistration_createServiceFactory(registry_callback_t callback, bundle_pt bundle, const char* serviceName, long serviceId, const void* serviceObject, properties_pt dictionary) {
service_registration_pt serviceRegistration_createServiceFactory(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId, const void* serviceObject, properties_pt dictionary) {
mock_c()->actualCall("serviceRegistration_createServiceFactory")
->withParameterOfType("registry_callback_t", "callback", &callback)
->withPointerParameters("bundle", bundle)
->withStringParameters("serviceName", serviceName)
->withIntParameters("serviceId", serviceId)
->withUnsignedLongIntParameters("serviceId", serviceId)
->withPointerParameters("serviceObject", (void*) serviceObject)
->withPointerParameters("dictionary", dictionary);
return mock_c()->returnValue().value.pointerValue;
Expand Down
10 changes: 5 additions & 5 deletions framework/private/src/service_registration.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@
#include "constants.h"

static celix_status_t serviceRegistration_initializeProperties(service_registration_pt registration, properties_pt properties);
static celix_status_t serviceRegistration_createInternal(registry_callback_t callback, bundle_pt bundle, const char* serviceName, long serviceId,
static celix_status_t serviceRegistration_createInternal(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId,
const void * serviceObject, properties_pt dictionary, bool isFactory, service_registration_pt *registration);
static celix_status_t serviceRegistration_destroy(service_registration_pt registration);

service_registration_pt serviceRegistration_create(registry_callback_t callback, bundle_pt bundle, const char* serviceName, long serviceId, const void * serviceObject, properties_pt dictionary) {
service_registration_pt serviceRegistration_create(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId, const void * serviceObject, properties_pt dictionary) {
service_registration_pt registration = NULL;
serviceRegistration_createInternal(callback, bundle, serviceName, serviceId, serviceObject, dictionary, false, &registration);
return registration;
}

service_registration_pt serviceRegistration_createServiceFactory(registry_callback_t callback, bundle_pt bundle, const char* serviceName, long serviceId, const void * serviceObject, properties_pt dictionary) {
service_registration_pt serviceRegistration_createServiceFactory(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId, const void * serviceObject, properties_pt dictionary) {
service_registration_pt registration = NULL;
serviceRegistration_createInternal(callback, bundle, serviceName, serviceId, serviceObject, dictionary, true, &registration);
return registration;
}

static celix_status_t serviceRegistration_createInternal(registry_callback_t callback, bundle_pt bundle, const char* serviceName, long serviceId,
static celix_status_t serviceRegistration_createInternal(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId,
const void * serviceObject, properties_pt dictionary, bool isFactory, service_registration_pt *out) {
celix_status_t status = CELIX_SUCCESS;

Expand Down Expand Up @@ -128,7 +128,7 @@ static celix_status_t serviceRegistration_initializeProperties(service_registrat
}


snprintf(sId, 32, "%ld", registration->serviceId);
snprintf(sId, 32, "%lu", registration->serviceId);
properties_set(dictionary, (char *) OSGI_FRAMEWORK_SERVICE_ID, sId);

if (properties_get(dictionary, (char *) OSGI_FRAMEWORK_OBJECTCLASS) == NULL) {
Expand Down
18 changes: 9 additions & 9 deletions framework/private/src/service_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ celix_status_t serviceRegistry_create(framework_pt framework, serviceChanged_fun
reg->serviceChanged = serviceChanged;
reg->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
reg->framework = framework;
reg->currentServiceId = 1l;
reg->currentServiceId = 1UL;
reg->serviceReferences = hashMap_create(NULL, NULL, NULL, NULL);

reg->checkDeletedReferences = CHECK_DELETED_REFERENCES;
Expand Down Expand Up @@ -218,7 +218,7 @@ celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, b
while (hashMapIterator_hasNext(iter)) {
hash_map_pt refsMap = hashMapIterator_nextValue(iter);
service_reference_pt ref = refsMap != NULL ?
hashMap_get(refsMap, registration) : NULL;
hashMap_get(refsMap, (void*)registration->serviceId) : NULL;
if (ref != NULL) {
serviceReference_invalidate(ref);
}
Expand Down Expand Up @@ -302,15 +302,15 @@ static celix_status_t serviceRegistry_getServiceReference_internal(service_regis
hashMap_put(registry->serviceReferences, owner, references);
}

ref = hashMap_get(references, registration);
ref = hashMap_get(references, (void*)registration->serviceId);

if (ref == NULL) {
status = serviceRegistration_getBundle(registration, &bundle);
if (status == CELIX_SUCCESS) {
status = serviceReference_create(registry->callback, owner, registration, &ref);
}
if (status == CELIX_SUCCESS) {
hashMap_put(references, registration, ref);
hashMap_put(references, (void*)registration->serviceId, ref);
hashMap_put(registry->deletedServiceReferences, ref, (void *)false);
}
} else {
Expand Down Expand Up @@ -453,25 +453,25 @@ celix_status_t serviceRegistry_ungetServiceReference(service_registry_pt registr

hash_map_pt refsMap = hashMap_get(registry->serviceReferences, bundle);

service_registration_pt reg = NULL;
unsigned long reg = 0UL;
service_reference_pt ref = NULL;
hash_map_iterator_pt iter = hashMapIterator_create(refsMap);
while (hashMapIterator_hasNext(iter)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
reg = hashMapEntry_getKey(entry); //note could be invalid e.g. freed
reg = (unsigned long)hashMapEntry_getKey(entry); //note could be invalid e.g. freed
ref = hashMapEntry_getValue(entry);

if (ref == reference) {
break;
} else {
ref = NULL;
reg = NULL;
reg = 0UL;
}
}
hashMapIterator_destroy(iter);

if (ref != NULL) {
hashMap_remove(refsMap, reg);
hashMap_remove(refsMap, (void*)reg);
int size = hashMap_size(refsMap);
if (size == 0) {
hashMap_destroy(refsMap, false, false);
Expand Down Expand Up @@ -771,7 +771,7 @@ static celix_status_t serviceRegistry_getUsingBundles(service_registry_pt regist
hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
bundle_pt registrationUser = hashMapEntry_getKey(entry);
hash_map_pt regMap = hashMapEntry_getValue(entry);
if (hashMap_containsKey(regMap, registration)) {
if (hashMap_containsKey(regMap, (void*)registration->serviceId)) {
arrayList_add(bundles, registrationUser);
}
}
Expand Down
2 changes: 1 addition & 1 deletion framework/private/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ celix_status_t utils_isNumeric(const char *number, bool *ret) {
}


FRAMEWORK_EXPORT int utils_compareServiceIdsAndRanking(long servId, long servRank, long otherServId, long otherServRank) {
FRAMEWORK_EXPORT int utils_compareServiceIdsAndRanking(unsigned long servId, long servRank, unsigned long otherServId, long otherServRank) {
int result;

if (servId == otherServId) {
Expand Down
9 changes: 5 additions & 4 deletions framework/private/test/service_registration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ TEST(service_registration, create) {
callback.handle = registry;
char * name = my_strdup("sevice_name");
bundle_pt bundle = (bundle_pt) 0x20;
long serviceId = 1l;
unsigned long serviceId = 1UL;
void *service = (void *) 0x30;

service_registration_pt registration = serviceRegistration_create(callback, bundle, name, serviceId, service, NULL);

STRCMP_EQUAL(name, registration->className);
POINTERS_EQUAL(bundle, registration->bundle);
POINTERS_EQUAL(service, registration->svcObj);
LONGS_EQUAL(serviceId, registration->serviceId);
UNSIGNED_LONGS_EQUAL(serviceId, registration->serviceId);

LONGS_EQUAL(0, registration->isUnregistering);
LONGS_EQUAL(0, registration->isServiceFactory);
POINTERS_EQUAL(NULL, registration->serviceFactory);
Expand All @@ -132,15 +133,15 @@ TEST(service_registration, createServiceFactory) {
callback.handle = registry;
char * name = my_strdup("sevice_name");
bundle_pt bundle = (bundle_pt) 0x20;
long serviceId = 1l;
unsigned long serviceId = 1UL;
void *service = (void *) 0x30;

service_registration_pt registration = serviceRegistration_createServiceFactory(callback, bundle, name, serviceId, service, NULL);

STRCMP_EQUAL(name, registration->className);
POINTERS_EQUAL(bundle, registration->bundle);
POINTERS_EQUAL(service, registration->svcObj);
LONGS_EQUAL(serviceId, registration->serviceId);
UNSIGNED_LONGS_EQUAL(serviceId, registration->serviceId);
LONGS_EQUAL(0, registration->isUnregistering);
LONGS_EQUAL(1, registration->isServiceFactory);
POINTERS_EQUAL(service, registration->serviceFactory);
Expand Down
Loading

0 comments on commit 652741c

Please sign in to comment.