diff options
Diffstat (limited to 'CommonAPI-Examples/E07Mainloop')
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/.cproject | 71 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/.gitignore | 2 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/.project | 33 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/CMakeLists.txt | 125 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/README | 6 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/commonapi4dbus.ini | 8 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/commonapi4someip.ini | 8 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/fidl/E07Mainloop.fdepl | 40 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/fidl/E07Mainloop.fidl | 22 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/src/E07MainloopClient.cpp | 196 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/src/E07MainloopService.cpp | 140 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/src/E07MainloopStubImpl.cpp | 33 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/src/E07MainloopStubImpl.hpp | 24 | ||||
-rw-r--r-- | CommonAPI-Examples/E07Mainloop/vsomeip.json | 47 |
14 files changed, 755 insertions, 0 deletions
diff --git a/CommonAPI-Examples/E07Mainloop/.cproject b/CommonAPI-Examples/E07Mainloop/.cproject new file mode 100644 index 0000000..fc8a4e4 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/.cproject @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> + <storageModule moduleId="org.eclipse.cdt.core.settings"> + <cconfiguration id="0.416559588"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.416559588" moduleId="org.eclipse.cdt.core.settings" name="Default"> + <externalSettings/> + <extensions> + <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactName="${ProjName}" buildProperties="" description="" id="0.416559588" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg"> + <folderInfo id="0.416559588." name="/" resourcePath=""> + <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1038958730" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain"> + <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1038958730.2115115764" name=""/> + <builder arguments="-C ${ProjDirPath}/build VERBOSE=0" buildPath="" command="make" id="org.eclipse.cdt.build.core.settings.default.builder.1812880292" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/> + <tool id="org.eclipse.cdt.build.core.settings.holder.libs.1019901481" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/> + <tool id="org.eclipse.cdt.build.core.settings.holder.259363632" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder"> + <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.840421715" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> + </tool> + <tool id="org.eclipse.cdt.build.core.settings.holder.1212471744" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder"> + <option id="org.eclipse.cdt.build.core.settings.holder.incpaths.427233418" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath"> + <listOptionValue builtIn="false" value=""${workspace_loc:/ascgit017.CommonAPI/include}""/> + <listOptionValue builtIn="false" value=""${workspace_loc:/E01HelloWorld/src-gen}""/> + <listOptionValue builtIn="false" value="/usr/include/c++/4.8.2"/> + </option> + <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1678702299" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> + </tool> + <tool id="org.eclipse.cdt.build.core.settings.holder.291757453" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder"> + <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1117944646" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <project id="e01HelloWorld.null.741055877" name="e01HelloWorld"/> + </storageModule> + <storageModule moduleId="scannerConfiguration"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + <scannerConfigBuildInfo instanceId="0.416559588"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> + <storageModule moduleId="refreshScope" versionNumber="2"> + <configuration configurationName="Default"> + <resource resourceType="PROJECT" workspacePath="/e01HelloWorld"/> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"> + <buildTargets> + <target name="Run cmake" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> + <buildCommand>cmake</buildCommand> + <buildArguments>-E chdir build/ cmake -D CMAKE_BUILD_TYPE=Debug -DUSE_INSTALLED_COMMONAPI=OFF -DUSE_INSTALLED_DBUS=OFF ../</buildArguments> + <buildTarget/> + <stopOnError>true</stopOnError> + <useDefaultCommand>false</useDefaultCommand> + <runAllBuilders>true</runAllBuilders> + </target> + </buildTargets> + </storageModule> +</cproject> diff --git a/CommonAPI-Examples/E07Mainloop/.gitignore b/CommonAPI-Examples/E07Mainloop/.gitignore new file mode 100644 index 0000000..5fb7e99 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/.gitignore @@ -0,0 +1,2 @@ +build +src-gen diff --git a/CommonAPI-Examples/E07Mainloop/.project b/CommonAPI-Examples/E07Mainloop/.project new file mode 100644 index 0000000..93b34d5 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>E07Mainloop</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.xtext.ui.shared.xtextBuilder</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.xtext.ui.shared.xtextNature</nature> + </natures> +</projectDescription> diff --git a/CommonAPI-Examples/E07Mainloop/CMakeLists.txt b/CommonAPI-Examples/E07Mainloop/CMakeLists.txt new file mode 100644 index 0000000..2642156 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/CMakeLists.txt @@ -0,0 +1,125 @@ +# Copyright (C) 2015 BMW Group +# Author: Lutz Bichler (lutz.bichler@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) + +set(PRJ_NAME E07Mainloop) + +set(CMAKE_VERBOSE_MAKEFILE on) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -Wall -O0 -std=c++0x -D_GLIBCXX_USE_NANOSLEEP -DLINUX") + +message(STATUS "Compiler options: ${CMAKE_CXX_FLAGS}") + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING + "Choose the type of build, options are: Debug Release." FORCE) +endif(NOT CMAKE_BUILD_TYPE) +message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") + +OPTION(USE_INSTALLED_COMMONAPI "Set to OFF to use the local (build tree) version of CommonAPI" ON) +message(STATUS "USE_INSTALLED_COMMONAPI is set to value: ${USE_INSTALLED_COMMONAPI}") + +if ("${USE_INSTALLED_COMMONAPI}" STREQUAL "ON") + FIND_PACKAGE(CommonAPI REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) + FIND_PACKAGE(CommonAPI-DBus REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) +else() + FIND_PACKAGE(CommonAPI REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) + FIND_PACKAGE(CommonAPI-DBus REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) +endif() + +message(STATUS "CommonAPI_CONSIDERED_CONFIGS: ${CommonAPI_CONSIDERED_CONFIGS}") +message(STATUS "COMMONAPI_INCLUDE_DIRS: ${COMMONAPI_INCLUDE_DIRS}") +message(STATUS "CommonAPI-DBus_CONSIDERED_CONFIGS: ${CommonAPI-DBus_CONSIDERED_CONFIGS}") +message(STATUS "COMMONAPI_DBUS_INCLUDE_DIRS: ${COMMONAPI_DBUS_INCLUDE_DIRS}") + +# CommonAPI +include(FindPkgConfig) +pkg_check_modules (DBUS "dbus-1 >= 1.4") + +# SOME/IP +find_package (CommonAPI-SomeIP 3.1.1 REQUIRED) +find_package (vsomeip 1.1.0 REQUIRED) + +# GLib +FIND_PACKAGE(glib-2.0) +if (GLIB_FOUND) + message ( STATUS "Glib found: " ${GLIB_INCLUDE_DIRS} " " ${_GLIB_LIBRARY_DIR} " " ${GLIBCONFIG_INCLUDE_DIR} ) + include_directories(${GLIB_INCLUDE_DIRS} ${GLIBCONFIG_INCLUDE_DIR}) + #link_directories(${_GLIB_LIBRARY_DIR}) +else (GLIB_FOUND) + message ( WARNING "Glib not found.") +endif (GLIB_FOUND) + +# Source Files +set(PRJ_SRC_PATH src) +set(PRJ_SRC_GEN_PATH src-gen) +set(PRJ_SRC_GEN_COMMONAPI_PATH ${PRJ_SRC_GEN_PATH}/core/v1_0/commonapi/examples) +set(PRJ_SRC_GEN_COMMONAPI_DBUS_PATH ${PRJ_SRC_GEN_PATH}/dbus/v1_0/commonapi/examples) +set(PRJ_SRC_GEN_COMMONAPI_SOMEIP_PATH ${PRJ_SRC_GEN_PATH}/someip/v1_0/commonapi/examples) + +set(PRJ_NAME_CLIENT ${PRJ_NAME}Client) +set(PRJ_NAME_SERVICE ${PRJ_NAME}Service) + +# Application +FILE(GLOB PRJ_PROXY_GEN_SRCS ${PRJ_SRC_GEN_COMMONAPI_PATH}/*Proxy.cpp) +FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_COMMONAPI_PATH}/*Stub*.cpp) +FILE(GLOB PRJ_STUB_IMPL_SRCS ${PRJ_SRC_COMMONAPI_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_SRC_PATH}/${PRJ_NAME}StubImpl.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS}) + +# DBus library +FILE(GLOB PRJ_DBUS_LIB_SRCS ${PRJ_SRC_GEN_COMMONAPI_DBUS_PATH}/*cpp) + +# SOME/IP library +FILE(GLOB PRJ_SOMEIP_LIB_SRCS ${PRJ_SRC_GEN_COMMONAPI_SOMEIP_PATH}/*cpp) + +# Paths +OPTION(USE_INSTALLED_DBUS "Set to OFF to use the local (patched) version of dbus" ON) +message(STATUS "USE_INSTALLED_DBUS is set to value: ${USE_INSTALLED_DBUS}") + +include_directories( + src-gen/core + src-gen/dbus + src-gen/someip + ${COMMONAPI_INCLUDE_DIRS} + ${COMMONAPI_DBUS_INCLUDE_DIRS} + ${COMMONAPI_SOMEIP_INCLUDE_DIRS} + ${DBUS_INCLUDE_DIRS} + ${VSOMEIP_INCLUDE_DIRS} +) + +if ("${USE_INSTALLED_DBUS}" STREQUAL "ON") +link_directories( + ${COMMONAPI_LIBDIR} + ${COMMONAPI_DBUS_LIBDIR} + ${COMMONAPI_SOMEIP_CMAKE_DIR}/build +) +else() +link_directories( + ${COMMONAPI_LIBDIR} + ${COMMONAPI_DBUS_LIBDIR} + ${COMMONAPI_SOMEIP_CMAKE_DIR}/build + ${DBUS_INCLUDE_DIRS}/dbus/.libs +) +endif() + +set(LINK_LIBRARIES -Wl,--as-needed CommonAPI glib-2.0) + +# Build Client +add_executable(${PRJ_NAME_CLIENT} ${PRJ_CLIENT_SRCS}) +target_link_libraries(${PRJ_NAME_CLIENT} ${LINK_LIBRARIES}) + +# Build service +add_executable(${PRJ_NAME_SERVICE} ${PRJ_SERVICE_SRCS}) +target_link_libraries(${PRJ_NAME_SERVICE} ${LINK_LIBRARIES}) + +# Build DBus library +add_library (${PRJ_NAME}-DBus SHARED ${PRJ_DBUS_LIB_SRCS}) +target_link_libraries(${PRJ_NAME}-DBus CommonAPI-DBus) + +# Build SOME/IP library +add_library (${PRJ_NAME}-SomeIP SHARED ${PRJ_SOMEIP_LIB_SRCS}) +target_link_libraries(${PRJ_NAME}-SomeIP CommonAPI-SomeIP)
\ No newline at end of file diff --git a/CommonAPI-Examples/E07Mainloop/README b/CommonAPI-Examples/E07Mainloop/README new file mode 100644 index 0000000..b8c99d7 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/README @@ -0,0 +1,6 @@ +=== Example 07: Mainloop + +This example shows how CommonAPI can be integrated with an external main loop. For demonstration purposes the +glib+ main loop is used. + +CommonAPI does not contain a main loop implementation itself; just a demo implementation is provided for test purposes (please have a look to the verification tests in the CommonAPI tools project to find out how the demo main loop is used). + diff --git a/CommonAPI-Examples/E07Mainloop/commonapi4dbus.ini b/CommonAPI-Examples/E07Mainloop/commonapi4dbus.ini new file mode 100644 index 0000000..39a52b7 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/commonapi4dbus.ini @@ -0,0 +1,8 @@ +[default] +binding=dbus + +[proxy] +local:commonapi.examples.E07Mainloop:commonapi.examples.Mainloop=libE07Mainloop-DBus.so + +[stub] +local:commonapi.examples.E07Mainloop:commonapi.examples.Mainloop=libE07Mainloop-DBus.so diff --git a/CommonAPI-Examples/E07Mainloop/commonapi4someip.ini b/CommonAPI-Examples/E07Mainloop/commonapi4someip.ini new file mode 100644 index 0000000..0c68943 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/commonapi4someip.ini @@ -0,0 +1,8 @@ +[default] +binding=someip + +[proxy] +local:commonapi.examples.E07Mainloop:commonapi.examples.Mainloop=libE07Mainloop-SomeIP.so + +[stub] +local:commonapi.examples.E07Mainloop:commonapi.examples.Mainloop=libE07Mainloop-SomeIP.so diff --git a/CommonAPI-Examples/E07Mainloop/fidl/E07Mainloop.fdepl b/CommonAPI-Examples/E07Mainloop/fidl/E07Mainloop.fdepl new file mode 100644 index 0000000..c617777 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/fidl/E07Mainloop.fdepl @@ -0,0 +1,40 @@ +/* Copyright (C) 2015 BMW Group + * Author: Lutz Bichler (lutz.bichler@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/. */ +import "platform:/plugin/org.genivi.commonapi.someip/deployment/CommonAPI-SOMEIP_deployment_spec.fdepl" +import "E07Mainloop.fidl" + +define org.genivi.commonapi.someip.deployment for interface commonapi.examples.E07Mainloop { + SomeIpServiceID = 4660 + + attribute x { + SomeIpGetterID = 3000 + SomeIpSetterID = 3001 + SomeIpNotifierID = 33010 + SomeIpEventGroups = { 33010 } + } + + method sayHello { + SomeIpMethodID = 33000 + + in { + name { + SomeIpStringEncoding = utf16le + } + } + } + +} + +define org.genivi.commonapi.someip.deployment for provider Service { + instance commonapi.examples.E07Mainloop { + InstanceId = "commonapi.examples.Mainloop" + + SomeIpInstanceID = 22136 + + SomeIpUnicastAddress = "192.168.0.2" + SomeIpUnicastPort = 30499 + } +}
\ No newline at end of file diff --git a/CommonAPI-Examples/E07Mainloop/fidl/E07Mainloop.fidl b/CommonAPI-Examples/E07Mainloop/fidl/E07Mainloop.fidl new file mode 100644 index 0000000..c835cd9 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/fidl/E07Mainloop.fidl @@ -0,0 +1,22 @@ +/* Copyright (C) 2015 BMW Group + * Author: Lutz Bichler (lutz.bichler@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 E07Mainloop { + version { major 1 minor 0 } + + attribute Int32 x + + method sayHello { + in { + String name + } + out { + String message + } + } +}
\ No newline at end of file diff --git a/CommonAPI-Examples/E07Mainloop/src/E07MainloopClient.cpp b/CommonAPI-Examples/E07Mainloop/src/E07MainloopClient.cpp new file mode 100644 index 0000000..02954be --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/src/E07MainloopClient.cpp @@ -0,0 +1,196 @@ +/* Copyright (C) 2015 BMW Group + * Author: Lutz Bichler (lutz.bichler@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 <unistd.h> +#include <sstream> + +#include <glib.h> + +#include <CommonAPI/CommonAPI.hpp> +#include <v1_0/commonapi/examples/E07MainloopProxy.hpp> + +using namespace v1_0::commonapi::examples; + +GIOChannel* channel; + +std::future<CommonAPI::CallStatus> gFutureCallStatus; +std::future<CommonAPI::CallStatus> gFutureCallStatusISIA; +std::future<CommonAPI::CallStatus> gFutureCallStatusGetAttrX; + +int32_t gValueForX = 428394; + +void myAttrXCallback(const CommonAPI::CallStatus& callStatus, const int32_t& val) { + std::cout << "Receive callback for Attribute x: " << val << std::endl; +} + +void mySayHelloCallback(const CommonAPI::CallStatus& _callStatus, const std::string& _returnMessage) { + + if (_callStatus != CommonAPI::CallStatus::SUCCESS) { + std::cerr << "Remote call failed!\n"; + return; + } + std::cout << "Got message: '" << _returnMessage << "'\n"; + +} + +gboolean callSetAttrX(void* proxy) { + + std::cout << "callSetAttrX called ..." << std::endl; + + E07MainloopProxy<>* myProxy = static_cast<E07MainloopProxy<>*>(proxy); + myProxy->getXAttribute().setValueAsync(gValueForX , myAttrXCallback); + + return false; +} + +gboolean callGetAttrX(void* proxy) { + + std::cout << "callGetAttrX called ..." << std::endl; + + E07MainloopProxy<>* myProxy = static_cast<E07MainloopProxy<>*>(proxy); + myProxy->getXAttribute().getValueAsync(myAttrXCallback); + + return false; +} + +gboolean callSayHello(void* proxy) { + + std::cout << "callSayHello called ..." << std::endl; + + static int number = 1; + + std::stringstream stream; + stream << "World (" << number << ")"; + const std::string name = stream.str(); + + E07MainloopProxy<>* myProxy = static_cast<E07MainloopProxy<>*>(proxy); + gFutureCallStatus = myProxy->sayHelloAsync(name, mySayHelloCallback); + + number++; + + return true; +} + +class GDispatchWrapper: public GSource { + public: + GDispatchWrapper(CommonAPI::DispatchSource* dispatchSource): dispatchSource_(dispatchSource) {} + CommonAPI::DispatchSource* dispatchSource_; +}; + +gboolean dispatchPrepare ( GSource* source, gint* timeout ) { + + bool result = false; + int64_t eventTimeout; + + result = static_cast<GDispatchWrapper*>(source)->dispatchSource_->prepare(eventTimeout); + + *timeout = eventTimeout; + + return result; +} + +gboolean dispatchCheck ( GSource* source ) { + + return static_cast<GDispatchWrapper*>(source)->dispatchSource_->check(); +} + +gboolean dispatchExecute ( GSource* source, GSourceFunc callback, gpointer userData ) { + + static_cast<GDispatchWrapper*>(source)->dispatchSource_->dispatch(); + return true; +} + +static GSourceFuncs standardGLibSourceCallbackFuncs = { + dispatchPrepare, + dispatchCheck, + dispatchExecute, + NULL +}; + +gboolean gWatchDispatcher ( GIOChannel *source, GIOCondition condition, gpointer userData ) { + + CommonAPI::Watch* watch = static_cast<CommonAPI::Watch*>(userData); + watch->dispatch(condition); + return true; +} + +gboolean gTimeoutDispatcher ( void* userData ) { + + return static_cast<CommonAPI::DispatchSource*>(userData)->dispatch(); +} + +void watchAddedCallback ( CommonAPI::Watch* watch, const CommonAPI::DispatchPriority dispatchPriority ) { + + const pollfd& fileDesc = watch->getAssociatedFileDescriptor(); + channel = g_io_channel_unix_new(fileDesc.fd); + + GSource* gWatch = g_io_create_watch(channel, static_cast<GIOCondition>(fileDesc.events)); + g_source_set_callback(gWatch, reinterpret_cast<GSourceFunc>(&gWatchDispatcher), watch, NULL); + + const auto& dependentSources = watch->getDependentDispatchSources(); + for (auto dependentSourceIterator = dependentSources.begin(); + dependentSourceIterator != dependentSources.end(); + dependentSourceIterator++) { + GSource* gDispatchSource = g_source_new(&standardGLibSourceCallbackFuncs, sizeof(GDispatchWrapper)); + static_cast<GDispatchWrapper*>(gDispatchSource)->dispatchSource_ = *dependentSourceIterator; + + g_source_add_child_source(gWatch, gDispatchSource); + + } + g_source_attach(gWatch, NULL); +} + +void watchRemovedCallback ( CommonAPI::Watch* watch ) { + + g_source_remove_by_user_data(watch); + + if(channel) { + g_io_channel_unref(channel); + channel = NULL; + } +} + +int main() { + std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::get(); + + std::string domain = "local"; + std::string instance = "commonapi.examples.Mainloop"; + std::string connection = "client-sample"; + + std::shared_ptr<CommonAPI::MainLoopContext> mainloopContext = std::make_shared<CommonAPI::MainLoopContext>(connection); + + std::function<void(CommonAPI::Watch*, const CommonAPI::DispatchPriority)> f_watchAddedCallback = watchAddedCallback; + std::function<void(CommonAPI::Watch*)> f_watchRemovedCallback = watchRemovedCallback; + mainloopContext->subscribeForWatches(f_watchAddedCallback, f_watchRemovedCallback); + + std::shared_ptr<E07MainloopProxyDefault> myProxy = runtime->buildProxy<E07MainloopProxy>(domain, + instance, mainloopContext); + + std::cout << "Checking availability" << std::flush; + static constexpr bool mayBlock = false; + int count = 0; + while (!myProxy->isAvailable()) { + if (count % 10 == 0) + std::cout << "." << std::flush; + g_main_context_iteration(NULL, mayBlock); + usleep(50000); + } + std::cout << "done." << std::endl; + + GMainLoop* mainloop = NULL; + mainloop = g_main_loop_new(NULL, FALSE); + + void *proxyPtr = (void*)myProxy.get(); + g_timeout_add(100, callSayHello, proxyPtr); + g_timeout_add(5000, callGetAttrX, proxyPtr); + g_timeout_add(9000, callSetAttrX, proxyPtr); + + g_main_loop_run (mainloop); + g_main_loop_unref (mainloop); + + return 0; +} diff --git a/CommonAPI-Examples/E07Mainloop/src/E07MainloopService.cpp b/CommonAPI-Examples/E07Mainloop/src/E07MainloopService.cpp new file mode 100644 index 0000000..e57f192 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/src/E07MainloopService.cpp @@ -0,0 +1,140 @@ +/* Copyright (C) 2015 BMW Group + * Author: Lutz Bichler (lutz.bichler@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 <glib.h> + +#include <CommonAPI/CommonAPI.hpp> +#include "E07MainloopStubImpl.hpp" + +using namespace std; + +GIOChannel* channel; + +gboolean callIncCounter(void* service) { + + E07MainloopStubImpl* myService = static_cast<E07MainloopStubImpl*>(service); + myService->incAttrX(); + + return true; +} + +gboolean callWaitingInfo(void* service) { + std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl; + + return true; +} + +class GDispatchWrapper: public GSource { + public: + GDispatchWrapper(CommonAPI::DispatchSource* dispatchSource): dispatchSource_(dispatchSource) {} + CommonAPI::DispatchSource* dispatchSource_; +}; + +gboolean dispatchPrepare ( GSource* source, gint* timeout ) { + + bool result = false; + int64_t eventTimeout; + + result = static_cast<GDispatchWrapper*>(source)->dispatchSource_->prepare(eventTimeout); + + *timeout = eventTimeout; + + return result; +} + +gboolean dispatchCheck ( GSource* source ) { + + return static_cast<GDispatchWrapper*>(source)->dispatchSource_->check(); +} + +gboolean dispatchExecute ( GSource* source, GSourceFunc callback, gpointer userData ) { + + static_cast<GDispatchWrapper*>(source)->dispatchSource_->dispatch(); + return true; +} + +static GSourceFuncs standardGLibSourceCallbackFuncs = { + dispatchPrepare, + dispatchCheck, + dispatchExecute, + NULL +}; + +gboolean gWatchDispatcher ( GIOChannel *source, GIOCondition condition, gpointer userData ) { + + CommonAPI::Watch* watch = static_cast<CommonAPI::Watch*>(userData); + watch->dispatch(condition); + return true; +} + +gboolean gTimeoutDispatcher ( void* userData ) { + + return static_cast<CommonAPI::DispatchSource*>(userData)->dispatch(); +} + +void watchAddedCallback ( CommonAPI::Watch* watch, const CommonAPI::DispatchPriority dispatchPriority ) { + + const pollfd& fileDesc = watch->getAssociatedFileDescriptor(); + channel = g_io_channel_unix_new(fileDesc.fd); + + GSource* gWatch = g_io_create_watch(channel, static_cast<GIOCondition>(fileDesc.events)); + g_source_set_callback(gWatch, reinterpret_cast<GSourceFunc>(&gWatchDispatcher), watch, NULL); + + const auto& dependentSources = watch->getDependentDispatchSources(); + for (auto dependentSourceIterator = dependentSources.begin(); + dependentSourceIterator != dependentSources.end(); + dependentSourceIterator++) { + GSource* gDispatchSource = g_source_new(&standardGLibSourceCallbackFuncs, sizeof(GDispatchWrapper)); + static_cast<GDispatchWrapper*>(gDispatchSource)->dispatchSource_ = *dependentSourceIterator; + + g_source_add_child_source(gWatch, gDispatchSource); + + } + g_source_attach(gWatch, NULL); +} + +void watchRemovedCallback ( CommonAPI::Watch* watch ) { + + g_source_remove_by_user_data(watch); + + if(channel) { + g_io_channel_unref(channel); + channel = NULL; + } +} + +int main() { + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get(); + + std::string domain = "local"; + std::string instance = "commonapi.examples.Mainloop"; + std::string connection = "service-sample"; + + std::shared_ptr<CommonAPI::MainLoopContext> mainloopContext = std::make_shared<CommonAPI::MainLoopContext>(connection); + + std::function<void(CommonAPI::Watch*, const CommonAPI::DispatchPriority)> f_watchAddedCallback = watchAddedCallback; + std::function<void(CommonAPI::Watch*)> f_watchRemovedCallback = watchRemovedCallback; + mainloopContext->subscribeForWatches(f_watchAddedCallback, f_watchRemovedCallback); + + std::shared_ptr<E07MainloopStubImpl> myService = std::make_shared<E07MainloopStubImpl>(); + runtime->registerService(domain, instance, myService, mainloopContext); + + GMainLoop* mainloop = NULL; + mainloop = g_main_loop_new(NULL, FALSE); + + void *servicePtr = (void*)myService.get(); + g_timeout_add_seconds(10, callWaitingInfo, servicePtr); + + g_timeout_add(2500, callIncCounter, servicePtr); + + g_main_loop_run (mainloop); + g_main_loop_unref (mainloop); + + return 0; +} diff --git a/CommonAPI-Examples/E07Mainloop/src/E07MainloopStubImpl.cpp b/CommonAPI-Examples/E07Mainloop/src/E07MainloopStubImpl.cpp new file mode 100644 index 0000000..53a2cd0 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/src/E07MainloopStubImpl.cpp @@ -0,0 +1,33 @@ +/* Copyright (C) 2015 BMW Group + * Author: Lutz Bichler (lutz.bichler@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 "E07MainloopStubImpl.hpp" + +E07MainloopStubImpl::E07MainloopStubImpl() { + setXAttribute(0); +} + +E07MainloopStubImpl::~E07MainloopStubImpl() { +} + +void E07MainloopStubImpl::sayHello(const std::shared_ptr<CommonAPI::ClientId> _client, + std::string _name, + sayHelloReply_t _reply) { + + std::stringstream messageStream; + + messageStream << "Hello " << _name << "!"; + std::cout << "sayHello('" << _name << "'): '" << messageStream.str() << "'\n"; + + _reply(messageStream.str()); +} + +void E07MainloopStubImpl::incAttrX() { + int32_t xValue = getXAttribute(); + xValue++; + setXAttribute((int32_t)xValue); + std::cout << "New counter value = " << xValue << "!" << std::endl; +} diff --git a/CommonAPI-Examples/E07Mainloop/src/E07MainloopStubImpl.hpp b/CommonAPI-Examples/E07Mainloop/src/E07MainloopStubImpl.hpp new file mode 100644 index 0000000..1cd82b1 --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/src/E07MainloopStubImpl.hpp @@ -0,0 +1,24 @@ +/* Copyright (C) 2015 BMW Group + * Author: Lutz Bichler (lutz.bichler@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 E07MAINLOOPSTUBIMPL_H_ +#define E07MAINLOOPSTUBIMPL_H_ + +#include <CommonAPI/CommonAPI.hpp> +#include <v1_0/commonapi/examples/E07MainloopStubDefault.hpp> + +class E07MainloopStubImpl: public v1_0::commonapi::examples::E07MainloopStubDefault { + +public: + E07MainloopStubImpl(); + virtual ~E07MainloopStubImpl(); + + virtual void sayHello(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _name, sayHelloReply_t _return); + virtual void incAttrX(); + +}; + +#endif /* E07MAINLOOPSTUBIMPL_H_ */ diff --git a/CommonAPI-Examples/E07Mainloop/vsomeip.json b/CommonAPI-Examples/E07Mainloop/vsomeip.json new file mode 100644 index 0000000..641f13b --- /dev/null +++ b/CommonAPI-Examples/E07Mainloop/vsomeip.json @@ -0,0 +1,47 @@ +{ + "unicast" : "192.168.0.235", + "logging" : + { + "level" : "info", + "console" : "true", + "file" : { "enable" : "false", "path" : "/var/log/vsomeip.log" }, + "dlt" : "false" + }, + "applications" : + [ + { + "name" : "client-sample", + "id" : "0x1343" + }, + { + "name" : "other-client-sample", + "id" : "0x1344" + }, + { + "name" : "service-sample", + "id" : "0x1277" + } + ], + "servicegroups" : + [ + { + "name" : "default", + "delays" : + { + "initial" : { "minimum" : "10", "maximum" : "100" }, + "repetition-base" : "200", + "repetition-max" : "3", + "cyclic-offer" : "2000", + "cyclic-request" : "2001" + } + } + ], + "routing" : "client-sample", + "service-discovery" : + { + "enable" : "true", + "multicast" : "224.244.224.245", + "port" : "30490", + "protocol" : "udp" + } +} |