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 16:10:10 UTC
[44/50] [abbrv] celix git commit: CELIX-269: Updated for shell
refactoring
CELIX-269: Updated for shell refactoring
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/04b68623
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/04b68623
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/04b68623
Branch: refs/heads/master
Commit: 04b686237ca75157a2f3039256cbe7c60d540478
Parents: 9af85ce
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Nov 3 10:37:51 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Nov 3 10:37:51 2015 +0100
----------------------------------------------------------------------
.../private/include/dm_shell_list_command.h | 7 ++--
.../private/src/dm_shell_activator.c | 31 ++++++++++++-----
.../private/src/dm_shell_list_command.c | 35 ++++----------------
examples/dm_example/deploy.cmake | 17 ++++++----
shell/CMakeLists.txt | 3 ++
shell/private/include/shell_private.h | 2 ++
shell/private/src/shell.c | 9 +++--
7 files changed, 54 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/dependency_manager/private/include/dm_shell_list_command.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_shell_list_command.h b/dependency_manager/private/include/dm_shell_list_command.h
index bbccdc1..01c5065 100644
--- a/dependency_manager/private/include/dm_shell_list_command.h
+++ b/dependency_manager/private/include/dm_shell_list_command.h
@@ -26,9 +26,6 @@
#include <stdlib.h>
#include <string.h>
-#include "command_impl.h"
+#include "command.h"
-char * dmListCommand_getName(command_pt command);
-char * dmListCommand_getUsage(command_pt command);
-char * dmListCommand_getShortDescription(command_pt command);
-void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *));
\ No newline at end of file
+void dmListCommand_execute(bundle_context_pt context, char * line, FILE *out, FILE *err);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/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 4adfd0a..178b460 100644
--- a/dependency_manager/private/src/dm_shell_activator.c
+++ b/dependency_manager/private/src/dm_shell_activator.c
@@ -32,7 +32,7 @@
struct bundle_instance {
service_registration_pt reg;
- command_pt dmListCmd;
+ command_service_pt dmCommand;
};
typedef struct bundle_instance * bundle_instance_pt;
@@ -66,13 +66,24 @@ 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));
- commandService->getName = dmListCommand_getName;
- commandService->command = context;
- commandService->executeCommand = dmListCommand_execute;
- commandService->getShortDescription = dmListCommand_getShortDescription;
- commandService->getUsage = dmListCommand_getUsage;
+ if (commandService != NULL) {
+ commandService->handle = context;
+ commandService->executeCommand = dmListCommand_execute;
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, commandService, NULL, &bi->reg);
+ properties_pt props = properties_create();
+ properties_set(props, OSGI_SHELL_COMMAND_NAME, "dm");
+ properties_set(props, OSGI_SHELL_COMMAND_USAGE, "dm");
+ properties_set(props, OSGI_SHELL_COMMAND_DESCRIPTION,
+ "Gives an overview of the component managemend by a dependency manager.");
+
+ bi->dmCommand = commandService;
+
+ status = bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, commandService, props,
+ &bi->reg);
+ } else {
+ status = CELIX_ENOMEM;
+ free(commandService);
+ }
return status;
}
@@ -84,7 +95,11 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context)
}
celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- free(userData);
+ bundle_instance_pt bi = (bundle_instance_pt) userData;
+ if (bi != NULL) {
+ free(bi->dmCommand);
+ }
+ free(bi);
return CELIX_SUCCESS;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/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 1855664..fd7c5d9 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -28,7 +28,6 @@
#include <dm_dependency_manager.h>
#include "dm_info.h"
#include "service_reference.h"
-#include "command_impl.h"
#include "array_list.h"
#include "bundle_context.h"
#include "bundle.h"
@@ -40,23 +39,9 @@ static const char * const WARNING_COLOR = "\033[93m";
static const char * const NOK_COLOR = "\033[91m";
static const char * const END_COLOR = "\033[m";
-char * dmListCommand_getName(command_pt command) {
- return "dm";
-}
-
-char * dmListCommand_getUsage(command_pt command) {
- return "dm [overview|notavail]";
-}
-
-char * dmListCommand_getShortDescription(command_pt command) {
- 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];
+void dmListCommand_execute(bundle_context_pt context, char * line, FILE *out, FILE *err) {
array_list_pt servRefs = NULL;
int i;
- bundle_context_pt context = (void *)command;
bundleContext_getServiceReferences(context, DM_INFO_SERVICE_NAME ,NULL, &servRefs);
char *term = getenv("TERM");
bool colors = false;
@@ -81,22 +66,18 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
startColors = compInfo->active ? OK_COLOR : NOK_COLOR;
endColors = END_COLOR;
}
- 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);
+ fprintf(out, "Component: Name=%s\n|- ID=%s, %sActive=%s%s, State=%s\n", compInfo->name, compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state);
int interfCnt;
- sprintf(outString, "|- Interfaces (%d):\n", arrayList_size(compInfo->interfaces));
- out(outString);
+ fprintf(out, "|- Interfaces (%d):\n", arrayList_size(compInfo->interfaces));
for(interfCnt = 0 ;interfCnt < arrayList_size(compInfo->interfaces); interfCnt++) {
char * interface;
interface = arrayList_get(compInfo->interfaces, interfCnt);
- sprintf(outString, " |- Interface: %s\n", interface);
- out(outString);
+ fprintf(out, " |- Interface: %s\n", interface);
}
int depCnt;
- sprintf(outString, "|- Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
- out(outString);
+ fprintf(out, "|- Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
for(depCnt = 0 ;depCnt < arrayList_size(compInfo->dependency_list); depCnt++) {
dm_service_dependency_info_pt dependency;
dependency = arrayList_get(compInfo->dependency_list, depCnt);
@@ -111,17 +92,15 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
endColors = END_COLOR;
}
- sprintf(outString, " |- Dependency: %sAvailable = %s%s, Required = %s, Filter = %s\n",
+ fprintf(out, " |- Dependency: %sAvailable = %s%s, Required = %s, Filter = %s\n",
startColors,
dependency->available ? "true " : "false" ,
endColors,
dependency->required ? "true " : "false",
dependency->filter
);
- out(outString);
}
- sprintf(outString, "\n");
- out(outString);
+ fprintf(out, "\n");
infoServ->destroyInfo(infoServ->handle, info);
}
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/examples/dm_example/deploy.cmake
----------------------------------------------------------------------
diff --git a/examples/dm_example/deploy.cmake b/examples/dm_example/deploy.cmake
index 47072f4..1def6fc 100644
--- a/examples/dm_example/deploy.cmake
+++ b/examples/dm_example/deploy.cmake
@@ -17,13 +17,16 @@
if (BUILD_EXAMPLES AND BUILD_DEPENDENCY_MANAGER AND BUILD_SHELL AND BUILD_SHELL_TUI)
deploy("dm_example"
BUNDLES
- phase1
- phase2a
- phase2b
- phase3
- shell
- shell_tui
- dm_shell
+ phase1
+ phase2a
+ phase2b
+ phase3
+ shell
+ shell_tui
+ dm_shell
+ PROPERTIES
+ LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+
)
endif ()
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt
index 32aa08f..235f348 100644
--- a/shell/CMakeLists.txt
+++ b/shell/CMakeLists.txt
@@ -35,6 +35,9 @@ if (SHELL)
private/src/log_command
private/src/inspect_command
private/src/help_command
+
+ ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+
)
install_bundle(shell
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/shell/private/include/shell_private.h
----------------------------------------------------------------------
diff --git a/shell/private/include/shell_private.h b/shell/private/include/shell_private.h
index 092f6e3..c3a3386 100644
--- a/shell/private/include/shell_private.h
+++ b/shell/private/include/shell_private.h
@@ -31,11 +31,13 @@
#include "shell.h"
#include "hash_map.h"
#include "command.h"
+#include "log_helper.h"
struct shell {
bundle_context_pt bundle_context_ptr;
hash_map_pt command_reference_map_ptr;
hash_map_pt command_name_map_ptr;
+ log_helper_pt logHelper;
};
celix_status_t shell_create(bundle_context_pt context_ptr, shell_service_pt *shell_service_ptr);
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/shell/private/src/shell.c
----------------------------------------------------------------------
diff --git a/shell/private/src/shell.c b/shell/private/src/shell.c
index 8a37e88..d4fe9cc 100644
--- a/shell/private/src/shell.c
+++ b/shell/private/src/shell.c
@@ -25,6 +25,7 @@
*/
#include <stdlib.h>
#include <string.h>
+#include <log_helper.h>
#include "celix_errno.h"
@@ -67,6 +68,8 @@ celix_status_t shell_create(bundle_context_pt context_ptr, shell_service_pt *she
(*shell_service_ptr)->getCommandUsage = shell_getCommandUsage;
(*shell_service_ptr)->getCommandReference = shell_getCommandReference;
(*shell_service_ptr)->executeCommand = shell_executeCommand;
+
+ status = logHelper_create(context_ptr, &(*shell_service_ptr)->shell->logHelper);
}
if (status != CELIX_SUCCESS) {
@@ -120,6 +123,7 @@ celix_status_t shell_addCommand(shell_pt shell_ptr, service_reference_pt referen
if (status == CELIX_SUCCESS) {
status = serviceReference_getProperty(reference_ptr, "command.name", &name_str);
if (!name_str) {
+ logHelper_log(shell_ptr->logHelper, OSGI_LOGSERVICE_ERROR, "Command service must contain a 'command.name' property!");
status = CELIX_BUNDLE_EXCEPTION;
}
}
@@ -131,8 +135,9 @@ celix_status_t shell_addCommand(shell_pt shell_ptr, service_reference_pt referen
if (status != CELIX_SUCCESS) {
shell_removeCommand(shell_ptr, reference_ptr);
- fprintf(stderr, "Could not add Command. TODO\n");
- //TODO log to log service
+ char err[32];
+ celix_strerror(status, err, 32);
+ logHelper_log(shell_ptr->logHelper, OSGI_LOGSERVICE_ERROR, "Could not add command, got error %s\n", err);
}
return status;