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 2018/05/27 18:52:39 UTC
[31/60] [abbrv] [partial] celix git commit: CELIX-424: Cleans up the
directory structure. Moves all libraries to the libs subdir and all bundles
to the bundles subdir
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_api/include/calculator_service.h
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_api/include/calculator_service.h b/bundles/remote_services/examples/calculator_api/include/calculator_service.h
new file mode 100644
index 0000000..8e2f0dc
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_api/include/calculator_service.h
@@ -0,0 +1,56 @@
+/**
+ *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.
+ */
+/*
+ * calculator_service.h
+ *
+ * \date Oct 5, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef CALCULATOR_SERVICE_H_
+#define CALCULATOR_SERVICE_H_
+
+#define CALCULATOR_SERVICE "org.apache.celix.calc.api.Calculator"
+#define CALCULATOR2_SERVICE "org.apache.celix.calc.api.Calculator2"
+
+
+typedef struct calculator *calculator_pt;
+
+typedef struct calculator_service *calculator_service_pt;
+
+/*
+ * The calculator service definition corresponds to the following Java interface:
+ *
+ * interface Calculator {
+ * double add(double a, double b);
+ * double sub(double a, double b);
+ * double sqrt(double a);
+ * }
+ */
+struct calculator_service {
+ calculator_pt calculator;
+ int (*add)(calculator_pt calculator, double a, double b, double *result);
+ int (*sub)(calculator_pt calculator, double a, double b, double *result);
+ int (*sqrt)(calculator_pt calculator, double a, double *result);
+};
+
+
+
+#endif /* CALCULATOR_SERVICE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor b/bundles/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
new file mode 100644
index 0000000..b784838
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
@@ -0,0 +1,11 @@
+:header
+type=interface
+name=calculator
+version=1.3.0
+:annotations
+classname=org.example.Calculator
+:types
+:methods
+add(DD)D=add(#am=handle;PDD#am=pre;*D)N
+sub(DD)D=sub(#am=handle;PDD#am=pre;*D)N
+sqrt(D)D=sqrt(#am=handle;PD#am=pre;*D)N
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_service/CMakeLists.txt b/bundles/remote_services/examples/calculator_service/CMakeLists.txt
new file mode 100644
index 0000000..e3e739a
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_service/CMakeLists.txt
@@ -0,0 +1,29 @@
+# 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.
+
+add_celix_bundle(calculator
+ SOURCES
+ src/calculator_impl
+ src/calculator_activator
+ SYMBOLIC_NAME "apache_celix_remoting_calculator_impl"
+ VERSION 0.0.1
+)
+target_include_directories(calculator PRIVATE src)
+target_link_libraries(calculator PRIVATE Celix::rsa_spi calculator_api)
+
+get_target_property(DESCR calculator_api INTERFACE_CALCULATOR_DESCRIPTOR)
+celix_bundle_files(calculator ${DESCR} DESTINATION .)
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_service/src/calculator_activator.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_service/src/calculator_activator.c b/bundles/remote_services/examples/calculator_service/src/calculator_activator.c
new file mode 100644
index 0000000..688a7b0
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_service/src/calculator_activator.c
@@ -0,0 +1,110 @@
+/**
+ *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.
+ */
+/*
+ * calculator_activator.c
+ *
+ * \date Oct 5, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+
+#include "calculator_impl.h"
+#include "remote_constants.h"
+
+struct activator {
+ calculator_pt calculator;
+ calculator_service_pt service;
+
+ service_registration_pt calculatorReg;
+ service_registration_pt calculatorReg2;
+};
+
+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->calculatorReg = NULL;
+ activator->calculatorReg2 = 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;
+ properties_pt properties = NULL;
+
+ status = calculator_create(&activator->calculator);
+ if (status == CELIX_SUCCESS) {
+ activator->service = calloc(1, sizeof(*activator->service));
+ if (!activator->service) {
+ status = CELIX_ENOMEM;
+ } else {
+ activator->service->calculator = activator->calculator;
+ activator->service->add = calculator_add;
+ activator->service->sub = calculator_sub;
+ activator->service->sqrt = calculator_sqrt;
+
+ properties = properties_create();
+ properties_set(properties, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR_SERVICE);
+
+ bundleContext_registerService(context, (char *) CALCULATOR_SERVICE, activator->service, properties, &activator->calculatorReg);
+
+ properties_pt properties2 = properties_create();
+ properties_set(properties2, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR2_SERVICE);
+ bundleContext_registerService(context, CALCULATOR2_SERVICE, activator->service, properties2, &activator->calculatorReg2);
+ }
+ }
+
+ 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->calculatorReg);
+ serviceRegistration_unregister(activator->calculatorReg2);
+
+ free(activator->service);
+
+ calculator_destroy(&activator->calculator);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ free(userData);
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_service/src/calculator_impl.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_service/src/calculator_impl.c b/bundles/remote_services/examples/calculator_service/src/calculator_impl.c
new file mode 100644
index 0000000..adccb52
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_service/src/calculator_impl.c
@@ -0,0 +1,79 @@
+/**
+ *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.
+ */
+/*
+ * calculator_impl.c
+ *
+ * \date Oct 5, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <math.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "calculator_impl.h"
+
+celix_status_t calculator_create(calculator_pt *calculator) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *calculator = calloc(1, sizeof(**calculator));
+ if (!*calculator) {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t calculator_destroy(calculator_pt *calculator) {
+ free(*calculator);
+ return CELIX_SUCCESS;
+}
+
+celix_status_t calculator_add(calculator_pt calculator, double a, double b, double *result) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *result = a + b;
+ printf("CALCULATOR: Add: %f + %f = %f\n", a, b, *result);
+
+ return status;
+}
+
+celix_status_t calculator_sub(calculator_pt calculator, double a, double b, double *result) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *result = a - b;
+ printf("CALCULATOR: Sub: %f + %f = %f\n", a, b, *result);
+
+ return status;
+}
+
+celix_status_t calculator_sqrt(calculator_pt calculator, double a, double *result) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (a > 0) {
+ *result = sqrt(a);
+ printf("CALCULATOR: Sqrt: %f = %f\n", a, *result);
+ } else {
+ printf("CALCULATOR: Sqrt: %f = ERR\n", a);
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_service/src/calculator_impl.h
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_service/src/calculator_impl.h b/bundles/remote_services/examples/calculator_service/src/calculator_impl.h
new file mode 100644
index 0000000..5e075e4
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_service/src/calculator_impl.h
@@ -0,0 +1,43 @@
+/**
+ *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.
+ */
+/*
+ * calculator_impl.h
+ *
+ * \date Oct 5, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef CALCULATOR_IMPL_H_
+#define CALCULATOR_IMPL_H_
+
+#include "celix_errno.h"
+
+#include "calculator_service.h"
+
+struct calculator {
+};
+
+celix_status_t calculator_create(calculator_pt *calcuator);
+celix_status_t calculator_destroy(calculator_pt *calcuator);
+celix_status_t calculator_add(calculator_pt calcuator, double a, double b, double *result);
+celix_status_t calculator_sub(calculator_pt calcuator, double a, double b, double *result);
+celix_status_t calculator_sqrt(calculator_pt calcuator, double a, double *result);
+
+#endif /* CALCULATOR_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/CMakeLists.txt b/bundles/remote_services/examples/calculator_shell/CMakeLists.txt
new file mode 100644
index 0000000..1eef035
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/CMakeLists.txt
@@ -0,0 +1,36 @@
+# 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.
+
+add_celix_bundle(calculator_shell
+ SOURCES
+ src/add_command
+ src/sub_command
+ src/sqrt_command
+ src/calculator_shell_activator
+ VERSION 0.0.1
+ SYMBOLIC_NAME "apache_celix_remoting_calculator_shell"
+)
+target_include_directories(calculator_shell PRIVATE src)
+target_link_libraries(calculator_shell PRIVATE Celix::shell_api calculator_api)
+
+celix_bundle_files(calculator_shell
+ ../calculator_api/include/org.apache.celix.calc.api.Calculator2.descriptor
+ #src/org.apache.celix.calc.api.Calculator2.descriptor ##Use this descriptor in case you want to try out versioning!
+ DESTINATION .
+)
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/src/add_command.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/src/add_command.c b/bundles/remote_services/examples/calculator_shell/src/add_command.c
new file mode 100644
index 0000000..b2520ae
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/src/add_command.c
@@ -0,0 +1,101 @@
+/**
+ *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.
+ */
+/*
+ * add_command.c
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <command.h>
+
+#include "array_list.h"
+#include "bundle_context.h"
+#include "add_command.h"
+#include "calculator_service.h"
+
+
+static celix_status_t addCommand_isNumeric(char *number, bool *ret);
+
+void addCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
+ celix_status_t status = CELIX_SUCCESS;
+ service_reference_pt calculatorService = NULL;
+
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "ADD: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "ADD: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+ }
+ }
+ if (status == CELIX_SUCCESS) {
+ char *token = line;
+ strtok_r(line, " ", &token);
+ char *aStr = strtok_r(NULL, " ", &token);
+ char *bStr = strtok_r(NULL, " ", &token);
+ bool aNumeric, bNumeric;
+ if (aStr != NULL && bStr != NULL) {
+ addCommand_isNumeric(aStr, &aNumeric);
+ addCommand_isNumeric(bStr, &bNumeric);
+ if(aNumeric && bNumeric){
+ calculator_service_pt calculator = NULL;
+ status = bundleContext_getService(context, calculatorService, (void *) &calculator);
+ if (status == CELIX_SUCCESS && calculator != NULL) {
+ double a = atof(aStr);
+ double b = atof(bStr);
+ double result = 0;
+ status = calculator->add(calculator->calculator, a, b, &result);
+ if (status == CELIX_SUCCESS) {
+ fprintf(out, "CALCULATOR_SHELL: Add: %f + %f = %f\n", a, b, result);
+ } else {
+ fprintf(err, "ADD: Unexpected exception in Calc service\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+ } else {
+ fprintf(err, "ADD: Requires 2 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "ADD: Requires 2 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+
+ //return status;
+}
+
+static celix_status_t addCommand_isNumeric(char *number, bool *ret) {
+ celix_status_t status = CELIX_SUCCESS;
+ *ret = true;
+ while(*number) {
+ if(!isdigit(*number) && *number != '.') {
+ *ret = false;
+ break;
+ }
+ number++;
+ }
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/src/add_command.h
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/src/add_command.h b/bundles/remote_services/examples/calculator_shell/src/add_command.h
new file mode 100644
index 0000000..58a7bda
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/src/add_command.h
@@ -0,0 +1,32 @@
+/**
+ *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.
+ */
+/*
+ * add_command.h
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ADD_COMMAND_H_
+#define ADD_COMMAND_H_
+
+void addCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
+
+#endif /* ADD_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/src/calculator_shell_activator.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/src/calculator_shell_activator.c b/bundles/remote_services/examples/calculator_shell/src/calculator_shell_activator.c
new file mode 100644
index 0000000..d6b561b
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/src/calculator_shell_activator.c
@@ -0,0 +1,125 @@
+/**
+ *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.
+ */
+/*
+ * calculator_shell_activator.c
+ *
+ * \date Oct 13, 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 <command.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+
+#include "add_command.h"
+#include "sub_command.h"
+#include "sqrt_command.h"
+
+struct activator {
+ service_registration_pt addCommand;
+ command_service_pt addCmd;
+ command_service_pt addCmdSrv;
+
+ service_registration_pt subCommand;
+ command_service_pt subCmd;
+ command_service_pt subCmdSrv;
+
+ service_registration_pt sqrtCommand;
+ command_service_pt sqrtCmd;
+ command_service_pt sqrtCmdSrv;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ if (status == CELIX_SUCCESS) {
+ *userData = calloc(1, sizeof(struct activator));
+ if (!*userData) {
+ status = CELIX_ENOMEM;
+ } else {
+ ((struct activator *) (*userData))->addCommand = NULL;
+ ((struct activator *) (*userData))->subCommand = NULL;
+ ((struct activator *) (*userData))->sqrtCommand = NULL;
+
+ ((struct activator *) (*userData))->addCmd = NULL;
+ ((struct activator *) (*userData))->subCmd = NULL;
+ ((struct activator *) (*userData))->sqrtCmd = NULL;
+
+ ((struct activator *) (*userData))->addCmdSrv = NULL;
+ ((struct activator *) (*userData))->subCmdSrv = NULL;
+ ((struct activator *) (*userData))->sqrtCmdSrv = NULL;
+ }
+ }
+
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct activator * activator = (struct activator *) userData;
+
+ activator->addCmdSrv = calloc(1, sizeof(*activator->addCmdSrv));
+ activator->addCmdSrv->handle = context;
+ activator->addCmdSrv->executeCommand = (void *)addCommand_execute;
+ properties_pt props = properties_create();
+ properties_set(props, OSGI_SHELL_COMMAND_NAME, "add");
+ bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->addCmdSrv, props, &activator->addCommand);
+
+
+ activator->sqrtCmdSrv = calloc(1, sizeof(*activator->sqrtCmdSrv));
+ activator->sqrtCmdSrv->handle = context;
+ activator->sqrtCmdSrv->executeCommand = (void *)sqrtCommand_execute;
+ props = properties_create();
+ properties_set(props, OSGI_SHELL_COMMAND_NAME, "sqrt");
+ bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->sqrtCmdSrv, props, &activator->sqrtCommand);
+
+ activator->subCmdSrv = calloc(1, sizeof(*activator->subCmdSrv));
+ activator->subCmdSrv->handle = context;
+ activator->subCmdSrv->executeCommand = (void *)subCommand_execute;
+ props = properties_create();
+ properties_set(props, OSGI_SHELL_COMMAND_NAME, "sub");
+ bundleContext_registerService(context, (char *)OSGI_SHELL_COMMAND_SERVICE_NAME, activator->subCmdSrv, props, &activator->subCommand);
+
+ return status;
+}
+
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator * activator = (struct activator *) userData;
+ serviceRegistration_unregister(activator->addCommand);
+ serviceRegistration_unregister(activator->subCommand);
+ serviceRegistration_unregister(activator->sqrtCommand);
+
+ free(activator->addCmdSrv);
+ free(activator->subCmdSrv);
+ free(activator->sqrtCmdSrv);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ free(userData);
+ return CELIX_SUCCESS;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/src/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/src/org.apache.celix.calc.api.Calculator2.descriptor b/bundles/remote_services/examples/calculator_shell/src/org.apache.celix.calc.api.Calculator2.descriptor
new file mode 100644
index 0000000..789af9a
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/src/org.apache.celix.calc.api.Calculator2.descriptor
@@ -0,0 +1,11 @@
++:header
++type=interface
++name=calculator
++version=1.2.3
++:annotations
++classname=org.example.Calculator
++:types
++:methods
++add(DD)D=add(#am=handle;PDD#am=pre;*D)N
++sub(DD)D=sub(#am=handle;PDD#am=pre;*D)N
++sqrt(D)D=sqrt(#am=handle;PD#am=pre;*D)N
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/src/sqrt_command.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/src/sqrt_command.c b/bundles/remote_services/examples/calculator_shell/src/sqrt_command.c
new file mode 100644
index 0000000..2e7238c
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/src/sqrt_command.c
@@ -0,0 +1,96 @@
+/**
+ *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.
+ */
+/*
+ * sqrt_command.c
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "array_list.h"
+#include "bundle_context.h"
+#include "sqrt_command.h"
+#include "calculator_service.h"
+
+static celix_status_t sqrtCommand_isNumeric(char *number, bool *ret);
+
+void sqrtCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
+ celix_status_t status = CELIX_SUCCESS;
+ service_reference_pt calculatorService = NULL;
+
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "SQRT: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "SQRT: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+ }
+ }
+ if (status == CELIX_SUCCESS) {
+ char *token = line;
+ strtok_r(line, " ", &token);
+ char *aStr = strtok_r(NULL, " ", &token);
+ if(aStr != NULL){
+ bool numeric;
+ sqrtCommand_isNumeric(aStr, &numeric);
+ if (numeric) {
+ calculator_service_pt calculator = NULL;
+ status = bundleContext_getService(context, calculatorService, (void *) &calculator);
+ if (status == CELIX_SUCCESS && calculator != NULL) {
+ double a = atof(aStr);
+ double result = 0;
+ status = calculator->sqrt(calculator->calculator, a, &result);
+ if (status == CELIX_SUCCESS) {
+ fprintf(out, "CALCULATOR_SHELL: Sqrt: %f = %f\n", a, result);
+ } else {
+ fprintf(err, "SQRT: Unexpected exception in Calc service\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+ } else {
+ fprintf(err, "SQRT: Requires 1 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "SQRT: Requires 1 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+
+ //return status;
+}
+
+static celix_status_t sqrtCommand_isNumeric(char *number, bool *ret) {
+ celix_status_t status = CELIX_SUCCESS;
+ *ret = true;
+ while(*number) {
+ if(!isdigit(*number) && *number != '.') {
+ *ret = false;
+ break;
+ }
+ number++;
+ }
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/src/sqrt_command.h
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/src/sqrt_command.h b/bundles/remote_services/examples/calculator_shell/src/sqrt_command.h
new file mode 100644
index 0000000..c9d07d2
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/src/sqrt_command.h
@@ -0,0 +1,32 @@
+/**
+ *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.
+ */
+/*
+ * sqrt_command.h
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef SQRT_COMMAND_H_
+#define SQRT_COMMAND_H_
+
+void sqrtCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
+
+#endif /* SQRT_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/src/sub_command.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/src/sub_command.c b/bundles/remote_services/examples/calculator_shell/src/sub_command.c
new file mode 100644
index 0000000..672ea4c
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/src/sub_command.c
@@ -0,0 +1,99 @@
+/**
+ *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.
+ */
+/*
+ * sub_command.c
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "array_list.h"
+#include "bundle_context.h"
+#include "sub_command.h"
+#include "calculator_service.h"
+
+static celix_status_t subCommand_isNumeric(char *number, bool *ret);
+
+void subCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err) {
+ celix_status_t status = CELIX_SUCCESS;
+ service_reference_pt calculatorService = NULL;
+
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "SUB: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE, CALCULATOR2_SERVICE);
+ status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE, &calculatorService);
+ if (calculatorService == NULL) {
+ fprintf(err, "SUB: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+ }
+ }
+ if (status == CELIX_SUCCESS) {
+ char *token = line;
+ strtok_r(line, " ", &token);
+ char *aStr = strtok_r(NULL, " ", &token);
+ char *bStr = strtok_r(NULL, " ", &token);
+ if(aStr != NULL && bStr != NULL ){
+ bool aNumeric, bNumeric;
+ subCommand_isNumeric(aStr, &aNumeric);
+ subCommand_isNumeric(bStr, &bNumeric);
+ if (aNumeric && bNumeric) {
+ calculator_service_pt calculator = NULL;
+ status = bundleContext_getService(context, calculatorService, (void *) &calculator);
+ if (status == CELIX_SUCCESS && calculator != NULL) {
+ double a = atof(aStr);
+ double b = atof(bStr);
+ double result = 0;
+ status = calculator->sub(calculator->calculator, a, b, &result);
+ if (status == CELIX_SUCCESS) {
+ fprintf(out, "CALCULATOR_SHELL: Sub: %f - %f = %f\n", a, b, result);
+ } else {
+ fprintf(err, "SUB: Unexpected exception in Calc service\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+ } else {
+ fprintf(err, "SUB: Requires 2 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "SUB: Requires 2 numerical parameter\n");
+ }
+ } else {
+ fprintf(err, "No calc service available\n");
+ }
+
+ //return status;
+}
+
+static celix_status_t subCommand_isNumeric(char *number, bool *ret) {
+ celix_status_t status = CELIX_SUCCESS;
+ *ret = true;
+ while(*number) {
+ if(!isdigit(*number) && *number != '.') {
+ *ret = false;
+ break;
+ }
+ number++;
+ }
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/examples/calculator_shell/src/sub_command.h
----------------------------------------------------------------------
diff --git a/bundles/remote_services/examples/calculator_shell/src/sub_command.h b/bundles/remote_services/examples/calculator_shell/src/sub_command.h
new file mode 100644
index 0000000..cf13616
--- /dev/null
+++ b/bundles/remote_services/examples/calculator_shell/src/sub_command.h
@@ -0,0 +1,32 @@
+/**
+ *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.
+ */
+/*
+ * sub_command.h
+ *
+ * \date Oct 13, 2011
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef SUB_COMMAND_H_
+#define SUB_COMMAND_H_
+
+void subCommand_execute(bundle_context_pt context, char *line, FILE *out, FILE *err);
+
+#endif /* SUB_COMMAND_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/remote_service_admin_dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/bundles/remote_services/remote_service_admin_dfi/CMakeLists.txt b/bundles/remote_services/remote_service_admin_dfi/CMakeLists.txt
new file mode 100644
index 0000000..dcc25f7
--- /dev/null
+++ b/bundles/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -0,0 +1,55 @@
+# 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.
+
+
+celix_subproject(RSA_REMOTE_SERVICE_ADMIN_DFI "Option to enable building the Remote Service Admin Service DFI" ON DEPS TOPOLOGY_MANAGER)
+
+if (RSA_REMOTE_SERVICE_ADMIN_DFI)
+
+ find_package(CURL REQUIRED)
+ find_package(Jansson REQUIRED)
+
+ add_celix_bundle(rsa_dfi
+ VERSION 0.9.0
+ SYMBOLIC_NAME "apache_celix_remote_service_admin_dfi"
+ NAME "Apache Celix Remote Service Admin Dynamic Function Interface (DFI)"
+ SOURCES
+ 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_OBJECTS:Celix::civetweb>
+ )
+ celix_bundle_private_libs(rsa_dfi Celix::dfi)
+ target_include_directories(rsa_dfi PRIVATE src $<TARGET_PROPERTY:Celix::civetweb,INCLUDE_DIRECTORIES>)
+ target_include_directories(rsa_dfi SYSTEM PRIVATE ${CURL_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS})
+ target_link_libraries(rsa_dfi PRIVATE
+ Celix::dfi
+ Celix::log_helper
+ Celix::rsa_common
+ ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
+
+ if (ENABLE_TESTING)
+ add_subdirectory(test)
+ endif()
+
+
+ install_celix_bundle(rsa_dfi EXPORT celix COMPONENT rsa)
+ #Setup target aliases to match external usage
+ add_library(Celix::rsa_dfi ALIAS rsa_dfi)
+endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/bundles/remote_services/remote_service_admin_dfi/src/dfi_utils.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/dfi_utils.c b/bundles/remote_services/remote_service_admin_dfi/src/dfi_utils.c
new file mode 100644
index 0000000..631152d
--- /dev/null
+++ b/bundles/remote_services/remote_service_admin_dfi/src/dfi_utils.c
@@ -0,0 +1,108 @@
+/**
+ *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;
+
+ //Checking if descriptor is in root dir of bundle
+ char *path = NULL;
+ status = bundle_getEntry(bundle, fileName, &path);
+
+ char metaInfFileName[512];
+ if (status != CELIX_SUCCESS || path == NULL) {
+ free(path);
+ //Checking if descriptor is in META-INF/descriptors
+ snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/%s", fileName);
+ status = bundle_getEntry(bundle, metaInfFileName, &path);
+ }
+
+ if (status != CELIX_SUCCESS || path == NULL) {
+ free(path);
+ //Checking if descriptor is in META-INF/descriptors/services
+ snprintf(metaInfFileName, sizeof(metaInfFileName), "META-INF/descriptors/services/%s", fileName);
+ 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/3bce889b/bundles/remote_services/remote_service_admin_dfi/src/dfi_utils.h
----------------------------------------------------------------------
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/dfi_utils.h b/bundles/remote_services/remote_service_admin_dfi/src/dfi_utils.h
new file mode 100644
index 0000000..cec8aa1
--- /dev/null
+++ b/bundles/remote_services/remote_service_admin_dfi/src/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 <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/3bce889b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
new file mode 100644
index 0000000..b83b5a8
--- /dev/null
+++ b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
@@ -0,0 +1,251 @@
+/**
+ *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/3bce889b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
new file mode 100644
index 0000000..93f37ba
--- /dev/null
+++ b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
@@ -0,0 +1,38 @@
+/**
+ *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/3bce889b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
new file mode 100644
index 0000000..0b8dcf7
--- /dev/null
+++ b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
@@ -0,0 +1,402 @@
+/**
+ *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/3bce889b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
new file mode 100644
index 0000000..aac4bc7
--- /dev/null
+++ b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
@@ -0,0 +1,44 @@
+/**
+ *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/3bce889b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_activator.c b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_activator.c
new file mode 100644
index 0000000..d4cc765
--- /dev/null
+++ b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_activator.c
@@ -0,0 +1,124 @@
+/**
+ *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;
+}
+
+