Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-237_rsa-ffi da86474fb -> 30f7e8419


CELIX-237: Added setup for client - server ccputest. This test start two 
embedded Celix frameworks for remote services test


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/30f7e841
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/30f7e841
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/30f7e841

Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 30f7e8419c28d085e7e782a7dcd6828c1eb79e3f
Parents: da86474
Author: Pepijn Noltes <pepijnnol...@gmail.com>
Authored: Mon Aug 10 22:07:15 2015 +0200
Committer: Pepijn Noltes <pepijnnol...@gmail.com>
Committed: Mon Aug 10 22:07:15 2015 +0200

----------------------------------------------------------------------
 remote_services/CMakeLists.txt                  |   7 +-
 .../private/src/endpoint_discovery_poller.c     |   5 +-
 .../examples/calculator_service/CMakeLists.txt  |   2 +-
 ....apache.celix.calc.api.Calculator.descriptor |  11 --
 ...apache.celix.calc.api.Calculator2.descriptor |  11 ++
 .../examples/calculator_shell/CMakeLists.txt    |   4 +
 .../dynamic_function_interface/dyn_type.h       |   6 +-
 .../private/include/export_registration_dfi.h   |   2 +-
 .../private/src/export_registration_dfi.c       | 131 +++++++++++++++----
 .../private/src/import_registration_dfi.c       |  12 +-
 .../private/src/remote_service_admin_dfi.c      |  32 +----
 .../remote_service_admin_dfi/tst/CMakeLists.txt |  52 +++++---
 .../tst/bundle/CMakeLists.txt                   |  20 +++
 .../tst/bundle/tst_activator.c                  |  91 +++++++++++++
 .../tst/bundle/tst_service.h                    |  17 +++
 .../tst/client.properties.in                    |   7 +
 .../tst/config.properties.in                    |   3 +-
 .../tst/rsa_client_server_tests.cpp             | 118 +++++++++++++++++
 .../remote_service_admin_dfi/tst/rsa_tests.cpp  |  28 +++-
 .../tst/server.properties.in                    |   7 +
 20 files changed, 464 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index a16977f..abc9177 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -33,14 +33,15 @@ if (REMOTE_SERVICE_ADMIN)
 
     add_subdirectory(topology_manager)
 
+    add_subdirectory(discovery_configured)
+    add_subdirectory(discovery_etcd)
+    add_subdirectory(discovery_shm)
+
     add_subdirectory(remote_service_admin)
     add_subdirectory(remote_service_admin_http)
     add_subdirectory(remote_service_admin_dfi)
     add_subdirectory(remote_service_admin_shm)
 
-    add_subdirectory(discovery_configured)
-    add_subdirectory(discovery_etcd)
-    add_subdirectory(discovery_shm)
 
 endif (REMOTE_SERVICE_ADMIN)
 

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_discovery_poller.c 
b/remote_services/discovery/private/src/endpoint_discovery_poller.c
index 569d7a9..d8c16a5 100644
--- a/remote_services/discovery/private/src/endpoint_discovery_poller.c
+++ b/remote_services/discovery/private/src/endpoint_discovery_poller.c
@@ -325,6 +325,8 @@ static size_t endpointDiscoveryPoller_writeMemory(void 
*contents, size_t size, s
 static celix_status_t 
endpointDiscoveryPoller_getEndpoints(endpoint_discovery_poller_pt poller, char 
*url, array_list_pt *updatedEndpoints) {
     celix_status_t status = CELIX_SUCCESS;
 
+       logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "Polling url 
'%s'", url);
+
     CURL *curl = NULL;
     CURLcode res = CURLE_OK;
 
@@ -349,6 +351,7 @@ static celix_status_t 
endpointDiscoveryPoller_getEndpoints(endpoint_discovery_po
 
        status = endpointDescriptorReader_create(poller, &reader);
        if (status == CELIX_SUCCESS) {
+                       logHelper_log(*poller->loghelper, 
OSGI_LOGSERVICE_DEBUG, "Polled data '%s'", chunk.memory);
                        status = endpointDescriptorReader_parseDocument(reader, 
chunk.memory, updatedEndpoints);
        }
 
@@ -356,7 +359,7 @@ static celix_status_t 
endpointDiscoveryPoller_getEndpoints(endpoint_discovery_po
                        endpointDescriptorReader_destroy(reader);
        }
     } else {
-       logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_ERROR, 
"ENDPOINT_POLLER: unable to read endpoints, reason: %s", 
curl_easy_strerror(res));
+       logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_ERROR, 
"ENDPOINT_POLLER: unable to read endpoints at '%s', reason: %s", url, 
curl_easy_strerror(res));
     }
 
     // clean up endpoints file

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/CMakeLists.txt 
b/remote_services/examples/calculator_service/CMakeLists.txt
index 91596ab..a3cad0d 100644
--- a/remote_services/examples/calculator_service/CMakeLists.txt
+++ b/remote_services/examples/calculator_service/CMakeLists.txt
@@ -31,7 +31,7 @@ SET(BUNDLE_VERSION "0.0.1")
     private/include/calculator_impl.h
 
     FILES
