Repository: celix Updated Branches: refs/heads/feature/CELIX-230_Refactoring_of_the_shell_command_service c35a74c76 -> 3bf493eb0
CELIX-230: Renamed ps_command to lb_command Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/3bf493eb Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/3bf493eb Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/3bf493eb Branch: refs/heads/feature/CELIX-230_Refactoring_of_the_shell_command_service Commit: 3bf493eb08c598df9a6f8f23ff9127bdc4efc28e Parents: c35a74c Author: Pepijn Noltes <[email protected]> Authored: Tue Oct 27 16:26:01 2015 +0100 Committer: Pepijn Noltes <[email protected]> Committed: Tue Oct 27 16:26:01 2015 +0100 ---------------------------------------------------------------------- shell/CMakeLists.txt | 2 +- shell/private/src/lb_command.c | 181 ++++++++++++++++++++++++++++++++++++ shell/private/src/ps_command.c | 181 ------------------------------------ 3 files changed, 182 insertions(+), 182 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/3bf493eb/shell/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 8e83933..95bddd7 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -26,7 +26,7 @@ if (SHELL) private/src/activator private/src/shell - private/src/ps_command + private/src/lb_command private/src/start_command private/src/stop_command private/src/install_command http://git-wip-us.apache.org/repos/asf/celix/blob/3bf493eb/shell/private/src/lb_command.c ---------------------------------------------------------------------- diff --git a/shell/private/src/lb_command.c b/shell/private/src/lb_command.c new file mode 100644 index 0000000..fca93de --- /dev/null +++ b/shell/private/src/lb_command.c @@ -0,0 +1,181 @@ +/** + *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. + */ +/* + * std_shell_commands.c + * + * \date March 27, 2014 + * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> + * \copyright Apache License, Version 2.0 + */ +#include <stdlib.h> +#include <string.h> + +#include "array_list.h" +#include "bundle_context.h" + +#include "std_commands.h" + +static char * psCommand_stateString(bundle_state_e state); + +celix_status_t psCommand_execute(void *_ptr, char *command_line_str, FILE *out_ptr, FILE *err_ptr) { + celix_status_t status = CELIX_SUCCESS; + + bundle_context_pt context_ptr = _ptr; + array_list_pt bundles_ptr = NULL; + + bool show_location = false; + bool show_symbolic_name = false; + bool show_update_location = false; + char *message_str = "Name"; + + if (!context_ptr || !command_line_str || !out_ptr || !err_ptr) { + status = CELIX_ILLEGAL_ARGUMENT; + } + + if (status == CELIX_SUCCESS) { + status = bundleContext_getBundles(context_ptr, &bundles_ptr); + } + + if (status == CELIX_SUCCESS) { + char *sub_str = NULL; + char *save_ptr = NULL; + + strtok_r(command_line_str, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); + sub_str = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); + while (sub_str != NULL) { + if (strcmp(sub_str, "-l") == 0) { + show_location = true; + message_str = "Location"; + } else if (strcmp(sub_str, "-s") == 0) { + show_symbolic_name = true; + message_str = "Symbolic name"; + } else if (strcmp(sub_str, "-u") == 0) { + show_update_location = true; + message_str = "Update location"; + } + sub_str = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); + } + + fprintf(out_ptr, " %-5s %-12s %s\n", "ID", "State", message_str); + + unsigned int size = arrayList_size(bundles_ptr); + bundle_pt bundles_array_ptr[size]; + + for (unsigned int i = 0; i < size; i++) { + bundles_array_ptr[i] = arrayList_get(bundles_ptr, i); + } + + for (unsigned int i = 0; i < size - 1; i++) { + for (unsigned int j = i + 1; j < size; j++) { + bundle_pt first_ptr = bundles_array_ptr[i]; + bundle_pt second_ptr = bundles_array_ptr[j]; + + bundle_archive_pt first_archive_ptr = NULL; + bundle_archive_pt second_archive_ptr = NULL; + + long first_id; + long second_id; + + bundle_getArchive(first_ptr, &first_archive_ptr); + bundle_getArchive(second_ptr, &second_archive_ptr); + + bundleArchive_getId(first_archive_ptr, &first_id); + bundleArchive_getId(second_archive_ptr, &second_id); + + if (first_id > second_id) { + bundle_pt temp_ptr = bundles_array_ptr[i]; + bundles_array_ptr[i] = bundles_array_ptr[j]; + bundles_array_ptr[j] = temp_ptr; + } + } + } + + for (unsigned int i = 0; i < size - 1; i++) { + celix_status_t sub_status; + + bundle_pt bundle_ptr = bundles_array_ptr[i]; + + bundle_archive_pt archive_ptr = NULL; + long id = 0; + bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN; + char *state_str = NULL; + module_pt module_ptr = NULL; + char *name_str = NULL; + + sub_status = bundle_getArchive(bundle_ptr, &archive_ptr); + if (sub_status == CELIX_SUCCESS) { + sub_status = bundleArchive_getId(archive_ptr, &id); + } + + if (sub_status == CELIX_SUCCESS) { + sub_status = bundle_getState(bundle_ptr, &state); + } + + if (sub_status == CELIX_SUCCESS) { + state_str = psCommand_stateString(state); + + sub_status = bundle_getCurrentModule(bundle_ptr, &module_ptr); + } + + if (sub_status == CELIX_SUCCESS) { + sub_status = module_getSymbolicName(module_ptr, &name_str); + } + + if (sub_status == CELIX_SUCCESS) { + if (show_location) { + sub_status = bundleArchive_getLocation(archive_ptr, &name_str); + } else if (show_symbolic_name) { + // do nothing + } else if (show_update_location) { + sub_status = bundleArchive_getLocation(archive_ptr, &name_str); + } + } + + if (sub_status == CELIX_SUCCESS) { + fprintf(out_ptr, " %-5ld %-12s %s\n", id, state_str, name_str); + } + + if (sub_status != CELIX_SUCCESS) { + status = sub_status; + break; + } + } + + arrayList_destroy(bundles_ptr); + } + + return status; +} + +static char * psCommand_stateString(bundle_state_e state) { + switch (state) { + case OSGI_FRAMEWORK_BUNDLE_ACTIVE: + return "Active "; + case OSGI_FRAMEWORK_BUNDLE_INSTALLED: + return "Installed "; + case OSGI_FRAMEWORK_BUNDLE_RESOLVED: + return "Resolved "; + case OSGI_FRAMEWORK_BUNDLE_STARTING: + return "Starting "; + case OSGI_FRAMEWORK_BUNDLE_STOPPING: + return "Stopping "; + default: + return "Unknown "; + } +} http://git-wip-us.apache.org/repos/asf/celix/blob/3bf493eb/shell/private/src/ps_command.c ---------------------------------------------------------------------- diff --git a/shell/private/src/ps_command.c b/shell/private/src/ps_command.c deleted file mode 100644 index fca93de..0000000 --- a/shell/private/src/ps_command.c +++ /dev/null @@ -1,181 +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. - */ -/* - * std_shell_commands.c - * - * \date March 27, 2014 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ -#include <stdlib.h> -#include <string.h> - -#include "array_list.h" -#include "bundle_context.h" - -#include "std_commands.h" - -static char * psCommand_stateString(bundle_state_e state); - -celix_status_t psCommand_execute(void *_ptr, char *command_line_str, FILE *out_ptr, FILE *err_ptr) { - celix_status_t status = CELIX_SUCCESS; - - bundle_context_pt context_ptr = _ptr; - array_list_pt bundles_ptr = NULL; - - bool show_location = false; - bool show_symbolic_name = false; - bool show_update_location = false; - char *message_str = "Name"; - - if (!context_ptr || !command_line_str || !out_ptr || !err_ptr) { - status = CELIX_ILLEGAL_ARGUMENT; - } - - if (status == CELIX_SUCCESS) { - status = bundleContext_getBundles(context_ptr, &bundles_ptr); - } - - if (status == CELIX_SUCCESS) { - char *sub_str = NULL; - char *save_ptr = NULL; - - strtok_r(command_line_str, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); - sub_str = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); - while (sub_str != NULL) { - if (strcmp(sub_str, "-l") == 0) { - show_location = true; - message_str = "Location"; - } else if (strcmp(sub_str, "-s") == 0) { - show_symbolic_name = true; - message_str = "Symbolic name"; - } else if (strcmp(sub_str, "-u") == 0) { - show_update_location = true; - message_str = "Update location"; - } - sub_str = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); - } - - fprintf(out_ptr, " %-5s %-12s %s\n", "ID", "State", message_str); - - unsigned int size = arrayList_size(bundles_ptr); - bundle_pt bundles_array_ptr[size]; - - for (unsigned int i = 0; i < size; i++) { - bundles_array_ptr[i] = arrayList_get(bundles_ptr, i); - } - - for (unsigned int i = 0; i < size - 1; i++) { - for (unsigned int j = i + 1; j < size; j++) { - bundle_pt first_ptr = bundles_array_ptr[i]; - bundle_pt second_ptr = bundles_array_ptr[j]; - - bundle_archive_pt first_archive_ptr = NULL; - bundle_archive_pt second_archive_ptr = NULL; - - long first_id; - long second_id; - - bundle_getArchive(first_ptr, &first_archive_ptr); - bundle_getArchive(second_ptr, &second_archive_ptr); - - bundleArchive_getId(first_archive_ptr, &first_id); - bundleArchive_getId(second_archive_ptr, &second_id); - - if (first_id > second_id) { - bundle_pt temp_ptr = bundles_array_ptr[i]; - bundles_array_ptr[i] = bundles_array_ptr[j]; - bundles_array_ptr[j] = temp_ptr; - } - } - } - - for (unsigned int i = 0; i < size - 1; i++) { - celix_status_t sub_status; - - bundle_pt bundle_ptr = bundles_array_ptr[i]; - - bundle_archive_pt archive_ptr = NULL; - long id = 0; - bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN; - char *state_str = NULL; - module_pt module_ptr = NULL; - char *name_str = NULL; - - sub_status = bundle_getArchive(bundle_ptr, &archive_ptr); - if (sub_status == CELIX_SUCCESS) { - sub_status = bundleArchive_getId(archive_ptr, &id); - } - - if (sub_status == CELIX_SUCCESS) { - sub_status = bundle_getState(bundle_ptr, &state); - } - - if (sub_status == CELIX_SUCCESS) { - state_str = psCommand_stateString(state); - - sub_status = bundle_getCurrentModule(bundle_ptr, &module_ptr); - } - - if (sub_status == CELIX_SUCCESS) { - sub_status = module_getSymbolicName(module_ptr, &name_str); - } - - if (sub_status == CELIX_SUCCESS) { - if (show_location) { - sub_status = bundleArchive_getLocation(archive_ptr, &name_str); - } else if (show_symbolic_name) { - // do nothing - } else if (show_update_location) { - sub_status = bundleArchive_getLocation(archive_ptr, &name_str); - } - } - - if (sub_status == CELIX_SUCCESS) { - fprintf(out_ptr, " %-5ld %-12s %s\n", id, state_str, name_str); - } - - if (sub_status != CELIX_SUCCESS) { - status = sub_status; - break; - } - } - - arrayList_destroy(bundles_ptr); - } - - return status; -} - -static char * psCommand_stateString(bundle_state_e state) { - switch (state) { - case OSGI_FRAMEWORK_BUNDLE_ACTIVE: - return "Active "; - case OSGI_FRAMEWORK_BUNDLE_INSTALLED: - return "Installed "; - case OSGI_FRAMEWORK_BUNDLE_RESOLVED: - return "Resolved "; - case OSGI_FRAMEWORK_BUNDLE_STARTING: - return "Starting "; - case OSGI_FRAMEWORK_BUNDLE_STOPPING: - return "Stopping "; - default: - return "Unknown "; - } -}
