Skip to content

Commit

Permalink
CELIX-293: removing of fw_log calls, pthread_*, minor bugfixing, adde…
Browse files Browse the repository at this point in the history
…d test
  • Loading branch information
bpetri committed Nov 13, 2015
1 parent 3e0b7f8 commit c003b31
Show file tree
Hide file tree
Showing 18 changed files with 822 additions and 531 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ celix_status_t endpointDiscoveryServer_addEndpoint(endpoint_discovery_server_pt
celix_status_t endpointDiscoveryServer_removeEndpoint( endpoint_discovery_server_pt server, endpoint_description_pt endpoint);

/**
* Removes the url, which is used by the discovery server to announce the endpoints
* Returns the url, which is used by the discovery server to announce the endpoints
*
* @param server [in] the endpoint discovery server to retrieve the url from
* @param url [out] url which is used to announce the endpoints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ static size_t endpointDiscoveryPoller_writeMemory(void *contents, size_t size, s
static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_poller_pt poller, char *url, array_list_pt *updatedEndpoints) {
celix_status_t status = CELIX_SUCCESS;

logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "Polling url '%s'", url);

CURL *curl = NULL;
CURLcode res = CURLE_OK;
Expand Down Expand Up @@ -375,7 +374,6 @@ static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_po

status = endpointDescriptorReader_create(poller, &reader);
if (status == CELIX_SUCCESS) {
logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "Polled data '%s'", chunk.memory);
status = endpointDescriptorReader_parseDocument(reader, chunk.memory, updatedEndpoints);
}

Expand Down
4 changes: 2 additions & 2 deletions remote_services/discovery_shm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ find_package(CURL REQUIRED)
SET_HEADERS("Bundle-Name: Apache Celix RSA Discovery SHM")

bundle(discovery_shm SOURCES
private/src/shm
private/src/shm_watcher
private/src/discovery_shm
private/src/discovery_shmWatcher
private/src/discovery_impl
${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery_activator.c
${PROJECT_SOURCE_DIR}/remote_services/discovery/private/src/discovery.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include "endpoint_discovery_poller.h"
#include "endpoint_discovery_server.h"
#include "shm_watcher.h"
#include "discovery_shmWatcher.h"


#define DEFAULT_SERVER_IP "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@



#ifndef _SHM_H_
#define _SHM_H_
#ifndef _DISCOVERY_SHM_H_
#define _DISCOVERY_SHM_H_

#include <celix_errno.h>

Expand All @@ -44,13 +44,13 @@
typedef struct shmData* shmData_pt;

/* creates a new shared memory block */
celix_status_t discovery_shmCreate(shmData_pt* data);
celix_status_t discovery_shmAttach(shmData_pt* data);
celix_status_t discovery_shmSet(shmData_pt data, char *key, char* value);
celix_status_t discovery_shmGet(shmData_pt data, char* key, char* value);
celix_status_t discovery_shmGetKeys(shmData_pt data, char** keys, int* size);
celix_status_t discovery_shmRemove(shmData_pt data, char* key);
celix_status_t discovery_shmDetach(shmData_pt data);
celix_status_t discovery_shmDestroy(shmData_pt data);
celix_status_t discoveryShm_create(shmData_pt* data);
celix_status_t discoveryShm_attach(shmData_pt* data);
celix_status_t discoveryShm_set(shmData_pt data, char *key, char* value);
celix_status_t discoveryShm_get(shmData_pt data, char* key, char* value);
celix_status_t discoveryShm_getKeys(shmData_pt data, char** keys, int* size);
celix_status_t discoveryShm_remove(shmData_pt data, char* key);
celix_status_t discoveryShm_detach(shmData_pt data);
celix_status_t discoveryShm_destroy(shmData_pt data);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
* \copyright Apache License, Version 2.0
*/

#ifndef SHM_WATCHER_H_
#define SHM_WATCHER_H_
#ifndef DISCOVERY_SHM_WATCHER_H_
#define DISCOVERY_SHM_WATCHER_H_

#include "celix_errno.h"
#include "discovery.h"
#include "endpoint_discovery_poller.h"

typedef struct shm_watcher *shm_watcher_pt;

celix_status_t shmWatcher_create(endpoint_discovery_poller_pt poller, bundle_context_pt context, shm_watcher_pt *watcher);
celix_status_t shmWatcher_destroy(shm_watcher_pt watcher);
celix_status_t discoveryShmWatcher_create(discovery_pt discovery);
celix_status_t discoveryShmWatcher_destroy(discovery_pt discovery);


#endif /* SHM_WATCHER_H_ */
#endif /* DISCOVERY_SHM_WATCHER_H_ */
81 changes: 31 additions & 50 deletions remote_services/discovery_shm/private/src/discovery_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

#include "discovery.h"
#include "discovery_impl.h"
#include "shm_watcher.h"
#include "discovery_shmWatcher.h"
#include "endpoint_discovery_poller.h"
#include "endpoint_discovery_server.h"

Expand All @@ -64,8 +64,8 @@ celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discove
(*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
(*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);

status = celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
status = celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);
celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);

