celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erjanalt...@apache.org
Subject celix git commit: Added shell command to inspect internal state of ZMQ PS-admin
Date Tue, 06 Feb 2018 20:54:07 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 008b4f103 -> ea782bd38


Added shell command to inspect internal state of ZMQ PS-admin


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/ea782bd3
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/ea782bd3
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/ea782bd3

Branch: refs/heads/develop
Commit: ea782bd38a5a009c8e07a5f97ac6d841d7dac8ae
Parents: 008b4f1
Author: Erjan Altena <erjanaltena@gmail.com>
Authored: Tue Feb 6 21:53:48 2018 +0100
Committer: Erjan Altena <erjanaltena@gmail.com>
Committed: Tue Feb 6 21:53:48 2018 +0100

----------------------------------------------------------------------
 pubsub/pubsub_admin_zmq/CMakeLists.txt          |  4 +-
 pubsub/pubsub_admin_zmq/src/psa_activator.c     | 48 ++++++++++++++++++--
 pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h |  4 ++
 3 files changed, 51 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/ea782bd3/pubsub/pubsub_admin_zmq/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/CMakeLists.txt b/pubsub/pubsub_admin_zmq/CMakeLists.txt
index 6b3ecfd..ddc17eb 100644
--- a/pubsub/pubsub_admin_zmq/CMakeLists.txt
+++ b/pubsub/pubsub_admin_zmq/CMakeLists.txt
@@ -54,7 +54,7 @@ if (BUILD_PUBSUB_PSA_ZMQ)
 		src
 	)
 
-        install_celix_bundle(celix_pubsub_admin_zmq EXPORT celix COMPONENT pubsub)
-
+	install_celix_bundle(celix_pubsub_admin_zmq EXPORT celix COMPONENT pubsub)
+	target_link_libraries(celix_pubsub_admin_zmq PRIVATE Celix::shell_api)
 	add_library(Celix::pubsub_admin_zmq ALIAS celix_pubsub_admin_zmq)
 endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/ea782bd3/pubsub/pubsub_admin_zmq/src/psa_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/psa_activator.c b/pubsub/pubsub_admin_zmq/src/psa_activator.c
index fd07310..73c45fa 100644
--- a/pubsub/pubsub_admin_zmq/src/psa_activator.c
+++ b/pubsub/pubsub_admin_zmq/src/psa_activator.c
@@ -27,7 +27,6 @@
 #include <stdlib.h>
 
 #include "bundle_activator.h"
-#include "service_registration.h"
 #include "service_tracker.h"
 
 #include "pubsub_admin_impl.h"
@@ -40,6 +39,43 @@ struct activator {
 	service_tracker_pt serializerTracker;
 };
 
+
+static celix_status_t shellCommand(void *handle, char * commandLine, FILE *outStream, FILE
*errorStream) {
+    struct activator *act= (struct activator*)handle;
+    if (act->admin->externalPublications && !hashMap_isEmpty(act->admin->externalPublications))
{
+        fprintf(outStream, "External Publications:\n");
+        for(hash_map_iterator_t iter = hashMapIterator_construct(act->admin->externalPublications);
hashMapIterator_hasNext(&iter);) {
+            const char* key = (const char*)hashMapIterator_nextKey(&iter);
+            fprintf(outStream, "    %s\n", key);
+        }
+    }
+    if (act->admin->localPublications && !hashMap_isEmpty(act->admin->localPublications))
{
+        fprintf(outStream, "Local Publications:\n");
+        for (hash_map_iterator_t iter = hashMapIterator_construct(
+                act->admin->localPublications); hashMapIterator_hasNext(&iter);)
{
+            const char *key = (const char *) hashMapIterator_nextKey(&iter);
+            fprintf(outStream, "    %s\n", key);
+        }
+    }
+    if (act->admin->subscriptions && !hashMap_isEmpty(act->admin->subscriptions))
{
+        fprintf(outStream, "Active Subscriptions:\n");
+        for (hash_map_iterator_t iter = hashMapIterator_construct(
+                act->admin->subscriptions); hashMapIterator_hasNext(&iter);) {
+            const char *key = (const char *) hashMapIterator_nextKey(&iter);
+            fprintf(outStream, "    %s\n", key);
+        }
+    }
+    if (act->admin->pendingSubscriptions && !hashMap_isEmpty(act->admin->pendingSubscriptions))
{
+        fprintf(outStream, "Pending Subscriptions:\n");
+        for (hash_map_iterator_t iter = hashMapIterator_construct(
+                act->admin->pendingSubscriptions); hashMapIterator_hasNext(&iter);)
{
+            const char *key = (const char *) hashMapIterator_nextKey(&iter);
+            fprintf(outStream, "    %s\n", key);
+        }
+    }
+    return CELIX_SUCCESS;
+}
+
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator;
@@ -73,7 +109,13 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void
**userData
 			}
 		}
 	}
-
+    properties_pt shellProps = properties_create();
+    properties_set(shellProps, OSGI_SHELL_COMMAND_NAME, "psa_zmq_info");
+    properties_set(shellProps, OSGI_SHELL_COMMAND_USAGE, "psa_zmq_info");
+    properties_set(shellProps, OSGI_SHELL_COMMAND_DESCRIPTION, "psa_zmq_info: Overview of
PubSub ZMQ Admin");
+    activator->admin->shellCmdService.handle = activator;
+    activator->admin->shellCmdService.executeCommand = shellCommand;
+    bundleContext_registerService(context, OSGI_SHELL_COMMAND_SERVICE_NAME, &activator->admin->shellCmdService,
shellProps, &activator->admin->shellCmdReg);
 	return status;
 }
 
@@ -133,7 +175,7 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt
contex
 	serviceTracker_destroy(activator->serializerTracker);
 	pubsubAdmin_destroy(activator->admin);
 	activator->admin = NULL;
-
+    serviceRegistration_unregister(activator->admin->shellCmdReg);
 	free(activator);
 
 	return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/ea782bd3/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h b/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h
index 03e8556..040a0d3 100644
--- a/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h
+++ b/pubsub/pubsub_admin_zmq/src/pubsub_admin_impl.h
@@ -40,6 +40,7 @@
 #include "pubsub_admin.h"
 #include "pubsub_admin_match.h"
 #include "log_helper.h"
+#include "command.h"
 
 #define PSA_ZMQ_BASE_PORT "PSA_ZMQ_BASE_PORT"
 #define PSA_ZMQ_MAX_PORT "PSA_ZMQ_MAX_PORT"
@@ -87,6 +88,9 @@ struct pubsub_admin {
 
     unsigned int basePort;
     unsigned int maxPort;
+
+	command_service_t shellCmdService;
+	service_registration_pt  shellCmdReg;
 };
 
 celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt *admin);


Mime
View raw message