celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [5/5] celix git commit: CELIX-210: Some refactoring to move the dm_info service as part of the dep man component. Also added colors for the dm shell command, to easily stop issues.
Date Wed, 21 Oct 2015 15:08:36 GMT
CELIX-210: Some refactoring to move the dm_info service as part of the dep man component. Also
added colors for the dm shell command, to easily stop issues.


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

Branch: refs/heads/feature/CELIX-269_depman
Commit: 664845cac42f48a83e865a5c8bb87c160b8dec8b
Parents: 01c1968
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Wed Oct 21 17:06:54 2015 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Wed Oct 21 17:06:54 2015 +0200

----------------------------------------------------------------------
 dependency_manager/CMakeLists.txt               |  3 +-
 .../private/include/dm_component_impl.h         |  3 +-
 .../private/include/dm_server_impl.h            | 36 --------
 .../include/dm_service_dependency_impl.h        |  1 +
 .../private/src/dm_activator_base.c             | 28 +++---
 .../private/src/dm_component_impl.c             | 65 ++++++++++++-
 .../private/src/dm_dependency_manager_impl.c    | 28 +++++-
 dependency_manager/private/src/dm_server.c      | 97 --------------------
 .../private/src/dm_service_dependency.c         | 34 +++++++
 .../private/src/dm_shell_activator.c            | 10 +-
 .../private/src/dm_shell_list_command.c         | 73 +++++++++------
 .../public/include/dm_component.h               | 17 +++-
 .../public/include/dm_dependency_manager.h      | 10 +-
 dependency_manager/public/include/dm_info.h     | 63 +++++++++++++
 dependency_manager/public/include/dm_server.h   | 60 ------------
 .../public/include/dm_service_dependency.h      | 10 +-
 .../private/src/dependency_activator.c          |  2 +-
 17 files changed, 282 insertions(+), 258 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt
index 931dd3c..e4aeca1 100644
--- a/dependency_manager/CMakeLists.txt
+++ b/dependency_manager/CMakeLists.txt
@@ -47,7 +47,6 @@ if (DEPENDENCY_MANAGER)
     	private/src/dm_service_dependency
     	private/src/dm_event
     	private/src/dm_dependency_manager_impl
-        private/src/dm_server
     )
 
    	include_directories("public/include")
@@ -62,7 +61,7 @@ if (DEPENDENCY_MANAGER)
             public/include/dm_component.h
             public/include/dm_dependency_manager.h
             public/include/dm_service_dependency.h
