summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuergen Gehring <juergen.gehring@bmw.de>2014-03-07 16:34:56 +0100
committerJohannes Langlotz <johannes.langlotz@partner.bmw.de>2014-03-21 10:56:25 +0100
commit5e073a099fe590bcab00d8504647660df9e7c500 (patch)
tree2fc44b4708feb425c581bd63bf214802b45b8e71
parent2fae8eab1cae960a983733036edcca3ab149bcc0 (diff)
downloadgenivi-common-api-runtime-5e073a099fe590bcab00d8504647660df9e7c500.tar.gz
Add examples, extended tutorial and specification document.
Change-Id: If3e96c9676cd575be560ec9b485eea68bb4bf064
-rw-r--r--.gitignore2
-rw-r--r--CommonAPI-Examples/.gitignore32
-rw-r--r--CommonAPI-Examples/README52
-rw-r--r--CommonAPI-Examples/e01HelloWorld/.gitignore2
-rw-r--r--CommonAPI-Examples/e01HelloWorld/CMakeLists.txt70
-rw-r--r--CommonAPI-Examples/e01HelloWorld/README5
-rw-r--r--CommonAPI-Examples/e01HelloWorld/fidl/E01HelloWorld.fidl21
-rw-r--r--CommonAPI-Examples/e01HelloWorld/src/E01HelloWorldStubImpl.cpp25
-rw-r--r--CommonAPI-Examples/e01HelloWorld/src/E01HelloWorldStubImpl.h23
-rw-r--r--CommonAPI-Examples/e01HelloWorld/src/e01HelloWorldClient.cpp39
-rw-r--r--CommonAPI-Examples/e01HelloWorld/src/e01HelloWorldService.cpp31
-rw-r--r--CommonAPI-Examples/e02Attributes/.gitignore2
-rw-r--r--CommonAPI-Examples/e02Attributes/CMakeLists.txt70
-rw-r--r--CommonAPI-Examples/e02Attributes/README133
-rw-r--r--CommonAPI-Examples/e02Attributes/fidl/E02Attributes.fidl29
-rw-r--r--CommonAPI-Examples/e02Attributes/src/E02AttributesStubImpl.cpp21
-rw-r--r--CommonAPI-Examples/e02Attributes/src/E02AttributesStubImpl.h25
-rw-r--r--CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp79
-rw-r--r--CommonAPI-Examples/e02Attributes/src/e02AttributesService.cpp30
-rw-r--r--CommonAPI-Examples/e03Methods/.gitignore2
-rw-r--r--CommonAPI-Examples/e03Methods/CMakeLists.txt70
-rw-r--r--CommonAPI-Examples/e03Methods/README135
-rw-r--r--CommonAPI-Examples/e03Methods/fidl/E03Methods.fidl38
-rw-r--r--CommonAPI-Examples/e03Methods/src/E03MethodsStubImpl.cpp37
-rw-r--r--CommonAPI-Examples/e03Methods/src/E03MethodsStubImpl.h30
-rw-r--r--CommonAPI-Examples/e03Methods/src/e03MethodsClient.cpp79
-rw-r--r--CommonAPI-Examples/e03Methods/src/e03MethodsService.cpp30
-rw-r--r--CommonAPI-Examples/e04PhoneBook/.gitignore2
-rw-r--r--CommonAPI-Examples/e04PhoneBook/CMakeLists.txt71
-rw-r--r--CommonAPI-Examples/e04PhoneBook/README237
-rw-r--r--CommonAPI-Examples/e04PhoneBook/fidl/E04PhoneBook.fidl93
-rw-r--r--CommonAPI-Examples/e04PhoneBook/src/E04PhoneBookStubImpl.cpp146
-rw-r--r--CommonAPI-Examples/e04PhoneBook/src/E04PhoneBookStubImpl.h37
-rw-r--r--CommonAPI-Examples/e04PhoneBook/src/e04PhoneBookClient.cpp187
-rw-r--r--CommonAPI-Examples/e04PhoneBook/src/e04PhoneBookService.cpp31
-rw-r--r--CommonAPI-Examples/e05Manager/.gitignore2
-rw-r--r--CommonAPI-Examples/e05Manager/CMakeLists.txt71
-rw-r--r--CommonAPI-Examples/e05Manager/README135
-rw-r--r--CommonAPI-Examples/e05Manager/fidl/E05Manager.fidl29
-rw-r--r--CommonAPI-Examples/e05Manager/src/E05DeviceStubImpl.cpp22
-rw-r--r--CommonAPI-Examples/e05Manager/src/E05DeviceStubImpl.h22
-rw-r--r--CommonAPI-Examples/e05Manager/src/E05ManagerStubImpl.cpp86
-rw-r--r--CommonAPI-Examples/e05Manager/src/E05ManagerStubImpl.h46
-rw-r--r--CommonAPI-Examples/e05Manager/src/E05SpecialDeviceStubImpl.cpp22
-rw-r--r--CommonAPI-Examples/e05Manager/src/E05SpecialDeviceStubImpl.h23
-rw-r--r--CommonAPI-Examples/e05Manager/src/e05ManagerClient.cpp52
-rw-r--r--CommonAPI-Examples/e05Manager/src/e05ManagerService.cpp50
-rw-r--r--CommonAPI-Examples/e06Unions/.gitignore2
-rw-r--r--CommonAPI-Examples/e06Unions/CMakeLists.txt70
-rw-r--r--CommonAPI-Examples/e06Unions/README100
-rw-r--r--CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl32
-rw-r--r--CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp45
-rw-r--r--CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.h23
-rw-r--r--CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp51
-rw-r--r--CommonAPI-Examples/e06Unions/src/e06UnionsService.cpp37
-rw-r--r--Makefile10
-rw-r--r--Tutorial557
-rw-r--r--doc/CommonAPISpecification1065
-rw-r--r--doc/Makefile87
-rw-r--r--doc/Tutorial705
-rwxr-xr-xdoc/images/CodeGenerationFrancaIDL.pngbin0 -> 11443 bytes
-rwxr-xr-xdoc/images/Deployment.pngbin0 -> 14984 bytes
-rwxr-xr-xdoc/images/Diag_Attributes.pngbin0 -> 18429 bytes
-rwxr-xr-xdoc/images/Diag_GeneratedProxy.pngbin0 -> 16965 bytes
-rwxr-xr-xdoc/images/Diag_GeneratedStub.pngbin0 -> 66369 bytes
-rwxr-xr-xdoc/images/E04PhoneBook.pngbin0 -> 44793 bytes
-rwxr-xr-xdoc/images/E05Manager.pngbin0 -> 25028 bytes
-rwxr-xr-xdoc/images/icons/important.pngbin0 -> 3851 bytes
-rw-r--r--doc/images/icons/note.pngbin0 -> 4049 bytes
-rw-r--r--doc/mainpagetests/01_mainpage.dox27
-rw-r--r--git0
-rw-r--r--org.genivi.commonapi.core.validator/.classpath2
-rw-r--r--org.genivi.commonapi.core.verification/.autotools42
-rw-r--r--org.genivi.commonapi.core.verification/.gitignore21
-rw-r--r--org.genivi.commonapi.core.verification/.project34
-rw-r--r--org.genivi.commonapi.core.verification/configure.ac21
-rw-r--r--org.genivi.commonapi.core.verification/doxygen-test.cfg308
-rw-r--r--org.genivi.commonapi.core.verification/m4/.gitignore5
-rw-r--r--org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in53
-rw-r--r--org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp81
80 files changed, 5133 insertions, 721 deletions
diff --git a/.gitignore b/.gitignore
index ed13944..6f4f515 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
*/bin
*/src-gen
+*/doc-gen
*/xtend-gen
.DS_Store
+*~
diff --git a/CommonAPI-Examples/.gitignore b/CommonAPI-Examples/.gitignore
index 2258947..a39b383 100644
--- a/CommonAPI-Examples/.gitignore
+++ b/CommonAPI-Examples/.gitignore
@@ -1,26 +1,6 @@
-.deps
-.dirstamp
-.libs
-*.la
-*.lo
-*.o
-*.gz
-/.autotools
-/.cproject
-/.project
-/.settings
-/*.pc
-/Makefile
-/Makefile.in
-/aclocal.m4
-/autom4te.cache
-/build-aux
-/config.log
-/config.status
-/configure
-/libtool
-/m4/libtool.m4
-/m4/lt*.m4
-/src-gen
-/helloworld-proxy
-/helloworld-stub
+.cproject
+.project
+.autotools
+.settings
+*/src-gen
+*/build \ No newline at end of file
diff --git a/CommonAPI-Examples/README b/CommonAPI-Examples/README
index 7776028..19ce46c 100644
--- a/CommonAPI-Examples/README
+++ b/CommonAPI-Examples/README
@@ -1,23 +1,39 @@
-1) Generate CommonAPI and CommonAPI-DBus C++ files from src/helloworld.fidl
- - for now CommonAPI-DBus is mandatory, future versions of the examples won't depend on any middleware
+Preliminary remarks
+~~~~~~~~~~~~~~~~~~~
-2) Init autotools:
- $ autoreconf -i
+The examples describe how some standard problems of interface design and implementation can be solved with Franca IDL and CommonAPI. Before you start make sure that your environment is properly installed. That means:
-3) Compile sources:
- # optionally override the path where CommonAPI is installed
- $ export PKG_CONFIG_PATH=/path/to/CommonAPI:/path/to/CommonAPI-DBus:/path/to/dbus-patched
- $ ./configure
- $ make
+- You can start the code generator in your Eclipse installation or from command line.
+- Your PKG_CONFIG_PATH contains the paths to the package config files of CommnAPI, CommonAPI-DBus and your patched D-Bus.
+- You have patched the DBus library with the patch in CommonAPI-D-Bus and you are sure that your LD_LIBRARY_PATH contains the path to the patched DBus library.
+- Make sure dbus session bus is available ($ env |grep DBUS_SESSION_BUS_ADDRESS, output must not be empty!).
+- If your platform is Windows, please read the instructions for Windows first. The following instructions assume that your are working on a Linux platform.
-4) Make sure dbus session bus is available:
- $ env |grep DBUS_SESSION_BUS_ADDRESS
- (output must not be empty!)
+The examples provide a more or less generic CMake file for building the executables. Two executables are needed: a service and a client program. The standard procedure to build one of these example programs is:
-5) Run the stub
- $ ./helloworld-stub
- (should block and wait for calls)
+----
+$ mkdir build; cd build
+$ cmake -D DBUS_PATH_LOCAL=<your_local_path_of_the_patched_dbus_library> -D PRJ_NAME=<name_of_the_example> ..
+$ make
+----
+
+_name_of_the_example_ is +e01HelloWorld+ for the first example.
+
+Here are some hints if you want to configure your eclipse project for the CMake build:
+
+- Install the CMakeEd plug-in which provides an editor for CMake files (http://cmakeed.sourceforge.net/eclipse/).
+- Create a build directory (eg /build) directly in the project directory.
+- Select the projects properties, then C/C++ build and set the Build Command to your make call:
+----
+make -C ${ProjDirPath}/build VERBOSE=1
+----
+- The Build Directory must be empty.
+- Create a make target (eg via Window->Show View->Make Target). Set the build command to:
+
+----
+cmake -E chdir build/ cmake -D DBUS_PATH_LOCAL=
+ <your_local_path_of_the_patched_dbus_library> -D PRJ_NAME=<name_of_the_example> ..
+----
+
+and leave the Make Target field empty. Finally, create in "Run Configurations" two configurations for client and service. Note that it might be necessary to start the executables with a local setting of the +LD_LIBRARY_PATH+ (eg to +/usr/local/lib+) since CommonAPI applications use a patched version of libdbus.
-6) Run the client on another console, while the stub is running:
- $ ./helloworld-proxy
- (should call the stub and exit with the response)
diff --git a/CommonAPI-Examples/e01HelloWorld/.gitignore b/CommonAPI-Examples/e01HelloWorld/.gitignore
new file mode 100644
index 0000000..5897208
--- /dev/null
+++ b/CommonAPI-Examples/e01HelloWorld/.gitignore
@@ -0,0 +1,2 @@
+build
+src-gen \ No newline at end of file
diff --git a/CommonAPI-Examples/e01HelloWorld/CMakeLists.txt b/CommonAPI-Examples/e01HelloWorld/CMakeLists.txt
new file mode 100644
index 0000000..2ed85a7
--- /dev/null
+++ b/CommonAPI-Examples/e01HelloWorld/CMakeLists.txt
@@ -0,0 +1,70 @@
+# Copyright (C) 2014 BMW Group
+# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+# Author: Juergen Gehring (juergen.gehring@bmw.de)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+cmake_minimum_required(VERSION 2.8)
+
+# Project settings
+if (PRJ_NAME)
+ message(STATUS "Start CMake for Project " ${PRJ_NAME})
+else()
+ message(FATAL_ERROR "Please specify your project name using -D PRJ_NAME=yourName")
+endif()
+project(${PRJ_NAME})
+set(CMAKE_VERBOSE_MAKEFILE on)
+set(CMAKE_CXX_FLAGS "-Wall -std=c++0x")
+set(CMAKE_BUILD_TYPE Debug)
+
+# DBus Path
+if (DBUS_PATH_LOCAL)
+ message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+else()
+ message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath")
+endif()
+
+# CommonAPI
+include(FindPkgConfig)
+pkg_check_modules (COMMONAPI "CommonAPI >= 2.1")
+pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1")
+
+# Source Files
+set(PRJ_SRC_PATH src)
+set(PRJ_SRC_GEN_PATH src-gen/commonapi/examples)
+
+set(PRJ_NAME_CLIENT ${PROJECT_NAME}Client)
+set(PRJ_NAME_SERVICE ${PROJECT_NAME}Service)
+
+FILE(GLOB PRJ_PROXY_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Proxy.cpp)
+FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Stub*.cpp)
+FILE(GLOB PRJ_STUB_IMPL_SRCS ${PRJ_SRC_PATH}/*Stub*.cpp)
+
+set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS})
+set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS})
+
+# Paths
+message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR})
+message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR})
+
+include_directories(
+ src-gen
+ ${DBUS_PATH_LOCAL}
+ ${COMMONAPI_INCLUDEDIR}
+ ${COMMONAPI_DBUS_INCLUDEDIR}
+)
+
+link_directories(
+ ${COMMONAPI_LIBDIR}
+ ${COMMONAPI_DBUS_LIBDIR}
+)
+
+# Build Client
+add_executable(${PRJ_NAME_CLIENT} ${PRJ_CLIENT_SRCS})
+target_link_libraries(${PRJ_NAME_CLIENT} CommonAPI CommonAPI-DBus)
+
+# Build service
+add_executable(${PRJ_NAME_SERVICE} ${PRJ_SERVICE_SRCS})
+target_link_libraries(${PRJ_NAME_SERVICE} CommonAPI CommonAPI-DBus)
diff --git a/CommonAPI-Examples/e01HelloWorld/README b/CommonAPI-Examples/e01HelloWorld/README
new file mode 100644
index 0000000..8128fd9
--- /dev/null
+++ b/CommonAPI-Examples/e01HelloWorld/README
@@ -0,0 +1,5 @@
+Example 1: Hello World
+~~~~~~~~~~~~~~~~~~~~~~
+
+This example contains the code for the step by step introduction to CommonAPI.
+
diff --git a/CommonAPI-Examples/e01HelloWorld/fidl/E01HelloWorld.fidl b/CommonAPI-Examples/e01HelloWorld/fidl/E01HelloWorld.fidl
new file mode 100644
index 0000000..bb48cc3
--- /dev/null
+++ b/CommonAPI-Examples/e01HelloWorld/fidl/E01HelloWorld.fidl
@@ -0,0 +1,21 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package commonapi.examples
+
+interface E01HelloWorld {
+ version { major 0 minor 1 }
+
+ method sayHello {
+ in {
+ String name
+ }
+ out {
+ String message
+ }
+ }
+} \ No newline at end of file
diff --git a/CommonAPI-Examples/e01HelloWorld/src/E01HelloWorldStubImpl.cpp b/CommonAPI-Examples/e01HelloWorld/src/E01HelloWorldStubImpl.cpp
new file mode 100644
index 0000000..2e50ce9
--- /dev/null
+++ b/CommonAPI-Examples/e01HelloWorld/src/E01HelloWorldStubImpl.cpp
@@ -0,0 +1,25 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "E01HelloWorldStubImpl.h"
+
+E01HelloWorldStubImpl::E01HelloWorldStubImpl() {
+}
+
+E01HelloWorldStubImpl::~E01HelloWorldStubImpl() {
+}
+
+void E01HelloWorldStubImpl::sayHello(const std::shared_ptr<CommonAPI::ClientId> clientId,
+ std::string name,
+ std::string& message) {
+ std::stringstream messageStream;
+
+ messageStream << "Hello " << name << "!";
+ message = messageStream.str();
+
+ std::cout << "sayHello('" << name << "'): '" << message << "'\n";
+};
diff --git a/CommonAPI-Examples/e01HelloWorld/src/E01HelloWorldStubImpl.h b/CommonAPI-Examples/e01HelloWorld/src/E01HelloWorldStubImpl.h
new file mode 100644
index 0000000..1079949
--- /dev/null
+++ b/CommonAPI-Examples/e01HelloWorld/src/E01HelloWorldStubImpl.h
@@ -0,0 +1,23 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E01HELLOWORLDSTUBIMPL_H_
+#define E01HELLOWORLDSTUBIMPL_H_
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E01HelloWorldStubDefault.h>
+
+class E01HelloWorldStubImpl: public commonapi::examples::E01HelloWorldStubDefault {
+
+public:
+ E01HelloWorldStubImpl();
+ virtual ~E01HelloWorldStubImpl();
+ virtual void sayHello(const std::shared_ptr<CommonAPI::ClientId> clientId, std::string name, std::string& message);
+
+};
+
+#endif /* E01HELLOWORLDSTUBIMPL_H_ */
diff --git a/CommonAPI-Examples/e01HelloWorld/src/e01HelloWorldClient.cpp b/CommonAPI-Examples/e01HelloWorld/src/e01HelloWorldClient.cpp
new file mode 100644
index 0000000..6537a02
--- /dev/null
+++ b/CommonAPI-Examples/e01HelloWorld/src/e01HelloWorldClient.cpp
@@ -0,0 +1,39 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h> //Defined in the Common API Runtime library
+#include <commonapi/examples/E01HelloWorldProxy.h> //Part of the code we just generated
+
+using namespace commonapi::examples;
+
+int main() {
+ std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::load();
+
+ std::shared_ptr < CommonAPI::Factory > factory = runtime->createFactory();
+ const std::string& serviceAddress = "local:commonapi.examples.HelloWorld:commonapi.examples.HelloWorld";
+ std::shared_ptr<E01HelloWorldProxyDefault> myProxy = factory->buildProxy<E01HelloWorldProxy>(serviceAddress);
+
+ while (!myProxy->isAvailable()) {
+ usleep(10);
+ }
+
+ const std::string name = "World";
+ CommonAPI::CallStatus callStatus;
+ std::string returnMessage;
+
+ myProxy->sayHello(name, callStatus, returnMessage);
+ if (callStatus != CommonAPI::CallStatus::SUCCESS) {
+ std::cerr << "Remote call failed!\n";
+ return -1;
+ }
+
+ std::cout << "Got message: '" << returnMessage << "'\n";
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/e01HelloWorld/src/e01HelloWorldService.cpp b/CommonAPI-Examples/e01HelloWorld/src/e01HelloWorldService.cpp
new file mode 100644
index 0000000..5351065
--- /dev/null
+++ b/CommonAPI-Examples/e01HelloWorld/src/e01HelloWorldService.cpp
@@ -0,0 +1,31 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+#include <thread>
+
+#include <CommonAPI/CommonAPI.h>
+#include "E01HelloWorldStubImpl.h"
+
+using namespace std;
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher();
+
+ const std::string& serviceAddress = "local:commonapi.examples.HelloWorld:commonapi.examples.HelloWorld";
+ std::shared_ptr<E01HelloWorldStubImpl> myService = std::make_shared<E01HelloWorldStubImpl>();
+ servicePublisher->registerService(myService, serviceAddress, factory);
+
+ while (true) {
+ std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(60));
+ }
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/e02Attributes/.gitignore b/CommonAPI-Examples/e02Attributes/.gitignore
new file mode 100644
index 0000000..5897208
--- /dev/null
+++ b/CommonAPI-Examples/e02Attributes/.gitignore
@@ -0,0 +1,2 @@
+build
+src-gen \ No newline at end of file
diff --git a/CommonAPI-Examples/e02Attributes/CMakeLists.txt b/CommonAPI-Examples/e02Attributes/CMakeLists.txt
new file mode 100644
index 0000000..73fffbc
--- /dev/null
+++ b/CommonAPI-Examples/e02Attributes/CMakeLists.txt
@@ -0,0 +1,70 @@
+# Copyright (C) 2014 BMW Group
+# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+# Author: Juergen Gehring (juergen.gehring@bmw.de)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+cmake_minimum_required(VERSION 2.8)
+
+# Project settings
+if (PRJ_NAME)
+ message(STATUS "Start CMake for Project " ${PRJ_NAME})
+else()
+ message(FATAL_ERROR "Please specify your project name using -D PRJ_NAME=yourName")
+endif()
+project(${PRJ_NAME})
+set(CMAKE_VERBOSE_MAKEFILE on)
+set(CMAKE_CXX_FLAGS "-Wall -std=c++0x")
+set(CMAKE_BUILD_TYPE Debug)
+
+# DBus Path
+if (DBUS_PATH_LOCAL)
+ message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+else()
+ message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath")
+endif()
+
+# CommonAPI
+include(FindPkgConfig)
+pkg_check_modules (COMMONAPI "CommonAPI >= 2.1")
+pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1")
+
+# Source Files
+set(PRJ_SRC_PATH src)
+set(PRJ_SRC_GEN_PATH src-gen/commonapi/examples)
+
+set(PRJ_NAME_CLIENT ${PROJECT_NAME}Client)
+set(PRJ_NAME_SERVICE ${PROJECT_NAME}Service)
+
+FILE(GLOB PRJ_PROXY_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Proxy.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp)
+FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Stub*.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp)
+FILE(GLOB PRJ_STUB_IMPL_SRCS ${PRJ_SRC_PATH}/*Stub*.cpp)
+
+set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS})
+set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS})
+
+# Paths
+message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR})
+message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR})
+
+include_directories(
+ src-gen
+ ${DBUS_PATH_LOCAL}
+ ${COMMONAPI_INCLUDEDIR}
+ ${COMMONAPI_DBUS_INCLUDEDIR}
+)
+
+link_directories(
+ ${COMMONAPI_LIBDIR}
+ ${COMMONAPI_DBUS_LIBDIR}
+)
+
+# Build Client
+add_executable(${PRJ_NAME_CLIENT} ${PRJ_CLIENT_SRCS})
+target_link_libraries(${PRJ_NAME_CLIENT} CommonAPI CommonAPI-DBus)
+
+# Build service
+add_executable(${PRJ_NAME_SERVICE} ${PRJ_SERVICE_SRCS})
+target_link_libraries(${PRJ_NAME_SERVICE} CommonAPI CommonAPI-DBus)
diff --git a/CommonAPI-Examples/e02Attributes/README b/CommonAPI-Examples/e02Attributes/README
new file mode 100644
index 0000000..5f72951
--- /dev/null
+++ b/CommonAPI-Examples/e02Attributes/README
@@ -0,0 +1,133 @@
+Example 2: Attributes
+~~~~~~~~~~~~~~~~~~~~~~
+
+Consider the Franca IDL specification of example 2:
+
+[source,java]
+----
+package commonapi.examples
+
+interface E02Attributes {
+ version { major 1 minor 0 }
+
+ attribute Int32 x
+
+ attribute CommonTypes.a1Struct a1
+}
+
+typeCollection CommonTypes {
+
+ struct a1Struct {
+ String s
+ a2Struct a2
+ }
+
+ struct a2Struct {
+ Boolean b
+ Double d
+ }
+}
+----
+
+Modelling attributes in interfaces means in general that the service that implements this interface has an internal state which shall be visible for external clients like a HMI (Human Machine Interface). A developer of a client would normally expect that he can set and get the attribute and that he can notify or subscribe to changes of the value of the attribute. We will see below in the implementation how exactly this is realized by CommonAPI. Franca offers two key words that indicate exactly how the attribute can be accessed: +readonly+ and +noSubscriptions+. The default setting is that everything is allowed; with these two additional key words these possibilies can be limited (eg if someone tries to call a set method and the attribute is readonly he will get an error at compile time).
+
+The nested structure +a1Struct+ is defined in a type collection +CommonTypes+. Structures can be defined just like other type definitions within an interface definition or outside in a type collection. Since Franca 0.8.9 type collections can also be anonymous (without name). A type collection is transferred by the CommonAPI code generator in an additional namespace.
+
+The Franca interface specification of attributes does not contain any information about whether the access from client side is synchronous or asynchronous or whether the attribute is cached by the proxy. CommonAPI provides always methods for synchronous and asynchronous setter and getter methods; caching can be realized via an API extension.
+
+Now let's have a look to the CommonAPI code on the service side. The default implementation of the stub which is generated by the CommonAPI codegenerator defines the attribute as private attribute of the stub class. This attribute can be accessed from the stub implementation via getter and setter functions. Additionaly the API for the stub implementation provides some callbacks (the following code snippet shows parts of the generated stub class which refer to the attribute x):
+
+[source,{cppstr}]
+----
+class E02AttributesStubDefault : public virtual E02AttributesStub {
+ public:
+ E02AttributesStubDefault();
+
+ virtual const int32_t& getXAttribute(
+ const std::shared_ptr<CommonAPI::ClientId> clientId);
+
+ virtual void setXAttribute(
+ const std::shared_ptr<CommonAPI::ClientId> clientId, int32_t value);
+
+ protected:
+ virtual bool trySetXAttribute(int32_t value);
+ virtual bool validateXAttributeRequestedValue(const int32_t& value);
+ virtual void onRemoteXAttributeChanged();
+
+ private:
+ int32_t xAttributeValue_;
+};
+----
+
+If the implementation of the stub has to change the value of the attribute +x+, let's say in a class +E02AttributesStubImpl+ that is derived from +E02AttributesStubDefault+, then it can call +setXAttribute+ (analog the usage of +getXAttribute+). The callback +onRemoteXAttributeChanged+ informs that a change of the attribute +x+ has been completed. The other callbacks can prevent the set of the attribute (+validateXAttributeRequestedValue+) or change the given value from the client (+trySetXAttribute+).
+
+In the example the service increments a counter every 2 seconds and publishes the counter value via the interface attribute +x+.
+
+Now see the implementation of the client. The simplest case is to get the current value of +x+. The following extract is part of the main function:
+
+[source,{cppstr}]
+----
+CommonAPI::CallStatus callStatus;
+int32_t value = 0;
+
+// Get actual attribute value from service
+myProxy->getXAttribute().getValue(callStatus, value);
+if (callStatus != CommonAPI::CallStatus::SUCCESS) {
+ std::cerr << "Remote call A failed!\n";
+ return -1;
+}
+std::cout << "Got attribute value: " << value << std::endl;
+----
+
+The +getXAttribute+ method will deliver the type +XAttribute+ which has to be used for the access to +x+. Every access returns a flag named callStatus (please see the CommonAPI specification). Subscription requires in general the definition of a callback function which is called in case of an attribute change. The subscribe method of CommonAPI requires a function object; for a compact notation this function object can be defined as lambda function:
+
+[source,{cppstr}]
+----
+myProxy->getXAttribute().getChangedEvent().subscribe([&](const int32_t& val) {
+ std::cout << "Received change message: " << val << std::endl;
+});
+----
+
+Of course it is also possible to define a separate callback function with an user-defined name (here recv_cb):
+
+[source,{cppstr}]
+----
+void recv_cb(const CommonAPI::CallStatus& callStatus, const int32_t& val) {
+ std::cout << "Receive callback: " << val << std::endl;
+}
+
+.... // main method
+
+// Subscribe for receiving values, alternative implementation 1
+std::function<void (int32_t)> f = recv_msg;
+myProxy->getXAttribute().getChangedEvent().subscribe(f);
+
+// Subscribe for receiving values, alternative implementation 2
+myProxy->getXAttribute().getChangedEvent().subscribe(
+ std::bind(recv_msg, std::placeholders::_1));
+----
+
+Asynchronous setting of attributes via setValueAsync works analog as shown in the follwoing code extract where the more complex attribute _a1_ is set from the client:
+
+[source,{cppstr}]
+----
+void recv_cb_s(const CommonAPI::CallStatus& callStatus,
+ const CommonTypes::a1Struct& valStruct) {
+
+ std::cout << "Receive callback for structure: a1.s = " <<
+ valStruct.s << ", valStruct.a2.d = " << valStruct.a2.d << std::endl;
+}
+.... // main method
+
+CommonTypes::a1Struct valueStruct;
+
+valueStruct.s = "abc";
+valueStruct.a2.b = true;
+valueStruct.a2.d = 1234;
+
+std::function<void (const CommonAPI::CallStatus&, CommonTypes::a1Struct)> fcb_s =
+ recv_cb_s;
+
+myProxy->getA1Attribute().setValueAsync(valueStruct, fcb_s);
+----
+
diff --git a/CommonAPI-Examples/e02Attributes/fidl/E02Attributes.fidl b/CommonAPI-Examples/e02Attributes/fidl/E02Attributes.fidl
new file mode 100644
index 0000000..ff2ad7d
--- /dev/null
+++ b/CommonAPI-Examples/e02Attributes/fidl/E02Attributes.fidl
@@ -0,0 +1,29 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package commonapi.examples
+
+interface E02Attributes {
+ version { major 1 minor 0 }
+
+ attribute Int32 x
+
+ attribute CommonTypes.a1Struct a1
+}
+
+typeCollection CommonTypes {
+
+ struct a1Struct {
+ String s
+ a2Struct a2
+ }
+
+ struct a2Struct {
+ Boolean b
+ Double d
+ }
+} \ No newline at end of file
diff --git a/CommonAPI-Examples/e02Attributes/src/E02AttributesStubImpl.cpp b/CommonAPI-Examples/e02Attributes/src/E02AttributesStubImpl.cpp
new file mode 100644
index 0000000..b43d92d
--- /dev/null
+++ b/CommonAPI-Examples/e02Attributes/src/E02AttributesStubImpl.cpp
@@ -0,0 +1,21 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "E02AttributesStubImpl.h"
+
+E02AttributesStubImpl::E02AttributesStubImpl() {
+ cnt = 0;
+}
+
+E02AttributesStubImpl::~E02AttributesStubImpl() {
+}
+
+void E02AttributesStubImpl::incCounter() {
+ cnt++;
+ setXAttribute((int32_t)cnt);
+ std::cout << "New counter value = " << cnt << "!" << std::endl;
+}
diff --git a/CommonAPI-Examples/e02Attributes/src/E02AttributesStubImpl.h b/CommonAPI-Examples/e02Attributes/src/E02AttributesStubImpl.h
new file mode 100644
index 0000000..d415e77
--- /dev/null
+++ b/CommonAPI-Examples/e02Attributes/src/E02AttributesStubImpl.h
@@ -0,0 +1,25 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E02ATTRIBUTESSTUBIMPL_H_
+#define E02ATTRIBUTESSTUBIMPL_H_
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E02AttributesStubDefault.h>
+
+class E02AttributesStubImpl: public commonapi::examples::E02AttributesStubDefault {
+
+public:
+ E02AttributesStubImpl();
+ virtual ~E02AttributesStubImpl();
+ virtual void incCounter();
+
+private:
+ int cnt;
+};
+
+#endif /* E02ATTRIBUTESSTUBIMPL_H_ */
diff --git a/CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp b/CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp
new file mode 100644
index 0000000..6480c5c
--- /dev/null
+++ b/CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp
@@ -0,0 +1,79 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E02AttributesProxy.h>
+
+using namespace commonapi::examples;
+
+void recv_cb(const CommonAPI::CallStatus& callStatus, const int32_t& val) {
+ std::cout << "Receive callback: " << val << std::endl;
+}
+
+void recv_cb_s(const CommonAPI::CallStatus& callStatus, const CommonTypes::a1Struct& valStruct) {
+ std::cout << "Receive callback for structure: a1.s = " << valStruct.s << ", valStruct.a2.d = " << valStruct.a2.d
+ << std::endl;
+}
+
+int main() {
+ std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::load();
+
+ std::shared_ptr < CommonAPI::Factory > factory = runtime->createFactory();
+ const std::string& serviceAddress = "local:commonapi.examples.Attributes:commonapi.examples.Attributes";
+ std::shared_ptr < E02AttributesProxyDefault > myProxy = factory->buildProxy < E02AttributesProxy > (serviceAddress);
+
+ while (!myProxy->isAvailable()) {
+ usleep(10);
+ }
+
+ CommonAPI::CallStatus callStatus;
+
+ int32_t value = 0;
+
+ // Get actual attribute value from service
+ myProxy->getXAttribute().getValue(callStatus, value);
+ if (callStatus != CommonAPI::CallStatus::SUCCESS) {
+ std::cerr << "Remote call A failed!\n";
+ return -1;
+ }
+ std::cout << "Got attribute value: " << value << std::endl;
+
+ // Subscribe for receiving values
+ myProxy->getXAttribute().getChangedEvent().subscribe([&](const int32_t& val) {
+ std::cout << "Received change message: " << val << std::endl;
+ });
+
+ value = 100;
+
+ // Asynchronous call to set attribute of service
+ std::function<void(const CommonAPI::CallStatus&, int32_t)> fcb = recv_cb;
+ myProxy->getXAttribute().setValueAsync(value, fcb);
+ if (callStatus != CommonAPI::CallStatus::SUCCESS) {
+ std::cerr << "Remote call failed!\n";
+ return -1;
+ }
+
+ // Asynchronous call to set attribute of type structure in service
+ CommonTypes::a1Struct valueStruct;
+
+ valueStruct.s = "abc";
+ valueStruct.a2.b = true;
+ valueStruct.a2.d = 1234;
+
+ std::function<void(const CommonAPI::CallStatus&, CommonTypes::a1Struct)> fcb_s = recv_cb_s;
+ myProxy->getA1Attribute().setValueAsync(valueStruct, fcb_s);
+ if (callStatus != CommonAPI::CallStatus::SUCCESS) {
+ std::cerr << "Remote set of structure failed!\n";
+ return -1;
+ }
+
+ while (true) {
+ usleep(10);
+ }
+}
diff --git a/CommonAPI-Examples/e02Attributes/src/e02AttributesService.cpp b/CommonAPI-Examples/e02Attributes/src/e02AttributesService.cpp
new file mode 100644
index 0000000..8636a6e
--- /dev/null
+++ b/CommonAPI-Examples/e02Attributes/src/e02AttributesService.cpp
@@ -0,0 +1,30 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <thread>
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include "E02AttributesStubImpl.h"
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher();
+
+ const std::string& serviceAddress = "local:commonapi.examples.Attributes:commonapi.examples.Attributes";
+ std::shared_ptr<E02AttributesStubImpl> myService = std::make_shared<E02AttributesStubImpl>();
+ servicePublisher->registerService(myService, serviceAddress, factory);
+
+ while (true) {
+ myService->incCounter(); // Change value of attribute, see stub implementation
+ std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(2));
+ }
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/e03Methods/.gitignore b/CommonAPI-Examples/e03Methods/.gitignore
new file mode 100644
index 0000000..5897208
--- /dev/null
+++ b/CommonAPI-Examples/e03Methods/.gitignore
@@ -0,0 +1,2 @@
+build
+src-gen \ No newline at end of file
diff --git a/CommonAPI-Examples/e03Methods/CMakeLists.txt b/CommonAPI-Examples/e03Methods/CMakeLists.txt
new file mode 100644
index 0000000..73fffbc
--- /dev/null
+++ b/CommonAPI-Examples/e03Methods/CMakeLists.txt
@@ -0,0 +1,70 @@
+# Copyright (C) 2014 BMW Group
+# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+# Author: Juergen Gehring (juergen.gehring@bmw.de)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+cmake_minimum_required(VERSION 2.8)
+
+# Project settings
+if (PRJ_NAME)
+ message(STATUS "Start CMake for Project " ${PRJ_NAME})
+else()
+ message(FATAL_ERROR "Please specify your project name using -D PRJ_NAME=yourName")
+endif()
+project(${PRJ_NAME})
+set(CMAKE_VERBOSE_MAKEFILE on)
+set(CMAKE_CXX_FLAGS "-Wall -std=c++0x")
+set(CMAKE_BUILD_TYPE Debug)
+
+# DBus Path
+if (DBUS_PATH_LOCAL)
+ message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+else()
+ message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath")
+endif()
+
+# CommonAPI
+include(FindPkgConfig)
+pkg_check_modules (COMMONAPI "CommonAPI >= 2.1")
+pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1")
+
+# Source Files
+set(PRJ_SRC_PATH src)
+set(PRJ_SRC_GEN_PATH src-gen/commonapi/examples)
+
+set(PRJ_NAME_CLIENT ${PROJECT_NAME}Client)
+set(PRJ_NAME_SERVICE ${PROJECT_NAME}Service)
+
+FILE(GLOB PRJ_PROXY_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Proxy.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp)
+FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Stub*.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp)
+FILE(GLOB PRJ_STUB_IMPL_SRCS ${PRJ_SRC_PATH}/*Stub*.cpp)
+
+set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS})
+set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS})
+
+# Paths
+message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR})
+message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR})
+
+include_directories(
+ src-gen
+ ${DBUS_PATH_LOCAL}
+ ${COMMONAPI_INCLUDEDIR}
+ ${COMMONAPI_DBUS_INCLUDEDIR}
+)
+
+link_directories(
+ ${COMMONAPI_LIBDIR}
+ ${COMMONAPI_DBUS_LIBDIR}
+)
+
+# Build Client
+add_executable(${PRJ_NAME_CLIENT} ${PRJ_CLIENT_SRCS})
+target_link_libraries(${PRJ_NAME_CLIENT} CommonAPI CommonAPI-DBus)
+
+# Build service
+add_executable(${PRJ_NAME_SERVICE} ${PRJ_SERVICE_SRCS})
+target_link_libraries(${PRJ_NAME_SERVICE} CommonAPI CommonAPI-DBus)
diff --git a/CommonAPI-Examples/e03Methods/README b/CommonAPI-Examples/e03Methods/README
new file mode 100644
index 0000000..1216224
--- /dev/null
+++ b/CommonAPI-Examples/e03Methods/README
@@ -0,0 +1,135 @@
+Example 3: Methods
+~~~~~~~~~~~~~~~~~~
+
+Franca attributes represent status variables or data sets of services which shall be accessible by the clients of the service. In contrast, methods can be used for example to start a process in the service or to query for certain information (eg, from a database). See the following example 3:
+
+[source,java]
+----
+package commonapi.examples
+
+interface E03Methods {
+
+ version { major 1 minor 0 }
+
+ method foo {
+ in {
+ Int32 x1
+ String x2
+ }
+ out {
+ Int32 y1
+ String y2
+ }
+ error {
+ stdErrorTypeEnum
+ }
+ }
+
+ broadcast myStatus {
+ out {
+ Int32 myCurrentValue
+ }
+ }
+
+ enumeration stdErrorTypeEnum {
+ NO_FAULT
+ MY_FAULT
+ }
+}
+----
+
+Basically Franca methods have input parameters and output parameters and can return an optional application error which reports for example if the started process in the sevice could be finished successfully or not. Input and output parameters can have arbitrarily complex types, a separate definition of so-called InOut arguments of functions was not considered necessary.
+
+A special case are broadcasts. They can be used like readonly attributes. But there are several output parameters allowed (and no input parameters). Another difference is the additional optional keyword selective, which indicates that only selected clients can register on the broadcast see example 4).
+
+Another optional keyword (only for methods) is fireAndForget which indicates that neither return values nor a call status is expected.
+
+The implementation of the service class is straight:
+
+[source,{cppstr}]
+----
+#include "E03MethodsStubImpl.h"
+
+using namespace commonapi::examples;
+
+... // Additional code
+
+void E03MethodsStubImpl::foo(int32_t x1, std::string x2,
+ E03Methods::fooError& methodError, int32_t& y1, std::string& y2) {
+
+ std::cout << "foo called, setting new values." << std::endl;
+
+ methodError = (E03Methods::fooError)E03Methods::stdErrorTypeEnum::MY_FAULT;
+ y1 = 42;
+ y2 = "xyz";
+}
+----
+
+The input parameters are available as values, the output parameter as references. The standard name for the application error is methodError. In the example there is another function incCounter implemented which sends the broadcast myStatus via the generated method fireMyStatusEvent:
+
+[source,{cppstr}]
+----
+void E03MethodsStubImpl::incCounter() {
+ cnt++;
+ fireMyStatusEvent((int32_t)cnt);
+ std::cout << "New counter value = " << cnt << "!" << std::endl;
+};
+----
+The subscription to the broadcast is nearly identical to the subscription to the change of the value of an attribute. The example shows further an asynchronous and a synchronous call of the function foo; in the asynchronous case the callback function +recv_cb+ is defined.
+
+[source,{cppstr}]
+----
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E03MethodsProxy.h>
+
+using namespace commonapi::examples;
+
+void recv_cb(const CommonAPI::CallStatus& callStatus, const E03Methods::fooError& methodError,
+ const int32_t& y1, const std::string& y2) {
+
+... // your code
+}
+
+int main() {
+
+ // Subscribe to broadcast
+ myProxy->getMyStatusEvent().subscribe([&](const int32_t& val) {
+ std::cout << "Received status event: " << val << std::endl;
+ });
+
+ while(true) {
+
+ int32_t inX1 = 5;
+ std::string inX2 = "abc";
+ CommonAPI::CallStatus callStatus;
+ E03Methods::fooError methodError;
+ int32_t outY1;
+ std::string outY2;
+
+ // Synchronous call
+ std::cout << "Call foo with synchronous semantics ..." << std::endl ;
+ myProxy->foo(inX1, inX2, callStatus, methodError, outY1, outY2);
+
+ // Asynchronous call
+ std::cout << "Call foo with asynchronous semantics ..." << std::endl;
+
+ std::function<void (const CommonAPI::CallStatus&,
+ const E03Methods::fooError&, const int32_t&, const std::string&)> fcb = recv_cb;
+
+ myProxy->fooAsync(inX1, inX2, recv_cb);
+
+ std::this_thread::sleep_for(std::chrono::seconds(5));
+ }
+ return 0;
+}
+----
+
+A frequently asked question is what happens if the service does not answer. In this case, the callback function +recv_cb+ is called anyway, but the +callStatus+ has the value +REMOTE_ERROR+. It is however the responsibility of the specific middleware to implement this behavior. The CommonAPI specification says:
+
+- *NOT* considered to be a remote error is an application level error that is defined in the corresponding Franca interface, because from the point of view of the transport layer the service still returned a valid answer.
+- It *IS* considered to be a remote error if no answer for a sent remote method call is returned within a defined time. It is discouraged to allow the sending of any method calls without a defined timeout. This timeout may be middleware specific. This timeout may also be configurable by means of a Franca Deployment Model. It is *NOT* configurable at runtime by means of the Common API.
+
+The actual version of the D-Bus binding has a non configurable timeout of about 5 seconds.
+
diff --git a/CommonAPI-Examples/e03Methods/fidl/E03Methods.fidl b/CommonAPI-Examples/e03Methods/fidl/E03Methods.fidl
new file mode 100644
index 0000000..9c6c93e
--- /dev/null
+++ b/CommonAPI-Examples/e03Methods/fidl/E03Methods.fidl
@@ -0,0 +1,38 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package commonapi.examples
+
+interface E03Methods {
+
+ version { major 1 minor 0 }
+
+ method foo {
+ in {
+ Int32 x1
+ String x2
+ }
+ out {
+ Int32 y1
+ String y2
+ }
+ error {
+ stdErrorTypeEnum
+ }
+ }
+
+ broadcast myStatus {
+ out {
+ Int32 myCurrentValue
+ }
+ }
+
+ enumeration stdErrorTypeEnum {
+ NO_FAULT
+ MY_FAULT
+ }
+}
diff --git a/CommonAPI-Examples/e03Methods/src/E03MethodsStubImpl.cpp b/CommonAPI-Examples/e03Methods/src/E03MethodsStubImpl.cpp
new file mode 100644
index 0000000..e0b47ef
--- /dev/null
+++ b/CommonAPI-Examples/e03Methods/src/E03MethodsStubImpl.cpp
@@ -0,0 +1,37 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "E03MethodsStubImpl.h"
+
+using namespace commonapi::examples;
+
+E03MethodsStubImpl::E03MethodsStubImpl() {
+ cnt = 0;
+}
+
+E03MethodsStubImpl::~E03MethodsStubImpl() {
+}
+
+void E03MethodsStubImpl::incCounter() {
+ cnt++;
+ fireMyStatusEvent((int32_t) cnt);
+ std::cout << "New counter value = " << cnt << "!" << std::endl;
+}
+;
+
+void E03MethodsStubImpl::foo(int32_t x1,
+ std::string x2,
+ E03Methods::fooError& methodError,
+ int32_t& y1,
+ std::string& y2) {
+
+ std::cout << "foo called, setting new values." << std::endl;
+
+ methodError = (E03Methods::fooError) E03Methods::stdErrorTypeEnum::MY_FAULT;
+ y1 = 42;
+ y2 = "xyz";
+}
diff --git a/CommonAPI-Examples/e03Methods/src/E03MethodsStubImpl.h b/CommonAPI-Examples/e03Methods/src/E03MethodsStubImpl.h
new file mode 100644
index 0000000..654620c
--- /dev/null
+++ b/CommonAPI-Examples/e03Methods/src/E03MethodsStubImpl.h
@@ -0,0 +1,30 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E03METHODSSTUBIMPL_H_
+#define E03METHODSSTUBIMPL_H_
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E03MethodsStubDefault.h>
+
+class E03MethodsStubImpl: public commonapi::examples::E03MethodsStubDefault {
+
+public:
+ E03MethodsStubImpl();
+ virtual ~E03MethodsStubImpl();
+ virtual void incCounter();
+ void foo(int32_t x1,
+ std::string x2,
+ commonapi::examples::E03Methods::fooError& methodError,
+ int32_t& y1,
+ std::string& y2);
+
+private:
+ int cnt;
+};
+
+#endif /* E03METHODSSTUBIMPL_H_ */
diff --git a/CommonAPI-Examples/e03Methods/src/e03MethodsClient.cpp b/CommonAPI-Examples/e03Methods/src/e03MethodsClient.cpp
new file mode 100644
index 0000000..f5b4426
--- /dev/null
+++ b/CommonAPI-Examples/e03Methods/src/e03MethodsClient.cpp
@@ -0,0 +1,79 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E03MethodsProxy.h>
+
+using namespace commonapi::examples;
+
+void recv_cb(const CommonAPI::CallStatus& callStatus,
+ const E03Methods::fooError& methodError,
+ const int32_t& y1,
+ const std::string& y2) {
+ std::cout << "Result of asynchronous call of foo: " << std::endl;
+ std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS")
+ << std::endl;
+ std::cout << " error: "
+ << (((E03Methods::stdErrorTypeEnum) methodError == E03Methods::stdErrorTypeEnum::NO_FAULT) ? "NO_FAULT" :
+ "MY_FAULT") << std::endl;
+ std::cout << " Output values: y1 = " << y1 << ", y2 = " << y2 << std::endl;
+}
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ const std::string& serviceAddress = "local:commonapi.examples.Methods:commonapi.examples.Methods";
+ std::shared_ptr<E03MethodsProxyDefault> myProxy = factory->buildProxy < E03MethodsProxy > (serviceAddress);
+
+ while (!myProxy->isAvailable()) {
+ usleep(10);
+ }
+
+ // Subscribe to broadcast
+ myProxy->getMyStatusEvent().subscribe([&](const int32_t& val) {
+ std::cout << "Received status event: " << val << std::endl;
+ });
+
+ while (true) {
+ int32_t inX1 = 5;
+ std::string inX2 = "abc";
+ CommonAPI::CallStatus callStatus;
+ E03Methods::fooError methodError;
+ int32_t outY1;
+ std::string outY2;
+
+ // Synchronous call
+ std::cout << "Call foo with synchronous semantics ..." << std::endl;
+ myProxy->foo(inX1, inX2, callStatus, methodError, outY1, outY2);
+
+ std::cout << "Result of synchronous call of foo: " << std::endl;
+ std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS")
+ << std::endl;
+ std::cout << " error: "
+ << (((E03Methods::stdErrorTypeEnum) methodError == E03Methods::stdErrorTypeEnum::NO_FAULT) ? "NO_FAULT" : "MY_FAULT")
+ << std::endl;
+ std::cout << " Input values: x1 = " << inX1 << ", x2 = " << inX2 << std::endl;
+ std::cout << " Output values: y1 = " << outY1 << ", y2 = " << outY2 << std::endl;
+
+ // Asynchronous call
+ std::cout << "Call foo with asynchronous semantics ..." << std::endl;
+
+ std::function<
+ void(const CommonAPI::CallStatus&,
+ const E03Methods::fooError&,
+ const int32_t&,
+ const std::string&)> fcb = recv_cb;
+ myProxy->fooAsync(inX1, inX2, recv_cb);
+
+ std::this_thread::sleep_for(std::chrono::seconds(5));
+ }
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/e03Methods/src/e03MethodsService.cpp b/CommonAPI-Examples/e03Methods/src/e03MethodsService.cpp
new file mode 100644
index 0000000..71003bc
--- /dev/null
+++ b/CommonAPI-Examples/e03Methods/src/e03MethodsService.cpp
@@ -0,0 +1,30 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <thread>
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include "E03MethodsStubImpl.h"
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher();
+
+ const std::string& serviceAddress = "local:commonapi.examples.Methods:commonapi.examples.Methods";
+ std::shared_ptr<E03MethodsStubImpl> myService = std::make_shared<E03MethodsStubImpl>();
+ servicePublisher->registerService(myService, serviceAddress, factory);
+
+ while (true) {
+ myService->incCounter(); // Change value of attribute, see stub implementation
+ std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(2));
+ }
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/e04PhoneBook/.gitignore b/CommonAPI-Examples/e04PhoneBook/.gitignore
new file mode 100644
index 0000000..5897208
--- /dev/null
+++ b/CommonAPI-Examples/e04PhoneBook/.gitignore
@@ -0,0 +1,2 @@
+build
+src-gen \ No newline at end of file
diff --git a/CommonAPI-Examples/e04PhoneBook/CMakeLists.txt b/CommonAPI-Examples/e04PhoneBook/CMakeLists.txt
new file mode 100644
index 0000000..d0202e7
--- /dev/null
+++ b/CommonAPI-Examples/e04PhoneBook/CMakeLists.txt
@@ -0,0 +1,71 @@
+# Copyright (C) 2014 BMW Group
+# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+# Author: Juergen Gehring (juergen.gehring@bmw.de)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+cmake_minimum_required(VERSION 2.8)
+
+# Project settings
+if (PRJ_NAME)
+ message(STATUS "Start CMake for Project " ${PRJ_NAME})
+else()
+ message(FATAL_ERROR "Please specify your project name using -D PRJ_NAME=yourName")
+endif()
+project(${PRJ_NAME})
+set(CMAKE_VERBOSE_MAKEFILE on)
+set(CMAKE_CXX_FLAGS "-Wall -std=c++0x")
+set(CMAKE_BUILD_TYPE Debug)
+
+# DBus Path
+if (DBUS_PATH_LOCAL)
+ message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+else()
+ message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath")
+endif()
+
+# CommonAPI
+include(FindPkgConfig)
+pkg_check_modules (COMMONAPI "CommonAPI >= 2.1")
+pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1")
+
+# Source Files
+set(PRJ_SRC_PATH src)
+set(PRJ_SRC_GEN_PATH src-gen/commonapi/examples)
+
+set(PRJ_NAME_CLIENT ${PROJECT_NAME}Client)
+set(PRJ_NAME_SERVICE ${PROJECT_NAME}Service)
+
+STRING(REGEX REPLACE "^e" "E" PRJ_DATA_IMPL ${PRJ_NAME})
+FILE(GLOB PRJ_PROXY_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Proxy.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp ${PRJ_SRC_GEN_PATH}/${PRJ_DATA_IMPL}.cpp)
+FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Stub*.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp ${PRJ_SRC_GEN_PATH}/${PRJ_DATA_IMPL}.cpp)
+FILE(GLOB PRJ_STUB_IMPL_SRCS ${PRJ_SRC_PATH}/*Stub*.cpp)
+
+set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS})
+set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS})
+
+# Paths
+message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR})
+message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR})
+
+include_directories(
+ src-gen
+ ${DBUS_PATH_LOCAL}
+ ${COMMONAPI_INCLUDEDIR}
+ ${COMMONAPI_DBUS_INCLUDEDIR}
+)
+
+link_directories(
+ ${COMMONAPI_LIBDIR}
+ ${COMMONAPI_DBUS_LIBDIR}
+)
+
+# Build Client
+add_executable(${PRJ_NAME_CLIENT} ${PRJ_CLIENT_SRCS})
+target_link_libraries(${PRJ_NAME_CLIENT} CommonAPI CommonAPI-DBus)
+
+# Build service
+add_executable(${PRJ_NAME_SERVICE} ${PRJ_SERVICE_SRCS})
+target_link_libraries(${PRJ_NAME_SERVICE} CommonAPI CommonAPI-DBus)
diff --git a/CommonAPI-Examples/e04PhoneBook/README b/CommonAPI-Examples/e04PhoneBook/README
new file mode 100644
index 0000000..90a2eb5
--- /dev/null
+++ b/CommonAPI-Examples/e04PhoneBook/README
@@ -0,0 +1,237 @@
+Example 4: PhoneBook
+~~~~~~~~~~~~~~~~~~~~
+
+This slightly more complex example illustrates the application of some Franca features in combination with CommonAPI:
+
+- explicit named arrays and inline arrays
+- selective broadcasts
+- polymorphic structs
+
+Concerning arrays please note the following points:
+
+- In Franca there are two ways to define arrays: explicitly named (array myArray of UInt8) or implicit without defining a new name for the array (UInt8 []).
+- The implicit definition of multidimensional arrays is not possible at the moment (like UInt8 [][]), but multidimensional arrays can be defined with explicit names.
+- In CommonAPI arrays are implemented and generated as std::vector.
+
+A common problem in the specification of interfaces between user frontends and services which contain large data sets is, that the clients usually need only extracts from the database. That means that only a filtered excerpt from the database has to be transmitted via IPC to the client, but probably every client needs a different excerpt. The filter can affect the selection of the elements (element filter), the contents of the elements (content filter) or the number of elements (array window).
+
+The following example shows how different extracts of a central data array can be accessed by the several clients via a data filter mechansim and selective broadcasts. As example of a central data array a phonebook is selected; the following picture shows the basic content of the example.
+
+image::{imagedir}/E04PhoneBook.png[PhoneBookExample image]
+
+The Franca IDL specification is:
+
+[source,java]
+----
+package commonapi.examples
+
+interface E04PhoneBook {
+
+ version { major 1 minor 0 }
+
+ <** @description : the phone book itself **>
+ attribute phoneBookStruct [] phoneBook readonly
+
+ <** @description : filter operations **>
+ method setPhoneBookDataFilter {
+ in {
+ elementFilterStruct elementFilter
+ contentFilterStruct [] contentFilter
+ }
+ }
+
+ <** @description : filter result **>
+ broadcast phoneBookDataSet selective {
+ out {
+ phoneBookDataElementMap [] phoneBookDataSet
+ }
+ }
+
+ <** @description : Data types of the phone book itself **>
+ enumeration phoneNumberEnum {
+ WORK
+ HOME
+ MOBILE1
+ MOBILE2
+ }
+
+ map phoneNumberMap {
+ phoneNumberEnum to String
+ }
+
+ struct phoneBookStruct {
+ String name
+ String forename
+ String organisation
+ String address
+ String email
+ phoneNumberMap phoneNumber
+ }
+
+ <** @description : Data types for the filter operations **>
+
+ struct elementFilterStruct {
+ Boolean addName
+ Boolean addForename
+ Boolean addOrganisation
+ Boolean addAddress
+ Boolean addEmail
+ Boolean addPhoneNumber
+ }
+
+ struct contentFilterStruct {
+ phoneBookDataElementEnum element
+ String expression
+ }
+
+ <** @description : Data types for the result of the phone book filter **>
+ enumeration phoneBookDataElementEnum {
+ NAME
+ FORENAME
+ ORGANISATION
+ ADDRESS
+ EMAIL
+ PHONENUMBER
+ }
+
+ struct phoneBookDataElement polymorphic {
+ }
+
+ struct phoneBookDataElementString extends phoneBookDataElement {
+ String content
+ }
+
+ struct phoneBookDataElementPhoneNumber extends phoneBookDataElement {
+ phoneNumberMap content
+ }
+
+ map phoneBookDataElementMap {
+ phoneBookDataElementEnum to phoneBookDataElement
+ }
+}
+----
+
+The phone book itself is modeled as an attribute which is an array of the structure +phoneBookStruct+. Here the phone book is readonly, that means that the whole content can be accessed only via subscription and the getter function. A special difficulty is the phone number, because there are several kinds of phone numbers allowed (home, mobile, ...). Therefore the element +phoneNumber+ in +phoneBookStruct+ is a map with an enumeration key and a value of type string for the number. The client can set a filter to the phone book data (in the example only content filter and element filter, but other filters are conceivable) via the method +setPhoneBookDataFilter+ and gets the data back via the selective broadcast +phoneBookDataSet+. Since the content of the data set depends on the filter, the elements of the client specific data set are specified as maps where the key is the type of the element (name, forename, ...) and the value is the content of the element. The content can be of the type String or of the user defined type phoneNumberMap. Therefore the value is defined as polymorphic struct which can be a String or a phoneNumberMap.
+
+In the following we consider only some interesting implementation details, for the complete implementation please see the source code.
+
+The interesting part of the service is the implementation of the set function for the data filter. At the moment only the element filter is implemented, but the implementation of the other filters can be added analogously.
+
+- Each client is identified via its clientId; the implementation of client ID class allows the usage of cientId objects as key in a map (see the specification).
+- The data sets of the filtered data for the clients are stored in a map with the clientId as key; in this example the filtered data are sent back to the client directly in the filter set function. Please note, that firePhoneBookDataSetSelective sends the data to only one receiver.
+- The value of the key has to be the right type (+phoneNumberMap+ for phoneNumbers and Strings for the rest).
+
+[source,{cppstr}]
+----
+void E04PhoneBookStubImpl::setPhoneBookDataFilter (
+ const std::shared_ptr<CommonAPI::ClientId> clientId,
+ E04PhoneBook::elementFilterStruct elementFilter,
+ std::vector<E04PhoneBook::contentFilterStruct> contentFilter ) {
+
+ std::shared_ptr<CommonAPI::ClientIdList> clientIdList =
+ getSubscribersForPhoneBookDataSetSelective();
+
+ std::vector<E04PhoneBook::phoneBookDataElementMap> lPhoneBookDataSet;
+ phoneBookClientData.erase (clientId);
+
+ std::vector<E04PhoneBook::phoneBookStruct>::const_iterator it0;
+ for (it0 = getPhoneBookAttribute().begin();
+ it0 != getPhoneBookAttribute().end(); it0++ ) {
+
+ E04PhoneBook::phoneBookDataElementMap lPhoneBookDataElement;
+
+ if ( elementFilter.addName ) {
+ std::shared_ptr<E04PhoneBook::phoneBookDataElementString> name =
+ std::make_shared<E04PhoneBook::phoneBookDataElementString>();
+
+ name->content = it0->name;
+
+ lPhoneBookDataElement[E04PhoneBook::phoneBookDataElementEnum::NAME] =
+ name;
+ }
+
+ ... // analogue for the other elements
+
+ if ( elementFilter.addPhoneNumber ) {
+ std::shared_ptr<E04PhoneBook::phoneBookDataElementPhoneNumber> phoneNumber =
+ std::make_shared<E04PhoneBook::phoneBookDataElementPhoneNumber>();
+
+ phoneNumber->content = it0->phoneNumber;
+
+ lPhoneBookDataElement[E04PhoneBook::phoneBookDataElementEnum::PHONENUMBER] =
+ phoneNumber;
+ }
+
+ lPhoneBookDataSet.push_back(lPhoneBookDataElement);
+
+ }
+
+ phoneBookClientData[clientId] = lPhoneBookDataSet;
+
+ // Send client data
+ const std::shared_ptr<CommonAPI::ClientIdList> receivers(new CommonAPI::ClientIdList);
+ receivers->insert(clientId);
+
+ firePhoneBookDataSetSelective(lPhoneBookDataSet, receivers);
+ receivers->erase(clientId);
+}
+----
+
+On client side we create two proxies which shall set different filters and get different data sets. For these two proxies we need different factories! Otherwise CommonAPI cannot keep the proxies apart. Each proxy has to subscribe to phoneBookDataSet, but gets different contents depending on the filter. The whole phoneBookData can be obtained via the standard get function.
+
+[source,{cppstr}]
+----
+int main() {
+
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+
+ std::shared_ptr<CommonAPI::Factory> factoryA = runtime->createFactory();
+ std::shared_ptr<CommonAPI::Factory> factoryB = runtime->createFactory();
+
+ const std::string& serviceAddress =
+ "local:commonapi.examples.PhoneBook:commonapi.examples.PhoneBook";
+
+ std::shared_ptr<E04PhoneBookProxy<>> myProxyA =
+ factoryA->buildProxy<E04PhoneBookProxy>(serviceAddress);
+ while (!myProxyA->isAvailable()) { usleep(10); }
+
+ std::shared_ptr<E04PhoneBookProxy<>> myProxyB =
+ factoryB->buildProxy<E04PhoneBookProxy>(serviceAddress);
+ while (!myProxyB->isAvailable()) { usleep(10); }
+
+ // Subscribe A to broadcast
+ myProxyA->getPhoneBookDataSetSelectiveEvent().subscribe(
+ [&](const std::vector<E04PhoneBook::phoneBookDataElementMap>& phoneBookDataSet) {
+ printFilterResult(phoneBookDataSet, "A");
+ });
+
+ // Subscribe B to broadcast
+ myProxyB->getPhoneBookDataSetSelectiveEvent().subscribe(
+ [&](const std::vector<E04PhoneBook::phoneBookDataElementMap>& phoneBookDataSet) {
+ printFilterResult(phoneBookDataSet, "B");
+ });
+
+ // Get actual phoneBook from service
+ CommonAPI::CallStatus myCallStatus;
+ std::vector<E04PhoneBook::phoneBookStruct> myValue;
+ myProxyA->getPhoneBookAttribute().getValue(myCallStatus, myValue);
+
+ // Synchronous call setPhoneBookDataFilter
+ E04PhoneBook::elementFilterStruct lElementFilterA =
+ { true, true, false, false, false, false};
+
+ std::vector<E04PhoneBook::contentFilterStruct> lContentFilterA =
+ { {E04PhoneBook::phoneBookDataElementEnum::NAME, "*"} };
+ myProxyA->setPhoneBookDataFilter(lElementFilterA, lContentFilterA, myCallStatus);
+
+ E04PhoneBook::elementFilterStruct lElementFilterB =
+ { true, false, false, false, false, true };
+
+ std::vector<E04PhoneBook::contentFilterStruct> lContentFilterB =
+ { {E04PhoneBook::phoneBookDataElementEnum::NAME, "*"} };
+ myProxyB->setPhoneBookDataFilter(lElementFilterB, lContentFilterB, myCallStatus);
+
+ ... // further code
+}
+----
+
diff --git a/CommonAPI-Examples/e04PhoneBook/fidl/E04PhoneBook.fidl b/CommonAPI-Examples/e04PhoneBook/fidl/E04PhoneBook.fidl
new file mode 100644
index 0000000..929b296
--- /dev/null
+++ b/CommonAPI-Examples/e04PhoneBook/fidl/E04PhoneBook.fidl
@@ -0,0 +1,93 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package commonapi.examples
+
+interface E04PhoneBook {
+
+ version { major 1 minor 0 }
+
+ <** @description : the phone book itself **>
+ attribute phoneBookStruct [] phoneBook readonly
+
+ <** @description : filter operations **>
+ method setPhoneBookDataFilter {
+ in {
+ elementFilterStruct elementFilter
+ contentFilterStruct [] contentFilter
+ }
+ }
+
+ <** @description : filter result **>
+ broadcast phoneBookDataSet selective {
+ out {
+ phoneBookDataElementMap [] phoneBookDataSet
+ }
+ }
+
+ <** @description : Data types of the phone book itself **>
+ enumeration phoneNumberEnum {
+ WORK
+ HOME
+ MOBILE1
+ MOBILE2
+ }
+
+ map phoneNumberMap {
+ phoneNumberEnum to String
+ }
+
+ struct phoneBookStruct {
+ String name
+ String forename
+ String organisation
+ String address
+ String email
+ phoneNumberMap phoneNumber
+ }
+
+ <** @description : Data types for the filter operations **>
+
+ struct elementFilterStruct {
+ Boolean addName
+ Boolean addForename
+ Boolean addOrganisation
+ Boolean addAddress
+ Boolean addEmail
+ Boolean addPhoneNumber
+ }
+
+ struct contentFilterStruct {
+ phoneBookDataElementEnum element
+ String expression
+ }
+
+ <** @description : Data types for the result of the phone book filter **>
+ enumeration phoneBookDataElementEnum {
+ NAME
+ FORENAME
+ ORGANISATION
+ ADDRESS
+ EMAIL
+ PHONENUMBER
+ }
+
+ struct phoneBookDataElement polymorphic {
+ }
+
+ struct phoneBookDataElementString extends phoneBookDataElement {
+ String content
+ }
+
+ struct phoneBookDataElementPhoneNumber extends phoneBookDataElement {
+ phoneNumberMap content
+ }
+
+ map phoneBookDataElementMap {
+ phoneBookDataElementEnum to phoneBookDataElement
+ }
+} \ No newline at end of file
diff --git a/CommonAPI-Examples/e04PhoneBook/src/E04PhoneBookStubImpl.cpp b/CommonAPI-Examples/e04PhoneBook/src/E04PhoneBookStubImpl.cpp
new file mode 100644
index 0000000..a0a8e05
--- /dev/null
+++ b/CommonAPI-Examples/e04PhoneBook/src/E04PhoneBookStubImpl.cpp
@@ -0,0 +1,146 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "E04PhoneBookStubImpl.h"
+
+using namespace commonapi::examples;
+
+E04PhoneBookStubImpl::E04PhoneBookStubImpl() {
+}
+
+E04PhoneBookStubImpl::~E04PhoneBookStubImpl() {
+}
+
+bool E04PhoneBookStubImpl::contains(std::vector<E04PhoneBook::phoneBookDataElementEnum>& vec,
+ const E04PhoneBook::phoneBookDataElementEnum& el) {
+
+ if (std::find(vec.begin(), vec.end(), el) != vec.end()) {
+ return true;
+ }
+ return false;
+}
+
+void E04PhoneBookStubImpl::onPhoneBookDataSetSelectiveSubscriptionChanged(const std::shared_ptr<CommonAPI::ClientId> clientId,
+ const CommonAPI::SelectiveBroadcastSubscriptionEvent event) {
+
+ if (event == CommonAPI::SelectiveBroadcastSubscriptionEvent::SUBSCRIBED) {
+ std::cout << "onPhoneBookDataSetSelectiveSubscriptionChanged(SUBSCRIBED) called ("
+ << clientId->hashCode() << ")." << std::endl;
+
+ } else if (event == CommonAPI::SelectiveBroadcastSubscriptionEvent::UNSUBSCRIBED) {
+ std::cout << "onPhoneBookDataSetSelectiveSubscriptionChanged(UNSUBSCRIBED) called ("
+ << clientId->hashCode() << "." << std::endl;
+ }
+}
+
+void E04PhoneBookStubImpl::setPhoneBookDataFilter(const std::shared_ptr<CommonAPI::ClientId> clientId,
+ E04PhoneBook::elementFilterStruct elementFilter,
+ std::vector<E04PhoneBook::contentFilterStruct> contentFilter) {
+
+ std::shared_ptr < CommonAPI::ClientIdList > clientIdList = getSubscribersForPhoneBookDataSetSelective();
+ std::cout << "setPhoneBookDataFilter called from client " << clientId->hashCode() << " of ("
+ << clientIdList->size() << ")" << std::endl;
+
+ std::vector < E04PhoneBook::phoneBookDataElementMap > lPhoneBookDataSet;
+ phoneBookClientData.erase(clientId);
+
+ std::vector<E04PhoneBook::phoneBookStruct>::const_iterator it0;
+ for (it0 = getPhoneBookAttribute().begin(); it0 != getPhoneBookAttribute().end(); it0++) {
+
+ E04PhoneBook::phoneBookDataElementMap lPhoneBookDataElement;
+
+ if (elementFilter.addName) {
+ std::shared_ptr<E04PhoneBook::phoneBookDataElementString> name = std::make_shared<E04PhoneBook::phoneBookDataElementString>();
+ name->content = it0->name;
+ lPhoneBookDataElement[E04PhoneBook::phoneBookDataElementEnum::NAME] = name;
+ }
+
+ if (elementFilter.addForename) {
+ std::shared_ptr<E04PhoneBook::phoneBookDataElementString> forename = std::make_shared<E04PhoneBook::phoneBookDataElementString>();
+ forename->content = it0->forename;
+ lPhoneBookDataElement[E04PhoneBook::phoneBookDataElementEnum::FORENAME] = forename;
+ }
+
+ if (elementFilter.addOrganisation) {
+ std::shared_ptr<E04PhoneBook::phoneBookDataElementString> organisation = std::make_shared<E04PhoneBook::phoneBookDataElementString>();
+ organisation->content = it0->organisation;
+ lPhoneBookDataElement[E04PhoneBook::phoneBookDataElementEnum::ORGANISATION] = organisation;
+ }
+
+ if (elementFilter.addAddress) {
+ std::shared_ptr<E04PhoneBook::phoneBookDataElementString> address = std::make_shared<E04PhoneBook::phoneBookDataElementString>();
+ address->content = it0->address;
+ lPhoneBookDataElement[E04PhoneBook::phoneBookDataElementEnum::ADDRESS] = address;
+ }
+
+ if (elementFilter.addEmail) {
+ std::shared_ptr<E04PhoneBook::phoneBookDataElementString> email = std::make_shared<E04PhoneBook::phoneBookDataElementString>();
+ email->content = it0->email;
+ lPhoneBookDataElement[E04PhoneBook::phoneBookDataElementEnum::EMAIL] = email;
+ }
+
+ if (elementFilter.addPhoneNumber) {
+ std::shared_ptr<E04PhoneBook::phoneBookDataElementPhoneNumber> phoneNumber = std::make_shared<E04PhoneBook::phoneBookDataElementPhoneNumber>();
+ phoneNumber->content = it0->phoneNumber;
+ lPhoneBookDataElement[E04PhoneBook::phoneBookDataElementEnum::PHONENUMBER] = phoneNumber;
+ }
+
+ lPhoneBookDataSet.push_back(lPhoneBookDataElement);
+
+ }
+
+ phoneBookClientData[clientId] = lPhoneBookDataSet;
+
+ // Send client data
+ const std::shared_ptr<CommonAPI::ClientIdList> receivers(new CommonAPI::ClientIdList);
+ receivers->insert(clientId);
+ std::cout << "firePhoneBookDataSetSelective: " << receivers->size() << " / " << phoneBookClientData[clientId].size()
+ << std::endl;
+ firePhoneBookDataSetSelective(lPhoneBookDataSet, receivers);
+ receivers->erase(clientId);
+
+ std::cout << "setPhoneBookDataFilter end." << std::endl;
+}
+
+std::vector<E04PhoneBook::phoneBookStruct> E04PhoneBookStubImpl::createTestPhoneBook() {
+
+ std::vector<E04PhoneBook::phoneBookStruct> lPhoneBook;
+ E04PhoneBook::phoneBookStruct lPhoneBookEntry;
+
+ // 1. entry
+ lPhoneBookEntry.name = "Gehring";
+ lPhoneBookEntry.forename = "Jürgen";
+ lPhoneBookEntry.organisation = "BMW";
+ lPhoneBookEntry.address = "Max-Diamand-Straße 13, 80788 München";
+ lPhoneBookEntry.email = "juergen.gehring@bmw.de";
+ lPhoneBookEntry.phoneNumber[E04PhoneBook::phoneNumberEnum::WORK] = "0111/12345-0";
+ lPhoneBook.push_back(lPhoneBookEntry);
+ lPhoneBookEntry.phoneNumber.clear();
+
+ // 2. entry
+ lPhoneBookEntry.name = "Müller";
+ lPhoneBookEntry.forename = "Alfred";
+ lPhoneBookEntry.organisation = "Audi";
+ lPhoneBookEntry.address = "August-Horch-Straße 27, 85055 Ingolstadt";
+ lPhoneBookEntry.email = "alfred.mueller@audi.de";
+ lPhoneBookEntry.phoneNumber[E04PhoneBook::phoneNumberEnum::MOBILE1] = "0222/23456-0";
+ lPhoneBook.push_back(lPhoneBookEntry);
+ lPhoneBookEntry.phoneNumber.clear();
+
+ // 3. entry
+ lPhoneBookEntry.name = "Maier";
+ lPhoneBookEntry.forename = "Hansi";
+ lPhoneBookEntry.organisation = "Daimler";
+ lPhoneBookEntry.address = "Mercedesstraße 137, 70546 Stuttgart";
+ lPhoneBookEntry.email = "hansi.maier@daimler.de";
+ lPhoneBookEntry.phoneNumber[E04PhoneBook::phoneNumberEnum::HOME] = "0333/34567-0";
+ lPhoneBookEntry.phoneNumber[E04PhoneBook::phoneNumberEnum::WORK] = "0444/34567-1";
+ lPhoneBook.push_back(lPhoneBookEntry);
+ lPhoneBookEntry.phoneNumber.clear();
+
+ return lPhoneBook;
+}
diff --git a/CommonAPI-Examples/e04PhoneBook/src/E04PhoneBookStubImpl.h b/CommonAPI-Examples/e04PhoneBook/src/E04PhoneBookStubImpl.h
new file mode 100644
index 0000000..9eebb29
--- /dev/null
+++ b/CommonAPI-Examples/e04PhoneBook/src/E04PhoneBookStubImpl.h
@@ -0,0 +1,37 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E04PHONEBOOKSTUBIMPL_H_
+#define E04PHONEBOOKSTUBIMPL_H_
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E04PhoneBookStubDefault.h>
+
+using namespace commonapi::examples;
+
+class E04PhoneBookStubImpl: public commonapi::examples::E04PhoneBookStubDefault {
+
+public:
+ E04PhoneBookStubImpl();
+ virtual ~E04PhoneBookStubImpl();
+
+ std::vector<E04PhoneBook::phoneBookStruct> createTestPhoneBook();
+ bool contains(std::vector<E04PhoneBook::phoneBookDataElementEnum>&, const E04PhoneBook::phoneBookDataElementEnum&);
+ void onPhoneBookDataSetSelectiveSubscriptionChanged(
+ const std::shared_ptr<CommonAPI::ClientId>,
+ const CommonAPI::SelectiveBroadcastSubscriptionEvent);
+ void setPhoneBookDataFilter(
+ const std::shared_ptr<CommonAPI::ClientId>,
+ E04PhoneBook::elementFilterStruct,
+ std::vector<E04PhoneBook::contentFilterStruct>);
+
+private:
+ std::unordered_map<std::shared_ptr<CommonAPI::ClientId>, std::vector<E04PhoneBook::phoneBookDataElementMap>> phoneBookClientData;
+
+};
+
+#endif /* E04PHONEBOOKSTUBIMPL_H_ */
diff --git a/CommonAPI-Examples/e04PhoneBook/src/e04PhoneBookClient.cpp b/CommonAPI-Examples/e04PhoneBook/src/e04PhoneBookClient.cpp
new file mode 100644
index 0000000..eb9a7c5
--- /dev/null
+++ b/CommonAPI-Examples/e04PhoneBook/src/e04PhoneBookClient.cpp
@@ -0,0 +1,187 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <map>
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E04PhoneBook.h>
+#include <commonapi/examples/E04PhoneBookProxy.h>
+
+using namespace commonapi::examples;
+
+// Utility functions only for printing results to the console
+
+std::string phoneNumberType2String(E04PhoneBook::phoneNumberEnum phoneNumberType) {
+
+ switch (static_cast<int32_t>(phoneNumberType)) {
+ case 0:
+ return "WORK";
+ break;
+ case 1:
+ return "HOME";
+ break;
+ case 2:
+ return "MOBILE1";
+ break;
+ case 3:
+ return "MOBILE2";
+ break;
+ default:
+ return "";
+ break;
+ }
+}
+
+void printPhoneBook(const std::vector<E04PhoneBook::phoneBookStruct>& myPhoneBook) {
+ std::vector<E04PhoneBook::phoneBookStruct>::const_iterator myIterator;
+
+ std::cout << "Actual phoneBook content: " << std::endl;
+ for (myIterator = myPhoneBook.begin(); myIterator != myPhoneBook.end(); myIterator++) {
+
+ std::cout << "Name: " << myIterator->name << std::endl;
+ std::cout << "Forename: " << myIterator->forename << std::endl;
+ std::cout << "Organisation: " << myIterator->organisation << std::endl;
+ std::cout << "Address: " << myIterator->address << std::endl;
+ std::cout << "EMail: " << myIterator->email << std::endl;
+
+ for (E04PhoneBook::phoneNumberMap::const_iterator myPhoneNumberIterator = myIterator->phoneNumber.begin();
+ myPhoneNumberIterator != myIterator->phoneNumber.end();
+ myPhoneNumberIterator++) {
+ std::cout << "phoneNumber[" << phoneNumberType2String(myPhoneNumberIterator->first) << "]: ";
+ std::cout << myPhoneNumberIterator->second << std::endl;
+ }
+ std::cout << std::endl;
+ }
+}
+
+void printFilterResult(const std::vector<E04PhoneBook::phoneBookDataElementMap>& phoneBookDataSet, std::string proxy) {
+ std::vector<E04PhoneBook::phoneBookDataElementMap>::const_iterator it0;
+
+ std::cout << "Actual phoneBookDataSet for proxy " << proxy << ": " << std::endl;
+ for (it0 = phoneBookDataSet.begin(); it0 != phoneBookDataSet.end(); it0++) {
+ E04PhoneBook::phoneBookDataElementMap::const_iterator it1;
+
+ for (it1 = (*it0).begin(); it1 != (*it0).end(); it1++) {
+ switch (it1->first) {
+ case E04PhoneBook::phoneBookDataElementEnum::NAME: {
+ std::string name = (std::static_pointer_cast < E04PhoneBook::phoneBookDataElementString
+ > (it1->second))->content;
+ std::cout << "Name = " << name << std::endl;
+ }
+ break;
+
+ case E04PhoneBook::phoneBookDataElementEnum::FORENAME: {
+ std::string forename = (std::static_pointer_cast < E04PhoneBook::phoneBookDataElementString
+ > (it1->second))->content;
+ std::cout << "Forename = " << forename << std::endl;
+ }
+ break;
+
+ case E04PhoneBook::phoneBookDataElementEnum::ORGANISATION: {
+ std::string organisation = (std::static_pointer_cast < E04PhoneBook::phoneBookDataElementString
+ > ((*it0).at(E04PhoneBook::phoneBookDataElementEnum::ORGANISATION)))->content;
+ std::cout << "Organisation = " << organisation << std::endl;
+ }
+ break;
+
+ case E04PhoneBook::phoneBookDataElementEnum::ADDRESS: {
+ std::string address = (std::static_pointer_cast < E04PhoneBook::phoneBookDataElementString
+ > ((*it0).at(E04PhoneBook::phoneBookDataElementEnum::ADDRESS)))->content;
+ std::cout << "Address = " << address << std::endl;
+ }
+ break;
+
+ case E04PhoneBook::phoneBookDataElementEnum::EMAIL: {
+ std::string email = (std::static_pointer_cast < E04PhoneBook::phoneBookDataElementString
+ > ((*it0).at(E04PhoneBook::phoneBookDataElementEnum::EMAIL)))->content;
+ std::cout << "EMail = " << email << std::endl;
+ }
+ break;
+
+ case E04PhoneBook::phoneBookDataElementEnum::PHONENUMBER: {
+ E04PhoneBook::phoneNumberMap phoneNumber = (std::static_pointer_cast
+ < E04PhoneBook::phoneBookDataElementPhoneNumber
+ > ((*it0).at(E04PhoneBook::phoneBookDataElementEnum::PHONENUMBER)))->content;
+ for (E04PhoneBook::phoneNumberMap::iterator myPhoneNumberIterator = phoneNumber.begin();
+ myPhoneNumberIterator != phoneNumber.end();
+ myPhoneNumberIterator++) {
+ std::cout << "PhoneNumber[" << phoneNumberType2String(myPhoneNumberIterator->first) << "] = ";
+ std::cout << myPhoneNumberIterator->second << std::endl;
+ }
+ }
+ break;
+
+ default: {
+ std::cout << "No result." << std::endl;
+ }
+ break;
+ }
+ }
+ }
+}
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+
+ std::shared_ptr<CommonAPI::Factory> factoryA = runtime->createFactory();
+ std::shared_ptr<CommonAPI::Factory> factoryB = runtime->createFactory();
+
+ const std::string& serviceAddress = "local:commonapi.examples.PhoneBook:commonapi.examples.PhoneBook";
+ std::shared_ptr < E04PhoneBookProxyDefault > myProxyA = factoryA->buildProxy < E04PhoneBookProxy > (serviceAddress);
+ while (!myProxyA->isAvailable()) {
+ usleep(10);
+ }
+ std::shared_ptr < E04PhoneBookProxyDefault > myProxyB = factoryB->buildProxy < E04PhoneBookProxy > (serviceAddress);
+ while (!myProxyB->isAvailable()) {
+ usleep(10);
+ }
+
+ // Subscribe A to broadcast
+ myProxyA->getPhoneBookDataSetSelectiveEvent().subscribe(
+ [&](const std::vector<E04PhoneBook::phoneBookDataElementMap>& phoneBookDataSet) {
+ printFilterResult(phoneBookDataSet, "A");
+ });
+
+ // Subscribe B to broadcast
+ myProxyB->getPhoneBookDataSetSelectiveEvent().subscribe(
+ [&](const std::vector<E04PhoneBook::phoneBookDataElementMap>& phoneBookDataSet) {
+ printFilterResult(phoneBookDataSet, "B");
+ });
+
+ // Get actual phoneBook from service
+ CommonAPI::CallStatus myCallStatus;
+ std::vector<E04PhoneBook::phoneBookStruct> myValue;
+
+ myProxyA->getPhoneBookAttribute().getValue(myCallStatus, myValue);
+ if (myCallStatus != CommonAPI::CallStatus::SUCCESS)
+ std::cerr << "Remote call getPhoneBookAttribute failed!\n";
+ else
+ printPhoneBook (myValue);
+
+ // Synchronous call setPhoneBookDataFilter
+ std::cout << "Call setPhoneBookDataFilter A ..." << std::endl;
+ E04PhoneBook::elementFilterStruct lElementFilterA = {true, true, false, false, false, false};
+ std::vector<E04PhoneBook::contentFilterStruct> lContentFilterA = { {E04PhoneBook::phoneBookDataElementEnum::NAME, "*"}};
+
+ myProxyA->setPhoneBookDataFilter(lElementFilterA, lContentFilterA, myCallStatus);
+ if (myCallStatus != CommonAPI::CallStatus::SUCCESS)
+ std::cerr << "Remote call setPhoneBookDataFilter A failed: " << (int) myCallStatus << std::endl;
+
+ std::cout << "Call setPhoneBookDataFilter B ..." << std::endl;
+ E04PhoneBook::elementFilterStruct lElementFilterB = {true, false, false, false, false, true};
+ std::vector<E04PhoneBook::contentFilterStruct> lContentFilterB = { {E04PhoneBook::phoneBookDataElementEnum::NAME, "*"}};
+
+ myProxyB->setPhoneBookDataFilter(lElementFilterB, lContentFilterB, myCallStatus);
+ if (myCallStatus != CommonAPI::CallStatus::SUCCESS)
+ std::cerr << "Remote call setPhoneBookDataFilter B failed: " << (int) myCallStatus << std::endl;
+
+ while (true) {
+ std::this_thread::sleep_for(std::chrono::seconds(5));
+ }
+ return 0;
+}
diff --git a/CommonAPI-Examples/e04PhoneBook/src/e04PhoneBookService.cpp b/CommonAPI-Examples/e04PhoneBook/src/e04PhoneBookService.cpp
new file mode 100644
index 0000000..fba15a2
--- /dev/null
+++ b/CommonAPI-Examples/e04PhoneBook/src/e04PhoneBookService.cpp
@@ -0,0 +1,31 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <thread>
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include "E04PhoneBookStubImpl.h"
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher();
+
+ const std::string& serviceAddress = "local:commonapi.examples.PhoneBook:commonapi.examples.PhoneBook";
+ std::shared_ptr<E04PhoneBookStubImpl> myService = std::make_shared<E04PhoneBookStubImpl>();
+ servicePublisher->registerService(myService, serviceAddress, factory);
+
+ myService->setPhoneBookAttribute(myService->createTestPhoneBook());
+
+ while (true) {
+ std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(2));
+ }
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/e05Manager/.gitignore b/CommonAPI-Examples/e05Manager/.gitignore
new file mode 100644
index 0000000..5897208
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/.gitignore
@@ -0,0 +1,2 @@
+build
+src-gen \ No newline at end of file
diff --git a/CommonAPI-Examples/e05Manager/CMakeLists.txt b/CommonAPI-Examples/e05Manager/CMakeLists.txt
new file mode 100644
index 0000000..d0202e7
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/CMakeLists.txt
@@ -0,0 +1,71 @@
+# Copyright (C) 2014 BMW Group
+# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+# Author: Juergen Gehring (juergen.gehring@bmw.de)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+cmake_minimum_required(VERSION 2.8)
+
+# Project settings
+if (PRJ_NAME)
+ message(STATUS "Start CMake for Project " ${PRJ_NAME})
+else()
+ message(FATAL_ERROR "Please specify your project name using -D PRJ_NAME=yourName")
+endif()
+project(${PRJ_NAME})
+set(CMAKE_VERBOSE_MAKEFILE on)
+set(CMAKE_CXX_FLAGS "-Wall -std=c++0x")
+set(CMAKE_BUILD_TYPE Debug)
+
+# DBus Path
+if (DBUS_PATH_LOCAL)
+ message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+else()
+ message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath")
+endif()
+
+# CommonAPI
+include(FindPkgConfig)
+pkg_check_modules (COMMONAPI "CommonAPI >= 2.1")
+pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1")
+
+# Source Files
+set(PRJ_SRC_PATH src)
+set(PRJ_SRC_GEN_PATH src-gen/commonapi/examples)
+
+set(PRJ_NAME_CLIENT ${PROJECT_NAME}Client)
+set(PRJ_NAME_SERVICE ${PROJECT_NAME}Service)
+
+STRING(REGEX REPLACE "^e" "E" PRJ_DATA_IMPL ${PRJ_NAME})
+FILE(GLOB PRJ_PROXY_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Proxy.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp ${PRJ_SRC_GEN_PATH}/${PRJ_DATA_IMPL}.cpp)
+FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Stub*.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp ${PRJ_SRC_GEN_PATH}/${PRJ_DATA_IMPL}.cpp)
+FILE(GLOB PRJ_STUB_IMPL_SRCS ${PRJ_SRC_PATH}/*Stub*.cpp)
+
+set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS})
+set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS})
+
+# Paths
+message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR})
+message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR})
+
+include_directories(
+ src-gen
+ ${DBUS_PATH_LOCAL}
+ ${COMMONAPI_INCLUDEDIR}
+ ${COMMONAPI_DBUS_INCLUDEDIR}
+)
+
+link_directories(
+ ${COMMONAPI_LIBDIR}
+ ${COMMONAPI_DBUS_LIBDIR}
+)
+
+# Build Client
+add_executable(${PRJ_NAME_CLIENT} ${PRJ_CLIENT_SRCS})
+target_link_libraries(${PRJ_NAME_CLIENT} CommonAPI CommonAPI-DBus)
+
+# Build service
+add_executable(${PRJ_NAME_SERVICE} ${PRJ_SERVICE_SRCS})
+target_link_libraries(${PRJ_NAME_SERVICE} CommonAPI CommonAPI-DBus)
diff --git a/CommonAPI-Examples/e05Manager/README b/CommonAPI-Examples/e05Manager/README
new file mode 100644
index 0000000..5a1da8a
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/README
@@ -0,0 +1,135 @@
+Example 5: Managed
+~~~~~~~~~~~~~~~~~~
+
+So far we have looked at software systems, which consisted of services and users of these servces, the clients. However, in some systems there is a slightly different kind of relationship between the software components: a central manager manages other services (let's call them slaves or leaves). This central manager is a service itself but acts as client for the managed services. One example for such a system is, for example, a device manager that manages several devices, which can be availabe for usage in the system or not. The central manager handles all adminitrative tasks related to the slaves and provides a central, common interface to the user frontend.
+
+image::{imagedir}/E05Manager.png[ManagerExample image]
+
+Franca IDL supports this kind of software structure by the keyword _manages_, which can be added to the keyword interface. The following example illustrates the application of this keyword.
+
+[source,java]
+----
+package commonapi.examples
+
+interface E05Manager manages E05Device, E05SpecialDevice {
+ version { major 1 minor 0 }
+
+ attribute String [] myDevices
+}
+
+interface E05Device {
+ version { major 1 minor 0 }
+
+ method doSomething {
+ }
+}
+
+interface E05SpecialDevice extends E05Device {
+ version { major 1 minor 0 }
+
+ method doSomethingSpecial {
+ }
+}
+----
+
+The device manager has the service interface E05Manager and it manages devices with the interfaces E05Device and E05SpecialDevice. It is important to understand, that the exact meaning of the keyword +manages+ cannot be defined by the IDL; the keyword just indicates that there is a relationship between software components which implement manager and managed interfaces. It can be used in bindings as CommonAPI to provide API functions for a more convenient implementation of this certain kind of relationship.
+
+Therefore let's have a look at the generated and implemented source code. Since we have three interfaces the code generator generates for every interface proxy and stub classes. In our example we just want to illuminate one aspect of the managed interfaces: the registration of the managed interfaces via the manager. We assume that we have only one service (the manager) which gets informed about a detected or a removed device via the public function deviceDetected and deviceRemoved. The devices are distinguished by a number; in principle there is an arbitrary number of devices possible. The registration of the devices at CommonAPI does the manager in his stub implementation.
+
+[source,{cppstr}]
+----
+... // includes, namespaces, constructors as usual
+
+E05ManagerStubImpl::E05ManagerStubImpl (const std::string instanceName) {
+
+ managerInstanceName = instanceName;
+}
+
+void E05ManagerStubImpl::deviceDetected (unsigned int n) {
+
+ std::string deviceInstanceName = getDeviceName (n);
+ myDevices[deviceInstanceName] = DevicePtr (new E05DeviceStubImpl);
+ const bool deviceRegistered = this->registerManagedStubE05Device(
+ myDevices[deviceInstanceName], deviceInstanceName);
+}
+
+void E05ManagerStubImpl::deviceRemoved (unsigned int n) {
+
+ std::string deviceInstanceName = getDeviceName (n);
+ const bool deviceDeregistered = this->deregisterManagedStubE05Device(
+ deviceInstanceName);
+ if ( deviceDeregistered ) { myDevices.erase (deviceInstanceName); }
+}
+
+std::string E05ManagerStubImpl::getDeviceName (unsigned int n) {
+
+ std::stringstream ss;
+ ss << managerInstanceName <<
+ ".device" << std::setw(2) << std::hex << std::setfill('0') << n;
+ return ss.str();
+}
+
+... // implementation of special device analogously
+----
+
+The functions for the special device has been omitted for clarity.The implementations of the devices themselves are not important here as well. See now the implementation of the client. The client gets informed about new or removed devices including the addresses of these devices via the callback function newDeviceAvailable. This function can be subscribed as function object at an status event that is triggered when a device is added or removed.
+
+[source, {cppstr}]
+----
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E05ManagerProxy.h>
+
+using namespace commonapi::examples;
+
+void newDeviceAvailable (const std::string address,
+ const CommonAPI::AvailabilityStatus status) {
+
+ if ( status == CommonAPI::AvailabilityStatus::AVAILABLE ) {
+
+ std::cout << "New device available: " << address << std::endl;
+ }
+
+ if ( status == CommonAPI::AvailabilityStatus::NOT_AVAILABLE ) {
+
+ std::cout << "Device removed: " << address << std::endl;
+ }
+}
+
+int main() {
+
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+
+ const std::string& serviceAddress =
+ "local:commonapi.examples.Manager:commonapi.examples.Manager";
+
+ std::shared_ptr<E05ManagerProxy<>> myProxy =
+ factory->buildProxy<E05ManagerProxy>(serviceAddress);
+
+ while (!myProxy->isAvailable()) { usleep(10); }
+
+ std::cout << "Proxy available." << std::endl;
+
+ CommonAPI::ProxyManager::InstanceAvailabilityStatusChangedEvent& deviceEvent =
+ myProxy->getProxyManagerE05Device().
+ getInstanceAvailabilityStatusChangedEvent();
+
+ CommonAPI::ProxyManager::InstanceAvailabilityStatusChangedEvent& specialDeviceEvent =
+ myProxy->getProxyManagerE05SpecialDevice().
+ getInstanceAvailabilityStatusChangedEvent();
+
+ std::function<void (const std::string, const CommonAPI::AvailabilityStatus)>
+ newDeviceAvailableFunc = newDeviceAvailable;
+
+ deviceEvent.subscribe(newDeviceAvailableFunc);
+ specialDeviceEvent.subscribe(newDeviceAvailableFunc);
+
+ while(true) {
+ std::this_thread::sleep_for(std::chrono::seconds(5));
+ }
+ return 0;
+}
+----
diff --git a/CommonAPI-Examples/e05Manager/fidl/E05Manager.fidl b/CommonAPI-Examples/e05Manager/fidl/E05Manager.fidl
new file mode 100644
index 0000000..ff020b0
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/fidl/E05Manager.fidl
@@ -0,0 +1,29 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package commonapi.examples
+
+interface E05Manager manages E05Device, E05SpecialDevice {
+ version { major 1 minor 0 }
+
+ attribute String [] myDevices
+
+}
+
+interface E05Device {
+ version { major 1 minor 0 }
+
+ method doSomething {
+ }
+}
+
+interface E05SpecialDevice extends E05Device {
+ version { major 1 minor 0 }
+
+ method doSomethingSpecial {
+ }
+} \ No newline at end of file
diff --git a/CommonAPI-Examples/e05Manager/src/E05DeviceStubImpl.cpp b/CommonAPI-Examples/e05Manager/src/E05DeviceStubImpl.cpp
new file mode 100644
index 0000000..f8edfa9
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/src/E05DeviceStubImpl.cpp
@@ -0,0 +1,22 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+
+#include "E05DeviceStubImpl.h"
+
+using namespace commonapi::examples;
+
+E05DeviceStubImpl::E05DeviceStubImpl() {
+}
+
+E05DeviceStubImpl::~E05DeviceStubImpl() {
+}
+
+void E05DeviceStubImpl::doSomething() {
+ std::cout << "E05DeviceStubImpl::doSomething() called." << std::endl;
+}
diff --git a/CommonAPI-Examples/e05Manager/src/E05DeviceStubImpl.h b/CommonAPI-Examples/e05Manager/src/E05DeviceStubImpl.h
new file mode 100644
index 0000000..e61a3cb
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/src/E05DeviceStubImpl.h
@@ -0,0 +1,22 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E05DEVICESTUBIMPL_H_
+#define E05DEVICESTUBIMPL_H_
+
+#include <commonapi/examples/E05DeviceStubDefault.h>
+
+using namespace commonapi::examples;
+
+class E05DeviceStubImpl: public E05DeviceStubDefault {
+public:
+ E05DeviceStubImpl();
+ virtual ~E05DeviceStubImpl();
+ void doSomething();
+};
+
+#endif /* E05DEVICESTUBIMPL_H_ */
diff --git a/CommonAPI-Examples/e05Manager/src/E05ManagerStubImpl.cpp b/CommonAPI-Examples/e05Manager/src/E05ManagerStubImpl.cpp
new file mode 100644
index 0000000..ab02edd
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/src/E05ManagerStubImpl.cpp
@@ -0,0 +1,86 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <sstream>
+#include <iomanip>
+
+#include "E05ManagerStubImpl.h"
+
+using namespace commonapi::examples;
+
+E05ManagerStubImpl::E05ManagerStubImpl() {
+}
+
+E05ManagerStubImpl::E05ManagerStubImpl(const std::string instanceName) {
+ managerInstanceName = instanceName;
+}
+
+E05ManagerStubImpl::~E05ManagerStubImpl() {
+}
+
+void E05ManagerStubImpl::deviceDetected(unsigned int n) {
+ std::cout << "Device " << n << " detected!" << std::endl;
+
+ std::string deviceInstanceName = getDeviceName(n);
+ myDevices[deviceInstanceName] = DevicePtr(new E05DeviceStubImpl);
+ const bool deviceRegistered = this->registerManagedStubE05Device(myDevices[deviceInstanceName], deviceInstanceName);
+
+ if (!deviceRegistered) {
+ std::cout << "Error: Unable to register device: " << deviceInstanceName << std::endl;
+ }
+}
+
+void E05ManagerStubImpl::specialDeviceDetected(unsigned int n) {
+ std::cout << "Special device " << n << " detected!" << std::endl;
+
+ std::string specialDeviceInstanceName = getSpecialDeviceName(n);
+ mySpecialDevices[specialDeviceInstanceName] = SpecialDevicePtr(new E05SpecialDeviceStubImpl);
+ const bool specialDeviceRegistered = this->registerManagedStubE05SpecialDevice(mySpecialDevices[specialDeviceInstanceName],
+ specialDeviceInstanceName);
+
+ if (!specialDeviceRegistered) {
+ std::cout << "Error: Unable to register special device: " << specialDeviceInstanceName << std::endl;
+ }
+}
+
+void E05ManagerStubImpl::deviceRemoved(unsigned int n) {
+ std::cout << "Device " << n << " removed!" << std::endl;
+
+ std::string deviceInstanceName = getDeviceName(n);
+ const bool deviceDeregistered = this->deregisterManagedStubE05Device(deviceInstanceName);
+
+ if (!deviceDeregistered) {
+ std::cout << "Error: Unable to deregister device: " << deviceInstanceName << std::endl;
+ } else {
+ myDevices.erase(deviceInstanceName);
+ }
+}
+
+void E05ManagerStubImpl::specialDeviceRemoved(unsigned int n) {
+ std::cout << "Special device " << n << " removed!" << std::endl;
+
+ std::string specialDeviceInstanceName = getSpecialDeviceName(n);
+ const bool specialDeviceDeregistered = this->deregisterManagedStubE05SpecialDevice(specialDeviceInstanceName);
+
+ if (!specialDeviceDeregistered) {
+ std::cout << "Error: Unable to deregister special device: " << specialDeviceInstanceName << std::endl;
+ } else {
+ mySpecialDevices.erase(specialDeviceInstanceName);
+ }
+}
+
+std::string E05ManagerStubImpl::getDeviceName(unsigned int n) {
+ std::stringstream ss;
+ ss << managerInstanceName << ".device" << std::setw(2) << std::hex << std::setfill('0') << n;
+ return ss.str();
+}
+
+std::string E05ManagerStubImpl::getSpecialDeviceName(unsigned int n) {
+ std::stringstream ss;
+ ss << managerInstanceName << ".specialDevice" << std::setw(2) << std::hex << std::setfill('0') << n;
+ return ss.str();
+}
diff --git a/CommonAPI-Examples/e05Manager/src/E05ManagerStubImpl.h b/CommonAPI-Examples/e05Manager/src/E05ManagerStubImpl.h
new file mode 100644
index 0000000..c03c742
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/src/E05ManagerStubImpl.h
@@ -0,0 +1,46 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E05MANAGERSTUBIMPL_H_
+#define E05MANAGERSTUBIMPL_H_
+
+#include <map>
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E05ManagerStubDefault.h>
+
+#include "E05DeviceStubImpl.h"
+#include "E05SpecialDeviceStubImpl.h"
+
+using namespace commonapi::examples;
+
+class E05ManagerStubImpl: public E05ManagerStubDefault {
+
+public:
+ E05ManagerStubImpl();
+ E05ManagerStubImpl(const std::string);
+ virtual ~E05ManagerStubImpl();
+
+ void deviceDetected(unsigned int);
+ void specialDeviceDetected(unsigned int);
+
+ void deviceRemoved(unsigned int);
+ void specialDeviceRemoved(unsigned int);
+private:
+ std::string managerInstanceName;
+
+ typedef std::shared_ptr<E05DeviceStubImpl> DevicePtr;
+ typedef std::shared_ptr<E05SpecialDeviceStubImpl> SpecialDevicePtr;
+
+ std::map<std::string, DevicePtr> myDevices;
+ std::map<std::string, SpecialDevicePtr> mySpecialDevices;
+
+ std::string getDeviceName(unsigned int);
+ std::string getSpecialDeviceName(unsigned int);
+};
+
+#endif /* E05MANAGERSTUBIMPL_H_ */
diff --git a/CommonAPI-Examples/e05Manager/src/E05SpecialDeviceStubImpl.cpp b/CommonAPI-Examples/e05Manager/src/E05SpecialDeviceStubImpl.cpp
new file mode 100644
index 0000000..4bbcf88
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/src/E05SpecialDeviceStubImpl.cpp
@@ -0,0 +1,22 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+
+#include "E05SpecialDeviceStubImpl.h"
+
+using namespace commonapi::examples;
+
+E05SpecialDeviceStubImpl::E05SpecialDeviceStubImpl() {
+}
+
+E05SpecialDeviceStubImpl::~E05SpecialDeviceStubImpl() {
+}
+
+void E05SpecialDeviceStubImpl::doSomethingSpecial() {
+ std::cout << "E05SpecialDeviceStubImpl::doSomethingSpecial() called." << std::endl;
+}
diff --git a/CommonAPI-Examples/e05Manager/src/E05SpecialDeviceStubImpl.h b/CommonAPI-Examples/e05Manager/src/E05SpecialDeviceStubImpl.h
new file mode 100644
index 0000000..eb172f6
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/src/E05SpecialDeviceStubImpl.h
@@ -0,0 +1,23 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E05SPECIALDEVICESTUBIMPL_H_
+#define E05SPECIALDEVICESTUBIMPL_H_
+
+#include <commonapi/examples/E05SpecialDeviceStubDefault.h>
+
+using namespace commonapi::examples;
+
+class E05SpecialDeviceStubImpl: public E05SpecialDeviceStubDefault {
+public:
+ E05SpecialDeviceStubImpl();
+ virtual ~E05SpecialDeviceStubImpl();
+
+ void doSomethingSpecial();
+};
+
+#endif /* E05SPECIALDEVICESTUBIMPL_H_ */
diff --git a/CommonAPI-Examples/e05Manager/src/e05ManagerClient.cpp b/CommonAPI-Examples/e05Manager/src/e05ManagerClient.cpp
new file mode 100644
index 0000000..b04b56d
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/src/e05ManagerClient.cpp
@@ -0,0 +1,52 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E05ManagerProxy.h>
+
+using namespace commonapi::examples;
+
+void newDeviceAvailable(const std::string address, const CommonAPI::AvailabilityStatus status) {
+ if (status == CommonAPI::AvailabilityStatus::AVAILABLE) {
+ std::cout << "New device available: " << address << std::endl;
+ }
+
+ if (status == CommonAPI::AvailabilityStatus::NOT_AVAILABLE) {
+ std::cout << "Device removed: " << address << std::endl;
+ }
+}
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+
+ const std::string& serviceAddress = "local:commonapi.examples.Manager:commonapi.examples.Manager";
+ std::shared_ptr<E05ManagerProxyDefault> myProxy = factory->buildProxy<E05ManagerProxy>(serviceAddress);
+ while (!myProxy->isAvailable()) {
+ usleep(10);
+ }
+
+ std::cout << "Proxy available." << std::endl;
+
+ CommonAPI::ProxyManager::InstanceAvailabilityStatusChangedEvent& deviceEvent =
+ myProxy->getProxyManagerE05Device().getInstanceAvailabilityStatusChangedEvent();
+ CommonAPI::ProxyManager::InstanceAvailabilityStatusChangedEvent& specialDeviceEvent =
+ myProxy->getProxyManagerE05SpecialDevice().getInstanceAvailabilityStatusChangedEvent();
+
+ std::function<void(const std::string, const CommonAPI::AvailabilityStatus)> newDeviceAvailableFunc = newDeviceAvailable;
+
+ deviceEvent.subscribe(newDeviceAvailableFunc);
+ specialDeviceEvent.subscribe(newDeviceAvailableFunc);
+
+ while (true) {
+ std::this_thread::sleep_for(std::chrono::seconds(5));
+ }
+ return 0;
+}
diff --git a/CommonAPI-Examples/e05Manager/src/e05ManagerService.cpp b/CommonAPI-Examples/e05Manager/src/e05ManagerService.cpp
new file mode 100644
index 0000000..2ae5d07
--- /dev/null
+++ b/CommonAPI-Examples/e05Manager/src/e05ManagerService.cpp
@@ -0,0 +1,50 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <thread>
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include "E05ManagerStubImpl.h"
+
+using namespace commonapi::examples;
+
+static unsigned int cnt = 0; // counter for simulating external events
+const static unsigned int maxDeviceNumber = 3;
+const static std::string managerInstanceName = "commonapi.examples.Manager";
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher();
+
+ const std::string& serviceAddress = "local:commonapi.examples.Manager:" + managerInstanceName;
+ std::shared_ptr<E05ManagerStubImpl> myService = std::make_shared < E05ManagerStubImpl > (managerInstanceName);
+
+ const bool serviceRegistered = servicePublisher->registerService(myService, serviceAddress, factory);
+
+ if (!serviceRegistered) {
+ std::cout << "Error: Unable to register service." << std::endl;
+ }
+
+ while (true) {
+ // Simulate external events
+ if (cnt == 0) {
+ myService->specialDeviceDetected(cnt);
+ } else if (cnt < maxDeviceNumber) {
+ myService->deviceDetected(cnt);
+ } else if (cnt == maxDeviceNumber) {
+ myService->specialDeviceRemoved(cnt % maxDeviceNumber);
+ } else {
+ myService->deviceRemoved(cnt % maxDeviceNumber);
+ }
+
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ cnt = ++cnt < maxDeviceNumber << 1 ? cnt : 0;
+ }
+ return 0;
+}
diff --git a/CommonAPI-Examples/e06Unions/.gitignore b/CommonAPI-Examples/e06Unions/.gitignore
new file mode 100644
index 0000000..5897208
--- /dev/null
+++ b/CommonAPI-Examples/e06Unions/.gitignore
@@ -0,0 +1,2 @@
+build
+src-gen \ No newline at end of file
diff --git a/CommonAPI-Examples/e06Unions/CMakeLists.txt b/CommonAPI-Examples/e06Unions/CMakeLists.txt
new file mode 100644
index 0000000..73fffbc
--- /dev/null
+++ b/CommonAPI-Examples/e06Unions/CMakeLists.txt
@@ -0,0 +1,70 @@
+# Copyright (C) 2014 BMW Group
+# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+# Author: Juergen Gehring (juergen.gehring@bmw.de)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+cmake_minimum_required(VERSION 2.8)
+
+# Project settings
+if (PRJ_NAME)
+ message(STATUS "Start CMake for Project " ${PRJ_NAME})
+else()
+ message(FATAL_ERROR "Please specify your project name using -D PRJ_NAME=yourName")
+endif()
+project(${PRJ_NAME})
+set(CMAKE_VERBOSE_MAKEFILE on)
+set(CMAKE_CXX_FLAGS "-Wall -std=c++0x")
+set(CMAKE_BUILD_TYPE Debug)
+
+# DBus Path
+if (DBUS_PATH_LOCAL)
+ message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+else()
+ message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath")
+endif()
+
+# CommonAPI
+include(FindPkgConfig)
+pkg_check_modules (COMMONAPI "CommonAPI >= 2.1")
+pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1")
+
+# Source Files
+set(PRJ_SRC_PATH src)
+set(PRJ_SRC_GEN_PATH src-gen/commonapi/examples)
+
+set(PRJ_NAME_CLIENT ${PROJECT_NAME}Client)
+set(PRJ_NAME_SERVICE ${PROJECT_NAME}Service)
+
+FILE(GLOB PRJ_PROXY_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Proxy.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp)
+FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Stub*.cpp ${PRJ_SRC_GEN_PATH}/*Types.cpp)
+FILE(GLOB PRJ_STUB_IMPL_SRCS ${PRJ_SRC_PATH}/*Stub*.cpp)
+
+set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS})
+set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS})
+
+# Paths
+message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL})
+message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR})
+message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR})
+
+include_directories(
+ src-gen
+ ${DBUS_PATH_LOCAL}
+ ${COMMONAPI_INCLUDEDIR}
+ ${COMMONAPI_DBUS_INCLUDEDIR}
+)
+
+link_directories(
+ ${COMMONAPI_LIBDIR}
+ ${COMMONAPI_DBUS_LIBDIR}
+)
+
+# Build Client
+add_executable(${PRJ_NAME_CLIENT} ${PRJ_CLIENT_SRCS})
+target_link_libraries(${PRJ_NAME_CLIENT} CommonAPI CommonAPI-DBus)
+
+# Build service
+add_executable(${PRJ_NAME_SERVICE} ${PRJ_SERVICE_SRCS})
+target_link_libraries(${PRJ_NAME_SERVICE} CommonAPI CommonAPI-DBus)
diff --git a/CommonAPI-Examples/e06Unions/README b/CommonAPI-Examples/e06Unions/README
new file mode 100644
index 0000000..d983df8
--- /dev/null
+++ b/CommonAPI-Examples/e06Unions/README
@@ -0,0 +1,100 @@
+Example 6: Unions
+~~~~~~~~~~~~~~~~~
+
+Until now, some simple and complex data types in the examples already occurred. This example intends to describe the use of unions closer. Consider the following Franca IDL example:
+
+[source,java]
+----
+package commonapi.examples
+
+interface E06Unions {
+ version { major 1 minor 0 }
+
+ attribute CommonTypes.SettingsUnion u
+}
+
+typeCollection CommonTypes {
+
+ typedef MyTypedef is Int32
+
+ enumeration MyEnum {
+ DEFAULT
+ ON
+ OFF
+ }
+
+ union SettingsUnion {
+ MyTypedef id
+ MyEnum status
+ UInt8 channel
+ String name
+ }
+}
+----
+
+We first want to leave the question aside whether this example makes sense from an application point of view or not; it is just an example for demonstration purposes. Union is a sort of polymorphic type; with unions we can transmit data of different types in one attribute. D-Bus knows a similar data type which is called variant. Variants are used in the D-Bus binding for the implementation of unions. The interesting point is here not the definition of the union, but the realization in CommonAPI. I just want to point out here that it can lead to problems with the compiler or generally to problems with your toolchain if you define unions with an significant number of members (eg. >10), because each of these members appears in the generated C++ code as template argument in the template declaration.
+
+The implementation of the set function for the attribute u in the stub implementation could be as follows:
+
+[source,{cppstr}]
+----
+void E06UnionsStubImpl::setMyValue(int n) {
+
+ if ( n >= 0 && n < 4 ) {
+
+ CommonTypes::MyTypedef t0 = -5;
+ CommonTypes::MyEnum t1 = CommonTypes::MyEnum::OFF;
+ uint8_t t2 = 42;
+ std::string t3 = "abc";
+
+ if ( n == 0 ) {
+
+ CommonTypes::SettingsUnion v(t0);
+ setUAttribute(v);
+ } else if ( n == 1 ) {
+
+ CommonTypes::SettingsUnion v(t1);
+ setUAttribute(v);
+ } else if ( n == 2 ) {
+
+ CommonTypes::SettingsUnion v(t2);
+ setUAttribute(v);
+ } else if ( n == 3 ) {
+
+ CommonTypes::SettingsUnion v(t3);
+ setUAttribute(v);
+ }
+ }
+}
+----
+Depending on a condition (here the value of n) the attribute u is filled with data of different types. The code on client side is:
+
+[source,{cppstr}]
+----
+myProxy->getUAttribute().getChangedEvent().
+ subscribe([&](const CommonTypes::SettingsUnion& v) {
+
+ if ( v.isType<CommonTypes::MyTypedef>() ) {
+
+ std::cout << "Received MyTypedef with value " <<
+ v.get<CommonTypes::MyTypedef>() << std::endl;
+
+ } else if ( v.isType<CommonTypes::MyEnum>() ) {
+
+ std::cout << "Received MyEnum with value " <<
+ (int) (v.get<CommonTypes::MyEnum>()) << std::endl;
+
+ } else if ( v.isType<uint8_t>() ) {
+
+ std::cout << "Received uint8_t with value " <<
+ (int) (v.get<uint8_t>()) << std::endl;
+
+ } else if ( v.isType<std::string>() ) {
+
+ std::cout << "Received string with value " <<
+ v.get<std::string>() << std::endl;
+ }
+});
+----
+
+The example shows, how it is possible to detect the type and the value of the received attribute.
diff --git a/CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl b/CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl
new file mode 100644
index 0000000..9cfb3fa
--- /dev/null
+++ b/CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl
@@ -0,0 +1,32 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package commonapi.examples
+
+interface E06Unions {
+ version { major 1 minor 0 }
+
+ attribute CommonTypes.SettingsUnion u
+}
+
+typeCollection CommonTypes {
+
+ typedef MyTypedef is Int32
+
+ enumeration MyEnum {
+ DEFAULT
+ ON
+ OFF
+ }
+
+ union SettingsUnion {
+ MyTypedef id
+ MyEnum status
+ UInt8 channel
+ String name
+ }
+} \ No newline at end of file
diff --git a/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp b/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp
new file mode 100644
index 0000000..9ec5091
--- /dev/null
+++ b/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp
@@ -0,0 +1,45 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "E06UnionsStubImpl.h"
+#include <commonapi/examples/CommonTypes.h>
+
+using namespace commonapi::examples;
+
+E06UnionsStubImpl::E06UnionsStubImpl() {
+}
+
+E06UnionsStubImpl::~E06UnionsStubImpl() {
+}
+
+void E06UnionsStubImpl::setMyValue(int n) {
+ if (n >= 0 && n < 4) {
+ std::cout << "Set type " << n << " for attribute u." << std::endl;
+
+ CommonTypes::MyTypedef t0 = -5;
+ CommonTypes::MyEnum t1 = CommonTypes::MyEnum::OFF;
+ uint8_t t2 = 42;
+ std::string t3 = "∃y ∀x ¬(x ≺ y)";
+
+ if (n == 0) {
+ CommonTypes::SettingsUnion v(t0);
+ setUAttribute(v);
+ } else if (n == 1) {
+ CommonTypes::SettingsUnion v(t1);
+ setUAttribute(v);
+ } else if (n == 2) {
+ CommonTypes::SettingsUnion v(t2);
+ setUAttribute(v);
+ } else if (n == 3) {
+ CommonTypes::SettingsUnion v(t3);
+ setUAttribute(v);
+ }
+
+ } else {
+ std::cout << "Type number " << n << " not possible." << std::endl;
+ }
+}
diff --git a/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.h b/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.h
new file mode 100644
index 0000000..0297dbb
--- /dev/null
+++ b/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.h
@@ -0,0 +1,23 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E06UNIONSSTUBIMPL_H_
+#define E06UNIONSSTUBIMPL_H_
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E06UnionsStubDefault.h>
+
+class E06UnionsStubImpl: public commonapi::examples::E06UnionsStubDefault {
+
+public:
+ E06UnionsStubImpl();
+ virtual ~E06UnionsStubImpl();
+
+ virtual void setMyValue(int);
+};
+
+#endif /* E06UNIONSSTUBIMPL_H_ */
diff --git a/CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp b/CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp
new file mode 100644
index 0000000..eedd177
--- /dev/null
+++ b/CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp
@@ -0,0 +1,51 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include <commonapi/examples/E06UnionsProxy.h>
+#include <commonapi/examples/CommonTypes.h>
+
+using namespace commonapi::examples;
+
+int main() {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ const std::string& serviceAddress = "local:commonapi.examples.Unions:commonapi.examples.Unions";
+ std::shared_ptr<E06UnionsProxyDefault> myProxy = factory->buildProxy<E06UnionsProxy> (serviceAddress);
+
+ while (!myProxy->isAvailable()) {
+ usleep(10);
+ }
+
+ myProxy->getUAttribute().getChangedEvent().subscribe([&](const CommonTypes::SettingsUnion& v) {
+
+ std::cout << "Received change message." << std::endl;
+
+ if ( v.isType<CommonTypes::MyTypedef>() ) {
+
+ std::cout << "Received MyTypedef with value " << v.get<CommonTypes::MyTypedef>() << std::endl;
+ } else if ( v.isType<CommonTypes::MyEnum>() ) {
+
+ std::cout << "Received MyEnum with value " << (int) (v.get<CommonTypes::MyEnum>()) << std::endl;
+ } else if ( v.isType<uint8_t>() ) {
+
+ std::cout << "Received uint8_t with value " << (int) (v.get<uint8_t>()) << std::endl;
+ } else if ( v.isType<std::string>() ) {
+
+ std::cout << "Received string with value " << v.get<std::string>() << std::endl;
+ }
+ });
+
+ while (true) {
+ usleep(10);
+ }
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/e06Unions/src/e06UnionsService.cpp b/CommonAPI-Examples/e06Unions/src/e06UnionsService.cpp
new file mode 100644
index 0000000..d8486f5
--- /dev/null
+++ b/CommonAPI-Examples/e06Unions/src/e06UnionsService.cpp
@@ -0,0 +1,37 @@
+/* Copyright (C) 2014 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <thread>
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h>
+#include "E06UnionsStubImpl.h"
+
+int main() {
+ int n = 0;
+
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher();
+
+ const std::string& serviceAddress = "local:commonapi.examples.Unions:commonapi.examples.Unions";
+ std::shared_ptr<E06UnionsStubImpl> myService = std::make_shared<E06UnionsStubImpl>();
+ servicePublisher->registerService(myService, serviceAddress, factory);
+
+ while (true) {
+ std::cout << "Set value " << n << " for union u." << std::endl;
+ myService->setMyValue(n);
+ n++;
+ if (n == 4) {
+ n = 0;
+ }
+
+ std::this_thread::sleep_for(std::chrono::seconds(2));
+ }
+
+ return 0;
+}
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 5b5f08f..0000000
--- a/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-doc:
- mkdir -p doc/html
- asciidoc -b html -o doc/html/README.html README
- asciidoc -b html -o doc/html/Tutorial.html Tutorial
- cp -a CommonAPI-Examples doc/html/.
-
-clean:
- rm -rf doc/html/*
- rmdir doc/html
- rmdir doc
diff --git a/Tutorial b/Tutorial
deleted file mode 100644
index 9791a7f..0000000
--- a/Tutorial
+++ /dev/null
@@ -1,557 +0,0 @@
-GENIVI_CommonAPI
-================
-:Author: Juergen Gehring - juergen.gehring@bmw.de, Manfred Bathelt - manfred.bathelt@bmw.de
-:doctitle: GENIVI_CommonAPI_Tutorial
-
-Copyright
----------
-Copyright (C) 2013, GENIVI Alliance, Inc.
-Copyright (C) 2013, BMW AG
-
-This file is part of GENIVI Project IPC Common API.
-
-Contributions are licensed to the GENIVI Alliance under one or more
-Contribution License Agreements or MPL 2.0 .
-
-(C) Copyright
-This Source Code Form is subject to the terms of the
-Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
-this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-For further information see https://collab.genivi.org/wiki/display/genivi/SysInfraEGCommonIDLCommon APIGuide
-
-== License
-This project is licensed under MPL 2.0
-
-Contribution is done under GENIVI CLA or MPL2.0.
-
-== Version
-The current version can be taken from the git.
-
-== Common API Overview
-
-Common API and its mechanism specific bindings (e.g. Common API D-Bus) provide a set of libraries and tools to work with
-RMI communication in a way independent of wich mechanism is used. The main intention is to ease porting your project to
-new communication mechanisms and to enable testing of your application way before setting it up on the precise environment
-and the communication mechanism it is meant to use.
-
-Common API consists of two main parts:
-* The Common API runtime, which is the basic library required to enable Common API functionality.
-* The Common API generator Eclipse plugin, which allows the generation of Common API proxy and stub code out of Franca IDL files.
-
-The application will use both the Common API runtime and the generated code to implement client and/or service.
-
-In order to enable communication via a specific communication mechanism, the corresponding Common API middleware library
-and middleware generator plugin is required in addition. However, both the middleware specific library and the middleware
-specific generated code will NEVER be seen or used by the application code. It is solely the responsibility of the basic
-Common API library to enable communication by using this specific middleware library and code.
-
-
-== Getting started with Common API
-
-The following subsections are meant as a step by step tutorial on how to set up Common API on your system. Additionally,
-the Common API middleware library for D-Bus will be installed and an example application will be created that will
-communicate via D-Bus.
-
-Note that you later can switch D-Bus for any other communication layer (provided it has Common API support)
-_without the need to touch your code or your binary at all!_.
-
-Further information on Common API and Common API D-Bus is provided in the individual README files accompanying both packages.
-
-
-=== Setting up the Environment
-
-==== Requirements
-
-First, make sure all requirements to build the CommonAPI runtime are installed and in the correct version.
-CommonAPI was developed using gcc 4.6 and gcc 4.7, but is feature compatible to gcc 4.5 and compiler compatible to gcc 4.4.
-
-
-==== Setting up Common API
-
-Download the Common API runtime via git from the download site of http://projects.genivi.org/commonapi/, then compile and install the library on your computer:
-----
-$ git clone git://git.projects.genivi.org/ipc/common-api-runtime.git
-$ cd common-api-runtime
-$ autoreconf -i
-$ ./configure
-$ make
-$ sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu)
-----
-
-With this, the Common API runtime library will be installed in /usr/local/lib. The package is accessible for your application
-e.g. via pkgconfig. The pkgconfig data is located at /usr/local/lib/pkgconfig.
-
-
-==== Setting up Common API D-Bus
-
-To build Common API D-Bus, the Common API runtime and libdbus version 1.4.16 patched with the marshaling patch must be available through PkgConfig.
-The marshalling patch is provided within the Common API D-Bus package.
-
-Download the Common API D-Bus library via git from the download site of http://projects.genivi.org/commonapi/:
-----
-$ git clone git://git.projects.genivi.org/ipc/common-api-dbus-runtime.git
-----
-
-Download, patch and install version 1.4.16 of libdbus (*WARNING*: _Not_ following these instructions may result in corruption of the preinstalled libdbus
-library of your computer, thereby rendering your system unusable):
-----
-$ wget http://dbus.freedesktop.org/releases/dbus/dbus-1.4.16.tar.gz
-$ tar -xzf dbus-1.4.16.tar.gz
-$ cd dbus-1.4.16
-$ patch -p1 < </your/download/path>/common-api-dbus-runtime/dbus-DBusMessage-add-support-for-custom-marshaling.patch
-$ ./configure --prefix=/usr/local
-$ make -C dbus
-$ sudo make -C dbus install
-$ sudo make install-pkgconfigDATA
-----
-
-The path to CommonAPI and patched libdbus pkgconfig files must be added to the PKG_CONFIG_PATH for the rest of the entire build process.
-If you followed the instructions above, both will be located in _/usr/local/lib/pkgconfig_, so you can just type:
-----
-$ export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
-----
-
-Now, compile and install the Common API D-Bus library on your computer
-----
-$ cd </your/download/path>/common-api-dbus-runtime
-$ autoreconf -i
-$ ./configure
-$ make
-$ sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu)
-----
-
-With this, the libraries for Common API and Common API D-Bus are installed and ready for use. The next steps will provide you with the means
-to efficiently design and implement your Common API applications via Eclipse.
-
-
-==== Setting up Eclipse
-
-In order to generate the Common API code that will be used by your client and your service, the Common API generator plugin is
-required. This plugin is an Eclipse plugin, and is provided as an Eclipse update site. For convenience, the generator plugins
-for Common API and Common API D-Bus are packed together.
-
-First, get an appropriate Eclipse up and running. The version of the Common API generator plugin contained in this package was tested
-with the Eclipse Modeling Tools package of Eclipse Juno (4.1) and Eclipse Kepler (4.2). You can get one of them from www.eclipse.org:
-----
-Eclipse Juno: http://www.eclipse.org/downloads/packages/eclipse-modeling-tools/junosr1
-Eclipse Kepler: http://www.eclipse.org/downloads/packages/eclipse-modeling-tools/keplerrc3
-----
-
-Because the generator plugin generates code from Franca IDL files (https://code.google.com/a/eclipselabs.org/p/franca/),
-you will need to have installed the Franca IDL feature in your Eclipse. The plugin was created for Franca IDL version 0.8.9.
-Franca IDL is a language to efficiently design the RMI interface of your applications, independent from specific communication
-mechanisms and also independent from specific programming languages.
-
-Get the appropriate zipped Franca IDL update site (named site_franca_0.8.9.xxx.zip) from
-----
-https://code.google.com/a/eclipselabs.org/p/franca/downloads/list
-----
-Also, download the Common API D-Bus Tooling via git from the download site of http://projects.genivi.org/commonapi/:
-----
-$ git clone git://git.projects.genivi.org/ipc/common-api-dbus-tools.git
-----
-
-Install the Franca IDL plugin and the CommonAPI generator plugins in your Eclipse:
-----
-Help->Install New Software...->Add...->Archive...
-----
-From Franca IDL, you will only need to install the sub-category "Franca Feature" for the Common API and Common API D-Bus generators to work.
-The update site of the Common API generator plugin is located at
-----
-</your/download/path>/common-api-dbus-tools/org.genivi.commonapi.dbus.feature/org.genivi.commonapi.dbus.updatesite.zip
-----
-To develop your application, you will only need the _GENIVI Common API C++ Core Generator_. However, for this tutorial to work and/or if you
-intend to enable your Common API application to communicate via D-Bus, you will also need the _GENIVI Common API C++ D-Bus Generator_.
-
-Restart Eclipse when you are prompted to do so. Now you should be able to use the CommonAPI generators in your Eclipse.
-
-
-=== Creating the Example
-
-The example that will be created in this tutorial from now onwards is provided as ready-to-use source package in
-----
-</your/download/path>/common-api-dbus-tools/CommonAPI-Examples
-----
-The example found here is more verbose than the one we will create, but functionally it will be the same. The example project can also
-be browsed online at link:CommonAPI-Examples[]
-
-It is assumed that you have created a C++ project in your Eclipse in which all further development will happen.
-
-
-==== Creating the RMI interface definition
-
-The first step in developing a Common API application likely will be the definition of the RMI interface the client will use to communicate with
-the server. In the context of CommonAPI, the definition of this interface always happens via the Franca IDL, regardless of which communication
-mechanism you intend to use in the end. For this tutorial, create an arbitrarily namend file ending in _.fidl_ in your Eclipse project. It is
-not relevant where in your project you have placed this file, as the the code generated from this file will always be put in the automatically
-created src-gen folder at the top level of the project hierarchy.
-
-Open your newly created _.fidl_-file, and type the following lines:
-----
-package commonapi.examples
-
-interface HelloWorldInterface {
- version { major 1 minor 0 }
-
- method sayHello {
- in {
- String name
- }
- out {
- String message
- }
- }
-}
-----
-Note that the _version_ parameter in every interface is mandatory! No code will be generated if it is malformed or not present!
-
-Now, save the _.fidl_ file and right click it. As you have installed the Common API and Common API D-Bus generators, you will see
-a menu item saying _"Common API"_, with sub menu items for generating either the Common API level code only ("_Generate C++ Code_")
-or for generating both the Common API level code and the glue code required to run applications with using Common API D-Bus
-("_Generate D-Bus C++ Code_").
-
-
-==== Generating code
-
-We do want to use D-Bus as middleware, so we will need the D-Bus specific glue code as well as the Common API level code which we will
-program agains. Therefore, you might want to chose the latter of the two options provided by the generator plugin ("_Generate D-Bus C++ Code_").
-After having done so, you will see the newly created src-gen folder and it's contents. The files will be created according to their
-fully qualified names relative to src-gen as the top level folder, as defined in the _.fidl_-file:
-----
-HelloWorldInterface.h
-HelloWorldInterfaceProxy.h
-HelloWorldInterfaceProxyBase.h
-HelloWorldInterfaceStub.h
-HelloWorldInterfaceStubDefault.cpp
-HelloWorldInterfaceStubDefault.h
-
-HelloWorldInterfaceDBusProxy.cpp
-HelloWorldInterfaceDBusProxy.h
-HelloWorldInterfaceDBusStubAdapter.cpp
-HelloWorldInterfaceDBusStubAdapter.h
-----
-
-All files that have a "DBus" in their name are glue code required by the D-Bus binding and are not relevant while developing your application,
-they only need to be compiled with your application (there are ways to NOT compile these sources with your applications and include them at
-runtime instead; see the README of Common API D-Bus for details).
-
-All other files that have a _Proxy_ in their name are relevant for you if you develop a client, all other files that have a _Stub_ in their name
-are relevant for you if you develop a service.
-
-A proxy is a class that provides method calls that will result in remote method invocations on the service, plus registration methods for events
-that can be broadcasted by the service.
-
-A stub is the part of the service that will be called when a remote method invocation from a client arrives. It also contains methods to fire
-events (broadcasts) to several or all clients. The Stub comes in two flavors: One default stub that contains empty implementations of all methods,
-thereby allowing you to implement only the ones you are interested in, and a Stub skeleton where you have to implement everything yourself before
-you can use it. A service will have to implement a subclass of either of the two in order to make itself available to the outside world
-(or just use the default stub if your service should not be able to do anything except firing events).
-
-In this tutorial, we will create both a client and a service in order to be able to see some communication going on.
-
-
-==== Implement the Client
-
-Start by creating a new .cpp source file in your project (e.g. helloworld-proxy.cpp). Make sure you have a main method in order to start the client application.
-
-Here, you will need two includes in order to access the Common API client functionality:
-----
-#include <CommonAPI/CommonAPI.h> //Defined in the Common API Runtime library
-#include <commonapi/examples/HelloWorldInterfaceProxy.h> //Part of the code we just generated
-#include <commonapi/examples/HelloWorldLeafProxy.h> //Part of the code we just generated
-
-#include <iostream>
-#include <future>
-----
-
-The first thing each and every Common API application will do is to load a runtime:
-----
-std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
-----
-If you link the Common API DBus library to and compile the generated DBus specific code with your executable, this runtime "magically" will be a
-runtime that provides access to the DBus communication infrastructure via a strictly CommonAPI level interface. If you link the library and add
-the generated code of another Common API middleware binding instead, this runtime will provide access to this other communication infrastructure.
-To not interrupt this tutorial, further explanation on this mechanism is done below in a separate chapter in "Further Reading".
-
-In order to be able to communicate with a specific service, we need a proxy. We can create a proxy by using a factory, which in turn we can get from
-the runtime we just created:
-----
-std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
-const std::string& commonApiAddress = "local:commonapi.examples.HelloWorld:commonapi.examples.HelloWorld";
-std::shared_ptr<commonapi::examples::HelloWorldInterfaceProxy<>> helloWorldProxy = factory->buildProxy<commonapi::examples::HelloWorldInterfaceProxy>(commonApiAddress);
-----
-The parameter _commonApiAddress_ is the address at which the service that shall be accessed will be available. This address will be translated
-internally to an actual DBus-Address - or whatever format fits the communication infrastructure you use. Semantically, this address consists of three parts,
-separated by colons:
-* Domain: The first part, defines in which domain the service is located. For DBus use cases, only "local" makes any sense, as no services that are more remote than
- "on the same operating system" are accessible.
-* ServiceID: The second part. This defines the name or type of the service that shall be accessed.
-* InstanceID: The third part. This defines the specific instance of this service that shall be accessed.
-
-There are ways to influence the translation of the Common API address to the specific address (of course once again without the need to change your code).
-Please have a look at the README of Common API DBus if you want to know more about this possibility in the context of DBus, or the corresponding documentation
-of the other middleware binding you are using.
-
-With this, the client is set up and ready to use. We should wait for the service to be available, then we can start issuing calls:
-----
-while (!helloWorldProxy->isAvailable()) {
- usleep(10);
-}
-
-const std::string name = "World";
-CommonAPI::CallStatus callStatus;
-std::string helloWorldReturnMessage;
-
-helloWorldProxy->sayHello(name, callStatus, helloWorldReturnMessage);
-if (callStatus != CommonAPI::CallStatus::SUCCESS) {
- std::cerr << "Remote call failed!\n";
- return -1;
-}
-
-std::cout << "Got message: '" << helloWorldReturnMessage << "'\n";
-----
-
-
-==== Implement the Service
-
-Works about the same way as implementing the client. The includes that are required are the following:
-----
-#include <commonapi/examples/HelloWorldInterfaceStubDefault.h>
-#include <commonapi/examples/HelloWorldLeafStubDefault.h>
-#include <CommonAPI/CommonAPI.h>
-
-#include <iostream>
-#include <sstream>
-#include <thread>
-----
-
-And we also need a stub that actually does something when the method we call in the client gets called:
-----
-class MyHelloWorldStub: public commonapi::examples::HelloWorldInterfaceStubDefault {
- public:
- virtual void sayHello(std::string name, std::string& message) {
- std::stringstream messageStream;
-
- messageStream << "Hello " << name << "!";
- message = messageStream.str();
-
- std::cout << "sayHello('" << name << "'): '" << message << "'\n";
- }
-};
-----
-
-The rest looks quite similar to the client side, with the difference that we do not issue calls via a proxy, but instead register a service that then
-will be provided to the outside world. The service is registered using the same Common API address, which allows the proxy to actually find the service.
-Afterwards, we just wait for calls:
-----
-std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
-std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
-std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher();
-
-const std::string& commonApiAddress = "local:commonapi.examples.HelloWorld:commonapi.examples.HelloWorld";
-std::shared_ptr<MyHelloWorldStub> helloWorldStub = std::make_shared<MyHelloWorldStub>();
-servicePublisher->registerService(helloWorldStub, commonApiAddress, factory);
-
-while(true) {
- std::cout << "Waiting for calls... (Abort with CTRL+C)\n";
- sleep(60);
-}
-----
-
-
-=== Running the Demo
-
-Build the two applications using your favourite build system. If all worked well, you should see communication ongoing via DBus (e.g. via dbus-monitor),
-and you should get output from your client once, saying
-----
-"Got Message: 'Hello World'".
-----
-
-== Advanced Features
-=== Selective
-
-Selective broadcasts, indicated with the selective keword after the name of the broadcast in Franca can be sent to individual clients rather
-than all participants. This is accomplished with the use of a ClientID parameter which can serve to identify the targets. Note if you wish to
-identify clients absolutely you must do this on the application level.
-
-We can add a block to our interface for the selective broadcast:
-
-----
-broadcast saySomething selective {
- out {
- String message
- }
-}
-----
-
-We can the add some code to our stub implementation to handle this:
-----
-virtual void onSaySomethingSelectiveSubscriptionChanged(const std::shared_ptr<CommonAPI::ClientId> clientId,
- const CommonAPI::SelectiveBroadcastSubscriptionEvent event) {
- if (event == CommonAPI::SelectiveBroadcastSubscriptionEvent::SUBSCRIBED) {
- lastId = clientId;
- }
-}
-----
-and to the sayHello method:
-----
-std::shared_ptr<CommonAPI::ClientIdList> receivers = std::make_shared<CommonAPI::ClientIdList>();
-if (lastId) {
- receivers->insert(lastId);
-}
-this->fireSaySomethingSelective("Broadcast to last ID", receivers);
-----
-and finally a member to the stub:
-----
-private:
- std::shared_ptr<CommonAPI::ClientId> lastId;
-----
-
-The onSaySomethingSelectiveSubscriptionChanged method is called when a subscription for this boroadcast changes. Is added, we set the
-memeber lastId to this value. Whenever sayHello is called we now also send a broadcast only to the last client which registered.
-The ClientIdList contains all the intended recipients, and the middleware will send the message to all memeber of this list who are
-registered for the broadcast. If NULL is passed instead the broadcast is sent to all clients.
-
-On the client side we can add this before the const std::string name = "World"; line:
-----
-helloWorldProxy->getSaySomethingSelectiveEvent().subscribe([&](const std::string& message) {
- std::cout << "Received broadcast message: " << message << "\n";
-});
-----
-This casues a subscription to the broadcast, and the lambda function will be called whenever we receive a message.
-
-=== Managed Stubs
-
-In franca a relationship between two interfaces can be declared in the form "x manages y". This indicates that x has a number of y as
-childeren whose lifecycle is tied to and managed by x. This allows a an application to activare y stubs on an instance of x stubs.
-Similarily on the proxy side a manager for y interfaces is available on the x proxy, where we can be informed of appearing and disappearing
-instances, and interrogate the network about the state of instances.
-
-In our franca change the defenition of the HelloWorldInterface to:
-----
-interface HelloWorldInterface manages HelloWorldLeaf {
-----
-
-and after this interface block add:
-----
-interface HelloWorldLeaf {
- version { major 1 minor 0 }
-
- method sayHelloLeaf {
- in {
- String name
- }
- out {
- String message
- }
- }
-}
-----
-
-This causes HelloWorldInterface to be able to manage HelloWorldLeaf instances. Note that HelloWorldLeaf instances can still be registered
-and accessed in the normal way via the service publisher and facotry.
-
-To the stub application add to the top as a new class defenition:
-
-----
-class MyHelloWorldLeafStub: public commonapi::examples::HelloWorldLeafStubDefault {
- public:
- virtual void sayHelloLeaf(std::string name, std::string& message) {
- std::stringstream messageStream;
-
- messageStream << "Hello Leaf " << name << "!";
- message = messageStream.str();
-
- std::cout << "sayHelloLeaf('" << name << "'): '" << message << "'\n";
- }
-};
-----
-
-To the bottom of the main function before the while loop add:
-----
-auto helloWorldLeafStub = std::make_shared<MyHelloWorldLeafStub>();
-const std::string leafInstance = "commonapi.examples.HelloWorld.Leaf";
-const bool leafOk = helloWorldStub->registerManagedStubHelloWorldLeaf(helloWorldLeafStub, leafInstance);
-if (!leafOk) {
- std::cerr << "Error: Unable to register leaf service!\n";
- return -1;
-}
-----
-
-To the client programm add to the bottom of the main function just before return 0:
-----
-const std::string leafInstance = "commonapi.examples.HelloWorld.Leaf";
-CommonAPI::CallStatus callStatusAv;
-CommonAPI::AvailabilityStatus availabilityStatus;
-helloWorldProxy->getProxyManagerHelloWorldLeaf().getInstanceAvailabilityStatus(leafInstance, callStatusAv, availabilityStatus);
-
-if (callStatusAv == CommonAPI::CallStatus::SUCCESS && availabilityStatus == CommonAPI::AvailabilityStatus::AVAILABLE) {
- auto helloWorldLeafProxy = helloWorldProxy->getProxyManagerHelloWorldLeaf().buildProxy<commonapi::examples::HelloWorldLeafProxy>(leafInstance);
-
- const std::string nameLeaf = "WorldLeaf";
- CommonAPI::CallStatus callStatusLeaf;
- std::string helloWorldLeafMessage;
-
- std::cout << "Sending name: '" << nameLeaf << "'\n";
- helloWorldLeafProxy->sayHelloLeaf("World", callStatusLeaf, helloWorldLeafMessage);
- if (callStatusLeaf != CommonAPI::CallStatus::SUCCESS) {
- std::cerr << "Remote call failed!\n";
- return -1;
- }
-
- std::cout << "Got message: '" << helloWorldLeafMessage << "'\n";
-
-} else {
- std::cout << "Leaf Proxy not available\n";
- sleep(5);
- return -1;
-}
-----
-
-This instantiates and calls a managed leaf stub and proxy respectively.
-
-== Further reading
-
-Aside from the README files of Common API and the specific bindings.
-
-
-=== The middleware loading mechanism of Common API
-
-
-==== CommonAPI::Runtime::load() returns no runtime object, why?
-
-As it was mentioned before, when you call _CommonAPI::Runtime::load()_.
-you "magically" will have access to a specific middleware library. In a very basic case, the library and thereby communication mechanism you will have access to
-will be the only Common API middleware library you linked to your executable during compilation.
-
-However, this call to _load()_ most likely will *FAIL* if you have no generated middleware specific code that is compiled with your application. Why that?
-The reason is simple, once understood: Most linkers are lazy. They do not link libraries that seem to be unused. Due to the fact that there is no reference
-whatsoever from Common API (and therefore your application) to any of the middleware libraries, the linker considers any and all middleware libraries
-as unused if not referenced by middleware specific generated code, and therefore will not add them to the executable.
-
-You can disable this behavior by passing the linker flag _whole-archive_ during the build process. Note however that this behavior _normally_ is a good optimization
-without repercussions - except probably in the context of CommonAPI.
-
-
-==== Using more than one middleware binding
-
-CommonAPI provides the possibility to use more than one middleware binding at once. In this case, you should no longer use _CommonAPI::Runtime::load()_,
-but instead _CommonAPI::Runtime::load("NameOfSomeMiddleware")_.
-
-The "NameOfSomeMiddleware" is the well known name of the middleware you want to load. It is defined and made public by each of the middlewares that support
-Common API. For DBus, this name is simply "DBus".
-
-
-==== Fully dynamic loading and additional information
-
-This topic is handled in-depth in the README of Common API. Please refer to this file for any further information.
-
-
-=== Online Documentation and Guides
-
-For an in-depth introduction to Franca IDL, please refer to the current user manual found on
-----
-https://code.google.com/a/eclipselabs.org/p/franca/downloads/list
-----
-At the time of writing of this tutorial, _FrancaUserGuide-0.3.0.pdf_ is the most recent version.
diff --git a/doc/CommonAPISpecification b/doc/CommonAPISpecification
new file mode 100644
index 0000000..5793b97
--- /dev/null
+++ b/doc/CommonAPISpecification
@@ -0,0 +1,1065 @@
+CommonAPI C++ Specification
+===========================
+:website: http://projects.genivi.org/commonapi/
+:version:
+:date:
+:toc:
+:revdate:
+:imagedir:
+:cppstr: c++
+
+This is the specification for *CommonAPI {version}* Revision Date {revdate}.
+
+.Copyright and License
+*******************************************************************************
+Copyright (C) 2013, GENIVI Alliance, Inc.
+Copyright (C) 2013, BMW AG
+
+This file is part of the GENIVI Project IPC Common API C++.
+
+Contributions are licensed to the GENIVI Alliance under one or more
+Contribution License Agreements or MPL 2.0.
+*******************************************************************************
+
+CommonAPI is a C++ standard API framework for Interprocess Communication (IPC). A specific IPC framework is not included but it can be used with any kind of IPC mechanism if a middleware specific CommonAPI binding is provided.
+
+Common API allows that applications (i.e., clients and servers using C++) developed against Common API can be linked against different Common API IPC backends without any changes to the application code. Thus, components which have been developed for a system which uses IPC X can be deployed for a system which uses IPC Y easily, just by generating some glue code and rebuilt. The actual interface definitions will be created using http://code.google.com/a/eclipselabs.org/p/franca/[Franca IDL], which is the Common IDL solution favored by http://www.genivi.org/[GENIVI].
+
+Common API will not be restricted to GENIVI members (cf. new GENIVI open source policy). It is available as open source code and some code generation tooling (see http://projects.genivi.org/).
+
+.This document
+********************************************************************************
+This document originates from a page in the GENIVI Wiki which was the result of some work of the System Infrastructure Expert Group
+for the IPC subdomain.
+
+If you're new to CommonAPI please read the introduction of this document and the CommonAPI Tutorial which can be found in the http://git.projects.genivi.org/?p=ipc/common-api-tools.git;a=summary[CommonAPI-Tools repository].
+********************************************************************************
+
+General Design
+--------------
+
+Basic Assumptions
+~~~~~~~~~~~~~~~~~
+
+- The applications use the client-server communication paradigm.
+- The C++ API is based on the common interface description language Franca IDL which provides the possibility to specify interfaces independent from the platform, middleware or programming language. That means that the application specific part of the API is generated via a code generator from a Franca IDL specification file (see figure 1).
+- CommonAPI specifies only an API and not an concrete IPC mechanism. It can only be used with a language binding that has to be developed for a special middleware.
+- In principle, the CommonAPI should be platform independent. However, this is without any restrictions very difficult to realize. Therefore it is agreed that CommonAPI attempts to use only features supported from the gnu C++ compiler version \<= 4.4.2. Please find supported ((compiler)) and compiler versions in the NEWS file of the CommonAPI distribution.
+
+.Code Generation from Franca IDL
+image::{imagedir}/CodeGenerationFrancaIDL.png[Code Generation image]
+
+Deployment
+~~~~~~~~~~
+
+One problem with definition of a middleware-independent C++ API is that depending on the middleware different configuration parameters for parts of the API could be necessary. Examples:
+
+- QoS parameter
+- Maximum length of arrays or strings
+- Endianness of data
+- Priorities
+
+The Franca IDL offers the possibility to specify these kind of parameters which depend on the used middleware in a middleware-specific or platform-specific deployment model (*.depl file). The deployment parameters can be specified arbitrarily.
+
+But as indicated above it is an explicit goal that an application written against CommonAPI can be linked against different CommonAPI IPC backends without any changes to the application code. This goal brings an important implicit restriction:
+
+[NOTE]
+The interface defined in Franca IDL is the only information that should be used to generate the CommonAPI headers that define the implementation API. Deployment models that are specific to the IPC backend must not affect the generated API. But a non specific deployment model is allowed.
+
+.Deployment Concept
+image::{imagedir}/Deployment.png[Deployment image]
+
+Basic Parts of CommonAPI
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+CommonAPI can be divided up into two parts:
+
+- The first part (Franca based part, generated by the CommonAPI code generator) refers to the variable (generated) part of the logical interface. That is the part of the interface which depends on the specifications in the Franca IDL file (data types, arrays, enumerations and interface basics as attributes, methods, callbacks, error handling, broadcast).
+- The second fixed part (CommonAPI Runtime features) which is mainly independent from the interface specifications. It refers to the CommonAPI library functions as service discovery, connect/disconnect, and address handling which relate primarily to the runtime environment provided by the underlying middleware. Furthermore this part contains common type definitions and base classes.
+
+Franca based part
+-----------------
+
+Namespaces
+~~~~~~~~~~
+
+The *namespace* of the CommonAPI base functions is CommonAPI; the ((namespace)) of a CommonAPI application depends on the the qualified package name of the interface specification.
+
+[cols="<50%asciidoc,<50%asciidoc",frame="none",grid="none"]
+|====
+|.FrancaIDL
+[source,java]
+----
+package example.user
+----
+|.CommonAPI C++
+[source,{cppstr}]
+----
+namespace example {
+namespace user {
+
+}
+}
+----
+|====
+
+Data Types
+~~~~~~~~~~
+
+Primitive Types
+^^^^^^^^^^^^^^^
+
+The integer data types used by Common API are defined in +stdint.h+.
+
+.Mapping Of Franca Primitive Types With CommonAPI C++ Types
+[width="100%",cols="3,5,8",options="header"]
+|=========================================================
+|Franca Type Name |CommonAPI C++ Type |Notes
+
+|+UInt8+ |+uint8_t+ |
+unsigned 8-bit integer (range 0..255).
+
+|+Int8+ |+int8_t+ |
+signed 8-bit integer (range -128..127).
+
+|+UInt16+ |+uint16_t+ |
+unsigned 16-bit integer (range 0..65535).
+
+|+Int16+ |+int16_t+ |
+signed 16-bit integer (range -32768..32767).
+
+|+UInt32+ |+uint32_t+ |
+unsigned 32-bit integer (range 0..4294967295).
+
+|+Int32+ |+int32_t+ |
+signed 32-bit integer (range -2147483648..2147483647).
+
+|+UInt64+ |+uint64_t+ |
+unsigned 64-bit integer.
+
+|+Int64+ |+int64_t+ |
+signed 64-bit integer.
+
+|+Boolean+ |+bool+ |
+boolean value, which can take one of two values: false or true.
+
+|+Float+ |+float+ |
+floating point number (4 bytes, range +/- 3.4e +/- 38, ~7 digits).
+
+|+Double+ |+double+ |
+double precision floating point number (8 bytes, range +/- 1.7e +/- 308, ~15 digits).
+
+|+String+ |+std::string+ |
+character string.
+
+|+ByteBuffer+ |+std::vector<uint8_t>+ |
+buffer of bytes (aka BLOB).
+|=========================================================
+
+Franca has only one string data type, and if necessary the wire format / ((encoding)) can be specified via deployment model. The Proxies always expect and deliver *UTF-8*.
+
+Arrays
+^^^^^^
+
+Franca ((array)) types (in explicit and implicit notation) are mapped to +std::vector<T>+. While explicitly defined array types will be made available as typedef with the name as it was given in Franca IDL, the implicit version will just be generated as +std::vector<T>+ wherever needed.
+
+Structures
+^^^^^^^^^^
+
+Franca struct types are mapped to C++ struct types.
+
+.FrancaIDL
+[source,java]
+----
+struct TestStruct {
+ UInt16 uintValue
+ String stringValue
+}
+----
+
+.CommonAPI C++
+[source,{cppstr}]
+----
+struct TestStruct: CommonAPI::SerializableStruct {
+ TestStruct() = default;
+ TestStruct(const uint16_t& uintValue, const std::string& stringValue);
+
+ virtual void readFromInputStream(CommonAPI::InputStream& inputStream);
+ virtual void writeToOutputStream(CommonAPI::OutputStream& outputStream) const;
+
+ uint16_t uintValue;
+ std::string stringValue;
+};
+----
+
+One problem is the possibility to inherit structures in Franca IDL. This feature can be mapped 1:1 to C\++ inheritance for structs. Due to the limitations of the C\++ language, we can make use of the C\++ virtual methods to guarantee proper serialization of derived struct types. For that we define +InputStream+ and +OutputStream+ classes which are part of the CommonAPI library. Each basic struct (the topmost parent in inheritance) must derive from +SerializableStruct+ which is also defined within the CommonAPI library. This will force each struct to implement two virtual methods: +readFromInputStream()+ and +writeToOutputStream()+.
+
+The CommonAPI library also defines the two input and output stream operators on +SerializableStruct+: +operator<<()+ and +operator>>()+, whose purpose is to signal the +InputStream+ and +OutputStream+ implementations that a struct is about to be serialized, and call the internal +readFromInputStream()+ or +writeToOutputStream()+ methods. The latter are CommonAPI specific and must not be accessible from the application or the individual bindings to avoid confusion. A typical application will create a struct instance, fill in the values and call a proxy method with the struct instance. The proxy method will be dispatched to the apropriate binding, which will eventually serialize the struct using the stream operators. This will result in calling the binding specific +InputStream+ or +OutputStream+ implementations through SerializableStruct's virtual methods +readFromInputStream()+ or +writeToOutputStream()+.
+
+Enumerations
+^^^^^^^^^^^^
+
+Franca ((enumerations)) will be mapped to C++ strongly typed enums. Enum backing datatype and wire format by default is +uint32_t+. If needed, the wire format can be specified via deployment model, but proxy only delivers and expects the default.
+
+.FrancaIDL
+[source,java]
+----
+enumeration MyEnum {
+ E_UNKNOWN = "0x00"
+}
+
+enumeration MyEnumExtended extends MyEnum {
+ E_NEW = "0x01"
+}
+----
+
+.CommonAPI C++
+[source,{cppstr}]
+----
+enum class MyEnum: int32_t {
+ E_UNKNOWN = 0 };
+
+// Definition of a comparator is necessary for GCC 4.4.1
+// Topic is fixed since 4.5.1
+struct MyEnumComparator;
+
+enum class MyEnumExtended: int32_t {
+ E_UNKNOWN = MyEnum::E_UNKNOWN,
+ E_NEW = 1
+};
+----
+
+[NOTE]
+To enable comparisons between enumerations in an inheritance hierarchy comparators have to be generated for the C\++ types, as C++ does not support enum-inheritance natively.
+
+Maps
+^^^^
+
+For efficiency reasons the CommonAPI data type for Franca ((maps)) is +std::unordered_map<K,V>+.
+
+[cols="<30%asciidoc,<70%asciidoc",frame="none",grid="none"]
+|====
+|[source,java]
+.FrancaIDL
+----
+map MyMap {
+ UInt32 to String
+}
+----
+|[source,{cppstr}]
+.CommonAPI C++
+----
+typedef std::unordered_map<uint32_t, std::string> MyMap;
+----
+|====
+
+Unions
+^^^^^^
+
+Franca ((union)) types are implemented as a typedef of CommonAPI generic templated C++ variant class.
+
+[cols="<40%asciidoc,<60%asciidoc",frame="none",grid="none"]
+|====
+|[source,java]
+.FrancaIDL
+----
+union MyUnion {
+ UInt32 MyUInt
+ String MyString
+}
+----
+|[source,{cppstr}]
+.CommonAPI C++
+----
+typedef Variant<uint32_t, std::string> MyUnion;
+----
+|====
+
+This uses a variadic template to define the possible options, and implements operators in the expected fashion.
+
+Assignment works by constructor or assignment operator:
+----
+MyUnion union = 5;
+MyUnion stringUnion("my String");
+----
+
+Getting the contained value is done via a get method templated to the type desired for type safety. This results in a compile error if an impossible type is attempted to be fetched. In case of fetching a type which can be contained but is not an exception is thrown. The choice of an exception at this point is made for the following reasons:
+
+- Returning pointers is inconvenient, especially in case of primitives.
+- Returning a temporary reference in case of failure is dangerous due to potential for segmentation faults in case of accidental use.
+- Returning a null heap object will be a memory leak if not deleted by the user.
+
+----
+MyUnion union = 5;
+int a = union.get<uint32_t>(); //Works!
+std::string b = union.get<std::string>(); //Throws exception
+----
+
+Also available is an templated isType method to test for the contained type:
+
+----
+MyUnion union = 5;
+bool contained = union.isType<uint32_t>(); //True!
+contained = union.isType<std::string>(); //False!
+----
+
+[NOTE]
+To enable comparisons between variants in an inheritance hierarchy comparators have to be generated for the C\++ types, as C++ as all ((variants)) are instances of the same generic class.
+
+Type Aliases
+^^^^^^^^^^^^
+
+Franca typedefs are mapped to C++ typedef.
+
+Type Collections
+^^^^^^^^^^^^^^^^
+
+In Franca a set of user-defined types can be defined as _type collection_. The name of the type collection, referred to as _typecollectionname_, can be empty. CommonAPI uses for empty type collection the default name _AnonymousTypeCollection_.
+
+The CommonAPI code generator generates the header file +typecollectionname.h+ and creates an own namespace for the type collection.
+
+[source,java]
+.FrancaIDL
+----
+package commonapi.examples
+
+typeCollection {
+// type definitions here
+}
+----
+
+[source,{cppstr}]
+.CommonAPI C++
+----
+namespace commonapi {
+namespace examples {
+namespace AnonymousTypeCollection {
+
+static inline const char* getTypeCollectionName() {
+ static const char* typeCollectionName = "commonapi.examples.AnonymousTypeCollection";
+ return typeCollectionName;
+}
+
+} // namespace AnonymousTypeCollection
+} // namespace examples
+} // namespace commonapi
+----
+
+Interfaces
+~~~~~~~~~~
+
+Basics
+^^^^^^
+
+For the Franca interface name, referred to as _interfacename_, a class name is generated which provides the methods +getInterfaceName+ and +getInterfaceVersion+. The ((version)) is mapped to a struct +CommonAPI::Version+.
+
+[NOTE]
+Specifying a version is mandatory for CommonAPI.
+
+[source,java]
+.FrancaIDL
+----
+package commonapi.examples
+
+interface ExampleInterface {
+ version { major 1 minor 0 }
+}
+----
+
+[source,{cppstr}]
+.CommonAPI C++
+----
+namespace commonapi {
+namespace examples {
+
+class ExampleInterface {
+ public:
+ virtual ~ExampleInterface() { }
+
+ static inline const char* getInterfaceId();
+ static inline CommonAPI::Version getInterfaceVersion();
+};
+
+const char* ExampleInterface::getInterfaceId() {
+ static const char* interfaceId = "commonapi.examples.ExampleInterface";
+ return interfaceId;
+}
+
+CommonAPI::Version ExampleInterface::getInterfaceVersion() {
+ return CommonAPI::Version(1, 0);
+}
+
+} // namespace examples
+} // namespace commonapi
+----
+
+The specification of the version structure is part of the namespace CommonAPI:
+[source,{cppstr}]
+----
+struct Version {
+ Version() = default;
+
+ Version(const uint32_t& majorValue, const uint32_t& minorValue):
+ Major(majorValue),
+ Minor(minorValue) {}
+
+ uint32_t Major;
+ uint32_t Minor;
+};
+----
+
+As described above it is a basic assumption that the applications use the client-server communication paradigm. That means that the CommonAPI code generator generates stub code for the server implementation and proxy code for the client implementation.
+
+At least the following files are generated:
+
+.Generated files of the CommmonAPI code generator for the example interface +ExampleInterface+
+[width="80%",cols="2,1"]
+|=========================================================
+|ExampleInterface.h | Common header file for client and service
+
+|ExampleInterfaceProxy.h | proxy class
+
+|ExampleInterfaceProxyBase.h | base class for proxy
+
+|ExampleInterfaceStub.h | stub
+
+|ExampleInterfaceStubDefault.cpp | stub default implementation
+
+|ExampleInterfaceStubDefault.h | stub default header
+
+|=========================================================
+
+The following picture shows the relationships between the proxy classes.
+
+.Proxy Classes
+image::{imagedir}/Diag_GeneratedProxy.png[Proxy image]
+
+On stub side it looks like this.
+
+.Stub Classes
+image::{imagedir}/Diag_GeneratedStub.png[Stub image]
+
+Methods
+^^^^^^^
+
+Franca IDL supports the definition of ((methods)) and ((broadcasts)). Methods can have several in and out parameters; if an additional flag ((fireAndForget)) is specified, no out parameters are permitted. Broadcasts can have only out parameters. Methods without the +fireAndForget+ flag can return an error which can be specified in Franca IDL as an enumeration. For broadcasts an additional flag +selective+ can be defined. This flag indicates that the message should not be sent to all registered participants but that the service makes a selection.
+
+[NOTE]
+- In Franca IDL there is no difference between an asynchronous or synchronous call of methods; the CommonAPI will provide both. The user of the API can decide which variant he calls.
+- The CommonAPI does not provide the possibility to cancel asynchronous calls.
+
+For methods without the +fireAndForget+ flag an additional return value ((CallStatus)) is provided which is defined as enumeration:
+
+[source,{cppstr}]
+----
+enum class CallStatus {
+ SUCCESS,
+ OUT_OF_MEMORY,
+ NOT_AVAILABLE,
+ CONNECTION_FAILED,
+ REMOTE_ERROR
+};
+----
+
+The +CallStatus+ defines the transport layer result of the call, i.e. it returns:
+
+- SUCCESS, if the remote call returned successfully.
+- OUT_OF_MEMORY, if sending the call or receiving the reply could not be completed due of a lack of memory.
+- NOT_AVAILABLE, if the corresponding service for the remote method call is not available.
+- CONNECTION_FAILED, if there is no connection to the communication medium available.
+- REMOTE_ERROR, if the sent remote call does not return (in time). *NOT* considered to be a remote error is an application level error that is defined in the corresponding Franca interface, because from the point of view of the transport layer the service still returned a valid answer. It *IS* considered to be a remote error if no answer for a sent remote method call is returned within a defined time. It is discouraged to allow the sending of any method calls without a defined timeout. This timeout may be middleware specific. This timeout may also be configurable by means of a Franca Deployment Model. It is *NOT* configurable at runtime by means of the Common API.
+
+For the return parameters a function object is created which is passed to the asynchronous method call. This function object can then be used directly in the client application as function pointer to a callback function or be bound to a function with a different signature. The usage of +std::bind+ is not enforced but must be possible. The bound callback function object will be called in any case:
+
+- If the call returns successfully: Once the remote method call successfully returns, the callback function object is called with SUCCESS for its CallStatus and any received parameters.
+- If a transport layer error occurs: If an error occurs that would trigger the method to return anything other but SUCCESS for its CallStatus, the callback has to be called with the corresponding CallStatus value. All other values that are input to the callback may remain unitialized in this case.
+
+The asynchronous call returns the CallStatus as ((future)) object. This allows the synchronization of asynchronous calls to a defined time. The future object will attain its value at the same time at which the callback function object is called.
+
+The following example shows the signatures of the generated functions. First, the Franca IDL example:
+
+[source,java]
+----
+package commonapi.examples
+
+interface ExampleInterface {
+
+ version { major 1 minor 0 }
+
+ method getProperty {
+ in {
+ UInt32 ID
+ }
+ out {
+ String Property
+ }
+ error {
+ OK
+ NOT_OK
+ }
+ }
+
+ method newMessage fireAndForget {
+ in {
+ String MessageName
+ }
+ }
+
+ broadcast signalChanged {
+ out {
+ UInt32 NewValue
+ }
+ }
+
+ broadcast signalSpecial selective {
+ out {
+ UInt32 MyValue
+ }
+ }
+}
+----
+
+See the generated function calls for the methods _getProperty_ and _newMessage_ on *proxy side*:
+
+[source,{cppstr}]
+----
+/* Calls getProperty with synchronous semantics. */
+virtual void getProperty(const uint32_t& ID, CommonAPI::CallStatus& callStatus, ExampleInterface::getPropertyError& methodError, std::string& Property);
+
+/* Calls getProperty with asynchronous semantics. */
+virtual std::future<CommonAPI::CallStatus> getPropertyAsync(const uint32_t& ID, GetPropertyAsyncCallback callback);
+
+/* Calls newMessage with Fire&Forget semantics. */
+virtual void newMessage(const std::string& MessageName, CommonAPI::CallStatus& callStatus);
+----
+
+- All const parameters are input parameters.
+- All non-const parameters will be filled with the returned values.
+- The CallStatus will be filled when the methods return and indicate either +SUCCESS+ or which type of error has occurred. In case of an error, *ONLY* the CallStatus will be set.
+- The provided callback of the asynchronous call will be called when the reply to this call arrives or an error occurs during the call. The +std::future+ returned by this method will be fulfilled at arrival of the reply. It will provide the same value for CallStatus as will be handed to the callback.
+
+On *stub side* the generated functions are part of the default stub (+ExampleInterfaceStubDefault.h+):
+
+[source,{cppstr}]
+----
+virtual void getProperty(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t ID, ExampleInterface::getPropertyError& methodError, std::string& Property);
+virtual void newMessage(const std::shared_ptr<CommonAPI::ClientId> clientId, std::string MessageName);
+----
+
+Note that it makes on the stub side no difference whether the function call was synchronous or asynchronous.
+
+On stub side the additional parameter of type _ClientId_ is passed. The _ClientId_ identifies a client sending a call to a stub. It is used to identify the caller within a stub and is supposed to be added by the middleware and can be compared using the == operator. The ClientId class is declared as:
+
+[source,{cppstr}]
+----
+class ClientId {
+public:
+ virtual ~ClientId() { }
+ virtual bool operator==(ClientId& clientIdToCompare) = 0;
+ virtual std::size_t hashCode() = 0;
+};
+----
+
+The pure virtual methods operator==() and hascode() have to be implemented by the middleware specific binding. Note that the value of the ClientId itself is irrelevant for CommonAPI. As API only the comparison operator is offered; the middleware specific identifier could be of any size as long as it is unique. The method hascode() is there so that the ClientId can be used as key in a hashmap.
+
+If we now consider the broadcast methods the generated functions on *proxy side* are:
+
+[source,{cppstr}]
+----
+virtual SignalChangedEvent& getSignalChangedEvent() {
+ return delegate_->getSignalChangedEvent();
+}
+
+virtual SignalSpecialSelectiveEvent& getSignalSpecialSelectiveEvent() {
+ return delegate_->getSignalSpecialSelectiveEvent();
+}
+----
+
+These methods return a wrapper class for an event that provides access to the broadcast +signalChanged+ (see below in this specification the CommonAPI definition of events). The wrapper class provides the methods subscribe and unsubscribe. The private property +delegate_+ is used for forwarding the function call to the specific binding.
+
+The generated stub provides methods to fire the broadcasts and some hooks:
+
+[source,{cppstr}]
+----
+virtual void fireSignalChangedEvent(const uint32_t& NewValue);
+virtual void fireSignalSpecialSelective(const uint32_t& MyValue, const std::shared_ptr<CommonAPI::ClientIdList> receivers = NULL);
+virtual std::shared_ptr<CommonAPI::ClientIdList> const getSubscribersForSignalSpecialSelective();
+
+/* Hook method for reacting on new subscriptions or removed subscriptions respectively for selective broadcasts. */
+virtual void onSignalSpecialSelectiveSubscriptionChanged(const std::shared_ptr<CommonAPI::ClientId> clientId, const CommonAPI::SelectiveBroadcastSubscriptionEvent event);
+/* Hook method for reacting accepting or denying new subscriptions */
+virtual bool onSignalSpecialSelectiveSubscriptionRequested(const std::shared_ptr<CommonAPI::ClientId> clientId);
+----
+
+Note that the Franca keyword _selective_ is implemented only on stub side by using the _ClientId_ and the provided hooks.
+
+[NOTE]
+The _ClientId_ can be generated only on the stub side due to middleware specific data that can be composed entirely arbitrary.
+
+Attributes
+^^^^^^^^^^
+
+An attribute of an interface is defined by name and type. Additionally the specification of an attribute can have two flags:
+
+- +noSubscriptions+
+- +readonly+
+
+CommonAPI provides a basic implementation of the attribute interface and a mechanism for so-called ((extensions)). The basic implementation is shown in the example below. There are four possible combinations of flags:
+
+- standard attributes with no additional flag.
+- readonly attributes (readonly flag is set).
+- non observable attributes (noSubscription flag).
+- and non observable and non writable attributes (both flags are set).
+
+Attributes which are non readable but only writable are not supported by Franca IDL and CommonAPI.
+
+Template classes for each of those four types of attributes are defined in the header file Attribute.h. The CommonAPI provides a getter function which returns a reference to an instance of the appropriate attribute template class.
+
+.Attributes
+image::{imagedir}/Diag_Attributes.png[Attribute image]
+
+Observable attributes provide a ChangedEvent which can be used to subscribe to updates to the attribute. This Event works exactly as all other events (see description below). By default, the attributes are not cached in client side. Creating a cache on client side is not an implementation-specific detail that should be a part of the logical interface specification, nor is it a platform- or middleware-dependent parameter. Moreover, the requirements for an attribute cache can be very different depending on the application specific use case. Differences in points of view include, but are not limited to:
+
+- Is the cache value to be updated on any value changed event or is it to be updated periodically?
+- Should calls to getters of potentially cached values be blocking or non-blocking?
+- Should caching be configurable per attribute or per proxy, or should caching always be enabled?
+- Is getting a cached value a distinct method call or is it to be included transparently within the standard getter methods?
+
+Because of this, there is a general scheme to include individual extensions in order to provide any additional features for attributes (Attribute Extensions). This would prevent an exponential growth of configuration possibilities within the Common API and also relieve Common API developers from the necessity to always implement all specified features for their specific middleware, regardless of whether the feature is supported by the middleware or not. On the other hand, it gives complete freedom to application developers to add an implementation for their specific needs to attribute handling.
+
+The basic principle is that the user of the API has to implement an extension class that is derived from the base class +AttributeExtension+. The +AttributeExtension+ is packed in a wrapper class which in turn is generated for each attribute the Proxy has. A wrapper for a given attribute only then is mixed into the proxy if an extension for this given attribute is defined during construction time. The wrapper forwards the correct attribute to the constructor of the extension, so that the extension sees nothing but the attribute it should extend. Wrappers are written as templates, so that all wrappers can be reused for all attributes of the same category. As soon as an extension for an attribute is defined during construction time, the extension class will be instantiated and a method to retrieve the extended attribute will be added to the proxy.
+
+Such an solution requires the proxy to be made ready for mixins. The proxy inherits from all mixins that are defined during construction time, so that their interface is added directly to the proxy itself. The interface that would be added to the proxies in our case would be the interface of the defined attribute extension wrappers, which in turn provide access to the actual attribute extensions. By using variadic templates the amount of possible mixins is arbitrary.
+
+[NOTE]
+Because a given proxy may not inherit from the same class twice, only one extension per attribute per proxy is possible.
+
+The base class for extensions is defined in +AttributeExtension.h+.
+
+The CommonAPI for attributes on *stub side* looks like this when we only consider the attribute +A+:
+
+[source,{cppstr}]
+----
+ public:
+ virtual const uint32_t& getAAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId);
+ virtual void setAAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value);
+
+ protected:
+ virtual bool trySetAAttribute(uint32_t value);
+ virtual bool validateAAttributeRequestedValue(const uint32_t& value);
+ virtual void onRemoteAAttributeChanged();
+----
+
+The attribue +A+ is stored in the default implementation of the stub class as private member and via CommonAPI accessible by calling the corresponding get function. CommonAPI defines furthermore three callbacks to handle remote set events related to the attributes defined in the IDL description for ExampleInterface.
+
+- The first, +validate<AttributeName>RequestedValue+, allows for verification of the attribute value before it actually is set. This callback receives the new requested value and should return true if the operation is possible or false if the operation cannot be completed at all. In the default case, this callback will return true.
+- The second, +trySet<AttributeName>Attribute+, setting and modification of the attribute value. This callback receives the new requested value as a reference and modifies this as needed. Additionally it returns true if the value was modified before setting, or false if it is set as requested. In the default case, this callback will return the same value and true (i.e. the new value for the attribute is accepted without further modifications).
+- The third callback, +onRemote<AttributeName>Changed+, is called if the new value of the attribute differs from the old, and allows the service to do arbitrary work in response to such an attribute change. This is called after the clients are informed of the change.
+
+These are protected to avoid exposing them to the API code, as they should only be called by the adapter. This is done via a generated class, the <interfaceName>StubRemoteEvent, which has access to these methods.
+
+The CommonAPI library will transmit any "attribute changed" event notifications to remote listeners after the verify callback but before the change callback, if and only if the value of the attribute actually has changed after verification.
+
+The default implementation of a generated stub does
+
+- nothing on method calls
+- return the new value of an attribute on a verify callback
+- do nothing on an attribute changed callback
+
+Events
+^^^^^^
+
+Events provide an asyncronous interface to remotely triggered actions. This covers broadcast methods in Franca IDL and change events for attributes Every proxy also provides an availabity event which can be used for notifications of the proxies status. The Events provide a subscribe and unsubscribe method which allow registration and de-registration of callbacks.
+
+The public interface of the event class is as follows:
+
+[source,{cppstr}]
+----
+template<typename ... _Arguments>
+class Event {
+ public:
+
+ typedef std::function<void(const _Arguments&...)> Listener;
+ typedef std::function<SubscriptionStatus(const _Arguments&...)> CancellableListener;
+ typedef std::list<CancellableListener> ListenersList;
+ typedef typename ListenersList::iterator Subscription;
+
+ class CancellableListenerWrapper;
+
+ /* Subscribe a listener to this event.*/
+ virtual inline Subscription subscribe(Listener listener);
+ /*Subscribe a cancellable listener to this event.*/
+ Subscription subscribeCancellableListener(CancellableListener listener);
+ void unsubscribe(Subscription listenerSubscription);
+
+ virtual ~Event() {}
+
+};
+----
+
+[NOTE]
+- You should not build new proxies or register services in callbacks from events. This can cause a deadlock or assert. Instead, you should set a trigger for your application to do this on the next iteration of your event loop if needed. The preferred solution is to build all proxies you need at the beginning and react to events appropriatly for each.
+- Do not call +unsubscribe+ inside a listener notification callback it will deadlock! Use cancellable listeners instead.
+
+Runtime
+-------
+
+Loading the Middleware
+~~~~~~~~~~~~~~~~~~~~~~
+
+The Common API ((Runtime)) is the base class from which all class loading starts. The Common API Runtime accesses a config file to determine which specific middleware runtime library shall be loaded. Middleware libraries are either linked statically or are provided as shared objects (file extension .so), so they can be loaded dynamically. To make dynamic loading controllable, additional configuration parameters are available, see the chapter on "Configuration Files" below.
+
+The public interface of the runtime class provides the following functions:
+
+[width="100%",cols="50%asciidoc,50%"]
+|=========================================================
+|[source,{cppstr}]
+----
+static std::shared_ptr<Runtime>
+load();
+----
+|Loads the runtime for the default middleware binding. This can be one of the middleware bindings that were linked at compile time. It is the first middleware binding that is encountered when resolving bindings at runtime or the middleware binding that was configured as default in the corresponding configuration file (throws an error if no such binding exists). The function returns the runtime object for the default binding, or null if any error occurred.
+
+|[source,{cppstr}]
+----
+static std::shared_ptr<Runtime>
+load(LoadState& loadState);
+----
+|The _loadState_ is an enumeration that will be set appropriately after loading has finished or aborted. May be used for debugging purposes.
+
+|[source,{cppstr}]
+----
+static std::shared_ptr<Runtime>
+load(const std::string&
+ middlewareIdOrAlias);
+----
+|Loads the runtime for the specified middleware binding. The given well known name can be either the well known name defined by a binding, or a configured alias for a binding.
+
+|[source,{cppstr}]
+----
+static std::shared_ptr<Runtime>
+load(const std::string&
+ middlewareIdOrAlias,
+ LoadState& loadState);
+----
+|
+
+|[source,{cppstr}]
+----
+std::shared_ptr<MainLoopContext>
+getNewMainLoopContext() const;
+----
+|Creates and returns a new MainLoopContext object. This context can be used to take complete control over the order and time of execution of the abstract middleware dispatching mechanism. Make sure to register all callback functions before subsequently handing it to createFactory(), as during creation of the factory object the callbacks may already be called.
+
+|[source,{cppstr}]
+----
+std::shared_ptr<Factory>
+createFactory(
+ std::shared_ptr<MainLoopContext>
+ mainLoopContext =
+ std::shared_ptr<MainLoopContext>(NULL),
+ const std::string factoryName = "",
+ const bool nullOnInvalidName = false);
+----
+|In case mainloop integration shall be used, a std::shared_ptr<MainLoopContext> can be passed in. If no parameter is given, internal threading will handle sending and receiving of messages automatically. If the mainloop context is not initialized, no factory will be returned. If additional configuration parameters for the specific middleware factory shall be provided, the appropriate set of parameters may be identified by the _factoryName_. If a factoryName is provided, the parameter _nullOnInvalidName_ determines whether the standard configuration for factories shall be used if the specific parameter set cannot be found, or if instead no factory shall be returned in this case.
+
+|[source,{cppstr}]
+----
+std::shared_ptr<Factory>
+createFactory(const std::string
+ factoryName,
+ const bool nullOnInvalidName = false);
+----
+|
+
+|[source,{cppstr}]
+----
+virtual std::shared_ptr<ServicePublisher>
+getServicePublisher() = 0;
+----
+| Returns the ServicePublisher object for this runtime. Use the interface provided by the ServicePublisher to publish and de-publish the services that your application will provide to the outside world over the middleware represented by this runtime. A ServicePublisher exists once per middleware.
+|=========================================================
+
+
+Linking the Middleware at Compile Time
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+A specific Middleware runtime registers itself with the Common API Runtime during startup time via static initialization. Static initialization is done via a statically defined method in a +.cpp+ file with +__attribute\((constructor))+ as prefix. Within this method, registerRuntimeLoader of the Common API Runtime will be called. A specific middleware runtime needs to register itself with a well known string identifier, e.g. +DBus+ for a D-Bus middleware.
+
+The architecture was chosen this way in order to ease later support of dynamic linkage. No template based architecture was used to cross the boundary from Common API to a specific middleware, because template parameters can not be substituted dynamically.
+
+[source,{cppstr}]
+----
+__attribute__((constructor)) void registerDBusMiddleware(void) {
+ Runtime::registerRuntimeLoader("DBus", &DBusRuntime::getInstance);
+}
+----
+
+[NOTE]
+These specification assumes that the operating system is Linux. For some reasons CommonAPI can be used for test purposes on Windows. Then, the procedure may be slightly different from the one described.
+
+Linking the Middleware at Runtime
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+CommonAPI supports the loading of Middleware specific libraries at runtime, without linking them to the executable beforehand. For this purpose, each Middleware binding library provides a struct defined as extern "C", which provides information on the well known name of the Middleware, plus a function pointer to its runtime loader.
+
+----
+extern "C" const CommonAPI::MiddlewareInfo middlewareInfo;
+----
+
+The type +CommonAPI::MiddlewareInfo+ is defined in CommonAPI/MiddlewareInfo.h:
+[source,{cppstr}]
+----
+typedef std::shared_ptr<Runtime> (*MiddlewareRuntimeLoadFunction) ();
+
+struct MiddlewareInfo {
+ const char* middlewareName_;
+ MiddlewareRuntimeLoadFunction getInstance_;
+ Version version_;
+};
+----
+
+Factory
+~~~~~~~
+
+Create Factory
+^^^^^^^^^^^^^^
+
+The +CommonAPI::Factory+ class builds the proxies and registers stubs for a specific instance of a commonapi runtime (i.e. a particular binding) and connection. This class provides templated build methods which return particular instances of proxies according to the templates and passed address.
+
+[NOTE]
+If there are multiple connections to the rpc mechanism (not a specific service) multiple instances of Factory are needed.
+
+A CommonAPI factory can be obtained with:
+
+[source,{cppstr}]
+----
+//Loads default or first runtime binding defined in config file
+std::shared_ptr<CommonAPI::Factory> factory = CommonAPI::Runtime::load()->createFactory();
+
+//Loads a named runtime binding, either according to a well known name defined in the binding or a defined arbitrary alias as stated in the config file
+std::shared_ptr<CommonAPI::Factory> factory2 = CommonAPI::Runtime::load("namedBinding")->createFactory();
+----
+
+The code to generate a factory is equal on both sides (stub and proxy).
+
+The factory provides functions for the creation of the proxies and for determining the available services.
+
+[source,{cppstr}]
+----
+/* Get a pointer to the runtime of this factory.*/
+inline std::shared_ptr<Runtime> getRuntime();
+
+/* Get all instances of a specific service name available. Synchronous call.*/
+virtual std::vector<std::string> getAvailableServiceInstances(const std::string& serviceName, const std::string& serviceDomainName = "local") = 0;
+
+/* Is a particular complete common api address available. Synchronous call.*/
+virtual bool isServiceInstanceAlive(const std::string& serviceAddress) = 0;
+
+/ * Is a particular complete common api address available. Synchronous call.*/
+virtual bool isServiceInstanceAlive(const std::string& serviceInstanceID, const std::string& serviceName, const std::string& serviceDomainName = "local") = 0;
+----
+
+The asynchronous functions are defined analogously.
+
+Create Proxy Objects
+^^^^^^^^^^^^^^^^^^^^
+
+The factory provides at least two functions for building the proxy:
+
+[source,{cppstr}]
+----
+template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions >
+std::shared_ptr<_ProxyClass<_AttributeExtensions...> > buildProxy(const std::string& serviceAddress);
+
+template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension>
+std::shared_ptr<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t> buildProxyWithDefaultAttributeExtension(const std::string& serviceAddress);
+----
+
+_isAvailable_ is a non-blocking check whether the remote service for this proxy currently is available. Always returns false until the availability of the proxy is determined. The proxy actively determines its availability status asynchronously and ASAP as soon as it is created, and maintains the correct state afterwards.
+
+- Calls to synchronous methods will block until the initial availability status of the proxy is determined. As soon as the availability status has been determined at least once, calls to synchronous methods will return NOT_AVAILABLE as value for the CallStatus whenever isAvailable() would return false.
+- Calls to asynchronous methods do not wait for the initial availability status to be determined. Calls to asynchronous methods will instantly call the given callback with NOT_AVAILABLE as value for the CallStatus whenever isAvailable() would return false.
+- You may subscribe to the ProxyStatusEvent in order to have a callback notified whenever the availability status of the proxy changes. It is guaranteed that the callback is notified of the proxy's currently known availability status at the same instant in which the subscription is done (i.e. the callback will most likely be called with a value of false if you subscribe for this event right after the proxy has been instantiated).
+
+The parameter +serviceAddress+ is the address at which the service that shall be accessed will be available. Semantically, this address consists of three parts, separated by colons:
+
+[width="80%",cols="3,10"]
+|=========================================================
+
+|Domain |
+The first part, defines in which domain the service is located.
+
+|ServiceID |
+The second part. This defines the name or type of the service that shall be accessed.
+
+|InstanceID |
+The third part. This defines the specific instance of this service that shall be accessed.
+
+|=========================================================
+
+Register Services
+^^^^^^^^^^^^^^^^^
+
+The Factory class provides a +registerService()+ and +unregisterService()+ method. These allow the activation and deactivation of services and stubs via a complete common api address and a provided stub. The usage is similar to that for Proxies, except that no object is returned. Included below is the header for Common API factory.
+
+Provider
+^^^^^^^^
+
+A ((provider)) is made up of two parts, the interface adapter and its helpers and the stub. The interface adapters need to be generated individually for each service, but they remain invisible to the application developer, except when designing a derived stub class.
+
+An interface adapter is responsible for serialization and deserialization of messages, as well as the dispatching of the (de-)serialized messages to a registered stub. The stub forwards the broadcasts that are fired by a call to the "fire<BroadcastName>" methods to the adapter via the held shared pointer in order to send them.
+
+An interface adapter for a specific middleware needs to be generated in order to provide dispatching and callback handling that matches the stub. The procedure to attain the correct interface adapter is equivalent to the procedure to attain the correct proxy on client side. A given instance of an interface handler can serve one and only one stub at a time. The connection from the adapter to the stub is established during build time by a call to the predefined initStubAdapter method of the Stub template class.
+
+The common ancestor of any middleware specific handler (+CommonAPI::StubAdapter+) and stub (+CommonAPI::Stub+) classes defines a basic interface to retrieve general information about the service.
+
+Stubs are the methods to be implemented by a provider. This includes the remotely callable methods defined in the interface and the callbacks for attribute accessors. These are provided as a default stub class with a default blank implementation for all methods and storage and handling of attribute values inside the stub, which allows the application developer to overwrite the methods in a subclass as needed. Alternatively the pure virtual root class can be implemented directly, which also allows delegation of attribute handlers to other parts of the code. A given instance of a stub can be appended to one and only one interface adapter.
+
+Threading Model
+~~~~~~~~~~~~~~~
+
+CommonAPI supports multithreaded execution (standard threading) as well as single threaded execution (i.e. ((mainloop) integration). The decision which of both is desired happens when +CommonAPI::Runtime::createFactory+ is called. If single threaded execution is desired, a +CommonAPI::MainLoopContext+ has to be created, and then has to be passed as an argument to this method. All objects that are created by a factory that was instantiated this way will be controllable via the mainloop context that was handed to this factory. If a factory is not given this parameter during instantiation, standard threading will be set up for all objects that are created by this factory.
+
+Standard Threading
+^^^^^^^^^^^^^^^^^^
+
+To create a factory that uses standard threading, a factory has to be created this way:
+
+[source,{cppstr}]
+----
+std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+----
+
+Mainloop Integration
+^^^^^^^^^^^^^^^^^^^^
+
+A +CommonAPI::MainLoopContext+ provides nothing but hooks for callbacks that will be called on specific binding internal events. Internal events may be
+
+- (De-)Registration of a +CommonAPI::DispatchSource+
+- (De-)Registration of a +CommonAPI::Watch+
+- (De-)Registration of a +CommonAPI::Timeout+
+- Issuing of a wakeup call
+
+Each of these calls has to be mapped to an appropriate method in the context of the actual Mainloop that does the single threaded execution. CommonAPI does *NOT* provide a fully fledged implementation for a Mainloop!
+
+What the mainloop related interfaces are meant for is this:
+
+- +CommonAPI::DispatchSource+: Hooks that may have work ready that is to be done, e.g. dispatching a method call to a stub, dispatching a method return to a proxy callback and the like. There is no constraint on what kind of work may be represented by a DispatchSource, *BUT* a dispatch source may *NOT* be directly related to a file descriptor that is used to actually read or write the incoming or outgoing transmission from or to a transport!
+- +CommonAPI::Watch+: Work that is related to a file descriptor that is used for reading from or writing to a transport is represented by Watches. *ANY* work that is not directly related to such a file descriptor may *NOT* be represented by watches!
+- +CommonAPI::Timeout+: Represents the work that has to be done when a timeout occurs (e.g. deleting the structures that are used to identify an answer to an asynchronous call and calling the callback that is waiting for it with an appropriate error flag). A timeout stores internally both the interval of time within which it is to be dispatched, and the next moment in time the timeout is to be dispatched.
+
+A binding developer *MUST* provide his own implementations for at least DispatchSource and Watch in order to ensure the functionality of his respective CommonAPI binding in the single threaded case, and must ensure that the appropriate instances of those classes are handed to the application via the MainLoopContext that was handed to the factory that is used to instantiate proxies and stubs.
+
+An application developer *MAY* provide additional implementations of all these classes.
+
+[NOTE]
+During instantiation (i.e. during the call to +CommonAPI::Runtime::createFactory+) a binding *MAY* already issue calls to the callbacks that are registered with the +CommonAPI::MainLoopContext+. Therefore, it is mandatory to do any registration of required callbacks *BEFORE* doing so.
+
+To create a factory that supports Mainloop integration, a factory has to be created this way:
+
+[source,{cppstr}]
+----
+std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+//Do any registration of callbacks for the actual Mainloop here!
+std::shared_ptr<CommonAPI::MainLoopContext> context = runtime->getNewMainLoopContext();
+std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory(context);
+----
+
+Configuring CommonAPI
+~~~~~~~~~~~~~~~~~~~~~
+
+Change the behavior of interfaces
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+There are basically two possibilities to realize a specific behavior of your interface or to realize new features:
+
+- As described above the middleware implementation can be changed without changing the API for the applications. Changes in the configuration in the middleware or platform can be realized by changing the deployment specification and the deployment settings in the *.depl files.
+- For attributes (see specification below) there is the possibility to define and implement so-called extensions. This allows the developer to extend the standard framework with own implementations in a predefined and specified way. One example is to implement a cache for attributes on proxy side.
+
+Configuration Files
+^^^^^^^^^^^^^^^^^^^
+
+Each CommonAPI configuration file will define additional parameters for specific categories. Which categories and which parameters for each of those categories are available will be detailed below. All parameters for all categories are optional. For each omitted parameter a reasonable default will be set. Because of this, it is not mandatory to provide a config file unless you want to alter any of the configurable default values.
+
+CommonAPI config files can be defined locally per binary, globally per binary or globally for all binaries. If more than one config file is defined for a given binary (e.g. one locally and one globally) and a given category is defined in several of these config files, for each parameter that may be provided for this category the value found in the most specific config file will take precedence. If a category is defined several times within the same config file, the first occurrence of each parameter will take precedence.
+
+All categories and all parameters are separated from each other by one or more newline characters.
+
+CommonAPI Config files have to be named this way:
+
+- Binary local: "<FqnOfBinary>.conf", e.g. "/usr/bin/myBinary.conf" if the binary is "/usr/bin/myBinary"
+- Binary global: "/etc/CommonApi/<NameOfBinary>.conf", e.g. "/etc/CommonAPI/myBinary.conf"
+- Global: "/etc/CommonAPI/CommonAPI.conf"
+
+Available categories
+++++++++++++++++++++
+
+_Well known names of specific middleware bindings_
+
+Allows to set parameters that influence the loading procedure of specific middleware bindings.
+
+The syntax is:
+
+----
+{binding:<well known binding name>}
+libpath=<Fully qualified name of the library of the binding>
+alias=<One or more desired aliases for the binding, separated by ":">
+genpath=<One or more fully qualified names to libraries containing additional (generated) code for this binding, separated by ":">
+default
+----
+
+- *libpath*: Provides a fully qualified name that replaces the search path when trying to dynamically load the identified binding.
+** The library found at libpath will take precedence over all other dynamically discoverable libraries for this binding.
+** If a library for the specified middleware binding is linked to the binary already, this parameter will have no effect.
+** Not finding an appropriate library at libpath is considered to be an error! In this case, no further attempts to resolve the library will be made, and the load function will return an empty std::shared_ptr<CommonAPI::Runtime>.
+** If an explicit error state is desired, one of the overloaded Runtime::load() functions may be called to pass in an instance of Runtime::LoadState as argument.
+
+- *alias*: In order to load a specific middleware binding, one normally has to know the well known name of the middleware (e.g. "DBus" for the D-Bus middleware binding) and pass this name as parameter when calling CommonAPI::Runtime::load("<name>"). _alias maps the well known name for this purpose to one or more arbitrary aliases, thereby decoupling the loading of a specific middleware binding from its specific name.
+** You *MAY* specify this parameter more than once for a binding. The effect will be the same as if you had one alias parameter specifying the exact same names separated by ":".
+** If the same alias is specified more than once, only the first occurrence of the alias will be considered.
+** As CommonAPI itself does not know about which well known middleware names there are, it is possible to specify the well known name of an actual binding as an alias for any other middleware binding. In this case, the actual middleware binding will not be accessible any longer, unless you specify another unique alias for it.
+- *genpath*: Specifies one or more paths at which a generic library containing additional (e.g. generated middleware and interface code for the middleware binding is to be found. This additional code will be injected when the specific middleware considers it to be the right time to do so.
+** You *MAY* specify this parameter more than once for a binding. The effect will be the same as if you had one genpath parameter specifying the exact same values separated by ":".
+** If No such parameter is defined, the standard search paths "/usr/lib" and "/usr/local/lib" plus any additional paths defined in the environment variable COMMONAPI_BINDING_PATH (see below) will be searched for any libraries that match the name pattern "lib<wellKnownMiddlewareName>Gen-<arbitraryName>.so[.major.minor.revision]". All matching libraries will be loaded.
+** Not finding an appropriate library at any single one of the defined genpaths may result in undefined behavior.
+- *default*: Specifies the library for this binding as the default that is to be loaded if no parameter is given to CommonAPI::Runtime::load().
+** Not finding an appropriate library for a configured default binding at neither specified nor the default paths is considered to be an error! In this case, no further attempts to resolve the library will be made, and the load function will return an empty std::shared_ptr<CommonAPI::Runtime>. If an explicit error state is desired, one of the overloaded Runtime::load() functions may be called to pass in an instance of Runtime::LoadState as argument.
+
+[NOTE]
+The genpath parameter will be parsed by the CommonAPI framework and stored in the singleton class CommonAPI::Configuration. Actually loading the libraries and following the rules described here however is task of the specific middleware binding. You might want to use the convenience methods provided in <CommonAPI/utils.h> for this purpose. By taking control of the actual proceedings, you may introduce additional mechanisms of discovering and loading such libraries, and you may defer the loading of these libraries until you deem it to be the right time to do so.
+
+Environment Variables
+^^^^^^^^^^^^^^^^^^^^^
+
+- *COMMONAPI_BINDING_PATH*: By default, the standard paths "/usr/lib" and "/usr/local/lib" will be searched for binding libraries that are loaded dynamically (i.e. at runtime without linking them to the binary beforehand). All paths defined in this environment variable will take precedence over those two default paths. Separator between several paths is ":".
+
+[glossary]
+Glossary
+--------
+
+[glossary]
+BLOB::
+ Binary Large Object.
+
+IDL::
+ Interface Description Language.
+
+IPC::
+ Interprocess Communication.
+
+GENIVI::
+ is a non-profit industry alliance committed to driving the broad adoption of an In-Vehicle Infotainment (IVI) open-source development platform.
+
+
+ifdef::backend-docbook[]
+[index]
+Example Index
+-------------
+////////////////////////////////////////////////////////////////
+The index is normally left completely empty, it's contents being
+generated automatically by the DocBook toolchain.
+////////////////////////////////////////////////////////////////
+endif::backend-docbook[]
+
diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 0000000..ac1cbab
--- /dev/null
+++ b/doc/Makefile
@@ -0,0 +1,87 @@
+# Creating CommonAPI documentation
+docgendir=../doc-gen
+iconsdir=../../images/icons
+imagedir=../../images
+datestring=$(shell date "+%m-%d-%y")
+verification_project_path=../org.genivi.commonapi.core.verification
+commonapi_version=2.1.5
+
+all: doc
+
+doc: spec_html spec_pdf tut_html tut_pdf test_html test_pdf
+
+spec_html: docgendir
+ mkdir -p $(docgendir)/spec/html
+ asciidoc \
+ -a revdate=$(datestring) \
+ -a icons \
+ -a iconsdir=$(iconsdir) \
+ -a imagedir=$(imagedir) \
+ -a version=$(commonapi_version) \
+ -a cppstr=cpp \
+ -a tabsize=4 \
+ -o $(docgendir)/spec/html/CommonAPISpecification.html \
+ CommonAPISpecification
+
+spec_pdf: docgendir
+ mkdir -p $(docgendir)/spec/pdf
+ a2x \
+ -a revdate=$(datestring) \
+ -a icons \
+ -a iconsdir=$(iconsdir) \
+ -a imagedir=$(imagedir) \
+ -a version=$(commonapi_version) \
+ -a tabsize=4 \
+ -f pdf \
+ --dblatex-opts "-P latex.output.revhistory=0" \
+ --icons \
+ -D $(docgendir)/spec/pdf \
+ CommonAPISpecification
+
+tut_html: docgendir
+ mkdir -p $(docgendir)/tutorial/html
+ asciidoc -a revdate=$(datestring) \
+ -a icons \
+ -a iconsdir=$(iconsdir) \
+ -a imagedir=$(imagedir) \
+ -a version=$(commonapi_version) \
+ -a cppstr=cpp \
+ -a tabsize=4 \
+ -b html \
+ -o $(docgendir)/tutorial/html/Tutorial.html \
+ Tutorial
+
+tut_pdf: docgendir
+ mkdir -p $(docgendir)/tutorial/pdf
+ a2x \
+ -a revdate=$(datestring) \
+ -a icons \
+ -a iconsdir=$(iconsdir) \
+ -a imagedir=$(imagedir) \
+ -a version=$(commonapi_version) \
+ -a tabsize=4 \
+ -f pdf \
+ --dblatex-opts "-P latex.output.revhistory=0 -P imagedata.default.scale=maxwidth=10cm,maxheight=8cm" \
+ --icons \
+ -D $(docgendir)/tutorial/pdf \
+ Tutorial
+
+test_html: docgendir
+ mkdir -p $(docgendir)/tests
+ OUTPUT_DIRECTORY=$(docgendir)/tests \
+ PROJECT_NAME=CommonAPITests \
+ SRC_DIR='$(verification_project_path)/src ../doc/mainpagetests' \
+ doxygen $(verification_project_path)/doxygen-test.cfg
+
+test_pdf: test_html
+ cd $(docgendir)/tests/latex; make > /dev/null
+ mkdir -p $(docgendir)/tests/pdf
+ cp $(docgendir)/tests/latex/refman.pdf $(docgendir)/tests/pdf/CommonAPITests.pdf
+ rm -rf $(docgendir)/tests/latex
+
+docgendir:
+ mkdir -p $(docgendir)
+ cp -rf images $(docgendir)/images
+
+clean:
+ rm -rf $(docgendir)
diff --git a/doc/Tutorial b/doc/Tutorial
new file mode 100644
index 0000000..73d7587
--- /dev/null
+++ b/doc/Tutorial
@@ -0,0 +1,705 @@
+CommonAPI C++ Tutorial
+======================
+:author: Juergen Gehring - juergen.gehring@bmw.de
+:doctitle: CommonAPI C++ Tutorial
+:website: http://projects.genivi.org/commonapi/
+:version:
+:date:
+:toc:
+:revdate:
+:imagedir:
+:cppstr: c++
+
+Introduction
+------------
+
+This tutorial has the following content:
+
+- installation instructions for CommonAPI and CommonAPI-DBus including the tools
+- a step by step tutorial on how you can write your first Hello World program
+- some examples with description which show the usage of CommonAPI in conjunction with Franca IDL
+- some special topics like deployment or the communication with legacy D-Bus applications
+
+Common API and its mechanism specific bindings (e.g. Common API D-Bus) provide a set of libraries and tools to work with RPC communication in a way independent of wich mechanism is used. Once you have implemented your services and clients and tested it with D-Bus you later can switch D-Bus for any other communication layer (provided it has Common API support) _without the need to touch your code or your binary at all!_.
+
+Further information on Common API and Common API D-Bus is provided in the individual README files accompanying both packages.
+
+Getting started
+---------------
+
+CommonAPI is a GENIVI project. Source code and latest news can be found at http://projects.genivi.org/commonapi/.
+
+For documentation please visit the GENIVI document page http://docs.projects.genivi.org/.
+
+CommonAPI currently consists of four subprojects:
+
+[width="80%",cols="3,10"]
+|=========================================================
+
+|CommonAPI |
+This is the base C++ library, which provides the application interface for users and can load runtime bindings such as dbus.
+
+|CommonAPI-Tools |
+The eclipse based tools for CommonAPI. This is essentially the code generator for Franca -> Common API C++ code. (This is the current package.)
+
+|CommonAPI-D-Bus |
+This is the D-Bus binding C++ library, which provides the necessary code to communicate over D-Bus. This is invisible to the application code, and simply needs to be linked against.
+
+|CommonAPI-D-Bus-Tools |
+The eclipse based tools for CommonAPI D-Bus. This is the code generator for Franca -> Common API D-Bus C++ code.
+
+|=========================================================
+
+Closely related to CommonAPI is the yamaica project which provides a full integration of all Franca IDL and CommonAPI plugins and some more enhanced features like the import and export of Franca files to Enterprise Architect (see http://projects.genivi.org/yamaica/). The yamaica project provides eclipse update-sites for CommonAPI and yamaica (see http://docs.projects.genivi.org/yamaica-update-site/) ready for installation.
+
+Before we proceed you should clarifiy whether you are a user, in the sense that you want to write applications based on CommonAPI or whether you want to contribute to CommonAPI yourself or write your own middleware specific binding.
+
+Requirements
+~~~~~~~~~~~~
+- Code generator and Franca tooling are based on Eclipse. Please make sure that you have an appropriate Eclipse version installed (see the compatibility table at the beginning of the document or the README file).
+- Make sure all requirements to build the CommonAPI Runtime are installed and in the correct version. CommonAPI was developed using gcc 4.6 and gcc 4.7, but is feature compatible to gcc 4.5 and compiler compatible to gcc 4.4.
+
+Set up your environment as CommonAPI user
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+CommonAPI Tools
+^^^^^^^^^^^^^^^
+
+The CommonAPI Tools are available as Eclipse update-site or (if you prefer not to use Eclipse) as commandline tool.
+
+First we assume that you use an Eclipse CDT development environment. Please make sure that you have installed Franca IDL first before you continue with installing the CommonAPI Tools. Please find the installing instructions for Franca IDL at https://code.google.com/a/eclipselabs.org/p/franca/.
+
+The simplest way to use the CommonAPI Tools is to add the update site available on the GENIVI project servers to your Eclipse. This is available under:
+
+Help->Install New Software->Add Button
+
+Enter the following URL: http://docs.projects.genivi.org/yamaica-update-site/CommonAPI/updatesite/ and confirm. This provides CommonAPI, CommonAPI-D-Bus, CommonAPI Validator and all dependencies. Then select the newly added site in the site selection dropdown box, and in the Software selection window, select the entire "GENIVI CommonAPI Generators" Tree. Ignore all the other entries in the selection part of the "Available Software" window.
+
+After the software has been installed in Eclipse you can right-click on any .fidl file and generate C++ code for CommonAPI D-Bus by selecting the "CommonAPI->Generate Common API Code" option.
+
+[NOTE]
+- The CommonAPI Validator must not necessarily be installed. But he recognizes Franca language constructs that Franca IDL permits, but result in non-executable or non-compilable code. An example is the use of C++ keywords in the interface specification.
+- From Franca IDL, you will only need to install the sub-category "Franca Feature" for the Common API and Common API D-Bus generators to work.
+
+
+If you want to use the command line version of the code generator, you can get the actual version at:
+
+http://docs.projects.genivi.org/yamaica-update-site/CommonAPI/generator/
+
+where should be a link to the git repository:
+
+http://git.projects.genivi.org/yamaica-update-site.git/
+
+For the usage of the command line version please consider the README file of the CommonAPI-Tools project.
+
+CommonAPI Runtime
+^^^^^^^^^^^^^^^^^
+
+Download the Common API runtime via git from the download site of http://projects.genivi.org/commonapi/, then compile and install the library on your computer:
+
+----
+$ git clone git://git.projects.genivi.org/ipc/common-api-runtime.git
+$ cd common-api-runtime
+$ autoreconf -i
+$ ./configure
+$ make
+$ sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu)
+----
+
+With this, the Common API runtime library will be installed in +/usr/local/lib+. The package is accessible for your application e.g. via pkgconfig. The pkgconfig data is located at /usr/local/lib/pkgconfig.
+
+To build Common API D-Bus, the Common API runtime and libdbus version 1.4.16 patched with the marshaling patch must be available through PkgConfig. The marshalling patch is provided within the Common API D-Bus package.
+
+Download the Common API D-Bus library via git from the download site of http://projects.genivi.org/commonapi/:
+
+----
+$ git clone git://git.projects.genivi.org/ipc/common-api-dbus-runtime.git
+----
+
+Download, patch and install version 1.4.16 of libdbus (*WARNING*: _Not_ following these instructions may result in corruption of the preinstalled libdbus library of your computer, thereby rendering your system unusable):
+
+----
+$ wget http://dbus.freedesktop.org/releases/dbus/dbus-1.4.16.tar.gz
+$ tar -xzf dbus-1.4.16.tar.gz
+$ cd dbus-1.4.16
+$ patch -p1 < </your/download/path>/common-api-dbus-runtime/dbus-DBusMessage-add-support-for-custom-marshaling.patch
+$ ./configure --prefix=/usr/local
+$ make -C dbus
+$ sudo make -C dbus install
+$ sudo make install-pkgconfigDATA
+----
+
+The path to CommonAPI and patched libdbus pkgconfig files must be added to the +PKG_CONFIG_PATH+ for the rest of the entire build process.
+If you followed the instructions above, both will be located in +/usr/local/lib/pkgconfig+, so you can just type:
+
+----
+$ export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
+----
+
+[NOTE]
+If you want to make sure that you do not destroy your linux installation then it is also possible not to install the patched lidbus. In this case you just have to set your package config path correctly.
+
+Now, compile and install the Common API D-Bus library on your computer
+
+----
+$ cd </your/download/path>/common-api-dbus-runtime
+$ autoreconf -i
+$ ./configure
+$ make
+$ sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu)
+----
+
+With this, the libraries for Common API and Common API D-Bus are installed and ready for use.
+
+[NOTE]
+- If you prefer to install CommonAPI from a tar file you can get the actual tar file from:
+http://docs.projects.genivi.org/yamaica-update-site/CommonAPI/runtime/
+- In Linux please don't forget to add the installation path of your CommonAPI libraries to your LD_LIBRARY_PATH environment variable.
+
+Set up your environment as CommonAPI contributor
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Preliminary remarks
+^^^^^^^^^^^^^^^^^^^
+
+First get the code from the git:
+----
+$ git clone
+----
+
+Get an overview of all branches:
+----
+$ git branch
+----
+
+Switch to the branch you want to work on (master is the feature branch) and verify that it has switched (* changed)
+----
+$ git checkout <your branch>
+$ git branch
+----
+
+Best practice is to create a local branch based on the current branch:
+----
+$ git branch working_branch
+----
+
+Start working, best practice is to commit smaller, compilable pieces during the development process that makes it easier to handle later on. If you want to commit you changes, send them to the author, you can create a patch like this:
+
+----
+$ git format-patch working_branch <your branch>
+----
+
+This creates a set of patches that are published via the mailing list.The patches will be discussed and then merged & uploaded on the git by the maintainer.
+
+Patches can be accepted either under GENIVI Cla or MPL 2.0 (see section License). Please be sure that the signed-off-by is set correctly. For more, check out http://gerrit.googlecode.com/svn/documentation/2.0/user-signedoffby.html
+
+CommonAPI Tools
+^^^^^^^^^^^^^^^
+
+For the build instructions of the CommonAPI tools with maven see again the README file.
+
+Hello World
+-----------
+
+The examples of the use of Franca IDL in conjunction with CommonAPI can be found in the folder CommonAPI-Examples in the subproject CommonAPI tools. The first example substantially contains the code for the Hello World example, which will be described below. But even if the code already exists, it is recommended to build the sample from scratch on for a better understanding of the individual steps.
+
+It is assumed that you have created a C++ project in your Eclipse in which all further development will happen.
+
+Creating the RMI interface definition
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The first step in developing a Common API application likely will be the definition of the RMI interface the client will use to communicate with the server. In the context of CommonAPI, the definition of this interface always happens via the Franca IDL, regardless of which communication mechanism you intend to use in the end. For this tutorial, create an arbitrarily namend file ending in _.fidl_ in your Eclipse project. It is
+not relevant where in your project you have placed this file, as the the code generated from this file will always be put in the automatically created src-gen folder at the top level of the project hierarchy.
+
+Open your newly created _.fidl_-file, and type the following lines:
+
+[source,java]
+----
+package commonapi.examples
+
+interface e01HelloWorld {
+ version { major 1 minor 0 }
+
+ method sayHello {
+ in {
+ String name
+ }
+ out {
+ String message
+ }
+ }
+}
+----
+
+[NOTE]
+The _version_ parameter in every interface is mandatory! No code will be generated if it is malformed or not present!
+
+
+Now, save the _.fidl_ file and right click it. As you have installed the Common API and Common API D-Bus generators, you will see a menu item saying _"Common API"_, with sub menu items for generating either the Common API level code only ("_Generate C\++ Code_") or for generating both the Common API level code and the glue code required to run applications with using Common API D-Bus ("_Generate D-Bus C++ Code_").
+
+Generating code
+~~~~~~~~~~~~~~~
+
+We do want to use D-Bus as middleware, so we will need the D-Bus specific glue code as well as the Common API level code which we will
+program agains. Therefore, you might want to chose the latter of the two options provided by the generator plugin ("_Generate D-Bus C++ Code_").
+After having done so, you will see the newly created src-gen folder and it's contents. The files will be created according to their
+fully qualified names relative to src-gen as the top level folder, as defined in the _.fidl_-file:
+
+----
+E01HelloWorld.h
+E01HelloWorldProxy.h
+E01HelloWorldProxyBase.h
+E01HelloWorldStub.h
+E01HelloWorldStubDefault.cpp
+E01HelloWorldStubDefault.h
+
+E01HelloWorldDBusProxy.cpp
+E01HelloWorldDBusProxy.h
+E01HelloWorldDBusStubAdapter.cpp
+E01HelloWorldDBusStubAdapter.h
+----
+
+All files that have a "DBus" in their name are glue code required by the D-Bus binding and are not relevant while developing your application, they only need to be compiled with your application (there are ways to NOT compile these sources with your applications and include them at runtime instead; see the README of Common API D-Bus for details).
+
+All other files that have a _Proxy_ in their name are relevant for you if you develop a client, all other files that have a _Stub_ in their name are relevant for you if you develop a service. A proxy is a class that provides method calls that will result in remote method invocations on the service, plus registration methods for events that can be broadcasted by the service.
+
+A stub is the part of the service that will be called when a remote method invocation from a client arrives. It also contains methods to fire events (broadcasts) to several or all clients. The Stub comes in two flavors: One default stub that contains empty implementations of all methods, thereby allowing you to implement only the ones you are interested in, and a Stub skeleton where you have to implement everything yourself before you can use it. A service will have to implement a subclass of either of the two in order to make itself available to the outside world (or just use the default stub if your service should not be able to do anything except firing events).
+
+In this tutorial, we will create both a client and a service in order to be able to see some communication going on.
+
+Implement the Client
+~~~~~~~~~~~~~~~~~~~~
+
+Start by creating a new .cpp source file in your project (e.g. e01HelloWorldClient.cpp). Make sure you have a main method in order to start the client application.
+
+Here, you will need two includes in order to access the Common API client functionality:
+
+[source,{cppstr}]
+----
+#include <iostream>
+
+#include <CommonAPI/CommonAPI.h> //Defined in the Common API Runtime library
+#include <commonapi/examples/E01HelloWorldProxy.h> //Part of the code we just generated
+----
+
+The first thing each and every Common API application will do is to load a runtime:
+
+[source,{cppstr}]
+----
+std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+----
+
+If you link the Common API DBus library to and compile the generated DBus specific code with your executable, this runtime "magically" will be a runtime that provides access to the DBus communication infrastructure via a strictly CommonAPI level interface. If you link the library and add the generated code of another Common API middleware binding instead, this runtime will provide access to this other communication infrastructure.
+
+In order to be able to communicate with a specific service, we need a proxy. We can create a proxy by using a factory, which in turn we can get from the runtime we just created:
+
+[source,{cppstr}]
+----
+std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+const std::string& serviceAddress = "local:commonapi.examples.HelloWorld:commonapi.examples.HelloWorld";
+std::shared_ptr<E01HelloWorldProxy<>> myProxy = factory->buildProxy<E01HelloWorldProxy>(serviceAddress);
+----
+
+The parameter _serviceAddress_ is the address at which the service that shall be accessed will be available. This address will be translated internally to an actual DBus-Address - or whatever format fits the communication infrastructure you use. Semantically, this address consists of three parts, separated by colons:
+
+[width="80%",cols="3,10"]
+|=========================================================
+
+|Domain |
+The first part, defines in which domain the service is located. For DBus use cases, only "local" makes any sense, as no services that are more remote than "on the same operating system" are accessible.
+
+|ServiceID |
+The second part. This defines the name or type of the service that shall be accessed.
+
+|InstanceID |
+The third part. This defines the specific instance of this service that shall be accessed.
+
+|=========================================================
+
+There are ways to influence the translation of the Common API address to the specific address (of course once again without the need to change your code). Please have a look at the README of Common API DBus if you want to know more about this possibility in the context of DBus, or the corresponding documentation of the other middleware binding you are using.
+
+With this, the client is set up and ready to use. We should wait for the service to be available, then we can start issuing calls:
+
+[source,{cppstr}]
+----
+while (!myProxy->isAvailable()) { usleep(10); }
+
+const std::string name = "World";
+CommonAPI::CallStatus callStatus;
+std::string returnMessage;
+
+myProxy->sayHello(name, callStatus, returnMessage);
+if (callStatus != CommonAPI::CallStatus::SUCCESS) {
+ std::cerr << "Remote call failed!\n";
+ return -1;
+}
+std::cout << "Got message: '" << returnMessage << "'\n";
+----
+
+Implement the Service
+~~~~~~~~~~~~~~~~~~~~~
+
+Works about the same way as implementing the client. The includes that are required are the following:
+
+[source,{cppstr}]
+----
+#include <iostream>
+#include <thread>
+
+#include <CommonAPI/CommonAPI.h>
+#include "E01HelloWorldStubImpl.h"
+----
+
+And we also need a stub that actually does something when the method we call in the client gets called:
+
+[source,{cppstr}]
+----
+void E01HelloWorldStubImpl::sayHello(const std::shared_ptr<CommonAPI::ClientId> clientId,
+ std::string name, std::string& message) {
+
+ std::stringstream messageStream;
+
+ messageStream << "Hello " << name << "!";
+ message = messageStream.str();
+ std::cout << "sayHello('" << name << "'): '" << message << "'\n";
+};
+----
+
+The rest looks quite similar to the client side, with the difference that we do not issue calls via a proxy, but instead register a service that then
+will be provided to the outside world. The service is registered using the same Common API address, which allows the proxy to actually find the service.
+Afterwards, we just wait for calls:
+
+[source,{cppstr}]
+----
+std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher =
+ runtime->getServicePublisher();
+
+const std::string& serviceAddress =
+ "local:commonapi.examples.HelloWorld:commonapi.examples.HelloWorld";
+
+std::shared_ptr<E01HelloWorldStubImpl> myService =
+ std::make_shared<E01HelloWorldStubImpl>();
+
+servicePublisher->registerService(myService, serviceAddress, factory);
+
+while(true) {
+ std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(60));
+}
+----
+
+Running the Demo
+~~~~~~~~~~~~~~~~
+
+Build the two applications using your favourite build system. If all worked well, you should see communication ongoing via DBus (e.g. via dbus-monitor), and you should get output from your client once, saying
+
+----
+"Got Message: 'Hello World'".
+----
+
+Advanced Topics
+---------------
+
+Special Franca Features
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Selective
+^^^^^^^^^
+
+Selective broadcasts, indicated with the selective keword after the name of the broadcast in Franca can be sent to individual clients rather
+than all participants. This is accomplished with the use of a ClientID parameter which can serve to identify the targets. Note if you wish to
+identify clients absolutely you must do this on the application level.
+
+We can add a block to our interface for the selective broadcast:
+
+[source,java]
+----
+broadcast saySomething selective {
+ out {
+ String message
+ }
+}
+----
+
+We can the add some code to our stub implementation to handle this:
+
+[source,{cppstr}]
+----
+virtual void onSaySomethingSelectiveSubscriptionChanged(
+ const std::shared_ptr<CommonAPI::ClientId> clientId,
+ const CommonAPI::SelectiveBroadcastSubscriptionEvent event) {
+
+ if (event == CommonAPI::SelectiveBroadcastSubscriptionEvent::SUBSCRIBED) {
+ lastId = clientId;
+ }
+}
+----
+
+and to the sayHello method:
+
+[source,{cppstr}]
+----
+std::shared_ptr<CommonAPI::ClientIdList> receivers =
+ std::make_shared<CommonAPI::ClientIdList>();
+
+if (lastId) {
+ receivers->insert(lastId);
+}
+
+this->fireSaySomethingSelective("Broadcast to last ID", receivers);
+----
+
+and finally a member to the stub:
+
+[source,{cppstr}]
+----
+private:
+ std::shared_ptr<CommonAPI::ClientId> lastId;
+----
+
+The onSaySomethingSelectiveSubscriptionChanged method is called when a subscription for this boroadcast changes. Is added, we set the memeber lastId to this value. Whenever sayHello is called we now also send a broadcast only to the last client which registered. The ClientIdList contains all the intended recipients, and the middleware will send the message to all memeber of this list who are registered for the broadcast. If NULL is passed instead the broadcast is sent to all clients.
+
+On the client side we can add this before the const std::string name = "World"; line:
+
+[source,{cppstr}]
+----
+helloWorldProxy->getSaySomethingSelectiveEvent().subscribe(
+ [&](const std::string& message) {
+ std::cout << "Received broadcast message: " << message << "\n";
+});
+----
+
+This casues a subscription to the broadcast, and the lambda function will be called whenever we receive a message.
+
+Managed Stubs
+^^^^^^^^^^^^^
+
+In Franca a relationship between two interfaces can be declared in the form "x manages y". This indicates that x has a number of y as childeren whose lifecycle is tied to and managed by x. This allows a an application to activare y stubs on an instance of x stubs. Similarily on the proxy side a manager for y interfaces is available on the x proxy, where we can be informed of appearing and disappearing instances, and interrogate the network about the state of instances.
+
+In our Franca file change the defenition of the HelloWorldInterface to:
+
+[source,java]
+----
+interface HelloWorldInterface manages HelloWorldLeaf {
+----
+
+and after this interface block add:
+
+[source,java]
+----
+interface HelloWorldLeaf {
+ version { major 1 minor 0 }
+
+ method sayHelloLeaf {
+ in {
+ String name
+ }
+ out {
+ String message
+ }
+ }
+}
+----
+
+This causes HelloWorldInterface to be able to manage HelloWorldLeaf instances. Note that HelloWorldLeaf instances can still be registered and accessed in the normal way via the service publisher and factory. To the stub application add to the top as a new class defenition:
+
+[source,{cppstr}]
+----
+class MyHelloWorldLeafStub: public commonapi::examples::HelloWorldLeafStubDefault {
+ public:
+ virtual void sayHelloLeaf(std::string name, std::string& message) {
+ std::stringstream messageStream;
+
+ messageStream << "Hello Leaf " << name << "!";
+ message = messageStream.str();
+
+ std::cout << "sayHelloLeaf('" << name << "'): '" << message << "'\n";
+ }
+};
+----
+
+To the bottom of the main function before the while loop add:
+
+[source,{cppstr}]
+----
+auto helloWorldLeafStub = std::make_shared<MyHelloWorldLeafStub>();
+
+const std::string leafInstance = "commonapi.examples.HelloWorld.Leaf";
+
+const bool leafOk = helloWorldStub->registerManagedStubHelloWorldLeaf(
+ helloWorldLeafStub, leafInstance);
+
+if (!leafOk) {
+ std::cerr << "Error: Unable to register leaf service!\n";
+ return -1;
+}
+----
+
+To the client programm add to the bottom of the main function just before return 0:
+
+[source,{cppstr}]
+----
+const std::string leafInstance = "commonapi.examples.HelloWorld.Leaf";
+CommonAPI::CallStatus callStatusAv;
+CommonAPI::AvailabilityStatus availabilityStatus;
+helloWorldProxy->getProxyManagerHelloWorldLeaf().getInstanceAvailabilityStatus(
+ leafInstance, callStatusAv, availabilityStatus);
+
+if (callStatusAv == CommonAPI::CallStatus::SUCCESS &&
+ availabilityStatus == CommonAPI::AvailabilityStatus::AVAILABLE) {
+
+ auto helloWorldLeafProxy =
+ helloWorldProxy->getProxyManagerHelloWorldLeaf().
+ buildProxy<commonapi::examples::HelloWorldLeafProxy>(leafInstance);
+
+ const std::string nameLeaf = "WorldLeaf";
+ CommonAPI::CallStatus callStatusLeaf;
+ std::string helloWorldLeafMessage;
+
+ std::cout << "Sending name: '" << nameLeaf << "'\n";
+ helloWorldLeafProxy->sayHelloLeaf(nameLeaf, callStatusLeaf, helloWorldLeafMessage);
+ if (callStatusLeaf != CommonAPI::CallStatus::SUCCESS) {
+ std::cerr << "Remote call failed!\n";
+ return -1;
+ }
+
+ std::cout << "Got message: '" << helloWorldLeafMessage << "'\n";
+
+} else {
+ std::cout << "Leaf Proxy not available\n";
+ sleep(5);
+ return -1;
+}
+----
+
+This instantiates and calls a managed leaf stub and proxy respectively.
+
+Attribute Extensions
+~~~~~~~~~~~~~~~~~~~~
+
+As described in the CommonAPI specification there is a general scheme to include individual extensions in order to provide any additional features for attributes. In principle Attribute Extensions work as follows:
+
+- Decide whether you want to implement a common attribute extension for all attributes of an interface or a specific extension for one attribute.
+- Define a so-called templated extension class which inherits from +CommonAPI::AttributeExtension+ within a hpp-file. The example below defined in +AttributeCacheExtension.hpp+ shows an extension class for the caching of attributes on proxy side.
+- Generate the proxy for your interface with the API method +buildProxyWithDefaultAttributeExtension+ if you want a common extension. For the specific extension call build proxy with the attribute extension as template parameter.
+- Now you can call the implemented functions of your extension via a +getNameAttributeExtension()+ call (where +Name+ is the name of your attribute).
+
+Example of an extension class for caching attributes (file +AttributeCacheExtension.hpp+):
+[source,{cppstr}]
+----
+#include <CommonAPI/CommonAPI.h>
+
+template<typename _AttributeType>
+class AttributeCacheExtension: public CommonAPI::AttributeExtension<_AttributeType> {
+ typedef CommonAPI::AttributeExtension<_AttributeType> __baseClass_t;
+
+ public:
+ typedef typename _AttributeType::ValueType value_t;
+ typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
+
+ AttributeCacheExtension(_AttributeType& baseAttribute) :
+ CommonAPI::AttributeExtension<_AttributeType>(baseAttribute),
+ isCacheValid_(false) {
+ }
+
+ ~AttributeCacheExtension() {}
+
+ bool getCachedValue(value_t& value) {
+
+ if (isCacheValid_) {
+
+ value = cachedValue_;
+ } else {
+
+ __baseClass_t::getBaseAttribute().getChangedEvent().subscribe(std::bind(
+ &AttributeCacheExtension<_AttributeType>::onValueUpdate,
+ this,
+ std::placeholders::_1));
+
+ CommonAPI::CallStatus callStatus;
+ __baseClass_t::getBaseAttribute().getValue(callStatus, value);
+ }
+
+ return isCacheValid_;
+ }
+
+ private:
+
+ void onValueUpdate(const value_t& t) {
+ isCacheValid_ = true;
+ cachedValue_ = t;
+ }
+
+ mutable bool isCacheValid_;
+ mutable value_t cachedValue_;
+};
+----
+
+In your main function you can call now:
+[source,{cppstr}]
+----
+#include "AttributeCacheExtension.hpp"
+using your::namespace; // eg commonapi::examples
+
+... // Other code here
+
+const std::string& serviceAddress = "...";
+
+// your proxy class is ProxyName
+std::shared_ptr<CommonAPI::DefaultAttributeProxyFactoryHelper<ProxyName,
+ AttributeCacheExtension>::class_t> myProxy =
+ factory->buildProxyWithDefaultAttributeExtension<ProxyName,
+ AttributeCacheExtension>(serviceAddress);
+
+// and then if your attribute is x of type Int32:
+int32_t valueCached = 0;
+myProxy->getXAttributeExtension().getCachedValue(valueCached);
+----
+
+Examples
+--------
+
+include::../CommonAPI-Examples/README[]
+include::../CommonAPI-Examples/e01HelloWorld/README[]
+include::../CommonAPI-Examples/e02Attributes/README[]
+include::../CommonAPI-Examples/e03Methods/README[]
+include::../CommonAPI-Examples/e04PhoneBook/README[]
+include::../CommonAPI-Examples/e05Manager/README[]
+include::../CommonAPI-Examples/e06Unions/README[]
+
+FAQ
+---
+
+The middleware loading mechanism of Common API
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+CommonAPI::Runtime::load() returns no runtime object, why?
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+As it was mentioned before, when you call +CommonAPI::Runtime::load()+ you "magically" will have access to a specific middleware library. In a very basic case, the library and thereby communication mechanism you will have access to will be the only Common API middleware library you linked to your executable during compilation.
+
+However, this call to +load()+ most likely will *FAIL* if you have no generated middleware specific code that is compiled with your application. Why that?
+
+The reason is simple, once understood: Most linkers are lazy. They do not link libraries that seem to be unused. Due to the fact that there is no reference whatsoever from Common API (and therefore your application) to any of the middleware libraries, the linker considers any and all middleware libraries as unused if not referenced by middleware specific generated code, and therefore will not add them to the executable.
+
+You can disable this behavior by passing the linker flag +whole-archive+ during the build process. Note however that this behavior normally is a good optimization
+without repercussions - except probably in the context of CommonAPI.
+
+
+How can I use Using more than one middleware binding?
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+CommonAPI provides the possibility to use more than one middleware binding at once. In this case, you should no longer use +CommonAPI::Runtime::load()+,
+but instead +CommonAPI::Runtime::load("NameOfSomeMiddleware")+.
+
+The "NameOfSomeMiddleware" is the well known name of the middleware you want to load. It is defined and made public by each of the middlewares that support
+Common API. For DBus, this name is simply "DBus".
+
+
+Fully dynamic loading and additional information
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+This topic is handled in-depth in the specification of Common API. Please refer to this file for any further information.
+
diff --git a/doc/images/CodeGenerationFrancaIDL.png b/doc/images/CodeGenerationFrancaIDL.png
new file mode 100755
index 0000000..f90c135
--- /dev/null
+++ b/doc/images/CodeGenerationFrancaIDL.png
Binary files differ
diff --git a/doc/images/Deployment.png b/doc/images/Deployment.png
new file mode 100755
index 0000000..16d4404
--- /dev/null
+++ b/doc/images/Deployment.png
Binary files differ
diff --git a/doc/images/Diag_Attributes.png b/doc/images/Diag_Attributes.png
new file mode 100755
index 0000000..36e25f7
--- /dev/null
+++ b/doc/images/Diag_Attributes.png
Binary files differ
diff --git a/doc/images/Diag_GeneratedProxy.png b/doc/images/Diag_GeneratedProxy.png
new file mode 100755
index 0000000..2f7fc3b
--- /dev/null
+++ b/doc/images/Diag_GeneratedProxy.png
Binary files differ
diff --git a/doc/images/Diag_GeneratedStub.png b/doc/images/Diag_GeneratedStub.png
new file mode 100755
index 0000000..8970c90
--- /dev/null
+++ b/doc/images/Diag_GeneratedStub.png
Binary files differ
diff --git a/doc/images/E04PhoneBook.png b/doc/images/E04PhoneBook.png
new file mode 100755
index 0000000..5cb2b40
--- /dev/null
+++ b/doc/images/E04PhoneBook.png
Binary files differ
diff --git a/doc/images/E05Manager.png b/doc/images/E05Manager.png
new file mode 100755
index 0000000..1538c0d
--- /dev/null
+++ b/doc/images/E05Manager.png
Binary files differ
diff --git a/doc/images/icons/important.png b/doc/images/icons/important.png
new file mode 100755
index 0000000..3148adb
--- /dev/null
+++ b/doc/images/icons/important.png
Binary files differ
diff --git a/doc/images/icons/note.png b/doc/images/icons/note.png
new file mode 100644
index 0000000..9859d6e
--- /dev/null
+++ b/doc/images/icons/note.png
Binary files differ
diff --git a/doc/mainpagetests/01_mainpage.dox b/doc/mainpagetests/01_mainpage.dox
new file mode 100644
index 0000000..1cb65df
--- /dev/null
+++ b/doc/mainpagetests/01_mainpage.dox
@@ -0,0 +1,27 @@
+/**
+ * Copyright (C) 2013 BMW AG
+ * *
+ * This file is part of GENIVI project IPC CommonAPI C++.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \author Juergen Gehring (juergen.gehring@bmw.de)
+ * \author Manfred Bathelt (manfred.bathelt@bmw.de)
+ *
+ */
+
+/*!
+\mainpage
+
+\par This document
+This document provides a list of tests which are implemented in the project +org.genivi.commonapi.core.verification+ which is part of CommonAPI-Tools. These tests are middleware independent and can be used to verify the correct implementation of middleware specific bindings.
+
+\par About IPC CommonAPI C++
+IPC CommonAPI C++ is a C++ based abstraction API for communication stacks, which enables applications to
+use different communication middleware - so called language bindings - as backend without any changes to the application code.
+
+\par More information
+can be found at the <a href="http://projects.genivi.org/commonapi/">project homepage</a> \n
+Please see the <a href="http://projects.genivi.org/commonapi/download">project download section</a> for available language bindings.
+*/
diff --git a/git b/git
deleted file mode 100644
index e69de29..0000000
--- a/git
+++ /dev/null
diff --git a/org.genivi.commonapi.core.validator/.classpath b/org.genivi.commonapi.core.validator/.classpath
index 098194c..ad32c83 100644
--- a/org.genivi.commonapi.core.validator/.classpath
+++ b/org.genivi.commonapi.core.validator/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
diff --git a/org.genivi.commonapi.core.verification/.autotools b/org.genivi.commonapi.core.verification/.autotools
deleted file mode 100644
index 0376395..0000000
--- a/org.genivi.commonapi.core.verification/.autotools
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configurations>
-<configuration id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.1685832897">
-<option id="configure" value="configure --with-gluecode-path=/home/hmi/work/CommonAPI-D-Bus-Tools/org.genivi.commonapi.dbus.verification --with-gluecode-a-name=libDBusGlue.a --with-binding-a=/home/hmi/work/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.a --with-binding-extra=/home/hmi/work/dbus-1.6.4/dbus/.libs/libdbus-1.so"/>
-<option id="configdir" value=""/>
-<option id="cache-file" value=""/>
-<option id="help" value="false"/>
-<option id="no-create" value="false"/>
-<option id="quiet" value="false"/>
-<option id="version" value="false"/>
-<option id="host" value=""/>
-<option id="build" value=""/>
-<option id="target" value=""/>
-<option id="prefix" value=""/>
-<option id="exec-prefix" value=""/>
-<option id="libdir" value=""/>
-<option id="bindir" value=""/>
-<option id="sbindir" value=""/>
-<option id="includedir" value=""/>
-<option id="datadir" value=""/>
-<option id="sysconfdir" value=""/>
-<option id="infodir" value=""/>
-<option id="mandir" value=""/>
-<option id="srcdir" value=""/>
-<option id="localstatedir" value=""/>
-<option id="sharedstatedir" value=""/>
-<option id="libexecdir" value=""/>
-<option id="oldincludedir" value=""/>
-<option id="program-prefix" value=""/>
-<option id="program-suffix" value=""/>
-<option id="program-transform-name" value=""/>
-<option id="enable-maintainer-mode" value="false"/>
-<flag id="CFLAGS">
-<flagvalue id="cflags-debug" value="false"/>
-<flagvalue id="cflags-gprof" value="false"/>
-<flagvalue id="cflags-gcov" value="false"/>
-</flag>
-<option id="user" value=""/>
-<option id="autogen" value="autogen.sh"/>
-<option id="autogenOpts" value=""/>
-</configuration>
-</configurations>
diff --git a/org.genivi.commonapi.core.verification/.gitignore b/org.genivi.commonapi.core.verification/.gitignore
new file mode 100644
index 0000000..4df666e
--- /dev/null
+++ b/org.genivi.commonapi.core.verification/.gitignore
@@ -0,0 +1,21 @@
+*.o
+/.deps
+/.libs
+/.settings
+/autom4te.cache
+/build-aux
+/.cproject
+/.project
+/.autotools
+/aclocal.m4
+/config.log
+/config.status
+/configure
+/DynamicLoadingVerification.conf
+/CommunicationVerification.conf
+/libtool
+/Makefile
+/Makefile.in
+/Build (GNU)
+/src/DynamicLoadingVerification.cpp
+/src/CommunicationVerification.cpp
diff --git a/org.genivi.commonapi.core.verification/.project b/org.genivi.commonapi.core.verification/.project
deleted file mode 100644
index d28cee5..0000000
--- a/org.genivi.commonapi.core.verification/.project
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.genivi.commonapi.core.verification</name>
- <comment></comment>
- <projects>
- <project>CommonAPI</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.cdt.autotools.core.genmakebuilderV2</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
- <triggers>clean,full,incremental,</triggers>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
- <triggers>full,incremental,</triggers>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.cdt.core.cnature</nature>
- <nature>org.eclipse.cdt.core.ccnature</nature>
- <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
- <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
- <nature>org.eclipse.cdt.autotools.core.autotoolsNatureV2</nature>
- </natures>
-</projectDescription>
diff --git a/org.genivi.commonapi.core.verification/configure.ac b/org.genivi.commonapi.core.verification/configure.ac
index fa6863f..a091ee5 100644
--- a/org.genivi.commonapi.core.verification/configure.ac
+++ b/org.genivi.commonapi.core.verification/configure.ac
@@ -26,9 +26,23 @@ AC_ARG_WITH([binding-name], [Well known name of the binding that is to be tested
AC_MSG_RESULT(${BINDING_NAME})
],[
AC_MSG_RESULT(no)
- AC_MSG_ERROR([A binding that shall be verified needs to be specified! Use '--with-binding=' to do so.])
+ AC_MSG_ERROR([A binding that shall be verified ne eds to be specified! Use '--with-binding=' to do so.])
])
+AC_MSG_RESULT([
+ $PACKAGE_NAME v$VERSION
+
+ COMMONAPI_CFLAGS: ${COMMONAPI_CFLAGS}
+ COMMONAPI_LIBS: ${COMMONAPI_LIBS}
+
+ BINDING_FQN: ${BINDING_FQN}
+ BINDING_SO: ${BINDING_SO}
+
+ BINDING_A: ${BINDING_A}
+ BINDING_EXTRA: ${BINDING_EXTRA}
+])
+
+
# Path to binding libraries
AC_ARG_WITH([binding], [full path to binding library, including name, excluding file ending. The .a and .so files with the given fqn will be used if present and when needed.], [
@@ -70,7 +84,6 @@ AC_ARG_WITH([binding-extra], [full path to additional library required by static
AM_CONDITIONAL(STATICALLY_LINKED_BINDING, [test -f "${GTEST_CONFIG}" && ${TESTS_CAN_BE_EXECUTED}])
AM_CONDITIONAL(DYNAMICALLY_LINKED_BINDING, [test -f "${GTEST_CONFIG}" && ${TESTS_CAN_BE_EXECUTED}])
-
#Libraries containing binding specific gluecode
AC_ARG_WITH([gluecode], [full path to gluecode libraries, including name, excluding file ending. The .a and .so files with the given name will be used if present and when needed.], [
GLUECODE_FQN=${withval}
@@ -153,6 +166,7 @@ AC_MSG_RESULT([
BINDING_FQN: ${BINDING_FQN}
BINDING_SO: ${BINDING_SO}
+
BINDING_A: ${BINDING_A}
BINDING_EXTRA: ${BINDING_EXTRA}
@@ -171,4 +185,5 @@ AC_MSG_RESULT([
LDFLAGS: ${LDFLAGS}
])
-AC_OUTPUT \ No newline at end of file
+AC_OUTPUT
+
diff --git a/org.genivi.commonapi.core.verification/doxygen-test.cfg b/org.genivi.commonapi.core.verification/doxygen-test.cfg
new file mode 100644
index 0000000..09fe94e
--- /dev/null
+++ b/org.genivi.commonapi.core.verification/doxygen-test.cfg
@@ -0,0 +1,308 @@
+# Doxyfile 1.8.6
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = $(PROJECT_NAME)
+PROJECT_NUMBER =
+PROJECT_BRIEF =
+PROJECT_LOGO =
+OUTPUT_DIRECTORY = $(OUTPUT_DIRECTORY)
+CREATE_SUBDIRS = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF =
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = NO
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 4
+ALIASES =
+TCL_SUBST =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+EXTENSION_MAPPING =
+MARKDOWN_SUPPORT = YES
+AUTOLINK_SUPPORT = YES
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = YES
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+INLINE_GROUPED_CLASSES = NO
+INLINE_SIMPLE_STRUCTS = NO
+TYPEDEF_HIDES_STRUCT = NO
+LOOKUP_CACHE_SIZE = 0
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = NO
+EXTRACT_PACKAGE = NO
+EXTRACT_STATIC = NO
+EXTRACT_LOCAL_CLASSES = NO
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = YES
+HIDE_UNDOC_CLASSES = YES
+HIDE_FRIEND_COMPOUNDS = YES
+HIDE_IN_BODY_DOCS = YES
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = YES
+SHOW_INCLUDE_FILES = NO
+SHOW_GROUPED_MEMB_INC = NO
+FORCE_LOCAL_INCLUDES = NO
+INLINE_INFO = NO
+SORT_MEMBER_DOCS = NO
+SORT_BRIEF_DOCS = NO
+SORT_MEMBERS_CTORS_1ST = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+STRICT_PROTO_MATCHING = NO
+GENERATE_TODOLIST = NO
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = NO
+GENERATE_DEPRECATEDLIST= NO
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = NO
+SHOW_FILES = YES
+SHOW_NAMESPACES = NO
+FILE_VERSION_FILTER =
+LAYOUT_FILE =
+CITE_BIB_FILES =
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = YES
+WARNINGS = NO
+WARN_IF_UNDOCUMENTED = NO
+WARN_IF_DOC_ERROR = NO
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = $(SRC_DIR)
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS = *.cpp *.dox
+RECURSIVE = NO
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS = std
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE =
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = NO
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_FILES =
+HTML_COLORSTYLE_HUE = 220
+HTML_COLORSTYLE_SAT = 100
+HTML_COLORSTYLE_GAMMA = 80
+HTML_TIMESTAMP = YES
+HTML_DYNAMIC_SECTIONS = NO
+HTML_INDEX_NUM_ENTRIES = 100
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+DOCSET_PUBLISHER_NAME = Publisher
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHP_CUST_FILTER_NAME =
+QHP_CUST_FILTER_ATTRS =
+QHP_SECT_FILTER_ATTRS =
+QHG_LOCATION =
+GENERATE_ECLIPSEHELP = NO
+ECLIPSE_DOC_ID = org.doxygen.Project
+DISABLE_INDEX = NO
+GENERATE_TREEVIEW = NO
+ENUM_VALUES_PER_LINE = 4
+TREEVIEW_WIDTH = 250
+EXT_LINKS_IN_WINDOW = NO
+FORMULA_FONTSIZE = 10
+FORMULA_TRANSPARENT = YES
+USE_MATHJAX = NO
+MATHJAX_FORMAT = HTML-CSS
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+MATHJAX_EXTENSIONS =
+MATHJAX_CODEFILE =
+SEARCHENGINE = YES
+SERVER_BASED_SEARCH = NO
+EXTERNAL_SEARCH = NO
+SEARCHENGINE_URL =
+SEARCHDATA_FILE = searchdata.xml
+EXTERNAL_SEARCH_ID =
+EXTRA_SEARCH_MAPPINGS =
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = YES
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4
+EXTRA_PACKAGES =
+LATEX_HEADER =
+LATEX_FOOTER =
+LATEX_EXTRA_FILES =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+LATEX_SOURCE_CODE = NO
+LATEX_BIB_STYLE = plain
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+GENERATE_DOCBOOK = NO
+DOCBOOK_OUTPUT = docbook
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = YES
+EXPAND_ONLY_PREDEF = YES
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED = "TEST_F(name1, name2)=void name1##_##name2##()"
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+EXTERNAL_PAGES = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = YES
+MSCGEN_PATH =
+DIA_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = NO
+DOT_NUM_THREADS = 0
+DOT_FONTNAME = Helvetica
+DOT_FONTSIZE = 10
+DOT_FONTPATH =
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+UML_LIMIT_NUM_FIELDS = 10
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+INTERACTIVE_SVG = NO
+DOT_PATH =
+DOTFILE_DIRS =
+MSCFILE_DIRS =
+DIAFILE_DIRS =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
diff --git a/org.genivi.commonapi.core.verification/m4/.gitignore b/org.genivi.commonapi.core.verification/m4/.gitignore
new file mode 100644
index 0000000..764b428
--- /dev/null
+++ b/org.genivi.commonapi.core.verification/m4/.gitignore
@@ -0,0 +1,5 @@
+/libtool.m4
+/lt~obsolete.m4
+/ltoptions.m4
+/ltsugar.m4
+/ltversion.m4
diff --git a/org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in b/org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in
index ba9b971..a39b544 100644
--- a/org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in
+++ b/org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in
@@ -5,6 +5,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+/**
+* @file Dynamic Loading
+*/
+
#include <functional>
#include <fstream>
#include <gtest/gtest.h>
@@ -25,8 +29,6 @@ const std::string configString =
const std::string COMMONAPI_CONFIG_SUFFIX = ".conf";
-
-
class Environment: public ::testing::Environment {
public:
virtual ~Environment() {
@@ -48,9 +50,6 @@ public:
std::string configFileName_;
};
-
-
-
class DynamicLoadingTest: public ::testing::Test {
protected:
@@ -63,22 +62,42 @@ protected:
std::string configFileName_;
};
-
+/**
+* @test Loads Default Runtime.
+* - Calls CommonAPI::Runtime::load().
+* - Success if return value is true.
+*/
TEST_F(DynamicLoadingTest, LoadsDefaultRuntime) {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
ASSERT_TRUE((bool)runtime);
}
+/**
+* @test Loads Runtime By Binding Name.
+* - Calls CommonAPI::Runtime::load("@BINDING_NAME@").
+* - Success if return value is true.
+*/
TEST_F(DynamicLoadingTest, LoadsRuntimeByBindingName) {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("@BINDING_NAME@");
ASSERT_TRUE((bool)runtime);
}
+/**
+* @test Loads Runtime By Alias.
+* - Calls CommonAPI::Runtime::load("TestAlias").
+* - Success if return value is true.
+*/
TEST_F(DynamicLoadingTest, LoadsRuntimeByAlias) {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("TestAlias");
ASSERT_TRUE((bool)runtime);
}
+/**
+* @test Loads Runtime and creates facory.
+* - Calls CommonAPI::Runtime::load("TestAlias") and checks if return value is true.
+* - Calls runtime->createFactory().
+* - Success if return value is true.
+*/
TEST_F(DynamicLoadingTest, LoadedRuntimeCanCreateFactory) {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("TestAlias");
ASSERT_TRUE((bool)runtime);
@@ -87,6 +106,16 @@ TEST_F(DynamicLoadingTest, LoadedRuntimeCanCreateFactory) {
ASSERT_TRUE((bool)factory);
}
+/**
+* @test Loads Runtime, creates facory and checks if proxies and stubs can be built.
+* - Calls CommonAPI::Runtime::load("TestAlias") and checks if return value is true.
+* - Calls runtime->createFactory() for proxy and checks if return value is true.
+* - Calls runtime->createFactory() for stub and checks if return value is true.
+* - Checks if test proxy with test address can be created.
+* - Calls runtime->getServicePublisher() checks if return value is true.
+* - Checks if test stub with test address can be created.
+* - Unregisters the test service.
+*/
TEST_F(DynamicLoadingTest, LoadedRuntimeCanBuildProxiesAndStubs) {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("TestAlias");
ASSERT_TRUE((bool)runtime);
@@ -110,6 +139,17 @@ TEST_F(DynamicLoadingTest, LoadedRuntimeCanBuildProxiesAndStubs) {
sleep(2);
}
+/**
+* @test Loads Runtime, creates facory, if proxies and stubs can be built and checks if they can communicate.
+* - Calls CommonAPI::Runtime::load("TestAlias") and checks if return value is true.
+* - Calls runtime->createFactory() for proxy and checks if return value is true.
+* - Calls runtime->createFactory() for stub and checks if return value is true.
+* - Checks if test proxy with test address can be created.
+* - Calls runtime->getServicePublisher() checks if return value is true.
+* - Checks if test stub with test address can be created.
+* - Checks isAvailable flag of proxy.
+* - Unregisters the test service.
+*/
TEST_F(DynamicLoadingTest, LoadedRuntimeCanBuildProxiesAndStubsThatCommunicate) {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("TestAlias");
ASSERT_TRUE((bool)runtime);
@@ -138,7 +178,6 @@ TEST_F(DynamicLoadingTest, LoadedRuntimeCanBuildProxiesAndStubsThatCommunicate)
if(proxy->isAvailable()) {
break;
}
-
usleep(50);
}
diff --git a/org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp b/org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp
index 7387f95..4f28cde 100644
--- a/org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp
+++ b/org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp
@@ -5,6 +5,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+/**
+* @file Main Loop Integration
+*/
+
#include <gtest/gtest.h>
#include "CommonAPI/CommonAPI.h"
#include "utils/VerificationMainLoop.h"
@@ -97,6 +101,15 @@ public:
}
};
+/**
+* @test Verifies Transport Reading When Dispatching Watches.
+* - get proxy with available flag = true
+* - generate big test data
+* - send asynchronous test message
+* - dispatch dispatchSource: the message must not be arrived
+* - dispatch watches (reads transport).
+* - dispatch dispatchSources again: now the message must be arrived.
+*/
TEST_F(MainLoopTest, VerifyTransportReadingWhenDispatchingWatches) {
auto proxy = mainloopFactoryProxy_->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress8);
ASSERT_TRUE((bool) proxy);
@@ -159,6 +172,13 @@ TEST_F(MainLoopTest, VerifyTransportReadingWhenDispatchingWatches) {
EXPECT_EQ(stub_->getCalledTestDerivedTypeMethod(), 1);
}
+/**
+* @test Verifies Synchronous Call Message Handling Order.
+* - get proxy with available flag = true
+* - subscribe for broadcast event
+* - generate 5 test broadcasts
+* - 5 broadcasts should arrive in the right order
+*/
TEST_F(MainLoopTest, VerifySyncCallMessageHandlingOrder) {
auto proxy = mainloopFactoryProxy_->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress8);
ASSERT_TRUE((bool) proxy);
@@ -196,6 +216,13 @@ TEST_F(MainLoopTest, VerifySyncCallMessageHandlingOrder) {
ASSERT_EQ(lastBroadcastNumber, 5);
}
+/**
+* @test Synchronous Calls Do Not Deadlock.
+* - get proxy with available flag = true
+* - call synchronous test method in syncCallThread
+* - 5 broadcasts should arrive in the right order
+* - run the mainloop again in order to give the syncCallThread a chance to return
+*/
TEST_F(MainLoopTest, SyncCallsDoNotDeadlock) {
auto proxy = mainloopFactoryProxy_->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress8);
ASSERT_TRUE((bool) proxy);
@@ -218,7 +245,6 @@ TEST_F(MainLoopTest, SyncCallsDoNotDeadlock) {
std::thread syncCallThread = std::thread(
[&]() {proxy->testPredefinedTypeMethod(inInt, inStr, callStatus, outInt, outStr);}
);
-
sleep(10);
ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, callStatus);
@@ -252,7 +278,8 @@ public:
void setAddresses(const std::string own, const std::string other, const std::string thirdParty) {
ownAddress_ = own;
- otherAddress_ = other;
+
+ otherAddress_ = other;
thirdPartyAddress_ = thirdParty;
}
@@ -315,7 +342,6 @@ protected:
&MainLoopThreadContext::setupMainLoopContext,
&threadCtx2_,
std::move(promiseContext2)));
-
mainLoopThread1_.detach();
mainLoopThread2_.detach();
@@ -331,10 +357,8 @@ protected:
std::future<bool> futureFactory1 = promiseFactory1.get_future();
std::future<bool> futureFactory2 = promiseFactory2.get_future();
- mainLoopThread1_ = std::thread(
- std::bind(&MainLoopThreadContext::setupFactory, &threadCtx1_, std::move(promiseFactory1)));
- mainLoopThread2_ = std::thread(
- std::bind(&MainLoopThreadContext::setupFactory, &threadCtx2_, std::move(promiseFactory2)));
+ mainLoopThread1_ = std::thread(std::bind(&MainLoopThreadContext::setupFactory, &threadCtx1_, std::move(promiseFactory1)));
+ mainLoopThread2_ = std::thread(std::bind(&MainLoopThreadContext::setupFactory, &threadCtx2_, std::move(promiseFactory2)));
mainLoopThread1_.detach();
mainLoopThread2_.detach();
@@ -355,8 +379,8 @@ protected:
threadCtx1_.createProxyAndStub();
threadCtx2_.createProxyAndStub();
- mainLoopThread1_ = std::thread([&]() {threadCtx1_.mainLoop_->run();});
- mainLoopThread2_ = std::thread([&]() {threadCtx2_.mainLoop_->run();});
+ mainLoopThread1_ = std::thread([&]() { threadCtx1_.mainLoop_->run(); });
+ mainLoopThread2_ = std::thread([&]() { threadCtx2_.mainLoop_->run(); });
usleep(200000);
@@ -378,10 +402,10 @@ protected:
threadCtx1_.mainLoop_->stop();
threadCtx2_.mainLoop_->stop();
- if (mainLoopThread1_.joinable()) {
+ if(mainLoopThread1_.joinable()) {
mainLoopThread1_.join();
}
- if (mainLoopThread2_.joinable()) {
+ if(mainLoopThread2_.joinable()) {
mainLoopThread2_.join();
}
}
@@ -390,6 +414,13 @@ protected:
std::thread mainLoopThread1_, mainLoopThread2_;
};
+/**
+* @test Proxy Receives Answer Only If Stub MainLoop Runs.
+* - start proxy in thread 1 and call testPredefinedTypeMethod
+* - proxy should not receive answer, if the stub mainloop does not run
+* - run mainloop of stub
+* - now the stub mainloop also runs, so the proxy should receive the answer
+*/
TEST_F(MainLoopIndependenceTest, ProxyReceivesAnswerOnlyIfStubMainLoopRuns) {
CommonAPI::CallStatus callStatus;
@@ -398,17 +429,17 @@ TEST_F(MainLoopIndependenceTest, ProxyReceivesAnswerOnlyIfStubMainLoopRuns) {
inInt = 1;
outInt = 0;
- std::thread mainLoopRunnerProxy([&]() {threadCtx1_.mainLoop_->runVerification(5, true, true);});
+ std::thread mainLoopRunnerProxy([&]() { threadCtx1_.mainLoop_->runVerification(5, true, true); });
mainLoopRunnerProxy.detach();
- mainLoopThread1_ = std::thread([&]() {threadCtx1_.proxy_->testPredefinedTypeMethod(inInt, inStr, callStatus, outInt, outStr);});
+ mainLoopThread1_ = std::thread([&]() { threadCtx1_.proxy_->testPredefinedTypeMethod(inInt, inStr, callStatus, outInt, outStr); });
mainLoopThread1_.detach();
sleep(1);
// proxy should not receive answer, if the stub mainloop does not run
ASSERT_EQ(0, outInt);
- mainLoopThread2_ = std::thread([&]() {threadCtx2_.mainLoop_->run();});
+ mainLoopThread2_ = std::thread([&]() { threadCtx2_.mainLoop_->run(); });
mainLoopThread2_.detach();
sleep(1);
@@ -417,13 +448,16 @@ TEST_F(MainLoopIndependenceTest, ProxyReceivesAnswerOnlyIfStubMainLoopRuns) {
ASSERT_EQ(1, outInt);
}
+/**
+* @test Proxy Receives Just His Own Answers.
+* - start 2 proxies in own threads
+* - call test method in each proxy
+* - now each proxy should have received the answer to his own request
+*/
TEST_F(MainLoopIndependenceTest, ProxyReceivesJustHisOwnAnswers) {
std::shared_ptr<PingPongTestStub> stubThirdParty = std::make_shared<PingPongTestStub>();
auto runtime = CommonAPI::Runtime::load();
- ASSERT_TRUE(runtime->getServicePublisher()->registerService(
- stubThirdParty,
- testAddress6,
- runtime->createFactory()));
+ ASSERT_TRUE(runtime->getServicePublisher()->registerService(stubThirdParty, testAddress6, runtime->createFactory()));
CommonAPI::CallStatus callStatusProxy1, callStatusProxy2;
@@ -433,17 +467,18 @@ TEST_F(MainLoopIndependenceTest, ProxyReceivesJustHisOwnAnswers) {
inIntProxy2 = 2;
outIntProxy1 = outIntProxy2 = 0;
- std::thread mainLoopRunnerProxy1([&]() {threadCtx1_.mainLoop_->run();});
- std::thread mainLoopRunnerProxy2([&]() {threadCtx2_.mainLoop_->run();});
+ std::thread mainLoopRunnerProxy1([&]() { threadCtx1_.mainLoop_->run(); });
+ std::thread mainLoopRunnerProxy2([&]() { threadCtx2_.mainLoop_->run(); });
mainLoopRunnerProxy1.detach();
mainLoopRunnerProxy2.detach();
- while (!(threadCtx1_.proxyThirdParty_->isAvailable() && threadCtx2_.proxyThirdParty_->isAvailable())) {
+ while(!(threadCtx1_.proxyThirdParty_->isAvailable() && threadCtx2_.proxyThirdParty_->isAvailable())) {
usleep(5000);
}
- mainLoopThread1_ = std::thread([&]() {threadCtx1_.proxyThirdParty_->testPredefinedTypeMethod(inIntProxy1, inStrProxy1, callStatusProxy1, outIntProxy1, outStrProxy1);});
- mainLoopThread2_ = std::thread([&]() {threadCtx2_.proxyThirdParty_->testPredefinedTypeMethod(inIntProxy2, inStrProxy2, callStatusProxy2, outIntProxy2, outStrProxy2);});
+
+ mainLoopThread1_ = std::thread([&]() { threadCtx1_.proxyThirdParty_->testPredefinedTypeMethod(inIntProxy1, inStrProxy1, callStatusProxy1, outIntProxy1, outStrProxy1); });
+ mainLoopThread2_ = std::thread([&]() { threadCtx2_.proxyThirdParty_->testPredefinedTypeMethod(inIntProxy2, inStrProxy2, callStatusProxy2, outIntProxy2, outStrProxy2); });
mainLoopThread1_.detach();
mainLoopThread2_.detach();