if (logHelper_create(context, &(*discovery)->loghelper) == CELIX_SUCCESS) {
logHelper_start((*discovery)->loghelper);
Expand Down Expand Up @@ -102,40 +102,24 @@ celix_status_t discovery_destroy(discovery_pt discovery) {

celixThreadMutex_destroy(&discovery->listenerReferencesMutex);




free(discovery);

return status;
}

celix_status_t discovery_start(discovery_pt discovery) {
celix_status_t status = CELIX_SUCCESS;
char *port = NULL;
char *path = NULL;


bundleContext_getProperty(discovery->context, DISCOVERY_SERVER_PORT, &port);
if (port == NULL) {
port = DEFAULT_SERVER_PORT;
}

bundleContext_getProperty(discovery->context, DISCOVERY_SERVER_PATH, &path);
if (path == NULL) {
path = DEFAULT_SERVER_PATH;
}
celix_status_t status;

status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}

status = shmWatcher_create(discovery->poller, discovery->context, &discovery->watcher);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
if (status == CELIX_SUCCESS) {
status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
}

status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
if (status == CELIX_SUCCESS) {
status = discoveryShmWatcher_create(discovery);
}

return status;
Expand All @@ -144,38 +128,35 @@ celix_status_t discovery_start(discovery_pt discovery) {
celix_status_t discovery_stop(discovery_pt discovery) {
celix_status_t status;

status = endpointDiscoveryServer_destroy(discovery->server);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
status = discoveryShmWatcher_destroy(discovery);

status = shmWatcher_destroy(discovery->watcher);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
if (status == CELIX_SUCCESS) {
status = endpointDiscoveryServer_destroy(discovery->server);
}

status = endpointDiscoveryPoller_destroy(discovery->poller);
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
if (status == CELIX_SUCCESS) {
status = endpointDiscoveryPoller_destroy(discovery->poller);
}

hash_map_iterator_pt iter;
if (status == CELIX_SUCCESS) {
hash_map_iterator_pt iter;

celixThreadMutex_lock(&discovery->discoveredServicesMutex);
celixThreadMutex_lock(&discovery->discoveredServicesMutex);

iter = hashMapIterator_create(discovery->discoveredServices);
while (hashMapIterator_hasNext(iter)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
endpoint_description_pt endpoint = hashMapEntry_getValue(entry);
iter = hashMapIterator_create(discovery->discoveredServices);
while (hashMapIterator_hasNext(iter)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
endpoint_description_pt endpoint = hashMapEntry_getValue(entry);

discovery_informEndpointListeners(discovery, endpoint, false);
}
hashMapIterator_destroy(iter);
discovery_informEndpointListeners(discovery, endpoint, false);
}
hashMapIterator_destroy(iter);

celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
celixThreadMutex_unlock(&discovery->discoveredServicesMutex);

logHelper_stop(discovery->loghelper);
logHelper_destroy(&discovery->loghelper);
logHelper_stop(discovery->loghelper);
logHelper_destroy(&discovery->loghelper);
}

return status;
}
Expand Down

0 comments on commit c003b31

Please sign in to comment.