-            public/include/dm_server.h
+            public/include/dm_info.h
 		DESTINATION 
 			include/celix/dependency_manager
 		COMPONENT 

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/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 ad742b8..3e86d62 100644
--- a/dependency_manager/private/include/dm_component_impl.h
+++ b/dependency_manager/private/include/dm_component_impl.h
@@ -50,9 +50,8 @@ typedef struct dm_interface_struct {
 } dm_interface;
 
 struct dm_component {
+    char *id;
     bundle_context_pt context;
-    dm_dependency_manager_pt manager;
-
     array_list_pt dm_interface;
 
     void *implementation;

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/include/dm_server_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_server_impl.h b/dependency_manager/private/include/dm_server_impl.h
deleted file mode 100644
index 117c561..0000000
--- a/dependency_manager/private/include/dm_server_impl.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements.  See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership.  The ASF licenses this file
- *to you under the Apache License, Version 2.0 (the
- *"License"); you may not use this file except in compliance
- *with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *Unless required by applicable law or agreed to in writing,
- *software distributed under the License is distributed on an
- *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- *specific language governing permissions and limitations
- *under the License.
- */
-/*
- * dm_server_impl.h
- *
- *  \date       16 Oct 2015
- *  \author     <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright  Apache License, Version 2.0
- */
-
-#include "dm_server.h"
-#include "dm_component.h"
-#include "dm_component_impl.h"
-#include "dm_dependency_manager_impl.h"
-
-celix_status_t dmServiceCreate(dm_server_pt * dmServ, bundle_context_pt context, struct dm_dependency_manager
*manager);
-celix_status_t dmServiceAddComponent(dm_server_pt dmServ, dm_component_pt component);
-celix_status_t dmServiceDestroy(dm_server_pt dmServ);
-celix_status_t dmService_getInfo(dm_server_pt dmServ, dm_info_pt info);
-

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/include/dm_service_dependency_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_service_dependency_impl.h b/dependency_manager/private/include/dm_service_dependency_impl.h
index 7f2a736..bde435f 100644
--- a/dependency_manager/private/include/dm_service_dependency_impl.h
+++ b/dependency_manager/private/include/dm_service_dependency_impl.h
@@ -34,6 +34,7 @@
 #include "service_tracker_customizer.h"
 
 #include "dm_service_dependency.h"
+#include "dm_component.h"
 
 struct dm_service_dependency {
 	dm_component_pt component;

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_activator_base.c b/dependency_manager/private/src/dm_activator_base.c
index 1c00ab1..2928c25 100644
--- a/dependency_manager/private/src/dm_activator_base.c
+++ b/dependency_manager/private/src/dm_activator_base.c
@@ -30,14 +30,13 @@
 
 #include "bundle_activator.h"
 #include "dm_activator_base.h"
-#include "dm_server.h"
-#include "dm_server_impl.h"
+#include "dm_info.h"
 
 struct dm_dependency_activator_base {
 	dm_dependency_manager_pt manager;
 	bundle_context_pt context;
-	dm_service_pt dmService;
 	service_registration_pt reg;
+	dm_info_service_pt info;
 	void* userData;
 };
 
@@ -47,14 +46,19 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void
**userData
 	celix_status_t status = CELIX_ENOMEM;
 
 	dependency_activator_base_pt dependency_activator = calloc(1, sizeof(struct dm_dependency_activator_base));
+	dm_info_service_pt serv = calloc(1, sizeof(*serv));
 
-	if (dependency_activator) {
+	if (dependency_activator != NULL && serv != NULL) {
 		dependency_activator->context = context;
 		dm_create(context, &dependency_activator->userData);
+		dependency_activator->info = serv;
 
-		(*userData) = dependency_activator;
+		(*userData) = dependency_activator;;
 
 		status = CELIX_SUCCESS;
+	} else {
+		free(dependency_activator);
+		free(serv);
 	}
 
 	return status;
@@ -71,10 +75,10 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt
context)
 	}
 
 	//Create the service
-	dependency_activator->dmService = calloc(sizeof(*(dependency_activator->dmService)),
1);
-	dependency_activator->dmService->getInfo = dmService_getInfo;
-	dmServiceCreate(&(dependency_activator->dmService->server), context, dependency_activator->manager);
-	bundleContext_registerService(context, DM_SERVICE_NAME, dependency_activator->dmService,
NULL, &(dependency_activator->reg));
+	dependency_activator->info->handle = dependency_activator->manager;
+	dependency_activator->info->getInfo = (void *)dependencyManager_getInfo;
+
+	bundleContext_registerService(context, DM_INFO_SERVICE_NAME, dependency_activator->info,
NULL, &(dependency_activator->reg));
 	return status;
 }
 
@@ -88,12 +92,9 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt
context _
 
 	// Remove the service
 	serviceRegistration_unregister(dependency_activator->reg);
-	dmServiceDestroy(dependency_activator->dmService->server);
-	free(dependency_activator->dmService);
 
 	dependency_activator->userData = NULL;
 	dependency_activator->manager = NULL;
-	dependency_activator->dmService = NULL;
 
 	return status;
 }
@@ -102,6 +103,9 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt
contex
 	celix_status_t status = CELIX_SUCCESS;
 	dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
 
