Return-Path: X-Original-To: apmail-celix-commits-archive@www.apache.org Delivered-To: apmail-celix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7364F1801E for ; Tue, 3 Nov 2015 09:38:57 +0000 (UTC) Received: (qmail 88156 invoked by uid 500); 3 Nov 2015 09:38:57 -0000 Delivered-To: apmail-celix-commits-archive@celix.apache.org Received: (qmail 88067 invoked by uid 500); 3 Nov 2015 09:38:57 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 88041 invoked by uid 99); 3 Nov 2015 09:38:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2015 09:38:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E3443E0418; Tue, 3 Nov 2015 09:38:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pnoltes@apache.org To: commits@celix.apache.org Date: Tue, 03 Nov 2015 09:38:57 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [02/13] celix git commit: CELIX-230: Fixed bug, added start command CELIX-230: Fixed bug, added start command Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/595f3e99 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/595f3e99 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/595f3e99 Branch: refs/heads/feature/CELIX-269_depman Commit: 595f3e9931f5b0ab11d2a2e6ea39360e85a40695 Parents: cea3f9e Author: Pepijn Noltes Authored: Fri Mar 27 17:58:31 2015 +0100 Committer: Pepijn Noltes Committed: Fri Mar 27 17:58:31 2015 +0100 ---------------------------------------------------------------------- shell/CMakeLists.txt | 2 +- shell/private/src/activator.c | 15 +++++++------- shell/private/src/start_command.c | 37 ++++++++++++---------------------- 3 files changed, 22 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/595f3e99/shell/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 8308369..09777d3 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -27,7 +27,7 @@ if (SHELL) private/src/activator private/src/shell private/src/ps_command - # private/src/start_command + private/src/start_command #private/src/stop_command #private/src/install_command #private/src/update_command http://git-wip-us.apache.org/repos/asf/celix/blob/595f3e99/shell/private/src/activator.c ---------------------------------------------------------------------- diff --git a/shell/private/src/activator.c b/shell/private/src/activator.c index 595894e..ce01b59 100644 --- a/shell/private/src/activator.c +++ b/shell/private/src/activator.c @@ -47,6 +47,7 @@ struct command { static struct command std_commands[] = { {psCommand_execute, "ps", "list installed bundles.", "ps [-l | -s | -u]", NULL, NULL, NULL}, + {startCommand_execute, "start", "start bundle(s).", "start [ ...]", NULL, NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} /*marker for last element*/ }; @@ -56,15 +57,8 @@ struct bundle_instance { service_registration_pt registration; service_listener_pt listener; - service_registration_pt commandRegistrations; - command_service_pt commandServices; - properties_pt commandProperties; - /* ps - service_registration_pt startCommand; - command_pt startCmd; - command_service_pt startCmdSrv; service_registration_pt stopCommand; command_pt stopCmd; @@ -180,6 +174,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) if (status != CELIX_SUCCESS) { break; } + i += 1; } } @@ -198,7 +193,9 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) while (std_commands[i].exec != NULL) { if (std_commands[i].reg!= NULL) { serviceRegistration_unregister(std_commands[i].reg); + std_commands[i].reg = NULL; } + i += 1; } status = bundleContext_removeServiceListener(context, bi->listener); @@ -220,5 +217,9 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt contex i += 1; } + if (bi != NULL) { + free(bi); + } + return CELIX_SUCCESS; } http://git-wip-us.apache.org/repos/asf/celix/blob/595f3e99/shell/private/src/start_command.c ---------------------------------------------------------------------- diff --git a/shell/private/src/start_command.c b/shell/private/src/start_command.c index 89103eb..0e5f5e0 100644 --- a/shell/private/src/start_command.c +++ b/shell/private/src/start_command.c @@ -25,51 +25,40 @@ */ #include #include +#include -#include "command_impl.h" +#include "celix_errno.h" +#include "std_commands.h" #include "array_list.h" #include "bundle_context.h" #include "bundle.h" -void startCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *)); +celix_status_t startCommand_execute(void *handle, char * line, FILE *outStream, FILE *errStream) { + celix_status_t status = CELIX_SUCCESS; + bundle_context_pt context = handle; -command_pt startCommand_create(bundle_context_pt context) { - command_pt command = (command_pt) malloc(sizeof(*command)); - command->bundleContext = context; - command->name = "start"; - command->shortDescription = "start bundle(s)."; - command->usage = "start [ ...]"; - command->executeCommand = startCommand_execute; - return command; -} - -void startCommand_destroy(command_pt command) { - free(command); -} - - -void startCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *)) { char delims[] = " "; char * sub = NULL; char *save_ptr = NULL; - char outString[256]; sub = strtok_r(line, delims, &save_ptr); sub = strtok_r(NULL, delims, &save_ptr); if (sub == NULL) { - err("Incorrect number of arguments.\n"); - sprintf(outString, "%s\n", command->usage); - out(outString); + fprintf(outStream, "Incorrect number of arguments.\n"); } else { while (sub != NULL) { long id = atol(sub); bundle_pt bundle = NULL; - bundleContext_getBundleById(command->bundleContext, id, &bundle); + bundleContext_getBundleById(context, id, &bundle); if (bundle != NULL) { bundle_startWithOptions(bundle, 0); } else { - err("Bundle id is invalid.\n"); + fprintf(errStream, "Bundle id '%li' is invalid\n", id); + status = CELIX_ILLEGAL_ARGUMENT; + break; } sub = strtok_r(NULL, delims, &save_ptr); } } + + return status; }