You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by bp...@apache.org on 2014/11/23 13:41:44 UTC
svn commit: r1641175 - in /celix/trunk/shell: CMakeLists.txt
private/include/shell_private.h private/src/activator.c private/src/shell.c
Author: bpetri
Date: Sun Nov 23 12:41:44 2014
New Revision: 1641175
URL: http://svn.apache.org/r1641175
Log:
CELIX-119: refactored shell bundled and removed apr
Added:
celix/trunk/shell/private/src/activator.c
Modified:
celix/trunk/shell/CMakeLists.txt
celix/trunk/shell/private/include/shell_private.h
celix/trunk/shell/private/src/shell.c
Modified: celix/trunk/shell/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/shell/CMakeLists.txt?rev=1641175&r1=1641174&r2=1641175&view=diff
==============================================================================
--- celix/trunk/shell/CMakeLists.txt (original)
+++ celix/trunk/shell/CMakeLists.txt Sun Nov 23 12:41:44 2014
@@ -24,7 +24,8 @@ if (SHELL)
bundle(shell SOURCES
public/src/command
-
+
+ private/src/activator
private/src/shell
private/src/ps_command
private/src/start_command
Modified: celix/trunk/shell/private/include/shell_private.h
URL: http://svn.apache.org/viewvc/celix/trunk/shell/private/include/shell_private.h?rev=1641175&r1=1641174&r2=1641175&view=diff
==============================================================================
--- celix/trunk/shell/private/include/shell_private.h (original)
+++ celix/trunk/shell/private/include/shell_private.h Sun Nov 23 12:41:44 2014
@@ -27,26 +27,26 @@
#ifndef SHELL_PRIVATE_H_
#define SHELL_PRIVATE_H_
-#include <apr_general.h>
-
+#include "bundle_context.h"
#include "shell.h"
#include "hash_map.h"
#include "command.h"
struct shell {
- apr_pool_t *pool;
bundle_context_pt bundleContext;
hash_map_pt commandReferenceMap;
hash_map_pt commandNameMap;
};
-shell_pt shell_create();
+celix_status_t shell_create(bundle_context_pt, shell_service_pt* shellService);
+celix_status_t shell_destroy(shell_service_pt* shellService);
+celix_status_t shell_addCommand(shell_pt shell, service_reference_pt reference);
+
+
char * shell_getCommandUsage(shell_pt shell, char * commandName);
char * shell_getCommandDescription(shell_pt shell, char * commandName);
service_reference_pt shell_getCommandReference(shell_pt shell, char * command);
void shell_executeCommand(shell_pt shell, char * commandLine, void (*out)(char *), void (*error)(char *));
-
-command_service_pt shell_getCommand(shell_pt shell, char * commandName);
-
+void shell_serviceChanged(service_listener_pt listener, service_event_pt event);
#endif /* SHELL_PRIVATE_H_ */
Added: celix/trunk/shell/private/src/activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/shell/private/src/activator.c?rev=1641175&view=auto
==============================================================================
--- celix/trunk/shell/private/src/activator.c (added)
+++ celix/trunk/shell/private/src/activator.c Sun Nov 23 12:41:44 2014
@@ -0,0 +1,273 @@
+/**
+ *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.
+ */
+/*
+ * shell.c
+ *
+ * \date Aug 13, 2010
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "shell_private.h"
+#include "bundle_activator.h"
+#include "command_impl.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+#include "service_listener.h"
+
+#include "ps_command.h"
+#include "start_command.h"
+#include "stop_command.h"
+#include "install_command.h"
+#include "uninstall_command.h"
+#include "update_command.h"
+#include "log_command.h"
+#include "inspect_command.h"
+#include "help_command.h"
+
+#include "utils.h"
+
+struct bundle_instance {
+ shell_service_pt shellService;
+ service_registration_pt registration;
+ service_listener_pt listener;
+
+ service_registration_pt psCommand;
+ command_pt psCmd;
+ command_service_pt psCmdSrv;
+
+ service_registration_pt startCommand;
+ command_pt startCmd;
+ command_service_pt startCmdSrv;
+
+ service_registration_pt stopCommand;
+ command_pt stopCmd;
+ command_service_pt stopCmdSrv;
+
+ service_registration_pt installCommand;
+ command_pt installCmd;
+ command_service_pt installCmdSrv;
+
+ service_registration_pt uninstallCommand;
+ command_pt uninstallCmd;
+ command_service_pt uninstallCmdSrv;
+
+ service_registration_pt updateCommand;
+ command_pt updateCmd;
+ command_service_pt updateCmdSrv;
+
+ service_registration_pt logCommand;
+ command_pt logCmd;
+ command_service_pt logCmdSrv;
+
+ service_registration_pt inspectCommand;
+ command_pt inspectCmd;
+ command_service_pt inspectCmdSrv;
+
+ service_registration_pt helpCommand;
+ command_pt helpCmd;
+ command_service_pt helpCmdSrv;
+};
+
+typedef struct bundle_instance *bundle_instance_pt;
+
+static celix_status_t shell_createCommandService(command_pt command, command_service_pt *commandService) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *commandService = calloc(1, sizeof(**commandService));
+
+ if (!*commandService) {
+ status = CELIX_ENOMEM;
+ }
+ else {
+ (*commandService)->command = command;
+ (*commandService)->executeCommand = command->executeCommand;
+ (*commandService)->getName = command_getName;
+ (*commandService)->getShortDescription = command_getShortDescription;
+ (*commandService)->getUsage = command_getUsage;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ bundle_instance_pt bi = (bundle_instance_pt) calloc(1, sizeof(struct bundle_instance));
+
+ if (!bi) {
+ status = CELIX_ENOMEM;
+ }
+ else if (userData == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ free(bi);
+ }
+ else {
+ bi->listener = NULL;
+ bi->psCommand = NULL;
+ bi->startCommand = NULL;
+ bi->stopCommand = NULL;
+ bi->installCommand = NULL;
+ bi->uninstallCommand = NULL;
+ bi->updateCommand = NULL;
+ bi->logCommand = NULL;
+ bi->inspectCommand = NULL;
+ bi->helpCommand = NULL;
+ bi->registration = NULL;
+
+ status = shell_create(context, &bi->shellService);
+
+ if (status != CELIX_SUCCESS) {
+ printf("shell_create failed\n");
+ }
+
+ (*userData) = bi;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ bundle_instance_pt bi = (bundle_instance_pt) userData;
+
+ status = bundleContext_registerService(context, (char *) OSGI_SHELL_SERVICE_NAME, bi->shellService, NULL, &bi->registration);
+
+ if (status == CELIX_SUCCESS) {
+ array_list_pt references = NULL;
+ service_listener_pt listener = (service_listener_pt) calloc(1, sizeof(*listener));
+
+ bi->listener = listener;
+ listener->handle = bi->shellService->shell;
+ listener->serviceChanged = (void *) shell_serviceChanged;
+
+ status = bundleContext_addServiceListener(context, listener, "(objectClass=commandService)");
+ status = bundleContext_getServiceReferences(context, "commandService", NULL, &references);
+
+ if (status == CELIX_SUCCESS) {
+ int i = 0;
+
+ for (i = 0; i < arrayList_size(references); i++) {
+ shell_addCommand(bi->shellService->shell, arrayList_get(references, i));
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ bi->psCmd = psCommand_create(context);
+ shell_createCommandService(bi->psCmd, &bi->psCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->psCmdSrv, NULL, &bi->psCommand);
+
+ bi->startCmd = startCommand_create(context);
+ shell_createCommandService(bi->startCmd, &bi->startCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->startCmdSrv, NULL, &bi->startCommand);
+
+ bi->stopCmd = stopCommand_create(context);
+ shell_createCommandService(bi->stopCmd, &bi->stopCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->stopCmdSrv, NULL, &bi->stopCommand);
+
+ bi->installCmd = installCommand_create(context);
+ shell_createCommandService(bi->installCmd, &bi->installCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->installCmdSrv, NULL, &bi->installCommand);
+
+ bi->uninstallCmd = uninstallCommand_create(context);
+ shell_createCommandService(bi->uninstallCmd, &bi->uninstallCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->uninstallCmdSrv, NULL, &bi->uninstallCommand);
+
+ bi->updateCmd = updateCommand_create(context);
+ shell_createCommandService(bi->updateCmd, &bi->updateCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->updateCmdSrv, NULL, &bi->updateCommand);
+
+ bi->logCmd = logCommand_create(context);
+ shell_createCommandService(bi->logCmd, &bi->logCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->logCmdSrv, NULL, &bi->logCommand);
+
+ bi->inspectCmd = inspectCommand_create(context);
+ shell_createCommandService(bi->inspectCmd, &bi->inspectCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->inspectCmdSrv, NULL, &bi->inspectCommand);
+
+ bi->helpCmd = helpCommand_create(context);
+ shell_createCommandService(bi->helpCmd, &bi->helpCmdSrv);
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, bi->helpCmdSrv, NULL, &bi->helpCommand);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ bundle_instance_pt bi = (bundle_instance_pt) userData;
+
+ serviceRegistration_unregister(bi->registration);
+ serviceRegistration_unregister(bi->psCommand);
+ serviceRegistration_unregister(bi->startCommand);
+ serviceRegistration_unregister(bi->stopCommand);
+ serviceRegistration_unregister(bi->installCommand);
+ serviceRegistration_unregister(bi->uninstallCommand);
+ serviceRegistration_unregister(bi->updateCommand);
+ serviceRegistration_unregister(bi->logCommand);
+ serviceRegistration_unregister(bi->inspectCommand);
+ serviceRegistration_unregister(bi->helpCommand);
+
+ status = bundleContext_removeServiceListener(context, bi->listener);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ bundle_instance_pt bi = (bundle_instance_pt) userData;
+
+ psCommand_destroy(bi->psCmd);
+ free(bi->psCmdSrv);
+
+ startCommand_destroy(bi->startCmd);
+ free(bi->startCmdSrv);
+
+ stopCommand_destroy(bi->stopCmd);
+ free(bi->stopCmdSrv);
+
+ installCommand_destroy(bi->installCmd);
+ free(bi->installCmdSrv);
+
+ uninstallCommand_destroy(bi->uninstallCmd);
+ free(bi->uninstallCmdSrv);
+
+ updateCommand_destroy(bi->updateCmd);
+ free(bi->updateCmdSrv);
+
+ logCommand_destroy(bi->logCmd);
+ free(bi->logCmdSrv);
+
+ inspectCommand_destroy(bi->inspectCmd);
+ free(bi->inspectCmdSrv);
+
+ inspectCommand_destroy(bi->helpCmd);
+ free(bi->helpCmdSrv);
+
+ free(bi->listener);
+ bi->listener = NULL;
+
+ shell_destroy(&bi->shellService);
+ bi->shellService = NULL;
+ free(bi);
+
+ return CELIX_SUCCESS;
+}
Modified: celix/trunk/shell/private/src/shell.c
URL: http://svn.apache.org/viewvc/celix/trunk/shell/private/src/shell.c?rev=1641175&r1=1641174&r2=1641175&view=diff
==============================================================================
--- celix/trunk/shell/private/src/shell.c (original)
+++ celix/trunk/shell/private/src/shell.c Sun Nov 23 12:41:44 2014
@@ -26,6 +26,8 @@
#include <stdlib.h>
#include <string.h>
+#include "celix_errno.h"
+
#include "shell_private.h"
#include "bundle_activator.h"
#include "command_impl.h"
@@ -45,64 +47,70 @@
#include "utils.h"
-struct shellServiceActivator {
- apr_pool_t *pool;
- shell_pt shell;
- shell_service_pt shellService;
- service_registration_pt registration;
- service_listener_pt listener;
-
- service_registration_pt psCommand;
- command_pt psCmd;
- command_service_pt psCmdSrv;
-
- service_registration_pt startCommand;
- command_pt startCmd;
- command_service_pt startCmdSrv;
-
- service_registration_pt stopCommand;
- command_pt stopCmd;
- command_service_pt stopCmdSrv;
-
- service_registration_pt installCommand;
- command_pt installCmd;
- command_service_pt installCmdSrv;
-
- service_registration_pt uninstallCommand;
- command_pt uninstallCmd;
- command_service_pt uninstallCmdSrv;
-
- service_registration_pt updateCommand;
- command_pt updateCmd;
- command_service_pt updateCmdSrv;
-
- service_registration_pt logCommand;
- command_pt logCmd;
- command_service_pt logCmdSrv;
-
- service_registration_pt inspectCommand;
- command_pt inspectCmd;
- command_service_pt inspectCmdSrv;
-
- service_registration_pt helpCommand;
- command_pt helpCmd;
- command_service_pt helpCmdSrv;
-};
-
-static celix_status_t shell_createCommandService(apr_pool_t *pool, command_pt command, command_service_pt *commandService);
-
-shell_pt shell_create(apr_pool_t *pool) {
- shell_pt shell = (shell_pt) malloc(sizeof(*shell));
- shell->pool = pool;
- shell->commandNameMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- shell->commandReferenceMap = hashMap_create(NULL, NULL, NULL, NULL);
- return shell;
-}
-
-void shell_destroy(shell_pt shell) {
- hashMap_destroy(shell->commandNameMap, false, false);
- hashMap_destroy(shell->commandReferenceMap, false, false);
- free(shell);
+static command_service_pt shell_getCommand(shell_pt shell, char * commandName);
+array_list_pt shell_getCommands(shell_pt shell);
+
+celix_status_t shell_create(bundle_context_pt context, shell_service_pt* shellService) {
+ celix_status_t status = CELIX_ENOMEM;
+
+ shell_service_pt lclService = (shell_service_pt) calloc(1, sizeof(struct shellService));
+ shell_pt lclShell = (shell_pt) calloc(1, sizeof(struct shell));
+
+ if (lclService && lclShell) {
+ lclShell->bundleContext = context;
+ lclShell->commandNameMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+ lclShell->commandReferenceMap = hashMap_create(NULL, NULL, NULL, NULL);
+ lclService->shell = lclShell;
+
+ lclService->getCommands = shell_getCommands;
+ lclService->getCommandDescription = shell_getCommandDescription;
+ lclService->getCommandUsage = shell_getCommandUsage;
+ lclService->getCommandReference = shell_getCommandReference;
+ lclService->executeCommand = shell_executeCommand;
+
+ *shellService = lclService;
+ status = CELIX_SUCCESS;
+ }
+
+ return status;
+}
+
+celix_status_t shell_destroy(shell_service_pt* shellService) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ hashMap_destroy((*shellService)->shell->commandNameMap, false, false);
+ hashMap_destroy((*shellService)->shell->commandReferenceMap, false, false);
+
+ free((*shellService)->shell);
+ free(*shellService);
+
+ return status;
+}
+
+celix_status_t shell_addCommand(shell_pt shell, service_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ command_service_pt command = NULL;
+ void *cmd = NULL;
+ bundleContext_getService(shell->bundleContext, reference, &cmd);
+ command = (command_service_pt) cmd;
+ hashMap_put(shell->commandNameMap, command->getName(command->command), command);
+ hashMap_put(shell->commandReferenceMap, reference, command);
+
+ return status;
+}
+
+celix_status_t shell_removeCommand(shell_pt shell, service_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ command_service_pt command = (command_service_pt) hashMap_remove(shell->commandReferenceMap, reference);
+ if (command != NULL) {
+ bool result = false;
+ hashMap_remove(shell->commandNameMap, command->getName(command->command));
+ bundleContext_ungetService(shell->bundleContext, reference, &result);
+ }
+
+ return status;
}
array_list_pt shell_getCommands(shell_pt shell) {
@@ -143,201 +151,27 @@ service_reference_pt shell_getCommandRef
void shell_executeCommand(shell_pt shell, char * commandLine, void (*out)(char *), void (*error)(char *)) {
unsigned int pos = strcspn(commandLine, " ");
- char * commandName = (pos != strlen(commandLine)) ? string_ndup((char *)commandLine, pos) : strdup(commandLine);
+ char * commandName = (pos != strlen(commandLine)) ? string_ndup((char *) commandLine, pos) : strdup(commandLine);
command_service_pt command = shell_getCommand(shell, commandName);
if (command != NULL) {
command->executeCommand(command->command, commandLine, out, error);
} else {
- error("No such command\n");
+ error("No such command\n");
}
free(commandName);
}
-command_service_pt shell_getCommand(shell_pt shell, char * commandName) {
+static command_service_pt shell_getCommand(shell_pt shell, char * commandName) {
command_service_pt command = hashMap_get(shell->commandNameMap, commandName);
return (command == NULL) ? NULL : command;
}
-void shell_addCommand(shell_pt shell, service_reference_pt reference) {
- command_service_pt command = NULL;
- void *cmd = NULL;
- bundleContext_getService(shell->bundleContext, reference, &cmd);
- command = (command_service_pt) cmd;
- hashMap_put(shell->commandNameMap, command->getName(command->command), command);
- hashMap_put(shell->commandReferenceMap, reference, command);
-}
-
-void shell_removeCommand(shell_pt shell, service_reference_pt reference) {
- command_service_pt command = (command_service_pt) hashMap_remove(shell->commandReferenceMap, reference);
- if (command != NULL) {
- bool result = false;
- hashMap_remove(shell->commandNameMap, command->getName(command->command));
- bundleContext_ungetService(shell->bundleContext, reference, &result);
- }
-}
-
void shell_serviceChanged(service_listener_pt listener, service_event_pt event) {
shell_pt shell = (shell_pt) listener->handle;
if (event->type == OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED) {
shell_addCommand(shell, event->reference);
} else if (event->type == OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING) {
- shell_removeCommand(shell, event->reference);
- }
-}
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- apr_pool_t *pool = NULL;
- shell_pt shell = NULL;
- *userData = malloc(sizeof(struct shellServiceActivator));
-
- apr_pool_create(&pool, NULL);
-
- shell = shell_create(pool);
-// struct shellServiceActivator * activator = (struct shellServiceActivator *) (*userData);
- ((struct shellServiceActivator *) (*userData))->shell = shell;
- ((struct shellServiceActivator *) (*userData))->listener = NULL;
- ((struct shellServiceActivator *) (*userData))->psCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->startCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->stopCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->installCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->uninstallCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->updateCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->logCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->inspectCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->helpCommand = NULL;
- ((struct shellServiceActivator *) (*userData))->registration = NULL;
- ((struct shellServiceActivator *) (*userData))->pool = pool;
-
- //(*userData) = &(*activator);
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status;
-
- struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
- activator->shell->bundleContext = context;
-
- activator->shellService = (shell_service_pt) malloc(sizeof(*activator->shellService));
- activator->shellService->shell = activator->shell;
- activator->shellService->getCommands = shell_getCommands;
- activator->shellService->getCommandDescription = shell_getCommandDescription;
- activator->shellService->getCommandUsage = shell_getCommandUsage;
- activator->shellService->getCommandReference = shell_getCommandReference;
- activator->shellService->executeCommand = shell_executeCommand;
-
- status = bundleContext_registerService(context, (char *) OSGI_SHELL_SERVICE_NAME, activator->shellService, NULL, &activator->registration);
-
- if (status == CELIX_SUCCESS) {
- service_listener_pt listener = (service_listener_pt) malloc(sizeof(*listener));
- activator->listener = listener;
- listener->handle = activator->shell;
- listener->serviceChanged = (void *) shell_serviceChanged;
- status = bundleContext_addServiceListener(context, listener, "(objectClass=commandService)");
-
- array_list_pt references = NULL;
- status = bundleContext_getServiceReferences(context, "commandService", NULL, &references);
- if (status == CELIX_SUCCESS) {
- int i = 0;
- for (i = 0; i < arrayList_size(references); i++) {
- shell_addCommand(activator->shell, arrayList_get(references, i));
- }
- }
-
- if (status == CELIX_SUCCESS) {
- activator->psCmd = psCommand_create(context);
- shell_createCommandService(activator->pool, activator->psCmd, &activator->psCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->psCmdSrv, NULL, &activator->psCommand);
-
- activator->startCmd = startCommand_create(context);
- shell_createCommandService(activator->pool, activator->startCmd, &activator->startCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->startCmdSrv, NULL, &activator->startCommand);
-
- activator->stopCmd = stopCommand_create(context);
- shell_createCommandService(activator->pool, activator->stopCmd, &activator->stopCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->stopCmdSrv, NULL, &activator->stopCommand);
-
- activator->installCmd = installCommand_create(context);
- shell_createCommandService(activator->pool, activator->installCmd, &activator->installCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->installCmdSrv, NULL, &activator->installCommand);
-
- activator->uninstallCmd = uninstallCommand_create(context);
- shell_createCommandService(activator->pool, activator->uninstallCmd, &activator->uninstallCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->uninstallCmdSrv, NULL, &activator->uninstallCommand);
-
- activator->updateCmd = updateCommand_create(context);
- shell_createCommandService(activator->pool, activator->updateCmd, &activator->updateCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->updateCmdSrv, NULL, &activator->updateCommand);
-
- activator->logCmd = logCommand_create(context);
- shell_createCommandService(activator->pool, activator->logCmd, &activator->logCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->logCmdSrv, NULL, &activator->logCommand);
-
- activator->inspectCmd = inspectCommand_create(context);
- shell_createCommandService(activator->pool, activator->inspectCmd, &activator->inspectCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->inspectCmdSrv, NULL, &activator->inspectCommand);
-
- activator->helpCmd = helpCommand_create(context);
- shell_createCommandService(activator->pool, activator->helpCmd, &activator->helpCmdSrv);
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->helpCmdSrv, NULL, &activator->helpCommand);
- }
+ shell_removeCommand(shell, event->reference);
}
-
- return status;
}
-static celix_status_t shell_createCommandService(apr_pool_t *pool, command_pt command, command_service_pt *commandService) {
- *commandService = apr_palloc(pool, sizeof(**commandService));
- (*commandService)->command = command;
- (*commandService)->executeCommand = command->executeCommand;
- (*commandService)->getName = command_getName;
- (*commandService)->getShortDescription = command_getShortDescription;
- (*commandService)->getUsage = command_getUsage;
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
- serviceRegistration_unregister(activator->registration);
- serviceRegistration_unregister(activator->psCommand);
- serviceRegistration_unregister(activator->startCommand);
- serviceRegistration_unregister(activator->stopCommand);
- serviceRegistration_unregister(activator->installCommand);
- serviceRegistration_unregister(activator->uninstallCommand);
- serviceRegistration_unregister(activator->updateCommand);
- serviceRegistration_unregister(activator->logCommand);
- serviceRegistration_unregister(activator->inspectCommand);
- serviceRegistration_unregister(activator->helpCommand);
- status = bundleContext_removeServiceListener(context, activator->listener);
-
- if (status == CELIX_SUCCESS) {
- psCommand_destroy(activator->psCmd);
- startCommand_destroy(activator->startCmd);
- stopCommand_destroy(activator->stopCmd);
- installCommand_destroy(activator->installCmd);
- uninstallCommand_destroy(activator->uninstallCmd);
- updateCommand_destroy(activator->updateCmd);
- logCommand_destroy(activator->logCmd);
- inspectCommand_destroy(activator->inspectCmd);
- inspectCommand_destroy(activator->helpCmd);
-
- free(activator->shellService);
- activator->shellService = NULL;
-
- free(activator->listener);
- activator->listener = NULL;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
- shell_destroy(activator->shell);
- free(activator);
-
- return CELIX_SUCCESS;
-}