+	if (dependency_activator != NULL) {
+		free(dependency_activator->info);
+	}
 	free(dependency_activator);
 
 	return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/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 801d426..9b8ee54 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -95,15 +95,17 @@ 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_dependency_manager_pt manager,
dm_component_pt *component) {
+celix_status_t component_create(bundle_context_pt context, 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);
         (*component)->context = context;
-        (*component)->manager = manager;
 
 	arrayList_create(&((*component)->dm_interface));
 
@@ -316,6 +318,26 @@ celix_status_t component_addInterface(dm_component_pt component, char
*serviceNa
     return status;
 }
 
+celix_status_t component_getInterfaces(dm_component_pt component, array_list_pt *out) {
+    celix_status_t status = CELIX_SUCCESS;
+    array_list_pt names = NULL;
+    arrayList_create(&names);
+    celixThreadMutex_lock(&component->mutex);
+    int size = arrayList_size(component->dm_interface);
+    int i;
+    for (i = 0; i < size; i += 1) {
+        dm_interface *interface = arrayList_get(component->dm_interface, i);
+        arrayList_add(names, strdup(interface->serviceName));
+    }
+    celixThreadMutex_unlock(&component->mutex);
+
+    if (status == CELIX_SUCCESS) {
+        *out = names;
+    }
+
+    return status;
+}
+
 celix_status_t component_handleEvent(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt event) {
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -1284,3 +1306,42 @@ celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t
currentThrea
 
     return status;
 }
+
+celix_status_t component_getComponentInfo(dm_component_pt component, dm_component_info_pt
*out) {
+    celix_status_t status = CELIX_SUCCESS;
+    int i;
+    int size;
+    dm_component_info_pt info = NULL;
+    info = calloc(1, sizeof(*info));
+
+
+    if (info != NULL) {
+        arrayList_create(&info->dependency_list);
+        component_getInterfaces(component, &info->interfaces);
+        info->active = component->active;
+        info->id = strdup(component->id);
+    } else {
+        status = CELIX_ENOMEM;
+    }
+
+
+    celixThreadMutex_lock(&component->mutex);
+    size = arrayList_size(component->dependencies);
+    for (i = 0; status == CELIX_SUCCESS && i < size; i += 1) {
+        dm_service_dependency_pt dep = arrayList_get(component->dependencies, i);
+        dm_service_dependency_info_pt depInfo= NULL;
+        status = serviceDependency_getServiceDependencyInfo(dep, &depInfo);
+        if (status == CELIX_SUCCESS) {
+            arrayList_add(info->dependency_list, depInfo);
+        }
+    }
+    celixThreadMutex_unlock(&component->mutex);
+
+    if (status == CELIX_SUCCESS) {
+        *out = info;
+    } else if (info != NULL) {
+        //TODO cleanup
+    }
+
+    return status;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_dependency_manager_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_dependency_manager_impl.c b/dependency_manager/private/src/dm_dependency_manager_impl.c
index 265ecf0..59ba677 100644
--- a/dependency_manager/private/src/dm_dependency_manager_impl.c
+++ b/dependency_manager/private/src/dm_dependency_manager_impl.c
@@ -28,6 +28,7 @@
 
 #include <pthread.h>
 #include <stdlib.h>
+#include <dm_dependency_manager.h>
 
 #include "bundle_context.h"
 #include "dm_component_impl.h"
@@ -78,10 +79,33 @@ celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager,
dm_com
 	return status;
 }
 
-celix_status_t dependencyManager_getComponents(dm_dependency_manager_pt manager, array_list_pt*
components) {
+celix_status_t dependencyManager_getInfo(dm_dependency_manager_pt manager, dm_dependency_manager_info_pt
*out) {
 	celix_status_t status = CELIX_SUCCESS;
+	int i;
+	int size;
+	dm_component_info_pt cmpInfo = NULL;
+	dm_dependency_manager_info_pt info = calloc(1, sizeof(*info));
+
+	celixThreadMutex_lock(&manager->mutex);
+
+	if (info != NULL) {
+		arrayList_create(&info->components);
+		size = arrayList_size(manager->components);
+		for (i = 0; i < size; i += 1) {
+			dm_component_pt cmp = arrayList_get(manager->components, i);
+			cmpInfo = NULL;
+			component_getComponentInfo(cmp, &cmpInfo);
+			arrayList_add(info->components, cmpInfo);
+		}
+	} else {
+		status = CELIX_ENOMEM;
+	}
+
+	celixThreadMutex_unlock(&manager->mutex);
 
-	(*components) = manager->components;
+	if (status == CELIX_SUCCESS) {
+		*out = info;
+	}
 
 	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_server.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_server.c b/dependency_manager/private/src/dm_server.c
deleted file mode 100644
index 2976cf6..0000000
--- a/dependency_manager/private/src/dm_server.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements.  See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership.  The ASF licenses this file
- *to you under the Apache License, Version 2.0 (the
- *"License"); you may not use this file except in compliance
- *with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *Unless required by applicable law or agreed to in writing,
- *software distributed under the License is distributed on an
- *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- *specific language governing permissions and limitations
- *under the License.
- */
-/*
- * dm_component_impl.c
- *
- *  \date       9 Oct 2014
- *  \author     <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright  Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-
-#include "array_list.h"
-
-#include "dm_server.h"
-#include "dm_component.h"
-#include "dm_component_impl.h"
-#include "dm_dependency_manager_impl.h"
-
-struct dm_server {
-    struct dm_dependency_manager *manager;
-};
-
-celix_status_t dmServiceCreate(dm_server_pt * dmServ, bundle_context_pt context, struct dm_dependency_manager
*manager) {
-    *dmServ = calloc(sizeof(struct dm_server), 1);
-    (*dmServ)->manager = manager;
-    return CELIX_SUCCESS;
-}
-
-celix_status_t dmServiceDestroy(dm_server_pt dmServ) {
-    free(dmServ);
-    return CELIX_SUCCESS;
-}
-
-celix_status_t dmService_getInfo(dm_server_pt dmServ, dm_info_pt info) {
-    int compCnt;
-    arrayList_create(&(info->components));
-    array_list_pt  compList = dmServ->manager->components;
-
-    for (compCnt = 0; compCnt < arrayList_size(compList); compCnt++) {
-        int i;
-        struct dm_component *component = arrayList_get(compList, compCnt);
-
-        // Create a component info
-        dm_component_info_pt compInfo = calloc(sizeof(*compInfo),1);
-        arrayList_create(&(compInfo->interface_list));
-        arrayList_create(&(compInfo->dependency_list));
-
-        //Fill in the fields of the component
-        char *outstr;
-        asprintf(&outstr, "%p",component->implementation);
-        compInfo->id = outstr;
-        compInfo->active = component->active;
-
-        array_list_pt interfaces = component->dm_interface;
-        array_list_pt dependencies = component->dependencies;
-
-        for(i = 0; i < arrayList_size(interfaces); i++) {
-            dm_interface * interface = arrayList_get(interfaces, i);
-            arrayList_add(compInfo->interface_list, strdup(interface->serviceName));
-        }
-
-        for(i = 0; i < arrayList_size(dependencies); i++) {
-            dm_service_dependency_pt  dependency = arrayList_get(dependencies, i);
-
-            dependency_info_pt depInfo = calloc(sizeof(*depInfo), 1);
-            depInfo->available = dependency->available;
-            depInfo->required = dependency->required;
-            if(dependency->tracked_filter) {
-                depInfo->interface  = strdup(dependency->tracked_filter);
-            } else {
-                depInfo->interface = strdup(dependency->tracked_service_name);
-            }
-            arrayList_add(compInfo->dependency_list, depInfo);
-        }
-
-        arrayList_add(info->components, compInfo);
-    }
-
-    return CELIX_SUCCESS;
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
index f89dc94..61daa07 100644
--- a/dependency_manager/private/src/dm_service_dependency.c
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -150,6 +150,11 @@ celix_status_t serviceDependency_setService(dm_service_dependency_pt
dependency,
 	return status;
 }
 
+celix_status_t serviceDependency_getFilter(dm_service_dependency_pt dependency, char **filter)
{
+	*filter = dependency->tracked_filter;
+	return CELIX_SUCCESS;
+}
+
 celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_set_fpt
set, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt
swap) {
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -624,3 +629,32 @@ celix_status_t serviceDependency_removedService(void *_ptr, service_reference_pt
 
 	return status;
 }
+
+celix_status_t serviceDependency_getServiceDependencyInfo(dm_service_dependency_pt dep, dm_service_dependency_info_pt
*out) {
+	celix_status_t status = CELIX_SUCCESS;
+	dm_service_dependency_info_pt  info = calloc(1, sizeof(*info));
+	if (info != NULL) {
+		celixThreadMutex_lock(&dep->lock);
+		info->available = dep->available;
+		info->filter = dep->tracked_filter != NULL ? strdup(dep->tracked_filter) : NULL;
+        if (info->filter == NULL) {
+            info->filter = dep->tracked_service_name != NULL ? strdup(dep->tracked_service_name)
: NULL;
+        }
+        info->required = dep->required;
+
+		array_list_pt refs = serviceTracker_getServiceReferences(dep->tracker);
+		if (refs != NULL) {
+			info->count = arrayList_size(refs);
+		}
+
+		celixThreadMutex_unlock(&dep->lock);
+	} else {
+		status = CELIX_ENOMEM;
+	}
+
+	if (status == CELIX_SUCCESS) {
+		*out = info;
+	}
+
+	return status;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_shell_activator.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_activator.c b/dependency_manager/private/src/dm_shell_activator.c
index 7cdd561..4adfd0a 100644
--- a/dependency_manager/private/src/dm_shell_activator.c
+++ b/dependency_manager/private/src/dm_shell_activator.c
@@ -66,16 +66,8 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt
context)
     bundle_instance_pt bi = (bundle_instance_pt) userData;
     command_service_pt commandService = calloc(1, sizeof(*commandService));
 
-    command_pt command = calloc(sizeof(*command),1);
-    command->executeCommand = dmListCommand_execute;
-    command->bundleContext = context;
-    command->handle = NULL;
-    command->name ="dm:list";
-    command->shortDescription ="not_used";
-    command->usage="not_used";
-
     commandService->getName             = dmListCommand_getName;
-    commandService->command             = command;
+    commandService->command             = context;
     commandService->executeCommand      = dmListCommand_execute;
     commandService->getShortDescription = dmListCommand_getShortDescription;
     commandService->getUsage            = dmListCommand_getUsage;

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/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 74460fa..3c2c43d 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -25,7 +25,8 @@
  */
 #include <stdlib.h>
 #include <string.h>
-#include "dm_server.h"
+#include <dm_dependency_manager.h>
+#include "dm_info.h"
 #include "service_reference.h"
 #include "command_impl.h"
 #include "array_list.h"
@@ -34,65 +35,83 @@
 #include "shell.h"
 
 
-void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char
*));
-
-
 char * dmListCommand_getName(command_pt command) {
-    return "dm:list";
+    return "dm";
 }
 
 char * dmListCommand_getUsage(command_pt command) {
-    return "dm:list";
+    return "dm [overview|notavail]";
 }
 
 char * dmListCommand_getShortDescription(command_pt command) {
-    return "Get an overview of the dependency-managed components with their dependencies.";
+    return "\t overview: Get an overview of the dependency-managed components with their
dependencies.\n\tnotavail: Get an overview of dependency-managed compononentes where required
depencies are not available. ";
 }
 
 void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char
*)) {
     char outString[256];
     array_list_pt servRefs = NULL;
     int i;
-    bundleContext_getServiceReferences(command->bundleContext, DM_SERVICE_NAME ,NULL,
&servRefs);
+    bundle_context_pt context = (void *)command;
+    bundleContext_getServiceReferences(context, DM_INFO_SERVICE_NAME ,NULL, &servRefs);
+    char *term = getenv("TERM");
+    bool colors = false;
+    if (strcmp("xterm-256color", term) == 0) {
+        colors = true;
+    }
 
     for(i = 0; i < arrayList_size(servRefs); i++) {
-        struct dm_info info;
-        dm_service_pt dmService = NULL;
+        dm_dependency_manager_info_pt info = NULL;
+        dm_info_service_pt infoServ = NULL;
         service_reference_pt servRef = NULL;
         servRef = arrayList_get(servRefs, i);
-        bundleContext_getService(command->bundleContext,  servRef, (void**)&dmService);
-        dmService->getInfo(dmService->server, &info);
+        bundleContext_getService(context,  servRef, (void**)&infoServ);
+        infoServ->getInfo(infoServ->handle, &info);
 
         int cmpCnt;
-        for (cmpCnt = 0; cmpCnt < arrayList_size(info.components); cmpCnt++) {
-            dm_component_info_pt compInfo = arrayList_get(info.components, cmpCnt);
-            sprintf(outString, "Component: ID=%s, Active=%s\n", compInfo->id, compInfo->active
? "true" : "false");
+        for (cmpCnt = 0; cmpCnt < arrayList_size(info->components); cmpCnt++) {
+            dm_component_info_pt compInfo = arrayList_get(info->components, cmpCnt);
+            char *startColors = "";
+            char *endColors = "";
+            if (colors) {
+                startColors = compInfo->active ? "\033[92m" : "\033[91m";
+                endColors = "\033[m";
+            }
+            sprintf(outString, "Component: ID=%s, %sActive=%s%s\n", compInfo->id, startColors,
compInfo->active ? "true " : "false", endColors);
             out(outString);
 
             int interfCnt;
-            sprintf(outString, "    Interfaces (%d):\n", arrayList_size(compInfo->interface_list));
+            sprintf(outString, "|- Interfaces (%d):\n", arrayList_size(compInfo->interfaces));
             out(outString);
-            for(interfCnt = 0 ;interfCnt < arrayList_size(compInfo->interface_list);
interfCnt++) {
+            for(interfCnt = 0 ;interfCnt < arrayList_size(compInfo->interfaces); interfCnt++)
{
                 char * interface;
-                interface = arrayList_get(compInfo->interface_list, interfCnt);
-                sprintf(outString, "        Interface: %s\n", interface);
+                interface = arrayList_get(compInfo->interfaces, interfCnt);
+                sprintf(outString, "   |- Interface: %s\n", interface);
                 out(outString);
                 free(interface);
             }
-            arrayList_destroy(compInfo->interface_list);
+            arrayList_destroy(compInfo->interfaces);
 
             int depCnt;
-            sprintf(outString, "    Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
+            sprintf(outString, "|- Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
             out(outString);
             for(depCnt = 0 ;depCnt < arrayList_size(compInfo->dependency_list); depCnt++)
{
-                dependency_info_pt dependency;
+                dm_service_dependency_info_pt dependency;
                 dependency = arrayList_get(compInfo->dependency_list, depCnt);
-                sprintf(outString, "         Dependency: Available = %s, Required = %s, Filter
= %s\n",
-                        dependency->available? "true" : "false" ,
-                        dependency->required ? "true" : "false",
-                        dependency->interface);
+                char *startColors = "";
+                char *endColors = "";
+                if (colors) {
+                    startColors = dependency->available ? "\033[92m" : "\033[91m";
+                    endColors = "\033[m";
+                }
+                sprintf(outString, "   |- Dependency: %sAvailable = %s%s, Required = %s,
Filter = %s\n",
+                        startColors,
+                        dependency->available ? "true " : "false" ,
+                        endColors,
+                        dependency->required ? "true " : "false",
+                        dependency->filter
+                );
                 out(outString);
-                free(dependency->interface);
+                free(dependency->filter);
                 free(dependency);
             }
             arrayList_destroy(compInfo->dependency_list);

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/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 6b875b2..ab8ac80 100644
--- a/dependency_manager/public/include/dm_component.h
+++ b/dependency_manager/public/include/dm_component.h
@@ -30,25 +30,36 @@
 #include <bundle_context.h>
 #include <celix_errno.h>
 
+#include "dm_service_dependency.h"
+
 typedef struct dm_component *dm_component_pt;
 
-#include "dm_dependency_manager.h"
-#include "dm_service_dependency.h"
+#include "dm_component.h"
 
 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_dependency_manager_pt manager,
dm_component_pt *component);
+celix_status_t component_create(bundle_context_pt context, 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);
 celix_status_t component_setImplementation(dm_component_pt component, void *implementation);
 
+/**
+ * Returns an arraylist of service names. The caller owns the arraylist and strings (char
*)
+ */
+celix_status_t component_getInterfaces(dm_component_pt component, array_list_pt *servicesNames);
+
 celix_status_t component_addServiceDependency(dm_component_pt component, ...);
 celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt
dependency);
 
 celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt
start, stop_fpt stop, deinit_fpt deinit);
 
+/**
+ * returns a dm_component_info_pt. Caller has ownership.
+ */
+celix_status_t component_getComponentInfo(dm_component_pt component, dm_component_info_pt
*info);
+
 #endif /* COMPONENT_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/public/include/dm_dependency_manager.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_dependency_manager.h b/dependency_manager/public/include/dm_dependency_manager.h
index 4311d3a..ab6e27f 100644
--- a/dependency_manager/public/include/dm_dependency_manager.h
+++ b/dependency_manager/public/include/dm_dependency_manager.h
@@ -30,16 +30,20 @@
 #include "bundle_context.h"
 #include "celix_errno.h"
 #include "array_list.h"
+#include "dm_info.h"
+#include "dm_component.h"
 
 typedef struct dm_dependency_manager *dm_dependency_manager_pt;
 
-#include "dm_component.h"
-
 celix_status_t dependencyManager_create(bundle_context_pt context, dm_dependency_manager_pt
*manager);
 celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager);
 
 celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component);
 celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt
component);
-celix_status_t dependencyManager_getComponents(dm_dependency_manager_pt manager, array_list_pt*
components);
+
+/**
+ * returns a dm_ of dm_dependency_manager_info. Caller has ownership.
+ */
+celix_status_t dependencyManager_getInfo(dm_dependency_manager_pt manager, dm_dependency_manager_info_pt
*info);
 
 #endif /* DM_DEPENDENCY_MANAGER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/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
new file mode 100644
index 0000000..f010387
--- /dev/null
+++ b/dependency_manager/public/include/dm_info.h
@@ -0,0 +1,63 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+/*
+ * dm_server.h
+ *
+ *  \date       15 Oct 2015
+ *  \author     <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright  Apache License, Version 2.0
+ */
+#ifndef CELIX_DM_INFO_SERVICE_H
+#define CELIX_DM_INFO_SERVICE_H
+
+#include <stdbool.h>
+#include "array_list.h"
+
+#define DM_INFO_SERVICE_NAME "dm_info"
+
+
+typedef struct dm_service_dependency_info {
+    char *filter;
+    bool available;
+    bool required;
+    size_t count;
+} * dm_service_dependency_info_pt;
+
+typedef struct dm_component_info {
+    char *id;
+    bool active;
+    array_list_pt interfaces;   // type char*
+    array_list_pt dependency_list;  // type interface_info_pt
+} * dm_component_info_pt;
+
+typedef struct dm_dependency_manager_info {
+    array_list_pt  components;      // type dm_component_info
+} * dm_dependency_manager_info_pt;
+
+struct dm_info_service {
+    void *handle;
+
+    /*Note: dm_caller has the ownership of the result.*/
+    celix_status_t (*getInfo)(void *handle, dm_dependency_manager_info_pt *info);
+};
+
+typedef struct dm_info_service * dm_info_service_pt;
+
+
+#endif //CELIX_DM_INFO_SERVICE_H

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/public/include/dm_server.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_server.h b/dependency_manager/public/include/dm_server.h
deleted file mode 100644
index 15c87d5..0000000
--- a/dependency_manager/public/include/dm_server.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements.  See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership.  The ASF licenses this file
- *to you under the Apache License, Version 2.0 (the
- *"License"); you may not use this file except in compliance
- *with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *Unless required by applicable law or agreed to in writing,
- *software distributed under the License is distributed on an
- *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- *specific language governing permissions and limitations
- *under the License.
- */
-/*
- * dm_server.h
- *
- *  \date       15 Oct 2015
- *  \author     <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright  Apache License, Version 2.0
- */
-#ifndef CELIX_DM_SERVICE_H
-#define CELIX_DM_SERVICE_H
-
-#include "bundle_context.h"
-
-#define DM_SERVICE_NAME "dm_server"
-
-typedef struct dm_server * dm_server_pt;
-
-typedef struct dependency_info {
-    char *interface;
-    bool available;
-    bool required;
-} * dependency_info_pt;
-
-typedef struct dm_component_info {
-    char *id;
-    bool active;
-    array_list_pt interface_list;       // type char*
-    array_list_pt dependency_list;  // type interface_info_pt
-} * dm_component_info_pt;
-
-typedef struct dm_info {
-    array_list_pt  components;      // type dm_component_info
-} * dm_info_pt;
-
-struct dm_service {
-    dm_server_pt server;
-    celix_status_t (*getInfo)(dm_server_pt server, dm_info_pt info);
-};
-
-typedef struct dm_service * dm_service_pt;
-
-
-#endif //CELIX_DM_SERVICE_H

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_service_dependency.h b/dependency_manager/public/include/dm_service_dependency.h
index f267ab7..4a9c991 100644
--- a/dependency_manager/public/include/dm_service_dependency.h
+++ b/dependency_manager/public/include/dm_service_dependency.h
@@ -28,10 +28,10 @@
 #define DM_SERVICE_DEPENDENCY_H_
 
 #include "celix_errno.h"
+#include "dm_info.h"
 
-typedef struct dm_service_dependency *dm_service_dependency_pt;
 
-#include "dm_component.h"
+typedef struct dm_service_dependency *dm_service_dependency_pt;
 
 typedef celix_status_t (*service_set_fpt)(void *handle, void *service);
 typedef celix_status_t (*service_add_fpt)(void *handle, void *service);
@@ -50,8 +50,14 @@ celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_pt
 
 celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
 celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName,
char *filter);
+celix_status_t serviceDependency_getFilter(dm_service_dependency_pt dependency, char **filter);
 celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_set_fpt
set, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt
swap);
 celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt
dependency, service_set_with_ref_fpt set, service_add_with_ref_fpt add, service_change_with_ref_fpt
change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap);
 celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t
*service_lock, void **field);
 
+/**
+ * Return a service dependency info. The caller is the owner
+ */
+celix_status_t serviceDependency_getServiceDependencyInfo(dm_service_dependency_pt, dm_service_dependency_info_pt
*info);
+
 #endif /* DM_SERVICE_DEPENDENCY_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/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 5dd8d1e..51e22d6 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, manager, &service);
+	component_create(context, &service);
 	component_setImplementation(service, data);
 	component_setCallbacks(service, service_init, service_start, service_stop, service_deinit);
 


Mime
View raw message