Skip to content

Commit

Permalink
CELIX-352: Added support for an framework extender path to load descr…
Browse files Browse the repository at this point in the history
…iptors from the framework bundle.
  • Loading branch information
pnoltes committed Feb 11, 2016
1 parent 91ba2a1 commit 58f521f
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 57 deletions.
18 changes: 9 additions & 9 deletions dependency_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions remote_services/remote_service_admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include "celix_errno.h"


celix_status_t dfi_findDescriptor(bundle_context_pt context, bundle_pt bundle, const char *name, FILE **out);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define CELIX_IMPORT_REGISTRATION_DFI_H

#include "import_registration.h"
#include "dfi_utils.h"

#include <celix_errno.h>

Expand Down
100 changes: 100 additions & 0 deletions remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c
Original file line number Diff line number Diff line change
@@ -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 <stdlib.h>
#include <unistd.h>

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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <json_rpc.h>
#include "constants.h"
#include "export_registration_dfi.h"
#include "dfi_utils.h"

struct export_reference {
endpoint_description_pt endpoint; //owner
Expand Down Expand Up @@ -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, &reg->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, &reg->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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 58f521f

Please sign in to comment.