Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/674-use-pro…
Browse files Browse the repository at this point in the history
…perties-type-in-filter
  • Loading branch information
pnoltes committed Nov 29, 2023
2 parents 51f8c6d + bc4db0b commit f55c848
Show file tree
Hide file tree
Showing 22 changed files with 694 additions and 58 deletions.
25 changes: 10 additions & 15 deletions bundles/http_admin/http_admin/src/http_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct http_admin_manager {
struct mg_context *mgCtx;
char *root;

celix_thread_mutex_t admin_lock; //protects below
celix_thread_rwlock_t admin_lock; //protects below

celix_http_info_service_t infoSvc;
long infoSvcId;
Expand Down Expand Up @@ -70,7 +70,7 @@ http_admin_manager_t *httpAdmin_create(celix_bundle_context_t *context, char *ro
admin->root = root;
admin->infoSvcId = -1L;

status = celixThreadMutex_create(&admin->admin_lock, NULL);
status = celixThreadRwlock_create(&admin->admin_lock, NULL);
admin->aliasList = celix_arrayList_create();

if (status == CELIX_SUCCESS) {
Expand All @@ -93,7 +93,7 @@ http_admin_manager_t *httpAdmin_create(celix_bundle_context_t *context, char *ro
if (admin->mgCtx != NULL) {
mg_stop(admin->mgCtx);
}
celixThreadMutex_destroy(&admin->admin_lock);
celixThreadRwlock_destroy(&admin->admin_lock);

celix_arrayList_destroy(admin->aliasList);
free(admin);
Expand All @@ -103,14 +103,13 @@ http_admin_manager_t *httpAdmin_create(celix_bundle_context_t *context, char *ro
}

void httpAdmin_destroy(http_admin_manager_t *admin) {
celixThreadMutex_lock(&(admin->admin_lock));

if(admin->mgCtx != NULL) {
mg_stop(admin->mgCtx);
}

celixThreadRwlock_writeLock(&(admin->admin_lock));
celix_bundleContext_unregisterService(admin->context, admin->infoSvcId);

destroyServiceTree(&admin->http_svc_tree);

//Destroy alias map by removing symbolic links first.
Expand All @@ -129,8 +128,8 @@ void httpAdmin_destroy(http_admin_manager_t *admin) {
}
celix_arrayList_destroy(admin->aliasList);

celixThreadMutex_unlock(&(admin->admin_lock));
celixThreadMutex_destroy(&(admin->admin_lock));
celixThreadRwlock_unlock(&(admin->admin_lock));
celixThreadRwlock_destroy(&(admin->admin_lock));

free(admin->root);
free(admin);
Expand All @@ -147,11 +146,10 @@ void http_admin_addHttpService(void *handle, void *svc, const celix_properties_t
const char *uri = celix_properties_get(props, HTTP_ADMIN_URI, NULL);

if(uri != NULL) {
celixThreadMutex_lock(&(admin->admin_lock));
celix_auto(celix_rwlock_wlock_guard_t) lock = celixRwlockWlockGuard_init(&(admin->admin_lock));
if(!addServiceNode(&admin->http_svc_tree, uri, httpSvc)) {
printf("HTTP service with URI %s already exists!\n", uri);
}
celixThreadMutex_unlock(&(admin->admin_lock));
}
}

Expand All @@ -161,7 +159,7 @@ void http_admin_removeHttpService(void *handle, void *svc CELIX_UNUSED, const ce
const char *uri = celix_properties_get(props, HTTP_ADMIN_URI, NULL);

if(uri != NULL) {
celixThreadMutex_lock(&(admin->admin_lock));
celix_auto(celix_rwlock_wlock_guard_t) lock = celixRwlockWlockGuard_init(&(admin->admin_lock));
service_tree_node_t *node = NULL;

node = findServiceNodeInTree(&admin->http_svc_tree, uri);
Expand All @@ -171,8 +169,6 @@ void http_admin_removeHttpService(void *handle, void *svc CELIX_UNUSED, const ce
} else {
printf("Couldn't remove HTTP service with URI: %s, it doesn't exist\n", uri);
}

celixThreadMutex_unlock(&(admin->admin_lock));
}
}

Expand All @@ -189,6 +185,7 @@ int http_request_handle(struct mg_connection *connection) {
ret_status = 0; //... so return zero to let the civetweb server handle the request.
}
else {
celix_auto(celix_rwlock_rlock_guard_t) lock = celixRwlockRlockGuard_init(&(admin->admin_lock));
const char *req_uri = ri->request_uri;
node = findServiceNodeInTree(&admin->http_svc_tree, req_uri);

Expand Down Expand Up @@ -367,7 +364,7 @@ static void httpAdmin_updateInfoSvc(http_admin_manager_t *admin) {
}
fclose(stream);

celixThreadMutex_lock(&admin->admin_lock);
celix_auto(celix_rwlock_wlock_guard_t) lock = celixRwlockWlockGuard_init(&(admin->admin_lock));
celix_bundleContext_unregisterService(admin->context, admin->infoSvcId);

celix_properties_t *properties = celix_properties_create();
Expand All @@ -377,8 +374,6 @@ static void httpAdmin_updateInfoSvc(http_admin_manager_t *admin) {
}
admin->infoSvcId = celix_bundleContext_registerService(admin->context, &admin->infoSvc, HTTP_ADMIN_INFO_SERVICE_NAME, properties);

celixThreadMutex_unlock(&admin->admin_lock);

free(resources_urls);
}

Expand Down
20 changes: 11 additions & 9 deletions bundles/http_admin/http_admin/src/websocket_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct websocket_admin_manager {
struct mg_context *mg_ctx;

service_tree_t sock_svc_tree;
celix_thread_mutex_t admin_lock;
celix_thread_rwlock_t admin_lock;
};

websocket_admin_manager_t *websocketAdmin_create(celix_bundle_context_t *context, struct mg_context *svr_ctx) {
Expand All @@ -49,7 +49,7 @@ websocket_admin_manager_t *websocketAdmin_create(celix_bundle_context_t *context

admin->context = context;
admin->mg_ctx = svr_ctx;
status = celixThreadMutex_create(&admin->admin_lock, NULL);
status = celixThreadRwlock_create(&admin->admin_lock, NULL);

if(status != CELIX_SUCCESS) {
//No need to destroy other things
Expand All @@ -60,14 +60,14 @@ websocket_admin_manager_t *websocketAdmin_create(celix_bundle_context_t *context
}

void websocketAdmin_destroy(websocket_admin_manager_t *admin) {
celixThreadMutex_lock(&(admin->admin_lock));
celixThreadRwlock_writeLock(&(admin->admin_lock));

//Destroy tree with services
destroyServiceTree(&admin->sock_svc_tree);

celixThreadMutex_unlock(&(admin->admin_lock));
celixThreadRwlock_unlock(&(admin->admin_lock));

celixThreadMutex_destroy(&(admin->admin_lock));
celixThreadRwlock_destroy(&(admin->admin_lock));

free(admin);
}
Expand All @@ -79,14 +79,13 @@ void websocket_admin_addWebsocketService(void *handle, void *svc, const celix_pr
const char *uri = celix_properties_get(props, WEBSOCKET_ADMIN_URI, NULL);

if(uri != NULL) {
celixThreadMutex_lock(&(admin->admin_lock));
celix_auto(celix_rwlock_wlock_guard_t) lock = celixRwlockWlockGuard_init(&(admin->admin_lock));
if(addServiceNode(&admin->sock_svc_tree, uri, websockSvc)) {
mg_set_websocket_handler(admin->mg_ctx, uri, websocket_connect_handler, websocket_ready_handler,
websocket_data_handler, websocket_close_handler, admin);
} else {
printf("Websocket service with URI %s already exists!\n", uri);
}
celixThreadMutex_unlock(&(admin->admin_lock));
}
}

Expand All @@ -96,7 +95,7 @@ void websocket_admin_removeWebsocketService(void *handle, void *svc CELIX_UNUSED
const char *uri = celix_properties_get(props, WEBSOCKET_ADMIN_URI, NULL);

if(uri != NULL) {
celixThreadMutex_lock(&(admin->admin_lock));
celix_auto(celix_rwlock_wlock_guard_t) lock = celixRwlockWlockGuard_init(&(admin->admin_lock));
service_tree_node_t *node = NULL;

node = findServiceNodeInTree(&admin->sock_svc_tree, uri);
Expand All @@ -107,7 +106,6 @@ void websocket_admin_removeWebsocketService(void *handle, void *svc CELIX_UNUSED
printf("Couldn't remove websocket service with URI: %s, it doesn't exist\n", uri);
}

celixThreadMutex_unlock(&(admin->admin_lock));
}
}

Expand All @@ -120,6 +118,7 @@ int websocket_connect_handler(const struct mg_connection *connection, void *hand
const char *req_uri = ri->request_uri;
service_tree_node_t *node = NULL;

celix_auto(celix_rwlock_rlock_guard_t) lock = celixRwlockRlockGuard_init(&(admin->admin_lock));
node = findServiceNodeInTree(&admin->sock_svc_tree, req_uri);

if(node != NULL) {
Expand Down Expand Up @@ -147,6 +146,7 @@ void websocket_ready_handler(struct mg_connection *connection, void *handle) {
const char *req_uri = ri->request_uri;
service_tree_node_t *node = NULL;

celix_auto(celix_rwlock_rlock_guard_t) lock = celixRwlockRlockGuard_init(&(admin->admin_lock));
node = findServiceNodeInTree(&admin->sock_svc_tree, req_uri);

if(node != NULL) {
Expand All @@ -169,6 +169,7 @@ int websocket_data_handler(struct mg_connection *connection, int op_code, char *
const char *req_uri = ri->request_uri;
service_tree_node_t *node = NULL;

celix_auto(celix_rwlock_rlock_guard_t) lock = celixRwlockRlockGuard_init(&(admin->admin_lock));
node = findServiceNodeInTree(&admin->sock_svc_tree, req_uri);

if(node != NULL) {
Expand All @@ -192,6 +193,7 @@ void websocket_close_handler(const struct mg_connection *connection, void *handl
const char *req_uri = ri->request_uri;
service_tree_node_t *node = NULL;

celix_auto(celix_rwlock_rlock_guard_t) lock = celixRwlockRlockGuard_init(&(admin->admin_lock));
node = findServiceNodeInTree(&admin->sock_svc_tree, req_uri);

if(node != NULL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ celix_status_t celix_bundleActivator_start(void * userData, celix_bundle_context
int rc = asprintf(&scope, "(&(%s=*)(%s=%s))", CELIX_FRAMEWORK_SERVICE_NAME, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
status = rc < 0 ? CELIX_ENOMEM : CELIX_SUCCESS;

celix_properties_t *props = NULL;
celix_autoptr(celix_properties_t) props = NULL;
if (status == CELIX_SUCCESS) {
celix_logHelper_debug(activator->loghelper, "using scope %s.", scope);

Expand All @@ -131,16 +131,14 @@ celix_status_t celix_bundleActivator_start(void * userData, celix_bundle_context
endpointListener->endpointAdded = discovery_endpointAdded;
endpointListener->endpointRemoved = discovery_endpointRemoved;

status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);
status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener,
celix_steal_ptr(props), &activator->endpointListenerService);

if (status == CELIX_SUCCESS) {
activator->endpointListener = endpointListener;
}
}
} else {
celix_properties_destroy(props);
}

}
// We can release the scope, as celix_properties_set makes a copy of the key & value...
free(scope);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ static void* importRegistration_getService(void *handle, const celix_bundle_t *r
void importRegistration_ungetService(void *handle, const celix_bundle_t *requestingBundle, const celix_properties_t *svcProperties) {
import_registration_t* import = handle;
assert(import != NULL);
assert(import->proxies != NULL);
pthread_mutex_lock(&import->proxiesMutex);
assert(import->proxies != NULL);
struct service_proxy *proxy = hashMap_get(import->proxies, requestingBundle);
if (proxy != NULL) {
proxy->count -= 1;
Expand Down
2 changes: 2 additions & 0 deletions examples/celix-examples/dm_example/phase2a/src/phase2a_cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ static void *phase2a_thread(void *data) {
}

int phase2a_getData(phase2a_cmp_t *cmp, double *data) {
celixThreadMutex_lock(&cmp->mutex);
*data = cmp->currentValue;
celixThreadMutex_unlock(&cmp->mutex);
return 0;
}
2 changes: 2 additions & 0 deletions examples/celix-examples/dm_example/phase2b/src/phase2b_cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ static void *phase2b_thread(void *data) {
}

int phase2b_getData(phase2b_cmp_t *cmp, double *data) {
celixThreadMutex_lock(&cmp->mutex);
*data = cmp->currentValue;
celixThreadMutex_unlock(&cmp->mutex);
return 0;
}
2 changes: 2 additions & 0 deletions libs/dfi/gtest/descriptors/example4.descriptor
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ version=1.0.0
:types
:methods
getName(V)t=getName(#am=handle;P#am=out;*t)N
setName=setName(#am=handle;Pt)N
setConstName=setConstName(#am=handle;P#const=true;t)N
9 changes: 9 additions & 0 deletions libs/dfi/gtest/descriptors/example6.descriptor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:header
type=interface
name=example6
version=1.0.0
:annotations
:types
CptData={Dt[D#v1=1;#v2=2;E d t s e}
:methods
compatibility=cpt(#am=handle;PLCptData;#am=out;*LCptData;)N
9 changes: 9 additions & 0 deletions libs/dfi/gtest/descriptors/invalids/invalidHeader.descriptor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:header
type=interface
name=
version=1.0.0
:annotations
:types
item={DD a b}
:methods
example1=items(#am=handle;P#am=out;**[Litem;)N
6 changes: 6 additions & 0 deletions libs/dfi/gtest/src/dyn_interface_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ extern "C" {
ASSERT_EQ(1, status); //Test fails because of a space at the end of the name
fclose(desc); desc=NULL;

/* Invalid header */
desc = fopen("descriptors/invalids/invalidHeader.descriptor", "r");
assert(desc != NULL);
status = dynInterface_parse(desc, &dynIntf);
ASSERT_EQ(1, status); //Test fails because of missing name value
fclose(desc); desc=NULL;

/* Header without Version */
desc = fopen("descriptors/invalids/noVersion.descriptor", "r");
Expand Down
49 changes: 49 additions & 0 deletions libs/dfi/gtest/src/dyn_type_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C" {

#include "dyn_common.h"
#include "dyn_type.h"
#include "celix_err.h"

static void stdLog(void*, int level, const char *file, int line, const char *msg, ...) {
va_list ap;
Expand Down Expand Up @@ -323,4 +324,52 @@ TEST_F(DynTypeTests, NrOfEntriesTest) {
ASSERT_EQ(0, rc);
ASSERT_EQ(4, dynType_complex_nrOfEntries(type));
dynType_destroy(type);
}

TEST_F(DynTypeTests, ComplexHasEmptyName) {
dyn_type *type = NULL;
auto rc = dynType_parseWithStr(R"({II a })", nullptr, nullptr, &type);
ASSERT_EQ(1, rc);
celix_err_printErrors(stderr, nullptr, nullptr);
}

TEST_F(DynTypeTests, SchemaEndsWithoutNullTerminator) {
dyn_type *type = NULL;
//ends with '-'
auto rc = dynType_parseWithStr(R"({II a b}-)", nullptr, nullptr, &type);
ASSERT_EQ(3, rc);
celix_err_printErrors(stderr, nullptr, nullptr);
}

TEST_F(DynTypeTests, MetaInfoMissingValue) {
dyn_type *type = NULL;
auto rc = dynType_parseWithStr(R"(#testMetaInfo=)", nullptr, nullptr, &type);
ASSERT_EQ(1, rc);
celix_err_printErrors(stderr, nullptr, nullptr);
}

TEST_F(DynTypeTests, ParseNestedTypeFailed) {
dyn_type *type = NULL;
//missing '='
auto rc = dynType_parseWithStr(R"(Ttype)", nullptr, nullptr, &type);
ASSERT_EQ(3, rc);
celix_err_printErrors(stderr, nullptr, nullptr);

//missing value
rc = dynType_parseWithStr(R"(Ttype=)", nullptr, nullptr, &type);
ASSERT_EQ(3, rc);
celix_err_printErrors(stderr, nullptr, nullptr);

//missing ';'
rc = dynType_parseWithStr(R"(Ttype={DD a b})", nullptr, nullptr, &type);
ASSERT_EQ(3, rc);
celix_err_printErrors(stderr, nullptr, nullptr);
}

TEST_F(DynTypeTests, ParseReferenceFailed) {
dyn_type *type = NULL;
//missing ';'
auto rc = dynType_parseWithStr(R"(Ttype={DD a b};ltype)", nullptr, nullptr, &type);
ASSERT_EQ(3, rc);
celix_err_printErrors(stderr, nullptr, nullptr);
}
Loading

0 comments on commit f55c848

Please sign in to comment.