Return-Path: X-Original-To: apmail-incubator-celix-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-celix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B4FC410EFF for ; Tue, 7 Jan 2014 14:43:16 +0000 (UTC) Received: (qmail 80556 invoked by uid 500); 7 Jan 2014 14:43:11 -0000 Delivered-To: apmail-incubator-celix-commits-archive@incubator.apache.org Received: (qmail 80161 invoked by uid 500); 7 Jan 2014 14:42:57 -0000 Mailing-List: contact celix-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: celix-dev@incubator.apache.org Delivered-To: mailing list celix-commits@incubator.apache.org Received: (qmail 80124 invoked by uid 99); 7 Jan 2014 14:42:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jan 2014 14:42:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jan 2014 14:42:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2DFCD2388860; Tue, 7 Jan 2014 14:42:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1556228 - /incubator/celix/trunk/shell/private/src/inspect_command.c Date: Tue, 07 Jan 2014 14:42:33 -0000 To: celix-commits@incubator.apache.org From: abroekhuis@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140107144233.2DFCD2388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: abroekhuis Date: Tue Jan 7 14:42:32 2014 New Revision: 1556228 URL: http://svn.apache.org/r1556228 Log: CELIX-97: Added additional information to the inspect command. It now prints all properties for capabilities and requirements. Modified: incubator/celix/trunk/shell/private/src/inspect_command.c Modified: incubator/celix/trunk/shell/private/src/inspect_command.c URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/private/src/inspect_command.c?rev=1556228&r1=1556227&r2=1556228&view=diff ============================================================================== --- incubator/celix/trunk/shell/private/src/inspect_command.c (original) +++ incubator/celix/trunk/shell/private/src/inspect_command.c Tue Jan 7 14:42:32 2014 @@ -36,13 +36,15 @@ #include "constants.h" #include "service_registration.h" #include "service_reference.h" +#include "hash_map.h" #define SERVICE_TYPE "service" -#define capability_pt "capability" +#define CAPABILITY "capability" #define REQUIREMENT "requirement" void inspectCommand_execute(command_pt command, char * commandline, void (*out)(char *), void (*err)(char *)); celix_status_t inspectCommand_printExportedServices(command_pt command, array_list_pt ids, void (*out)(char *), void (*err)(char *)); +celix_status_t inspectCommand_printImportedServices(command_pt command, array_list_pt ids, void (*out)(char *), void (*err)(char *)); command_pt inspectCommand_create(bundle_context_pt context) { command_pt command = (command_pt) malloc(sizeof(*command)); @@ -79,16 +81,25 @@ void inspectCommand_execute(command_pt c } if (strcmp(type, SERVICE_TYPE) == 0) { - if (strcmp(direction, capability_pt) == 0) { + if (strcmp(direction, CAPABILITY) == 0) { status = inspectCommand_printExportedServices(command, ids, out, err); if (status != CELIX_SUCCESS) { out("INSPECT: Error\n"); } + } else if (strcmp(direction, REQUIREMENT) == 0) { + status = inspectCommand_printImportedServices(command, ids, out, err); + if (status != CELIX_SUCCESS) { + out("INSPECT: Error\n"); + } } else { - out("INSPECT: Not implemented\n"); + out("INSPECT: Invalid argument\n"); + sprintf(outString, "%s\n", command->usage); + out(outString); } } else { out("INSPECT: Invalid argument\n"); + sprintf(outString, "%s\n", command->usage); + out(outString); } } else { out("INSPECT: Too few arguments\n"); @@ -169,9 +180,15 @@ celix_status_t inspectCommand_printExpor serviceReference_getServiceRegistration(ref, ®); serviceRegistration_getProperties(reg, &props); - objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS); - sprintf(line, "ObjectClass = %s\n", objectClass); - out(line); + hash_map_iterator_pt iter = hashMapIterator_create(props); + while (hashMapIterator_hasNext(iter)) { + hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); + sprintf(line, "%s = %s\n", hashMapEntry_getKey(entry), hashMapEntry_getValue(entry)); + out(line); + } + +// objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS); +// sprintf(line, "ObjectClass = %s\n", objectClass); if ((j + 1) < arrayList_size(refs)) { out("----\n"); } @@ -187,3 +204,105 @@ celix_status_t inspectCommand_printExpor return status; } + +celix_status_t inspectCommand_printImportedServices(command_pt command, array_list_pt ids, void (*out)(char *), void (*err)(char *)) { + celix_status_t status = CELIX_SUCCESS; + array_list_pt bundles = NULL; + + if (arrayList_isEmpty(ids)) { + celix_status_t status = bundleContext_getBundles(command->bundleContext, &bundles); + } else { + apr_pool_t *pool = NULL; + unsigned int i; + + bundleContext_getMemoryPool(command->bundleContext, &pool); + arrayList_create(&bundles); + for (i = 0; i < arrayList_size(ids); i++) { + char *idStr = (char *) arrayList_get(ids, i); + long id = atol(idStr); + bundle_pt b = NULL; + celix_status_t st = bundleContext_getBundleById(command->bundleContext, id, &b); + if (st == CELIX_SUCCESS) { + arrayList_add(bundles, b); + } else { + char line[256]; + sprintf(line, "INSPECT: Invalid bundle ID: %ld\n", id); + out(line); + } + } + } + + if (status == CELIX_SUCCESS) { + unsigned int i = 0; + for (i = 0; i < arrayList_size(bundles); i++) { + bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i); + + if (i > 0) { + out("\n"); + } + + if (bundle != NULL) { + apr_pool_t *pool; + array_list_pt refs = NULL; + + bundleContext_getMemoryPool(command->bundleContext, &pool); + if (bundle_getServicesInUse(bundle, &refs) == CELIX_SUCCESS) { + char line[256]; + module_pt module = NULL; + char * name = NULL; + status = bundle_getCurrentModule(bundle, &module); + if (status == CELIX_SUCCESS) { + status = module_getSymbolicName(module, &name); + if (status == CELIX_SUCCESS) { + sprintf(line, "%s requires services:\n", name); + out(line); + out("==============\n"); + + if (refs == NULL || arrayList_size(refs) == 0) { + out("Nothing\n"); + } else { + unsigned int j = 0; + for (j = 0; j < arrayList_size(refs); j++) { + service_reference_pt ref = (service_reference_pt) arrayList_get(refs, j); + service_registration_pt reg = NULL; + properties_pt props = NULL; + char line[256]; + bundle_pt usedBundle = NULL; + module_pt usedModule = NULL; + char *usedSymbolicName = NULL; + long usedBundleId; + + serviceReference_getBundle(ref, &usedBundle); + bundle_getBundleId(usedBundle, &usedBundleId); + bundle_getCurrentModule(usedBundle, &usedModule); + module_getSymbolicName(usedModule, &usedSymbolicName); + + sprintf(line, "%s [%ld]\n", usedSymbolicName, usedBundleId); + out(line); + + serviceReference_getServiceRegistration(ref, ®); + serviceRegistration_getProperties(reg, &props); + hash_map_iterator_pt iter = hashMapIterator_create(props); + while (hashMapIterator_hasNext(iter)) { + hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); + sprintf(line, "%s = %s\n", hashMapEntry_getKey(entry), hashMapEntry_getValue(entry)); + out(line); + } + +// objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS); +// sprintf(line, "ObjectClass = %s\n", objectClass); + if ((j + 1) < arrayList_size(refs)) { + out("----\n"); + } + } + } + } + } + } + } + } + } + + + return status; +}