xuzhenbao commented on code in PR #710:
URL: https://github.com/apache/celix/pull/710#discussion_r1442794202


##########
bundles/remote_services/discovery_zeroconf/src/discovery_zeroconf_activator.c:
##########
@@ -18,43 +18,116 @@
  */
 #include "discovery_zeroconf_announcer.h"
 #include "discovery_zeroconf_watcher.h"
+#include "endpoint_listener.h"
+#include "remote_constants.h"
+#include "remote_service_admin.h"
 #include "celix_log_helper.h"
 #include "celix_bundle_activator.h"
-#include "celix_types.h"
+#include "celix_dm_component.h"
+#include "celix_dm_service_dependency.h"
+#include "celix_constants.h"
 #include "celix_errno.h"
+#include <stdio.h>
+#include <assert.h>
 
 typedef struct discovery_zeroconf_activator {
     celix_log_helper_t *logHelper;
     discovery_zeroconf_announcer_t *announcer;
     discovery_zeroconf_watcher_t  *watcher;
+    endpoint_listener_t endpointListener;
 }discovery_zeroconf_activator_t;
 
 celix_status_t discoveryZeroconfActivator_start(discovery_zeroconf_activator_t 
*act, celix_bundle_context_t *ctx) {
     celix_status_t status = CELIX_SUCCESS;
-    celix_autoptr(celix_log_helper_t) logger = 
celix_logHelper_create(ctx,"celix_rsa_zeroconf_discovery");
+    const char *fwUuid = celix_bundleContext_getProperty(ctx, 
CELIX_FRAMEWORK_UUID, NULL);
+    if (fwUuid == NULL) {
+        return CELIX_BUNDLE_EXCEPTION;
+    }
+    celix_autoptr(celix_log_helper_t) logger = celix_logHelper_create(ctx, 
"celix_rsa_zeroconf_discovery");
     if (logger == NULL) {
         return CELIX_ENOMEM;
     }
-    celix_autoptr(discovery_zeroconf_announcer_t) announcer = NULL;
-    status = discoveryZeroconfAnnouncer_create(ctx, logger, &announcer);
+    //init announcer
+    celix_autoptr(celix_dm_component_t) announcerCmp = 
celix_dmComponent_create(ctx, "DZC_ANNOUNCER_CMP");
+    if (announcerCmp == NULL) {
+        return CELIX_ENOMEM;
+    }
+    status = discoveryZeroconfAnnouncer_create(ctx, logger, &act->announcer);
     if (status != CELIX_SUCCESS) {
         return status;
     }
-    celix_autoptr(discovery_zeroconf_watcher_t) watcher = NULL;
-    status = discoveryZeroconfWatcher_create(ctx, logger, &watcher);
+    celix_dmComponent_setImplementation(announcerCmp, act->announcer);
+    CELIX_DM_COMPONENT_SET_IMPLEMENTATION_DESTROY_FUNCTION(announcerCmp, 
discovery_zeroconf_announcer_t, discoveryZeroconfAnnouncer_destroy);
+    celix_properties_t *props = celix_properties_create();
+    if (props == NULL) {
+        return CELIX_ENOMEM;
+    }
+    char scope[256] = {0};
+    (void)snprintf(scope, sizeof(scope), "(&(%s=*)(%s=%s))", 
CELIX_FRAMEWORK_SERVICE_NAME,
+                    OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, fwUuid);
+    celix_properties_set(props, OSGI_ENDPOINT_LISTENER_SCOPE, scope);
+    celix_properties_set(props, "DISCOVERY", "true");//Only use to avoid the 
discovery calls to unnecessary endpoint listener service.Endpoint should be 
filtered by the scope.

Review Comment:
   > Is the "DISCOVERY" property added for additional performance optimization?
   
   yes, `ENDPOINT_LISTENER_SCOPE` is enough to ensure that the endpoint 
listener of discovery only sees local endpoint.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to