You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/11/03 12:09:50 UTC

[13/21] celix git commit: CELIX-210: Added optional name for dm component. This should help in keeping an overview of the components. Note that in C we cannot use the runtime available classname for info purpose.

CELIX-210: Added optional name for dm component. This should help in keeping an overview of the components. Note that in C we cannot use the runtime available classname for info purpose.


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

Branch: refs/heads/develop
Commit: 224617488a2137935d7013b49cf46a77eb494ad2
Parents: f48fee1
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Oct 23 09:41:29 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Oct 23 09:41:29 2015 +0200

----------------------------------------------------------------------
 .../private/include/dm_component_impl.h              |  3 ++-
 dependency_manager/private/src/dm_component_impl.c   | 15 ++++++++++-----
 .../private/src/dm_shell_list_command.c              |  4 +++-
 dependency_manager/public/include/dm_component.h     |  5 ++++-
 dependency_manager/public/include/dm_info.h          |  3 ++-
 .../private/src/dependency_activator.c               |  2 +-
 6 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_component_impl.h b/dependency_manager/private/include/dm_component_impl.h
index 42857d2..4963b44 100644
--- a/dependency_manager/private/include/dm_component_impl.h
+++ b/dependency_manager/private/include/dm_component_impl.h
@@ -50,7 +50,8 @@ typedef struct dm_interface_struct {
 } dm_interface;
 
 struct dm_component {
-    char *id;
+    char id[DM_COMPONENT_MAX_ID_LENGTH];
+    char name[DM_COMPONENT_MAX_NAME_LENGTH];
     bundle_context_pt context;
     array_list_pt dm_interface;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 500d613..ec13933 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -95,16 +95,19 @@ static celix_status_t component_handleChanged(dm_component_pt component, dm_serv
 static celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
 static celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent);
 
-celix_status_t component_create(bundle_context_pt context, dm_component_pt *component) {
+celix_status_t component_create(bundle_context_pt context, const char *name, dm_component_pt *component) {
     celix_status_t status = CELIX_SUCCESS;
 
     *component = malloc(sizeof(**component));
     if (!*component) {
         status = CELIX_ENOMEM;
     } else {
-        char id[16];
-        snprintf(id, 16, "%p", *component);
-        (*component)->id = strdup(id);
+        snprintf((*component)->id, DM_COMPONENT_MAX_ID_LENGTH, "%p", *component);
+        if (name == NULL) {
+            snprintf((*component)->name, DM_COMPONENT_MAX_NAME_LENGTH, "%s", "n/a");
+        } else {
+            snprintf((*component)->name, DM_COMPONENT_MAX_NAME_LENGTH, "%s", name);
+        }
         (*component)->context = context;
 
 	arrayList_create(&((*component)->dm_interface));
@@ -1320,7 +1323,9 @@ celix_status_t component_getComponentInfo(dm_component_pt component, dm_componen
         arrayList_create(&info->dependency_list);
         component_getInterfaces(component, &info->interfaces);
         info->active = false;
-        info->id = strdup(component->id);
+        memcpy(info->id, component->id, DM_COMPONENT_MAX_ID_LENGTH);
+        memcpy(info->name, component->name, DM_COMPONENT_MAX_NAME_LENGTH);
+
         switch (component->state) {
             case DM_CMP_STATE_INACTIVE :
                 info->state = strdup("INACTIVE");

http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 030d909..4d08068 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -81,7 +81,7 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
                 startColors = compInfo->active ? OK_COLOR : NOK_COLOR;
                 endColors = END_COLOR;
             }
-            sprintf(outString, "Component: ID=%s, %sActive=%s%s, State=%s\n", compInfo->id, startColors, compInfo->active ?  "true " : "false", endColors, compInfo->state);
+            sprintf(outString, "Component: Name=%s\n|- ID=%s, %sActive=%s%s, State=%s\n", compInfo->name, compInfo->id, startColors, compInfo->active ?  "true " : "false", endColors, compInfo->state);
             out(outString);
 
             int interfCnt;
@@ -120,6 +120,8 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
                 );
                 out(outString);
             }
+            sprintf(outString, "\n");
+            out(outString);
 
             infoServ->destroyInfo(infoServ->handle, info);
         }

http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_component.h b/dependency_manager/public/include/dm_component.h
index c26cc05..12dbcca 100644
--- a/dependency_manager/public/include/dm_component.h
+++ b/dependency_manager/public/include/dm_component.h
@@ -36,12 +36,15 @@ typedef struct dm_component *dm_component_pt;
 
 #include "dm_component.h"
 
+#define DM_COMPONENT_MAX_ID_LENGTH 64
+#define DM_COMPONENT_MAX_NAME_LENGTH 128
+
 typedef celix_status_t (*init_fpt)(void *userData);
 typedef celix_status_t (*start_fpt)(void *userData);
 typedef celix_status_t (*stop_fpt)(void *userData);
 typedef celix_status_t (*deinit_fpt)(void *userData);
 
-celix_status_t component_create(bundle_context_pt context, dm_component_pt *component);
+celix_status_t component_create(bundle_context_pt context, const char *name, dm_component_pt *component);
 celix_status_t component_destroy(dm_component_pt *component);
 
 celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties);

http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/public/include/dm_info.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_info.h b/dependency_manager/public/include/dm_info.h
index 16ee0f8..dd9947c 100644
--- a/dependency_manager/public/include/dm_info.h
+++ b/dependency_manager/public/include/dm_info.h
@@ -40,7 +40,8 @@ typedef struct dm_service_dependency_info {
 } * dm_service_dependency_info_pt;
 
 typedef struct dm_component_info {
-    char *id;
+    char id[64];
+    char name[128];
     bool active;
     char * state;
     array_list_pt interfaces;   // type char*

http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
index 51e22d6..4e36321 100644
--- a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
+++ b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
@@ -54,7 +54,7 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
 
 	data->context = context;
 
-	component_create(context, &service);
+	component_create(context, "ExampleCmp", &service);
 	component_setImplementation(service, data);
 	component_setCallbacks(service, service_init, service_start, service_stop, service_deinit);