-        org.apache.celix.calc.api.Calculator.descriptor
+        public/include/org.apache.celix.calc.api.Calculator2.descriptor
 )
 
 target_link_libraries(calculator celix_framework)

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
----------------------------------------------------------------------
diff --git 
a/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
 
b/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
deleted file mode 100644
index 711df0b..0000000
--- 
a/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
+++ /dev/null
@@ -1,11 +0,0 @@
-:header
-type=interface
-name=calculator
-version=1.0.0
-:annotations
-classname=org.example.Calculator
-:types
-:methods
-add(DD)D=add(PDD*D)N
-sub(DD)D=sub(PDD*D)N
-sqrt(D)D=sqrt(PD*D)N

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git 
a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
 
b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
new file mode 100644
index 0000000..711df0b
--- /dev/null
+++ 
b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
@@ -0,0 +1,11 @@
+:header
+type=interface
+name=calculator
+version=1.0.0
+:annotations
+classname=org.example.Calculator
+:types
+:methods
+add(DD)D=add(PDD*D)N
+sub(DD)D=sub(PDD*D)N
+sqrt(D)D=sqrt(PD*D)N

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/examples/calculator_shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/CMakeLists.txt 
b/remote_services/examples/calculator_shell/CMakeLists.txt
index 955e688..dcb8c8f 100644
--- a/remote_services/examples/calculator_shell/CMakeLists.txt
+++ b/remote_services/examples/calculator_shell/CMakeLists.txt
@@ -33,6 +33,10 @@ bundle(calculator_shell SOURCES
     private/include/sqrt_command.h
     private/include/sub_command.h
     ../../../shell/public/src/command.c
+
+
+        FILES
+            
../calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
 )
 
 target_link_libraries(calculator_shell celix_framework)

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h
 
b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h
index 9fdbff2..a409ff5 100644
--- 
a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h
+++ 
b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h
@@ -14,9 +14,9 @@
 
 #include "dfi_log_util.h"
 
