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/03/27 17:58:59 UTC
celix git commit: CELIX-230: Fixed bug, added start command
Repository: celix
Updated Branches:
refs/heads/shell_command cea3f9ec0 -> 595f3e993
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/shell_command
Commit: 595f3e9931f5b0ab11d2a2e6ea39360e85a40695
Parents: cea3f9e
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Mar 27 17:58:31 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
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 <id> [<id> ...]", 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 <stdlib.h>
#include <string.h>
+#include <stdio.h>
-#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 <id> [<id> ...]";
- 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;
}