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 DC62619C2E for ; Mon, 11 Apr 2016 12:00:16 +0000 (UTC) Received: (qmail 22590 invoked by uid 500); 11 Apr 2016 12:00:11 -0000 Delivered-To: apmail-celix-commits-archive@celix.apache.org Received: (qmail 22515 invoked by uid 500); 11 Apr 2016 12:00:11 -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 21917 invoked by uid 99); 11 Apr 2016 12:00:11 -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; Mon, 11 Apr 2016 12:00:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2864ADFC6F; Mon, 11 Apr 2016 12:00:11 +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: Mon, 11 Apr 2016 12:00:43 -0000 Message-Id: <32b1743a855f48aca06ef5e0529838e6@git.apache.org> In-Reply-To: <3aba73c7f879491bb1a81d4d4f94f182@git.apache.org> References: <3aba73c7f879491bb1a81d4d4f94f182@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [34/50] celix git commit: CELIX-352: Added support for an framework extender path to load descriptors from the framework bundle. CELIX-352: Added support for an framework extender path to load descriptors from the framework bundle. Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/58f521f6 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/58f521f6 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/58f521f6 Branch: refs/heads/master Commit: 58f521f6a10973d3dd84c99538e165bcb2ec11ac Parents: 91ba2a1 Author: Pepijn Noltes Authored: Thu Feb 11 16:40:20 2016 +0100 Committer: Pepijn Noltes Committed: Thu Feb 11 16:40:20 2016 +0100 ---------------------------------------------------------------------- dependency_manager/CMakeLists.txt | 18 ++-- remote_services/remote_service_admin/README.md | 1 + .../remote_service_admin_dfi/rsa/CMakeLists.txt | 1 + .../rsa/private/include/dfi_utils.h | 30 ++++++ .../private/include/import_registration_dfi.h | 1 + .../rsa/private/src/dfi_utils.c | 100 +++++++++++++++++++ .../rsa/private/src/export_registration_dfi.c | 47 ++++----- .../rsa/private/src/import_registration_dfi.c | 29 ++---- 8 files changed, 170 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/dependency_manager/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt index 7a2761b..8c1f74f 100644 --- a/dependency_manager/CMakeLists.txt +++ b/dependency_manager/CMakeLists.txt @@ -49,15 +49,15 @@ if (DEPENDENCY_MANAGER) private/src/dm_dependency_manager_impl ) - #add_library(dependency_manager SHARED - # private/src/dm_activator_base - # private/src/dm_component_impl - # private/src/dm_service_dependency - # private/src/dm_event - # private/src/dm_dependency_manager_impl - #) - #set_target_properties(dependency_manager PROPERTIES SOVERSION 1) - #target_link_libraries(dependency_manager celix_framework -undefined dynamic_load) + add_library(dependency_manager_so SHARED + private/src/dm_activator_base + private/src/dm_component_impl + private/src/dm_service_dependency + private/src/dm_event + private/src/dm_dependency_manager_impl + ) + set_target_properties(dependency_manager_so PROPERTIES SOVERSION 1) + target_link_libraries(dependency_manager_so celix_framework) include_directories("public/include") include_directories("private/include") http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin/README.md ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin/README.md b/remote_services/remote_service_admin/README.md index a2ee5cd..c4bdebd 100644 --- a/remote_services/remote_service_admin/README.md +++ b/remote_services/remote_service_admin/README.md @@ -8,3 +8,4 @@ Note that this folder contains code commonly used by the RSA implementations and ###### Properties ENDPOINTS defines the relative directory where endpoints and proxys can be found (default: endpoints) + CELIX_FRAMEWORK_EXTENDER_PATH Used in RSA_DFI only. Can be used to define a path to use as an extender path point for the framework bundle. For normal bundles the bundle cache is used. http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt index 17a0c02..c1a2150 100644 --- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt +++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt @@ -36,6 +36,7 @@ add_bundle(remote_service_admin_dfi private/src/remote_service_admin_activator.c private/src/export_registration_dfi.c private/src/import_registration_dfi.c + private/src/dfi_utils.c ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h b/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h new file mode 100644 index 0000000..cec8aa1 --- /dev/null +++ b/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h @@ -0,0 +1,30 @@ +/** + *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. + */ +#ifndef DFI_UTILS_H_ +#define DFI_UTILS_H_ + +#include "bundle.h" +#include "bundle_context.h" +#include +#include "celix_errno.h" + + +celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out); + +#endif http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h index 53eb604..aac4bc7 100644 --- a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h +++ b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h @@ -21,6 +21,7 @@ #define CELIX_IMPORT_REGISTRATION_DFI_H #include "import_registration.h" +#include "dfi_utils.h" #include http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c b/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c new file mode 100644 index 0000000..e9888f9 --- /dev/null +++ b/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c @@ -0,0 +1,100 @@ +/** + *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. + */ + +#include "dfi_utils.h" +#include +#include + +static celix_status_t dfi_findFileForFramework(bundle_context_pt context, const char *fileName, FILE **out) { + celix_status_t status; + + char cwd[1024]; + char *extPath = NULL; + char path[1024]; + + status = bundleContext_getProperty(context, "CELIX_FRAMEWORK_EXTENDER_PATH", &extPath); + if (status != CELIX_SUCCESS || extPath == NULL) { + getcwd(cwd, sizeof(cwd)); + extPath = cwd; + if (extPath == NULL) { + status = CELIX_FILE_IO_EXCEPTION; + } + } + + snprintf(path, sizeof(path), "%s/%s", extPath, fileName); + + if (status == CELIX_SUCCESS) { + FILE *df = fopen(path, "r"); + if (df == NULL) { + status = CELIX_FILE_IO_EXCEPTION; + } else { + *out = df; + } + } + + return status; +} + +static celix_status_t dfi_findFileForBundle(bundle_pt bundle, const char *fileName, FILE **out) { + celix_status_t status; + + char *path = NULL; + char metaInfFileName[128]; + snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/%s", fileName); + + status = bundle_getEntry(bundle, (char *)fileName, &path); + + if (status != CELIX_SUCCESS || path == NULL) { + status = bundle_getEntry(bundle, metaInfFileName, &path); + } + + if (status == CELIX_SUCCESS && path != NULL) { + FILE *df = fopen(path, "r"); + if (df == NULL) { + status = CELIX_FILE_IO_EXCEPTION; + } else { + *out = df; + } + + free(path); + } + return status; +} + +celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out) { + celix_status_t status; + char fileName[128]; + + snprintf(fileName, 128, "%s.descriptor", name); + + long id; + status = bundle_getBundleId(bundle, &id); + + if (status == CELIX_SUCCESS) { + if (id == 0) { + //framework bundle + status = dfi_findFileForFramework(context, fileName, out); + } else { + //normal bundle + status = dfi_findFileForBundle(bundle, fileName, out); + } + } + + return status; +} http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c index 6eb4b86..a8d61ff 100644 --- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c +++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c @@ -27,6 +27,7 @@ #include #include "constants.h" #include "export_registration_dfi.h" +#include "dfi_utils.h" struct export_reference { endpoint_description_pt endpoint; //owner @@ -83,44 +84,30 @@ celix_status_t exportRegistration_create(log_helper_pt helper, service_reference bundle_pt bundle = NULL; CELIX_DO_IF(status, serviceReference_getBundle(reference, &bundle)); - - char *descriptorFile = NULL; + FILE *descriptor = NULL; if (status == CELIX_SUCCESS) { - char name[128]; - snprintf(name, 128, "%s.descriptor", exports); - status = bundle_getEntry(bundle, name, &descriptorFile); - logHelper_log(helper, OSGI_LOGSERVICE_DEBUG, "RSA: Found descriptor '%s' for %'s'.", descriptorFile, exports); + status = dfi_findDescriptor(context, bundle, exports, &descriptor); } - if (descriptorFile == NULL) { - logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "RSA: Cannot find descrriptor in bundle for service '%s'", exports); - status = CELIX_ILLEGAL_ARGUMENT; + if (status != CELIX_SUCCESS || descriptor == NULL) { + status = CELIX_BUNDLE_EXCEPTION; + logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", exports); } if (status == CELIX_SUCCESS) { - FILE *df = fopen(descriptorFile, "r"); - if (df != NULL) { - int rc = dynInterface_parse(df, ®->intf); - fclose(df); - if (rc != 0) { - status = CELIX_BUNDLE_EXCEPTION; - logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor."); - } - else{ - /* Add the interface version as a property in the properties_map */ - char* intfVersion = NULL; - dynInterface_getVersionString(reg->intf, &intfVersion); - properties_set(endpoint->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion); - } - } else { + int rc = dynInterface_parse(descriptor, ®->intf); + fclose(descriptor); + if (rc != 0) { status = CELIX_BUNDLE_EXCEPTION; - logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot open descriptor '%s'", descriptorFile); + logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor."); } - - free(descriptorFile); - } - - + else{ + /* Add the interface version as a property in the properties_map */ + char* intfVersion = NULL; + dynInterface_getVersionString(reg->intf, &intfVersion); + properties_set(endpoint->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion); + } + } if (status == CELIX_SUCCESS) { service_tracker_customizer_pt cust = NULL; http://git-wip-us.apache.org/repos/asf/celix/blob/58f521f6/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c index 16e27a5..ee1dbbf 100644 --- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c +++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c @@ -196,29 +196,22 @@ celix_status_t importRegistration_getService(import_registration_pt import, bund static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle, struct service_proxy **out) { celix_status_t status; dyn_interface_type* intf = NULL; - char *descriptorFile = NULL; - char name[128]; + FILE *descriptor = NULL; - snprintf(name, 128, "%s.descriptor", import->classObject); - status = bundle_getEntry(bundle, name, &descriptorFile); - if (descriptorFile == NULL) { - printf("Cannot find entry '%s'\n", name); - status = CELIX_ILLEGAL_ARGUMENT; - } else { - printf("Found descriptor at '%s'\n", descriptorFile); + status = dfi_findDescriptor(import->context, bundle, import->classObject, &descriptor); + + if (status != CELIX_SUCCESS || descriptor == NULL) { + status = CELIX_BUNDLE_EXCEPTION; + //TODO use log helper logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot find/open descriptor for '%s'", import->classObject); + fprintf(stderr, "RSA_DFI: Cannot find/open descriptor for '%s'", import->classObject); } if (status == CELIX_SUCCESS) { - FILE *df = fopen(descriptorFile, "r"); - if (df != NULL) { - int rc = dynInterface_parse(df, &intf); - fclose(df); - if (rc != 0) { - status = CELIX_BUNDLE_EXCEPTION; - } + int rc = dynInterface_parse(descriptor, &intf); + fclose(descriptor); + if (rc != 0) { + status = CELIX_BUNDLE_EXCEPTION; } - - free(descriptorFile); } /* Check if the imported service version is compatible with the one in the consumer descriptor */