-#if defined(BSD) || defined(__APPLE__) 
-#include "open_memstream.h"
-#include "fmemopen.h"
+#if defined(BSD) || defined(__APPLE__)
+#include "memstream/open_memstream.h"
+#include "memstream/fmemopen.h"
 #endif
 
 /* Description string

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
 
b/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
index 4faf9b9..4356646 100644
--- 
a/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
+++ 
b/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
@@ -10,7 +10,7 @@
 #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_destroy(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);

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
 
b/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
index 7814d0d..95d58b9 100644
--- 
a/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
+++ 
b/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
@@ -4,35 +4,89 @@
 #include <jansson.h>
 #include <dyn_interface.h>
 #include <json_serializer.h>
+#include <remote_constants.h>
 #include "export_registration.h"
 #include "export_registration_dfi.h"
 #include "endpoint_description.h"
 
-struct export_registration {
-    endpoint_description_pt endpointDescription;
+struct export_reference {
+    endpoint_description_pt endpoint; //owner
     service_reference_pt reference;
-    dyn_interface_type *intf;
+};
+
+struct export_registration {
+    bundle_context_pt  context;
+    struct export_reference exportReference;
     void *service;
-    bundle_pt bundle;
+    dyn_interface_type *intf; //owner
 
+    //TODO add tracker and lock
     bool closed;
 };
 
-struct export_reference {
-    endpoint_description_pt endpoint;
-    service_reference_pt reference;
-};
-
-typedef void (*GEN_FUNC_TYPE)(void);
-
 struct generic_service_layout {
     void *handle;
-    GEN_FUNC_TYPE methods[];
+    void **methods;
 };
 
-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_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;
-    //TODO
+
+    export_registration_pt  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;
+    }
+
+    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));
+
+
+    char *descriptorFile = NULL;
+    if (status == CELIX_SUCCESS) {
+        char name[128];
+        snprintf(name, 128, "%s.descriptor", exports);
+        status = bundle_getEntry(bundle, name, &descriptorFile);
+        logHelper_log(helper, OSGI_LOGSERVICE_DEBUG, "RSA: Found descriptor 
'%s' for %'s'.", descriptorFile, exports);
+    }
+
+    if (descriptorFile == NULL) {
+        logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "RSA: Cannot find 
descrriptor in bundle for service '%s'", exports);
+        status = CELIX_ILLEGAL_ARGUMENT;
+    }
+
+    if (status == CELIX_SUCCESS) {
+        FILE *df = fopen(descriptorFile, "r");
+        if (df != NULL) {
+            int rc = dynInterface_parse(df, &reg->intf);
+            fclose(df);
+            if (rc != 0) {
+                status = CELIX_BUNDLE_EXCEPTION;
+                logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error 
parsing service descriptor.");
+            }
+        } else {
+            status = CELIX_BUNDLE_EXCEPTION;
+            logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot open 
descriptor '%s'", descriptorFile);
+        }
+    }
+
+    if (status == CELIX_SUCCESS) {
+        *out = reg;
+    } else {
+        logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Error creating export 
registration");
+        exportRegistration_destroy(reg);
+    }
+
     return status;
 }
 
@@ -108,27 +162,40 @@ celix_status_t 
exportRegistration_call(export_registration_pt export, char *data
     return status;
 }
 
-celix_status_t exportRegistration_destroy(export_registration_pt registration) 
{
-    celix_status_t status = CELIX_SUCCESS;
-    //TODO
-    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);
+        }
+
+        free(reg);
+    }
 }
 
-celix_status_t exportRegistration_start(export_registration_pt registration) {
+celix_status_t exportRegistration_start(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    status = bundleContext_getService(reg->context, 
reg->exportReference.reference, &reg->service); //TODO use tracker
     return status;
 }
 
-celix_status_t exportRegistration_stop(export_registration_pt registration) {
+celix_status_t exportRegistration_stop(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    status = bundleContext_ungetService(reg->context, 
reg->exportReference.reference, NULL);
     return status;
 }
 
-celix_status_t exportRegistration_close(export_registration_pt registration) {
+celix_status_t exportRegistration_close(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    exportRegistration_stop(reg);
+    //TODO callback to rsa to remove from list
     return status;
 }
 
@@ -138,9 +205,21 @@ celix_status_t 
exportRegistration_getException(export_registration_pt registrati
     return status;
 }
 
-celix_status_t exportRegistration_getExportReference(export_registration_pt 
registration, export_reference_pt *reference) {
+celix_status_t exportRegistration_getExportReference(export_registration_pt 
registration, export_reference_pt *out) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    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;
+        //TODO log
+    }
+
+    if (status == CELIX_SUCCESS) {
+        *out = ref;
+    }
+
     return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
 
b/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
index f8c544c..4e424a8 100644
--- 
a/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
+++ 
b/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
@@ -1,4 +1,4 @@
-#include <malloc.h>
+#include <stdlib.h>
 #include "dyn_interface.h"
 #include "import_registration.h"
 #include "import_registration_dfi.h"
@@ -84,6 +84,16 @@ 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 **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);
+     */
+
+
     struct service_proxy *proxy = hashMap_get(import->proxies, bundle); //TODO 
lock
     if (proxy == NULL) {
         status = importRegistration_createProxy(import, bundle, &proxy);

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
 
b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
index eae2816..5e11c3b 100644
--- 
a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
+++ 
b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
@@ -414,34 +414,8 @@ celix_status_t 
remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
         if (exports == NULL || provided == NULL || strcmp(exports, provided) 
!= 0) {
             logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No 
Services to export.");
             status = CELIX_ILLEGAL_STATE;
-        }
-    }
-
-    bundle_pt bundle = NULL;
-    if (status == CELIX_SUCCESS) {
-        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export 
service (%s)", provided);
-        status = serviceReference_getBundle(reference, &bundle);
-    }
-
-    char *descriptorFile = NULL;
-    if (status == CELIX_SUCCESS) {
-        char name[128];
-        snprintf(name, 128, "%s.descriptor", exports);
-        status = bundle_getEntry(bundle, name, &descriptorFile);
-    }
-
-    if (status == CELIX_SUCCESS) {
-        dyn_interface_type *intf = NULL;
-        if (descriptorFile != NULL) {
-            FILE *df = fopen(descriptorFile, "r");
-            if (df != NULL) {
-                int rc = dynInterface_parse(df, &intf);
-                fclose(df);
-                if (rc != 0) {
-                    status = CELIX_BUNDLE_EXCEPTION;
-                    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, 
"RSA: Error parsing service descriptor.");
-                }
-            }
+        } else {
+            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export 
service (%s)", provided);
         }
     }
 
