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 2017/11/21 20:08:04 UTC
[07/19] celix git commit: CELIX-417: Refactor for CMake usage in RSA,
PSA and Docker. mostly trying to identify the api and common libraries
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/export_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/export_registration_impl.c b/remote_services/remote_service_admin_common/src/export_registration_impl.c
new file mode 100644
index 0000000..1c684e7
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/export_registration_impl.c
@@ -0,0 +1,257 @@
+/**
+ *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.
+ */
+/*
+ * export_registration_impl.c
+ *
+ * \date Oct 6, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "constants.h"
+
+#include "celix_errno.h"
+
+#include "export_registration_impl.h"
+#include "remote_service_admin_impl.h"
+
+
+struct export_reference {
+ endpoint_description_pt endpoint;
+ service_reference_pt reference;
+};
+
+celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *service);
+celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service);
+celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service);
+
+celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker);
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration = calloc(1, sizeof(**registration));
+ if (!*registration) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration)->context = context;
+ (*registration)->closed = false;
+ (*registration)->endpointDescription = endpoint;
+ (*registration)->reference = reference;
+ (*registration)->rsa = rsa;
+ (*registration)->tracker = NULL;
+ (*registration)->endpoint = NULL;
+ (*registration)->endpointTracker = NULL;
+ (*registration)->exportReference = NULL;
+ (*registration)->bundle = NULL;
+ (*registration)->loghelper = helper;
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_destroy(export_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ remoteServiceAdmin_destroyEndpointDescription(&(*registration)->endpointDescription);
+ free(*registration);
+
+ return status;
+}
+
+celix_status_t exportRegistration_startTracking(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->endpointTracker == NULL) {
+ status = exportRegistration_createEndpointTracker(registration, ®istration->endpointTracker);
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_open(registration->endpointTracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_stopTracking(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->endpointTracker != NULL) {
+ status = serviceTracker_close(registration->endpointTracker);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close endpoint tracker");
+ }
+ else {
+ status = serviceTracker_destroy(registration->endpointTracker);
+ }
+ }
+ if (registration->tracker != NULL) {
+ status = serviceTracker_close(registration->tracker);
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(registration->loghelper, OSGI_LOGSERVICE_ERROR, "EXPORT_REGISTRATION: Could not close service tracker");
+ }
+ else {
+ status = serviceTracker_destroy(registration->tracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_createEndpointTracker(export_registration_pt registration, service_tracker_pt *tracker) {
+ celix_status_t status;
+
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(registration, exportRegistration_endpointAdding,
+ exportRegistration_endpointAdded, exportRegistration_endpointModified, exportRegistration_endpointRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ char filter[512];
+
+ snprintf(filter, 512, "(&(%s=%s)(remote.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_ENDPOINT, registration->endpointDescription->service);
+ status = serviceTracker_createWithFilter(registration->context, filter, customizer, tracker);
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service) {
+ celix_status_t status;
+ export_registration_pt registration = handle;
+
+ status = bundleContext_getService(registration->context, reference, service);
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *endpoint_service) {
+ celix_status_t status = CELIX_SUCCESS;
+ export_registration_pt registration = handle;
+
+ remote_endpoint_service_pt endpoint = endpoint_service;
+ if (registration->endpoint == NULL) {
+ registration->endpoint = endpoint;
+ void *service = NULL;
+ status = bundleContext_getService(registration->context, registration->reference, &service);
+ if (status == CELIX_SUCCESS) {
+ endpoint->setService(endpoint->endpoint, service);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ return status;
+}
+
+celix_status_t exportRegistration_endpointRemoved(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ export_registration_pt registration = handle;
+
+ remote_endpoint_service_pt endpoint = service;
+ if (registration->endpoint != NULL) {
+ endpoint->setService(endpoint->endpoint, NULL);
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_open(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ const char *bundleStore = NULL;
+
+ bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+
+ if (bundleStore == NULL) {
+ bundleStore = DEFAULT_BUNDLE_STORE;
+ }
+ char name[256];
+
+ snprintf(name, 256, "%s/%s_endpoint.zip", bundleStore, registration->endpointDescription->service);
+
+ status = bundleContext_installBundle(registration->context, name, ®istration->bundle);
+ if (status == CELIX_SUCCESS) {
+ status = bundle_start(registration->bundle);
+ if (status == CELIX_SUCCESS) {
+ }
+ }
+
+ return status;
+}
+
+celix_status_t exportRegistration_close(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ exportRegistration_stopTracking(registration);
+
+ bundle_uninstall(registration->bundle);
+
+
+ return status;
+}
+
+celix_status_t exportRegistration_getException(export_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ registration->exportReference = calloc(1, sizeof(*registration->exportReference));
+
+ if (registration->exportReference == NULL) {
+ status = CELIX_ENOMEM;
+ } else {
+ registration->exportReference->endpoint = registration->endpointDescription;
+ registration->exportReference->reference = registration->reference;
+ }
+
+ *reference = registration->exportReference;
+
+ return status;
+}
+
+celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ registration->endpointDescription = endpointDescription;
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *endpoint = reference->endpoint;
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ *service = reference->reference;
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/export_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/export_registration_impl.h b/remote_services/remote_service_admin_common/src/export_registration_impl.h
new file mode 100644
index 0000000..bb276f9
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/export_registration_impl.h
@@ -0,0 +1,61 @@
+/**
+ *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.
+ */
+/*
+ * export_registration_impl.h
+ *
+ * \date Oct 6, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef EXPORT_REGISTRATION_IMPL_H_
+#define EXPORT_REGISTRATION_IMPL_H_
+
+#include "remote_service_admin.h"
+#include "remote_endpoint.h"
+#include "service_tracker.h"
+#include "log_helper.h"
+
+struct export_registration {
+ bundle_context_pt context;
+ remote_service_admin_pt rsa;
+ endpoint_description_pt endpointDescription;
+ service_reference_pt reference;
+ log_helper_pt loghelper;
+
+ service_tracker_pt tracker;
+ service_tracker_pt endpointTracker;
+
+ remote_endpoint_service_pt endpoint;
+
+ export_reference_pt exportReference;
+ bundle_pt bundle;
+
+ bool closed;
+};
+
+celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration);
+celix_status_t exportRegistration_destroy(export_registration_pt *registration);
+celix_status_t exportRegistration_open(export_registration_pt registration);
+
+celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription);
+celix_status_t exportRegistration_startTracking(export_registration_pt registration);
+celix_status_t exportRegistration_stopTracking(export_registration_pt registration);
+
+#endif /* EXPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/import_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/import_registration_impl.c b/remote_services/remote_service_admin_common/src/import_registration_impl.c
new file mode 100644
index 0000000..9a84327
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/import_registration_impl.c
@@ -0,0 +1,274 @@
+/**
+ *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.
+ */
+/*
+ * import_registration_impl.c
+ *
+ * \date Oct 14, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <constants.h>
+
+#include "celix_errno.h"
+
+#include "import_registration_impl.h"
+#include "remote_service_admin_impl.h"
+
+struct import_reference {
+ endpoint_description_pt endpoint;
+ service_reference_pt reference;
+};
+
+
+
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service);
+
+celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration = calloc(1, sizeof(**registration));
+ if (!*registration) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration)->context = context;
+ (*registration)->closed = false;
+ (*registration)->endpointDescription = endpoint;
+ (*registration)->rsa = rsa;
+ (*registration)->sendToCallback = sendToCallback;
+ (*registration)->reference = NULL;
+ (*registration)->importReference = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t importRegistration_destroy(import_registration_pt registration)
+{
+ free(registration);
+
+ return CELIX_SUCCESS;
+}
+
+
+celix_status_t importRegistrationFactory_create(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *registration_factory = calloc(1, sizeof(**registration_factory));
+ if (!*registration_factory) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*registration_factory)->serviceName = strdup(serviceName);
+ (*registration_factory)->context = context;
+ (*registration_factory)->bundle = NULL;
+ (*registration_factory)->loghelper = helper;
+
+ arrayList_create(&(*registration_factory)->registrations);
+ }
+
+ return status;
+}
+
+
+
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (*registration_factory != NULL)
+ {
+ free((*registration_factory)->serviceName);
+ arrayList_destroy((*registration_factory)->registrations);
+
+ serviceTracker_destroy((*registration_factory)->proxyFactoryTracker);
+ free(*registration_factory);
+
+ *registration_factory = NULL;
+ }
+
+
+ return status;
+}
+
+
+celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory)
+{
+ celix_status_t status;
+
+ const char *bundleStore = NULL;
+ bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+
+ if (bundleStore == NULL) {
+ bundleStore = DEFAULT_BUNDLE_STORE;
+ }
+
+ char name[256];
+ snprintf(name, 256, "%s/%s_proxy.zip", bundleStore, registration_factory->serviceName);
+
+ status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle);
+
+ if (status == CELIX_SUCCESS) {
+ status = bundle_start(registration_factory->bundle);
+ if (status == CELIX_SUCCESS) {
+ logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_INFO, "%s successfully started.", name);
+ }
+ }
+ else {
+ logHelper_log(registration_factory->loghelper, OSGI_LOGSERVICE_ERROR, "%s could not be installed.", name);
+ }
+
+ return status;
+}
+
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory)
+{
+ celix_status_t status = CELIX_SUCCESS;
+
+
+ if (registration_factory->proxyFactoryTracker != NULL) {
+ serviceTracker_close(registration_factory->proxyFactoryTracker);
+ }
+
+ if (registration_factory->bundle != NULL) {
+ bundle_uninstall(registration_factory->bundle);
+ }
+
+ return status;
+}
+
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) {
+ celix_status_t status;
+ service_tracker_customizer_pt customizer = NULL;
+
+ status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer);
+
+ if (status == CELIX_SUCCESS) {
+ char filter[512];
+
+ snprintf(filter, 512, "(&(%s=%s)(proxy.interface=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, (char*) OSGI_RSA_REMOTE_PROXY_FACTORY, registration_factory->serviceName);
+ status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker);
+
+ if (status == CELIX_SUCCESS)
+ {
+ serviceTracker_open(*tracker);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service) {
+ celix_status_t status = CELIX_SUCCESS;
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+
+ bundleContext_getService(registration_factory->context, reference, service);
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+ registration_factory->trackedFactory = (remote_proxy_factory_service_pt) service;
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ return status;
+}
+
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+ registration_factory->trackedFactory = NULL;
+
+ return status;
+}
+
+
+
+celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory)
+{
+ celix_status_t status;
+
+ if ( (status = importRegistrationFactory_create(helper, serviceName, context, registration_factory)) == CELIX_SUCCESS) {
+ // starting the proxy tracker first allows us to pick up already available proxy factories
+ importRegistration_createProxyFactoryTracker(*registration_factory, &((*registration_factory)->proxyFactoryTracker));
+ logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_INFO, "remoteServiceAdmin_importService: new registration_factory added for %s at %p", serviceName, (*registration_factory)->proxyFactoryTracker);
+
+ // check whether factory is available
+ if (((*registration_factory)->trackedFactory == NULL) && ((status = importRegistrationFactory_open(*registration_factory)) != CELIX_SUCCESS)) {
+ logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_ERROR, "remoteServiceAdmin_importService: cannot open registration_factory for %s.", serviceName);
+
+ importRegistrationFactory_close(*registration_factory);
+ importRegistrationFactory_destroy(registration_factory);
+ }
+ }
+
+ return status;
+}
+
+
+
+
+celix_status_t importRegistration_getException(import_registration_pt registration) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (registration->importReference == NULL) {
+ registration->importReference = calloc(1, sizeof(*registration->importReference));
+ if (registration->importReference == NULL) {
+ status = CELIX_ENOMEM;
+ } else {
+ registration->importReference->endpoint = registration->endpointDescription;
+ registration->importReference->reference = registration->reference;
+ }
+ }
+
+ *reference = registration->importReference;
+
+ return status;
+}
+
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t importReference_getImportedService(import_reference_pt reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/import_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/import_registration_impl.h b/remote_services/remote_service_admin_common/src/import_registration_impl.h
new file mode 100644
index 0000000..7aa397f
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/import_registration_impl.h
@@ -0,0 +1,81 @@
+/**
+ *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.
+ */
+/*
+ * import_registration_impl.h
+ *
+ * \date Oct 14, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef IMPORT_REGISTRATION_IMPL_H_
+#define IMPORT_REGISTRATION_IMPL_H_
+
+#include "remote_service_admin.h"
+#include "remote_proxy.h"
+#include "service_tracker.h"
+#include "log_helper.h"
+
+struct import_registration {
+ bundle_context_pt context;
+ endpoint_description_pt endpointDescription;
+
+ service_reference_pt reference;
+ import_reference_pt importReference;
+
+ remote_service_admin_pt rsa;
+ sendToHandle sendToCallback;
+
+ bool closed;
+};
+
+
+
+struct import_registration_factory
+{
+ char* serviceName;
+ log_helper_pt loghelper;
+ remote_proxy_factory_service_pt trackedFactory;
+ service_tracker_pt proxyFactoryTracker;
+ bundle_context_pt context;
+ array_list_pt registrations;
+ bundle_pt bundle;
+};
+
+
+celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle callback, bundle_context_pt context, import_registration_pt *registration);
+celix_status_t importRegistration_destroy(import_registration_pt registration);
+
+celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription);
+celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler);
+celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback);
+
+celix_status_t importRegistration_getException(import_registration_pt registration);
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker);
+
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory);
+//celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory);
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory);
+celix_status_t importRegistrationFactory_install(log_helper_pt helper, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory);
+
+
+
+#endif /* IMPORT_REGISTRATION_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c b/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
new file mode 100644
index 0000000..9f996d6
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/remote_proxy_factory_impl.c
@@ -0,0 +1,252 @@
+/**
+ * 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.
+ */
+
+/*
+ * remote_proxy_factory_impl.c
+ *
+ * \date 22 Dec 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "remote_proxy.h"
+
+typedef struct proxy_instance {
+ service_registration_pt registration_ptr;
+ void *service;
+ properties_pt properties;
+} *proxy_instance_pt;
+
+static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback);
+static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription);
+
+celix_status_t remoteProxyFactory_create(bundle_context_pt context, char *service, void *handle,
+ createProxyService create, destroyProxyService destroy,
+ remote_proxy_factory_pt *remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *remote_proxy_factory_ptr = calloc(1, sizeof(**remote_proxy_factory_ptr));
+ if (!*remote_proxy_factory_ptr) {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ (*remote_proxy_factory_ptr)->context_ptr = context;
+ (*remote_proxy_factory_ptr)->service = strdup(service);
+
+ (*remote_proxy_factory_ptr)->remote_proxy_factory_service_ptr = NULL;
+ (*remote_proxy_factory_ptr)->properties = NULL;
+ (*remote_proxy_factory_ptr)->registration = NULL;
+
+ (*remote_proxy_factory_ptr)->proxy_instances = hashMap_create(NULL, NULL, NULL, NULL);
+
+ (*remote_proxy_factory_ptr)->handle = handle;
+
+ (*remote_proxy_factory_ptr)->create_proxy_service_ptr = create;
+ (*remote_proxy_factory_ptr)->destroy_proxy_service_ptr = destroy;
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_destroy(remote_proxy_factory_pt *remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!*remote_proxy_factory_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if ((*remote_proxy_factory_ptr)->proxy_instances) {
+ hashMap_destroy((*remote_proxy_factory_ptr)->proxy_instances, false, false);
+ (*remote_proxy_factory_ptr)->proxy_instances = NULL;
+ }
+ if ((*remote_proxy_factory_ptr)->service) {
+ free((*remote_proxy_factory_ptr)->service);
+ (*remote_proxy_factory_ptr)->service = NULL;
+ }
+ free(*remote_proxy_factory_ptr);
+ *remote_proxy_factory_ptr = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_register(remote_proxy_factory_pt remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr = calloc(1, sizeof(*remote_proxy_factory_ptr->remote_proxy_factory_service_ptr));
+ if (!remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->factory = remote_proxy_factory_ptr;
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->registerProxyService = remoteProxyFactory_registerProxyService;
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr->unregisterProxyService = remoteProxyFactory_unregisterProxyService;
+
+ remote_proxy_factory_ptr->properties = properties_create();
+ if (!remote_proxy_factory_ptr->properties) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ properties_set(remote_proxy_factory_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, OSGI_RSA_REMOTE_PROXY_FACTORY,
+ remote_proxy_factory_ptr->remote_proxy_factory_service_ptr, remote_proxy_factory_ptr->properties, &remote_proxy_factory_ptr->registration);
+ }
+
+ return status;
+}
+
+celix_status_t remoteProxyFactory_unregister(remote_proxy_factory_pt remote_proxy_factory_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!remote_proxy_factory_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ // #TODO Remove proxy registrations
+ if (status == CELIX_SUCCESS) {
+
+ hash_map_iterator_pt iter = hashMapIterator_create(remote_proxy_factory_ptr->proxy_instances);
+ while(hashMapIterator_hasNext(iter)){
+ proxy_instance_pt proxy_instance_ptr = (proxy_instance_pt)hashMapIterator_nextValue(iter);
+
+ if (proxy_instance_ptr->service) {
+ remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
+ }
+ free(proxy_instance_ptr);
+ }
+ hashMapIterator_destroy(iter);
+
+ if (remote_proxy_factory_ptr->registration) {
+ status = serviceRegistration_unregister(remote_proxy_factory_ptr->registration);
+ remote_proxy_factory_ptr->properties = NULL;
+ }
+ if (remote_proxy_factory_ptr->properties) {
+ properties_destroy(remote_proxy_factory_ptr->properties);
+ }
+ if (remote_proxy_factory_ptr->remote_proxy_factory_service_ptr) {
+ free(remote_proxy_factory_ptr->remote_proxy_factory_service_ptr);
+ }
+ }
+
+ return status;
+}
+
+
+static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback) {
+ celix_status_t status = CELIX_SUCCESS;
+ proxy_instance_pt proxy_instance_ptr = NULL;
+
+ if (!remote_proxy_factory_ptr || !remote_proxy_factory_ptr->create_proxy_service_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr = calloc(1, sizeof(*proxy_instance_ptr));
+ if (!proxy_instance_ptr) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr->properties = properties_create();
+ if (!proxy_instance_ptr->properties) {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = remote_proxy_factory_ptr->create_proxy_service_ptr(remote_proxy_factory_ptr->handle, endpointDescription, rsa, sendToCallback, proxy_instance_ptr->properties, &proxy_instance_ptr->service);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
+
+ hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ char *key = hashMapEntry_getKey(entry);
+ char *value = hashMapEntry_getValue(entry);
+
+ properties_set(proxy_instance_ptr->properties, key, value);
+ }
+ hashMapIterator_destroy(iter);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_registerService(remote_proxy_factory_ptr->context_ptr, remote_proxy_factory_ptr->service, proxy_instance_ptr->service, proxy_instance_ptr->properties, &proxy_instance_ptr->registration_ptr);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ hashMap_put(remote_proxy_factory_ptr->proxy_instances, endpointDescription, proxy_instance_ptr);
+ }
+
+ if(status!=CELIX_SUCCESS){
+ if(proxy_instance_ptr != NULL){
+ if(proxy_instance_ptr->properties != NULL){
+ properties_destroy(proxy_instance_ptr->properties);
+ }
+ free(proxy_instance_ptr);
+ }
+ }
+
+ return status;
+}
+
+static celix_status_t remoteProxyFactory_unregisterProxyService(remote_proxy_factory_pt remote_proxy_factory_ptr, endpoint_description_pt endpointDescription) {
+ celix_status_t status = CELIX_SUCCESS;
+ proxy_instance_pt proxy_instance_ptr = NULL;
+
+ if (!remote_proxy_factory_ptr || !endpointDescription || !remote_proxy_factory_ptr->proxy_instances || !remote_proxy_factory_ptr->handle) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ proxy_instance_ptr = hashMap_remove(remote_proxy_factory_ptr->proxy_instances, endpointDescription);
+ if (proxy_instance_ptr == NULL) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (proxy_instance_ptr->registration_ptr) {
+ status = serviceRegistration_unregister(proxy_instance_ptr->registration_ptr);
+ proxy_instance_ptr->properties = NULL;
+ }
+ if (proxy_instance_ptr->service) {
+ status = remote_proxy_factory_ptr->destroy_proxy_service_ptr(remote_proxy_factory_ptr->handle, proxy_instance_ptr->service);
+ }
+ if (proxy_instance_ptr->properties) {
+ properties_destroy(proxy_instance_ptr->properties);
+ }
+ free(proxy_instance_ptr);
+ }
+
+ return status;
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h b/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h
new file mode 100644
index 0000000..e8a5e1f
--- /dev/null
+++ b/remote_services/remote_service_admin_common/src/remote_service_admin_impl.h
@@ -0,0 +1,49 @@
+/**
+ *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.
+ */
+/*
+ * remote_service_admin_impl.h
+ *
+ * \date Dec 5, 2013
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef REMOTE_SERVICE_ADMIN_IMPL_H_
+#define REMOTE_SERVICE_ADMIN_IMPL_H_
+
+#include "remote_service_admin.h"
+
+#define BUNDLE_STORE_PROPERTY_NAME "ENDPOINTS"
+#define DEFAULT_BUNDLE_STORE "endpoints"
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
+
+celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char **reply, int* replyStatus);
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
+
+#endif /* REMOTE_SERVICE_ADMIN_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/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 01ab9bd..3efabf8 100644
--- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
@@ -15,33 +15,20 @@
# specific language governing permissions and limitations
# under the License.
-include_directories(
- private/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/log_service/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/include
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/include
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include
- ${PROJECT_SOURCE_DIR}/dfi/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
-)
-
add_bundle(remote_service_admin_dfi
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_remote_service_admin_dfi"
NAME "Apache Celix Remote Service Admin Dynamic Function Interface (DFI)"
SOURCES
- private/src/remote_service_admin_dfi.c
- 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
-
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
+ src/remote_service_admin_dfi.c
+ src/remote_service_admin_activator.c
+ src/export_registration_dfi.c
+ src/import_registration_dfi.c
+ src/dfi_utils.c
)
-target_link_libraries(remote_service_admin_dfi PRIVATE Celix::dfi Celix::log_helper ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
+target_include_directories(remote_service_admin_dfi PRIVATE src)
+target_link_libraries(remote_service_admin_dfi PRIVATE
+ Celix::dfi Celix::log_helper remote_service_admin_common
+ ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
install_bundle(remote_service_admin_dfi)
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/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
deleted file mode 100644
index cec8aa1..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/dfi_utils.h
+++ /dev/null
@@ -1,30 +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.
- */
-#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
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
deleted file mode 100644
index 93f37ba..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
+++ /dev/null
@@ -1,38 +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.
- */
-
-#ifndef CELIX_EXPORT_REGISTRATION_DFI_H
-#define CELIX_EXPORT_REGISTRATION_DFI_H
-
-
-#include "export_registration.h"
-#include "log_helper.h"
-#include "endpoint_description.h"
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *registration);
-celix_status_t exportRegistration_close(export_registration_pt registration);
-void exportRegistration_destroy(export_registration_pt registration);
-
-celix_status_t exportRegistration_start(export_registration_pt registration);
-celix_status_t exportRegistration_stop(export_registration_pt registration);
-
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **response, int *responseLength);
-
-
-#endif //CELIX_EXPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/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
deleted file mode 100644
index aac4bc7..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
+++ /dev/null
@@ -1,44 +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.
- */
-
-#ifndef CELIX_IMPORT_REGISTRATION_DFI_H
-#define CELIX_IMPORT_REGISTRATION_DFI_H
-
-#include "import_registration.h"
-#include "dfi_utils.h"
-
-#include <celix_errno.h>
-
-typedef void (*send_func_type)(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt description, const char *classObject, const char* serviceVersion,
- import_registration_pt *import);
-celix_status_t importRegistration_close(import_registration_pt import);
-void importRegistration_destroy(import_registration_pt import);
-
-celix_status_t importRegistration_setSendFn(import_registration_pt reg,
- send_func_type,
- void *handle);
-celix_status_t importRegistration_start(import_registration_pt import);
-celix_status_t importRegistration_stop(import_registration_pt import);
-
-celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
-celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
-
-#endif //CELIX_IMPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
deleted file mode 100644
index 8b282f1..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
+++ /dev/null
@@ -1,57 +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.
- */
-/*
- * remote_service_admin_http_impl.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-#define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-
-
-#include "bundle_context.h"
-#include "endpoint_description.h"
-
-//typedef struct remote_service_admin *remote_service_admin_pt;
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin);
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
-
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
-celix_status_t importReference_getImportedService(import_reference_pt reference);
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
-
-#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/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
deleted file mode 100644
index 1b1eb36..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/dfi_utils.c
+++ /dev/null
@@ -1,98 +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.
- */
-
-#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 pwd[1024];
- char path[1024];
- const char *extPath = NULL;
-
- status = bundleContext_getProperty(context, "CELIX_FRAMEWORK_EXTENDER_PATH", &extPath);
- if (status != CELIX_SUCCESS || extPath == NULL) {
- getcwd(pwd, sizeof(pwd));
- extPath = pwd;
- }
-
- 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[512];
- snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/%s", fileName);
-
- status = bundle_getEntry(bundle, 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/2a670f26/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
deleted file mode 100644
index b83b5a8..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ /dev/null
@@ -1,251 +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.
- */
-
-#include <jansson.h>
-#include <dyn_interface.h>
-#include <json_serializer.h>
-#include <remote_constants.h>
-#include <remote_service_admin.h>
-#include <service_tracker_customizer.h>
-#include <service_tracker.h>
-#include <json_rpc.h>
-#include "constants.h"
-#include "export_registration_dfi.h"
-#include "dfi_utils.h"
-
-struct export_reference {
- endpoint_description_pt endpoint; //owner
- service_reference_pt reference;
-};
-
-struct export_registration {
- bundle_context_pt context;
- struct export_reference exportReference;
- char *servId;
- dyn_interface_type *intf; //owner
- service_tracker_pt tracker;
-
- celix_thread_mutex_t mutex;
- void *service; //protected by mutex
-
- //TODO add tracker and lock
- bool closed;
-};
-
-static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service);
-static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service);
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
-
- const char *servId = NULL;
- status = serviceReference_getProperty(reference, "service.id", &servId);
- if (status != CELIX_SUCCESS) {
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Cannot find service.id for ref");
- }
-
- export_registration_pt reg = NULL;
- if (status == CELIX_SUCCESS) {
- reg = calloc(1, sizeof(*reg));
- if (reg == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
-
- if (status == CELIX_SUCCESS) {
- reg->context = context;
- reg->exportReference.endpoint = endpoint;
- reg->exportReference.reference = reference;
- reg->closed = false;
-
- celixThreadMutex_create(®->mutex, NULL);
- }
-
- const char *exports = NULL;
- CELIX_DO_IF(status, serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports));
-
- bundle_pt bundle = NULL;
- CELIX_DO_IF(status, serviceReference_getBundle(reference, &bundle));
-
- FILE *descriptor = NULL;
- if (status == CELIX_SUCCESS) {
- status = dfi_findDescriptor(context, bundle, exports, &descriptor);
- }
-
- 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) {
- int rc = dynInterface_parse(descriptor, ®->intf);
- fclose(descriptor);
- 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);
- const char *serviceVersion = properties_get(endpoint->properties,(char*) CELIX_FRAMEWORK_SERVICE_VERSION);
- if(serviceVersion!=NULL){
- if(strcmp(serviceVersion,intfVersion)!=0){
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Service version (%s) and interface version from the descriptor (%s) are not the same!",serviceVersion,intfVersion);
- }
- }
- else{
- properties_set(endpoint->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION, intfVersion);
- }
- }
- }
-
- if (status == CELIX_SUCCESS) {
- service_tracker_customizer_pt cust = NULL;
- status = serviceTrackerCustomizer_create(reg, NULL, (void *) exportRegistration_addServ, NULL,
- (void *) exportRegistration_removeServ, &cust);
- if (status == CELIX_SUCCESS) {
- char filter[32];
- snprintf(filter, 32, "(service.id=%s)", servId);
- status = serviceTracker_createWithFilter(reg->context, filter, cust, ®->tracker);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- *out = reg;
- } else {
- logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Error creating export registration");
- exportRegistration_destroy(reg);
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **responseOut, int *responseLength) {
- int status = CELIX_SUCCESS;
-
- //printf("calling for '%s'\n");
-
- *responseLength = -1;
- celixThreadMutex_lock(&export->mutex);
- status = jsonRpc_call(export->intf, export->service, data, responseOut);
- celixThreadMutex_unlock(&export->mutex);
-
- return status;
-}
-
-void exportRegistration_destroy(export_registration_pt reg) {
- if (reg != NULL) {
- if (reg->intf != NULL) {
- dyn_interface_type *intf = reg->intf;
- reg->intf = NULL;
- dynInterface_destroy(intf);
- }
-
- if (reg->exportReference.endpoint != NULL) {
- endpoint_description_pt ep = reg->exportReference.endpoint;
- reg->exportReference.endpoint = NULL;
- endpointDescription_destroy(ep);
- }
- if (reg->tracker != NULL) {
- serviceTracker_destroy(reg->tracker);
- }
- celixThreadMutex_destroy(®->mutex);
-
- free(reg);
- }
-}
-
-celix_status_t exportRegistration_start(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
-
- serviceTracker_open(reg->tracker);
- return status;
-}
-
-
-celix_status_t exportRegistration_stop(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- if (status == CELIX_SUCCESS) {
- status = bundleContext_ungetServiceReference(reg->context, reg->exportReference.reference);
- serviceTracker_close(reg->tracker);
- }
- return status;
-}
-
-static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service) {
- celixThreadMutex_lock(®->mutex);
- reg->service = service;
- celixThreadMutex_unlock(®->mutex);
-}
-
-static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service) {
- celixThreadMutex_lock(®->mutex);
- if (reg->service == service) {
- reg->service = NULL;
- }
- celixThreadMutex_unlock(®->mutex);
-}
-
-
-celix_status_t exportRegistration_close(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- exportRegistration_stop(reg);
- return status;
-}
-
-
-celix_status_t exportRegistration_getException(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- export_reference_pt ref = calloc(1, sizeof(*ref));
- if (ref != NULL) {
- ref->endpoint = registration->exportReference.endpoint;
- ref->reference = registration->exportReference.reference;
- } else {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- *out = ref;
- }
-
- return status;
-}
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
- celix_status_t status = CELIX_SUCCESS;
- *endpoint = reference->endpoint;
- return status;
-}
-
-celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *ref) {
- celix_status_t status = CELIX_SUCCESS;
- *ref = reference->reference;
- return status;
-}
-
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/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
deleted file mode 100644
index 0b8dcf7..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ /dev/null
@@ -1,402 +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.
- */
-
-#include <stdlib.h>
-#include <jansson.h>
-#include <json_rpc.h>
-#include <assert.h>
-#include "version.h"
-#include "json_serializer.h"
-#include "dyn_interface.h"
-#include "import_registration.h"
-#include "import_registration_dfi.h"
-
-struct import_registration {
- bundle_context_pt context;
- endpoint_description_pt endpoint; //TODO owner? -> free when destroyed
- const char *classObject; //NOTE owned by endpoint
- version_pt version;
-
- celix_thread_mutex_t mutex; //protects send & sendhandle
- send_func_type send;
- void *sendHandle;
-
- service_factory_pt factory;
- service_registration_pt factoryReg;
-
- hash_map_pt proxies; //key -> bundle, value -> service_proxy
- celix_thread_mutex_t proxiesMutex; //protects proxies
-};
-
-struct service_proxy {
- dyn_interface_type *intf;
- void *service;
- size_t count;
-};
-
-static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle,
- struct service_proxy **proxy);
-static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal);
-static void importRegistration_destroyProxy(struct service_proxy *proxy);
-static void importRegistration_clearProxies(import_registration_pt import);
-
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt endpoint, const char *classObject, const char* serviceVersion,
- import_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- import_registration_pt reg = calloc(1, sizeof(*reg));
-
- if (reg != NULL) {
- reg->factory = calloc(1, sizeof(*reg->factory));
- }
-
- if (reg != NULL && reg->factory != NULL) {
- reg->context = context;
- reg->endpoint = endpoint;
- reg->classObject = classObject;
- reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
-
- celixThreadMutex_create(®->mutex, NULL);
- celixThreadMutex_create(®->proxiesMutex, NULL);
- status = version_createVersionFromString((char*)serviceVersion,&(reg->version));
-
- reg->factory->handle = reg;
- reg->factory->getService = (void *)importRegistration_getService;
- reg->factory->ungetService = (void *)importRegistration_ungetService;
- } else {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- //printf("IMPORT REGISTRATION IS %p\n", reg);
- *out = reg;
- }
- else{
- importRegistration_destroy(reg);
- }
-
- return status;
-}
-
-
-celix_status_t importRegistration_setSendFn(import_registration_pt reg,
- send_func_type send,
- void *handle) {
- celixThreadMutex_lock(®->mutex);
- reg->send = send;
- reg->sendHandle = handle;
- celixThreadMutex_unlock(®->mutex);
-
- return CELIX_SUCCESS;
-}
-
-static void importRegistration_clearProxies(import_registration_pt import) {
- if (import != NULL) {
- pthread_mutex_lock(&import->proxiesMutex);
- if (import->proxies != NULL) {
- hash_map_iterator_pt iter = hashMapIterator_create(import->proxies);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- struct service_proxy *proxy = hashMapEntry_getValue(entry);
- importRegistration_destroyProxy(proxy);
- }
- hashMapIterator_destroy(iter);
- }
- pthread_mutex_unlock(&import->proxiesMutex);
- }
-}
-
-void importRegistration_destroy(import_registration_pt import) {
- if (import != NULL) {
- if (import->proxies != NULL) {
- hashMap_destroy(import->proxies, false, false);
- import->proxies = NULL;
- }
-
- pthread_mutex_destroy(&import->mutex);
- pthread_mutex_destroy(&import->proxiesMutex);
-
- if (import->factory != NULL) {
- free(import->factory);
- }
-
- if(import->version!=NULL){
- version_destroy(import->version);
- }
- free(import);
- }
-}
-
-celix_status_t importRegistration_start(import_registration_pt import) {
- celix_status_t status = CELIX_SUCCESS;
- if (import->factoryReg == NULL && import->factory != NULL) {
- properties_pt props = NULL;
- properties_copy(import->endpoint->properties, &props);
- status = bundleContext_registerServiceFactory(import->context, (char *)import->classObject, import->factory, props, &import->factoryReg);
- } else {
- status = CELIX_ILLEGAL_STATE;
- }
- return status;
-}
-
-celix_status_t importRegistration_stop(import_registration_pt import) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (import->factoryReg != NULL) {
- serviceRegistration_unregister(import->factoryReg);
- import->factoryReg = NULL;
- }
-
- importRegistration_clearProxies(import);
-
- return status;
-}
-
-
-celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
- celix_status_t status = CELIX_SUCCESS;
-
- /*
- module_pt module = NULL;
- char *name = NULL;
- bundle_getCurrentModule(bundle, &module);
- module_getSymbolicName(module, &name);
- printf("getting service for bundle '%s'\n", name);
- */
-
-
- pthread_mutex_lock(&import->proxiesMutex);
- struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
- if (proxy == NULL) {
- status = importRegistration_createProxy(import, bundle, &proxy);
- if (status == CELIX_SUCCESS) {
- hashMap_put(import->proxies, bundle, proxy);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy->count += 1;
- *out = proxy->service;
- }
- pthread_mutex_unlock(&import->proxiesMutex);
-
- return status;
-}
-
-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;
- FILE *descriptor = NULL;
-
- status = dfi_findDescriptor(import->context, bundle, import->classObject, &descriptor);
-
- if (status != CELIX_SUCCESS || descriptor == NULL) {
- //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);
- return CELIX_BUNDLE_EXCEPTION;
- }
-
- if (status == CELIX_SUCCESS) {
- int rc = dynInterface_parse(descriptor, &intf);
- fclose(descriptor);
- if (rc != 0 || intf==NULL) {
- return CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- /* Check if the imported service version is compatible with the one in the consumer descriptor */
- version_pt consumerVersion = NULL;
- bool isCompatible = false;
- dynInterface_getVersion(intf,&consumerVersion);
- version_isCompatible(consumerVersion,import->version,&isCompatible);
-
- if(!isCompatible){
- char* cVerString = NULL;
- char* pVerString = NULL;
- version_toString(consumerVersion,&cVerString);
- version_toString(import->version,&pVerString);
- printf("Service version mismatch: consumer has %s, provider has %s. NOT creating proxy.\n",cVerString,pVerString);
- dynInterface_destroy(intf);
- free(cVerString);
- free(pVerString);
- status = CELIX_SERVICE_EXCEPTION;
- }
-
- struct service_proxy *proxy = NULL;
- if (status == CELIX_SUCCESS) {
- proxy = calloc(1, sizeof(*proxy));
- if (proxy == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy->intf = intf;
- size_t count = dynInterface_nrOfMethods(proxy->intf);
- proxy->service = calloc(1 + count, sizeof(void *));
- if (proxy->service == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- void **serv = proxy->service;
- serv[0] = import;
-
- struct methods_head *list = NULL;
- dynInterface_methods(proxy->intf, &list);
- struct method_entry *entry = NULL;
- void (*fn)(void) = NULL;
- int index = 0;
- TAILQ_FOREACH(entry, list, entries) {
- int rc = dynFunction_createClosure(entry->dynFunc, importRegistration_proxyFunc, entry, &fn);
- serv[index + 1] = fn;
- index += 1;
-
- if (rc != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- break;
- }
- }
- }
-
- if (status == CELIX_SUCCESS) {
- *out = proxy;
- } else if (proxy != NULL) {
- if (proxy->intf != NULL) {
- dynInterface_destroy(proxy->intf);
- proxy->intf = NULL;
- }
- free(proxy->service);
- free(proxy);
- }
-
- return status;
-}
-
-static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal) {
- int status = CELIX_SUCCESS;
- struct method_entry *entry = userData;
- import_registration_pt import = *((void **)args[0]);
-
- if (import == NULL || import->send == NULL) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
-
- char *invokeRequest = NULL;
- if (status == CELIX_SUCCESS) {
- status = jsonRpc_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
- //printf("Need to send following json '%s'\n", invokeRequest);
- }
-
-
- if (status == CELIX_SUCCESS) {
- char *reply = NULL;
- int rc = 0;
- //printf("sending request\n");
- celixThreadMutex_lock(&import->mutex);
- if (import->send != NULL) {
- import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
- }
- celixThreadMutex_unlock(&import->mutex);
- //printf("request sended. got reply '%s' with status %i\n", reply, rc);
-
- if (rc == 0) {
- //fjprintf("Handling reply '%s'\n", reply);
- status = jsonRpc_handleReply(entry->dynFunc, reply, args);
- }
-
- *(int *) returnVal = rc;
-
- free(invokeRequest); //Allocated by json_dumps in jsonRpc_prepareInvokeRequest
- free(reply); //Allocated by json_dumps in remoteServiceAdmin_send through curl call
- }
-
- if (status != CELIX_SUCCESS) {
- //TODO log error
- }
-}
-
-celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
- celix_status_t status = CELIX_SUCCESS;
-
- assert(import != NULL);
- assert(import->proxies != NULL);
-
- pthread_mutex_lock(&import->proxiesMutex);
-
- struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
- if (proxy != NULL) {
- if (*out == proxy->service) {
- proxy->count -= 1;
- } else {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (proxy->count == 0) {
- hashMap_remove(import->proxies, bundle);
- importRegistration_destroyProxy(proxy);
- }
- }
-
- pthread_mutex_unlock(&import->proxiesMutex);
-
- return status;
-}
-
-static void importRegistration_destroyProxy(struct service_proxy *proxy) {
- if (proxy != NULL) {
- if (proxy->intf != NULL) {
- dynInterface_destroy(proxy->intf);
- }
- if (proxy->service != NULL) {
- free(proxy->service);
- }
- free(proxy);
- }
-}
-
-
-celix_status_t importRegistration_close(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- importRegistration_stop(registration);
- return status;
-}
-
-celix_status_t importRegistration_getException(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t importReference_getImportedService(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/2a670f26/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
deleted file mode 100644
index d4cc765..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
+++ /dev/null
@@ -1,124 +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.
- */
-/*
- * remote_service_admin_activator.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <remote_service_admin.h>
-
-#include "remote_service_admin_dfi.h"
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-
-#include "export_registration_dfi.h"
-#include "import_registration_dfi.h"
-
-struct activator {
- remote_service_admin_pt admin;
- remote_service_admin_service_pt adminService;
- service_registration_pt registration;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->admin = NULL;
- activator->registration = NULL;
-
- *userData = activator;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- remote_service_admin_service_pt remoteServiceAdmin = NULL;
-
- status = remoteServiceAdmin_create(context, &activator->admin);
- if (status == CELIX_SUCCESS) {
- remoteServiceAdmin = calloc(1, sizeof(*remoteServiceAdmin));
- if (!remoteServiceAdmin) {
- status = CELIX_ENOMEM;
- } else {
- remoteServiceAdmin->admin = activator->admin;
- remoteServiceAdmin->exportService = remoteServiceAdmin_exportService;
-
- remoteServiceAdmin->getExportedServices = remoteServiceAdmin_getExportedServices;
- remoteServiceAdmin->getImportedEndpoints = remoteServiceAdmin_getImportedEndpoints;
- remoteServiceAdmin->importService = remoteServiceAdmin_importService;
-
- remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
- remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
-
- remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
- remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
- remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
-
- remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
- remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
-
- remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
- remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
- remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
-
- status = bundleContext_registerService(context, OSGI_RSA_REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
- activator->adminService = remoteServiceAdmin;
- }
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceRegistration_unregister(activator->registration);
- activator->registration = NULL;
-
- remoteServiceAdmin_stop(activator->admin);
- remoteServiceAdmin_destroy(&activator->admin);
-
- free(activator->adminService);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- free(activator);
-
- return status;
-}
-
-