You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by rl...@apache.org on 2019/07/17 15:25:14 UTC
[celix] branch develop updated: Fixed scope in pubsub examples
This is an automated email from the ASF dual-hosted git repository.
rlenferink pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to refs/heads/develop by this push:
new 53428d9 Fixed scope in pubsub examples
53428d9 is described below
commit 53428d9d1112a1f3555b61b942a0c9f9f06258a8
Author: Roy Lenferink <le...@gmail.com>
AuthorDate: Wed Jul 17 08:15:07 2019 +0200
Fixed scope in pubsub examples
---
.../publisher/private/src/ps_pub_activator.c | 62 ++++++++++------------
.../subscriber/private/src/ps_sub_activator.c | 3 +-
2 files changed, 30 insertions(+), 35 deletions(-)
diff --git a/bundles/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c b/bundles/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
index b37a8e6..9b24e8d 100644
--- a/bundles/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
+++ b/bundles/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
@@ -27,46 +27,42 @@
#include "pubsub_publisher_private.h"
static const char * PUB_TOPICS[] = {
- "poi1",
- "poi2",
- NULL
+ "poi1",
+ "poi2",
+ NULL
};
-
struct publisherActivator {
- pubsub_sender_pt client;
- array_list_pt trackerList;//List<service_tracker_pt>
+ pubsub_sender_pt client;
+ array_list_pt trackerList;//List<service_tracker_pt>
};
static int pub_start(struct publisherActivator *act, celix_bundle_context_t *ctx) {
- const char *fwUUID = celix_bundleContext_getProperty(ctx,OSGI_FRAMEWORK_FRAMEWORK_UUID, NULL);
- if (fwUUID==NULL) {
- printf("PUBLISHER: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
+ const char *fwUUID = celix_bundleContext_getProperty(ctx,OSGI_FRAMEWORK_FRAMEWORK_UUID, NULL);
+ if (fwUUID==NULL) {
+ printf("PUBLISHER: Cannot retrieve fwUUID.\n");
+ return CELIX_INVALID_BUNDLE_CONTEXT;
+ }
- bundle_t *bnd = celix_bundleContext_getBundle(ctx);
- long bundleId = celix_bundle_getId(bnd);
+ bundle_t *bnd = celix_bundleContext_getBundle(ctx);
+ long bundleId = celix_bundle_getId(bnd);
- act->trackerList = celix_arrayList_create();
- act->client = publisher_create(act->trackerList, fwUUID, bundleId);
+ act->trackerList = celix_arrayList_create();
+ act->client = publisher_create(act->trackerList, fwUUID, bundleId);
- int i;
- char filter[128];
- for(i=0; PUB_TOPICS[i] != NULL; i++){
- const char* topic = PUB_TOPICS[i];
- memset(filter,0,128);
+ int i;
+ char filter[128];
+ for (i = 0; PUB_TOPICS[i] != NULL; i++) {
+ const char* topic = PUB_TOPICS[i];
+ memset(filter,0,128);
#ifdef USE_SCOPE
- char *scope;
- asprintf(&scope, "my_scope_%d", i);
- snprintf(filter, 128, "(&(&(%s=%s)(%s=%s))(%s=%s))",
- (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME,
- PUBSUB_PUBLISHER_TOPIC, topic,
- PUBLISHER_SCOPE, scope);
- free(scope);
+ char *scope;
+ asprintf(&scope, "my_scope_%d", i);
+ snprintf(filter, 128, "(%s=%s)(%s=%s)", PUBSUB_PUBLISHER_TOPIC, topic, PUBSUB_PUBLISHER_SCOPE, scope);
+ free(scope);
#else
- snprintf(filter, 128, "(%s=%s)", (char*) PUBSUB_PUBLISHER_TOPIC, topic);
+ snprintf(filter, 128, "(%s=%s)", (char*) PUBSUB_PUBLISHER_TOPIC, topic);
#endif
celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
opts.callbackHandle = act->client;
@@ -78,16 +74,16 @@ static int pub_start(struct publisherActivator *act, celix_bundle_context_t *ctx
long trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
celix_arrayList_addLong(act->trackerList,trackerId);
- }
+ }
- publisher_start(act->client);
+ publisher_start(act->client);
- return 0;
+ return 0;
}
static int pub_stop(struct publisherActivator *act, celix_bundle_context_t *ctx) {
- for (int i=0; i < arrayList_size(act->trackerList); i++) {
- long trkId = celix_arrayList_getLong(act->trackerList,i);
+ for (int i = 0; i < arrayList_size(act->trackerList); i++) {
+ long trkId = celix_arrayList_getLong(act->trackerList, i);
celix_bundleContext_stopTracker(ctx, trkId);
}
publisher_stop(act->client);
diff --git a/bundles/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c b/bundles/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
index 199a0bf..24ebf36 100644
--- a/bundles/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
+++ b/bundles/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
@@ -53,7 +53,6 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
struct subscriberActivator * act = (struct subscriberActivator *) userData;
-
pubsub_subscriber_pt subsvc = calloc(1,sizeof(*subsvc));
pubsub_receiver_pt sub = subscriber_create(SUB_NAME);
subsvc->handle = sub;
@@ -69,7 +68,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
#ifdef USE_SCOPE
char *scope;
asprintf(&scope, "my_scope_%d", i);
- celix_properties_set(props,SUBSCRIBER_SCOPE,scope);
+ celix_properties_set(props, PUBSUB_SUBSCRIBER_SCOPE, scope);
free(scope);
#endif
service_registration_pt reg = NULL;