@@ -452,6 +426,7 @@ celix_status_t 
remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
 
         remoteServiceAdmin_createEndpointDescription(admin, reference, 
interface, &endpoint);
         printf("RSA: Creating export registration with endpoint pointer %p\n", 
endpoint);
+        //TOOD precheck if descriptor exists
         status = exportRegistration_create(admin->loghelper, reference, 
endpoint, admin->context, &registration);
         if (status == CELIX_SUCCESS) {
             status = exportRegistration_start(registration);
@@ -461,6 +436,7 @@ celix_status_t 
remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
         }
     }
 
+
     if (status == CELIX_SUCCESS) {
         celixThreadMutex_lock(&admin->exportedServicesLock);
         hashMap_put(admin->exportedServices, reference, *registrations);

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt 
b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
index d0814c6..a184d21 100644
--- a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
@@ -2,34 +2,48 @@
 # Licensed under Apache License v2. See LICENSE for more information.
 #
 
-include_directories(
-       ${PROJECT_SOURCE_DIR}/launcher/public/include
-    ${CPPUTEST_INCLUDE_DIR}
-    ${PROJECT_SOURCE_DIR}/framework/public/include
-    ${PROJECT_SOURCE_DIR}/utils/public/include
-)
-
-#if (FRAMEWORK_TESTS) TODO
+#TODO add FRAMEWORK_TEST / TEST check
+#if (RSA_EXAMPLES)
+
+    add_subdirectory(bundle)
+
+    include_directories(
+        ${PROJECT_SOURCE_DIR}/launcher/public/include
+        ${CPPUTEST_INCLUDE_DIR}
+        ${PROJECT_SOURCE_DIR}/framework/public/include
+        ${PROJECT_SOURCE_DIR}/utils/public/include
+        bundle
+    )
+
     SET(CMAKE_SKIP_BUILD_RPATH  FALSE) #TODO needed?
     SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
     SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" 
"${PROJECT_BINARY_DIR}/utils")
 
-       add_executable(test_rsa_dfi
-           run_tests.cpp
-           rsa_tests.cpp
+    add_executable(test_rsa_dfi
+        run_tests.cpp
+        rsa_tests.cpp
+        rsa_client_server_tests.cpp
 
-           ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to 
libframework
-           
${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
-       )
-       target_link_libraries(test_rsa_dfi ${CPPUTEST_LIBRARY} celix_framework 
celix_utils ${CURL_LIBRARIES})
+        ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to 
libframework
+        
${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
+    )
+    target_link_libraries(test_rsa_dfi celix_framework celix_utils 
${CURL_LIBRARIES})
+
+    get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY 
BUNDLE)
+    get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)
+    get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY 
BUNDLE)
+    get_property(discovery_configured_bundle_file TARGET discovery_configured 
PROPERTY BUNDLE)
+    get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY 
BUNDLE)
+    get_property(tst_bundle_file TARGET rsa_dfi_tst_bundle PROPERTY BUNDLE)
 
-       get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY 
BUNDLE)
-       get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)
     configure_file(config.properties.in config.properties @ONLY)
+    configure_file(client.properties.in client.properties @ONLY)
+    configure_file(server.properties.in server.properties @ONLY)
 
     add_dependencies(test_rsa_dfi remote_service_admin_dfi calculator)
 
 
-       add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
-       SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi 
${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
+    add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
+    SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi 
${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
+
 #endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt 
b/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
new file mode 100644
index 0000000..e1d4fb3
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
@@ -0,0 +1,20 @@
+#
+# Licensed under Apache License v2. See LICENSE for more information.
+#
+
+include_directories(
+        ${PROJECT_SOURCE_DIR}/launcher/public/include
+        ${CPPUTEST_INCLUDE_DIR}
+        ${PROJECT_SOURCE_DIR}/framework/public/include
+        ${PROJECT_SOURCE_DIR}/utils/public/include
+)
+
+
+bundle(rsa_dfi_tst_bundle
+    SOURCES
+        tst_activator.c
+
+    FILES
+        
${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+)
+target_link_libraries(rsa_dfi_tst_bundle ${CPPUTEST_LIBRARY} celix_framework 
celix_utils)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c 
b/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
new file mode 100644
index 0000000..9b16e65
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
@@ -0,0 +1,91 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+#include "service_reference.h"
+#include "celix_errno.h"
+
+#include "tst_service.h"
+#include "calculator_service.h"
+
+
+struct activator {
+       bundle_context_pt context;
+       struct tst_service serv;
+       service_registration_pt  reg;
+};
+
+static void test(void *handle);
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **out) {
+       celix_status_t status = CELIX_SUCCESS;
+       struct activator *act = calloc(1, sizeof(*act));
+       if (act != NULL) {
+               act->context = context;
+               act->serv.handle = act;
+               act->serv.test = test;
+       } else {
+               status = CELIX_ENOMEM;
+       }
+
+       if (status == CELIX_SUCCESS) {
+               *out = act;
+       }
+
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt 
context) {
+    celix_status_t status = CELIX_SUCCESS;
+       struct activator * act = userData;
+
+       act->reg = NULL;
+       status = bundleContext_registerService(context, (char 
*)TST_SERVICE_NAME, &act->serv, NULL, &act->reg);
+
+       return status;
+}
+
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt 
context) {
+    celix_status_t status = CELIX_SUCCESS;
+       struct activator * act = userData;
+
+       status = serviceRegistration_unregister(act->reg);
+
+       return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt 
context) {
+       free(userData);
+       return CELIX_SUCCESS;
+}
+
+static void test(void *handle) {
+       struct activator *act = handle;
+       bundle_context_pt context = act->context;
+       //TODO improve. don't use asserts.
+
+       int rc = 0;
+       service_reference_pt ref = NULL;
+       calculator_service_pt calc = NULL;
+
+       rc = bundleContext_getServiceReference(context, (char 
*)CALCULATOR2_SERVICE, &ref);
+       assert(rc == 0);
+
+       rc = bundleContext_getService(context, ref, (void **)&calc);
+       assert(rc == 0);
+
+       double result = 0.0;
+       rc = calc->sqrt(calc->calculator, 4, &result);
+       assert(rc == 0);
+       assert(result == 2);
+
+       bundleContext_ungetService(context, ref, NULL);
+       bundleContext_ungetServiceReference(context, ref);
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h 
b/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
new file mode 100644
index 0000000..2fc2b21
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
@@ -0,0 +1,17 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+
+#ifndef CELIX_TST_SERVICE_H
+#define CELIX_TST_SERVICE_H
+
+#define TST_SERVICE_NAME "tst_service"
+
+struct tst_service {
+    void *handle;
+    void (*test)(void *handle);
+};
+
+typedef struct tst_service *tst_service_pt;
+
+#endif //CELIX_TST_SERVICE_H

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/client.properties.in 
b/remote_services/remote_service_admin_dfi/tst/client.properties.in
new file mode 100644
index 0000000..9cde4bd
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/client.properties.in
@@ -0,0 +1,7 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calculator_shell_bundle_file@ 
@discovery_configured_bundle_file@ @topology_manager_bundle_file@ 
@tst_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+RSA_PORT=50881
+DISCOVERY_CFG_SERVER_PORT=50991
+DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
+org.osgi.framework.storage.clean=onFirstInit
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/config.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/config.properties.in 
b/remote_services/remote_service_admin_dfi/tst/config.properties.in
index df5e625..8412214 100644
--- a/remote_services/remote_service_admin_dfi/tst/config.properties.in
+++ b/remote_services/remote_service_admin_dfi/tst/config.properties.in
@@ -1,2 +1,3 @@
 cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
\ No newline at end of file
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+org.osgi.framework.storage.clean=onFirstInit
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git 
a/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp 
b/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
new file mode 100644
index 0000000..5ffb47a
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
@@ -0,0 +1,118 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <CppUTest/TestHarness.h>
+#include <remote_constants.h>
+#include <constants.h>
+#include "CppUTest/CommandLineTestRunner.h"
+#include 
"../../examples/calculator_service/public/include/calculator_service.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#include "launcher.h"
+#include "framework.h"
+#include "remote_service_admin.h"
+#include "calculator_service.h"
+
+    static framework_pt serverFramework = NULL;
+    static bundle_context_pt serverContext = NULL;
+
+    static framework_pt clientFramework = NULL;
+    static bundle_context_pt clientContext = NULL;
+
+    static void setupFm(void) {
+        int rc = 0;
+        bundle_pt bundle = NULL;
+
+        //server
+        rc = celixLauncher_launch("server.properties", &serverFramework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle = NULL;
+        rc = framework_getFrameworkBundle(serverFramework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &serverContext);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+
+        //client
+        rc = celixLauncher_launch("client.properties", &clientFramework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle = NULL;
+        rc = framework_getFrameworkBundle(clientFramework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &clientContext);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+    }
+
+    static void teardownFm(void) {
+        int rc = 0;
+
+        celixLauncher_stop(serverFramework);
+        celixLauncher_waitForShutdown(serverFramework);
+        celixLauncher_destroy(serverFramework);
+
+        celixLauncher_stop(clientFramework);
+        celixLauncher_waitForShutdown(clientFramework);
+        celixLauncher_destroy(clientFramework);
+
+        serverContext = NULL;
+        serverFramework = NULL;
+        clientContext = NULL;
+        clientFramework = NULL;
+    }
+
+    static void test1(void) {
+        int rc = 0;
+        /* TODO use tst_service for (which has a descriptor file of the 
calculator service)
+        service_reference_pt ref = NULL;
+        calculator_service_pt calc = NULL;
+
+        usleep(5000000); //needed to accept connection (firewall)
+
+        bundleContext_getServiceReference(clientContext, (char 
*)CALCULATOR2_SERVICE, &ref);
+        CHECK_EQUAL(0, rc);
+        CHECK(ref != NULL);
+
+        //NOTE will not work. using framework context. need to use calc client 
context (lookup bundle / create own?)
+
+        bundleContext_getService(clientContext, ref, (void **)&calc);
+        CHECK_EQUAL(0, rc);
+        CHECK(calc != NULL);
+
+        double result = 0.0;
+        rc = calc->sqrt(calc->calculator, 4, &result);
+        CHECK_EQUAL(0, rc);
+        CHECK(result == 2.0);
+
+        bundleContext_ungetService(clientContext, ref, NULL);
+        bundleContext_ungetServiceReference(clientContext, ref);
+         */
+    }
+
+}
+
+
+TEST_GROUP(RsaDfiClientServerTests) {
+    void setup() {
+        setupFm();
+    }
+
+    void teardown() {
+        teardownFm();
+    }
+};
+
+TEST(RsaDfiClientServerTests, Test1) {
+    test1();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp 
b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
index 060b15b..1384573 100644
--- a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
@@ -21,14 +21,14 @@ extern "C" {
 #include "calculator_service.h"
 
 
-    framework_pt framework = NULL;
-    bundle_context_pt context = NULL;
+    static framework_pt framework = NULL;
+    static bundle_context_pt context = NULL;
 
-    service_reference_pt rsaRef = NULL;
-    remote_service_admin_service_pt rsa = NULL;
+    static service_reference_pt rsaRef = NULL;
+    static remote_service_admin_service_pt rsa = NULL;
 
-    service_reference_pt calcRef = NULL;
-    calculator_service_pt calc = NULL;
+    static service_reference_pt calcRef = NULL;
+    static calculator_service_pt calc = NULL;
 
     static void setupFm(void) {
         int rc = 0;
@@ -50,7 +50,7 @@ extern "C" {
         rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
         CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-        rc = bundleContext_getServiceReference(context, (char 
*)CALCULATOR_SERVICE, &calcRef);
+        rc = bundleContext_getServiceReference(context, (char 
*)CALCULATOR2_SERVICE, &calcRef);
         CHECK_EQUAL(CELIX_SUCCESS, rc);
         CHECK(calcRef != NULL);
 
@@ -154,6 +154,20 @@ extern "C" {
         CHECK_EQUAL(0, rc);
         CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc
 
+        /*
+        int size = arrayList_size(bundles);
+        int i;
+        for (i = 0; i < size; i += 1) {
+            bundle_pt bundle = NULL;
+            module_pt module = NULL;
+            char *name = NULL;
+
+            bundle = (bundle_pt) arrayList_get(bundles, i);
+            bundle_getCurrentModule(bundle, &module);
+            module_getSymbolicName(module, &name);
+            printf("got bundle with symbolic name '%s'", name);
+        }*/
+
         arrayList_destroy(bundles);
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/server.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/server.properties.in 
b/remote_services/remote_service_admin_dfi/tst/server.properties.in
new file mode 100644
index 0000000..f75bf24
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/server.properties.in
@@ -0,0 +1,7 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@ 
@discovery_configured_bundle_file@ @topology_manager_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+RSA_PORT=50882
+DISCOVERY_CFG_SERVER_PORT=50992
+DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50991/org.apache.celix.discovery.configured
+org.osgi.framework.storage.clean=onFirstInit
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

Reply via email to