CommonAPI介绍
CommonAPI C++是一个标准化的C++ API规范,用于开发分布式的应用程序。这些应用程序通过进程间通信的中间件进行通信。其目的是封装通信协议和相邻的中间件,使C++接口与底层的IPC无关。
CommonAPI C++ 依赖Franca-IDL来描述静态接口以及通信和协议配置参数。你可以用代码生成器(CommonAPI-Tools)来生成proxy- 和stub- 代码。然后通过生成的函数体实现stub函数,通过生成的proxy来实现接口的调用。
要获得可执行应用程序(客户端和服务),请使用特定的代码生成器(DBus or SOME/IP)生成IPC框架特定的黏性代码(glue-code),然后与依赖的runtime库一起编译。
- CommonAPI C++ 被划分成与中间件无关的部分(CommonAPI C++ Core),以及与中间件相关部分(CommonAPI C++ Binding)
- CommonAPI使用接口描述语言FrancaIDL来规范接口,FrancaIDL的代码生成是CommonAPI的一个集成部分
-
CommonAPI C++ Binding代码生成器需要特定的中间件参数,这个参数定义在Francal 部署文件中(*.fdepl)
- user API被分成了两部分
基于FrancaIDL生成的部分,其中包含与FrancaIDL文件的类型、属性和方法相关的API函数
“common”部分(Runtime API),其中包含用于加载Runtime环境、创建代理等的API函数 - CommonAPI Core和IPC之间没有直接关系
- 生成的CommonAPI Binding代码与CommonAPI的其他部分都有接口
开发一个基于CommonAPI的应用程序的基本流程如下:
- 创建一个FrancaIDL文件,其中指定了一个具有方法和属性的接口
- 通过启动CommonAPI代码生成器为客户端和服务生成代码
- 通过在生成的框架中实现方法来实现服务端
- 通过创建代理并使用代理调用这些方法来实现客户端
CommonAPI用户集成指南
CommonAPI是GENIVI开发的,可以在Linux平台上运行。此外,出于测试和开发目的,也可以在Windows下运行。
CommonAPI使用了许多C++11特性,如可变模板,std::bind,std::function等。需要确保目标平台的编译器能够编译(例如gcc 4.8)
CommonAPI依赖CMake编译,需要确定你的编译平台已支持CMake,并且CMake版本大于2.8.12
代码生成器的构建工具链是Maven,确保你的编译平台的Maven3是有效的
模块 | 链接 | Comment |
---|---|---|
capicxx-core-runtime | https://github.com/COVESA/capicxx-core-runtime | CommonAPI runtime库,包含用于构建runtime库的源代码 |
capicxx-someip-runtime | https://github.com/COVESA/capicxx-someip-runtime | CommonAPI SOME/IP runtime库和源代码,用于构建SOME/IP binding的runtime库 |
capicxx-core-tools |
https://github.com/COVESA/capicxx-core-tools Release版本 https://github.com/COVESA/capicxx-core-tools/releases |
CommonAPI 代码生成器库,包含CommonAPI代码生成器的源代码(java/xtend eclipse插件) 如果不想编译,可以直接下载release版本 |
capicxx-someip-tools |
https://github.com/COVESA/capicxx-someip-tools Release版本 https://github.com/COVESA/capicxx-someip-tools/releases |
CommonAPI SOME/IP代码生成器库,其中包含CommonAPI SOME/IP代码生成器的源代码(java/xtend eclipse插件),该生成器是生成SOME/IP特定源代码(SOME/IP粘合代码)所需的 如果不想编译,可以直接下载release版本 |
编译
capicxx-core-runtime
$ cd capicxx-core-runtime-master/
capicxx-core-runtime-master$ ls
Android.bp CHANGES CMakeLists.txt commonapi.spec.in doxygen.in INSTALL README.md
AUTHORS cmake CommonAPI.pc.in docx include LICENSE src
capicxx-core-runtime-master$ mkdir build
capicxx-core-runtime-master$ cd build/ capicxx-core-runtime-master/build$ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Project name: libcommonapi
-- This is CMake for Common API C++ Version 3.2.0.
-- CMAKE_INSTALL_PREFIX set to: /usr/local
-- BUILD_SHARED_LIBS is set to value: ON
-- MAX_LOG_LEVEL is set to value: DEBUG
-- Setting build type to 'RelWithDebInfo' as none was specified.
-- USE_FILE is set to value: OFF
-- USE_CONSOLE is set to value: OFF
-- RPM packet version set to r0
-- Build type: RelWithDebInfo
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'automotive-dlt >= 2.11'
--
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Doxygen is not installed. Documentation can not be built.
-- Configuring done
-- Generating done
-- Build files have been written to: capicxx-core-runtime-master/build
capicxx-core-runtime-master/build$ make
Scanning dependencies of target CommonAPI
[ 9%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/Address.cpp.o
[ 18%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/CallInfo.cpp.o
[ 27%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/ContainerUtils.cpp.o
[ 36%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/IniFileReader.cpp.o
[ 45%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/Logger.cpp.o
[ 54%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/MainLoopContext.cpp.o
[ 63%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/Proxy.cpp.o
[ 72%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/ProxyManager.cpp.o
[ 81%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/Runtime.cpp.o
[ 90%] Building CXX object CMakeFiles/CommonAPI.dir/src/CommonAPI/Utils.cpp.o
[100%] Linking C shared library libCommonAPI.so
[100%] Built target CommonAPI
capicxx-core-runtime-master/build$ ls
CMakeCache.txt cmake_install.cmake CommonAPIConfigVersion.cmake commonapi.spec libCommonAPI.so Makefile
CMakeFiles CommonAPIConfig.cmake CommonAPI.pc CommonAPITargets.cmake libCommonAPI.so.3.2.0
capicxx-someip-runtime
capicxx-someip-runtime-master$ ls
Android.bp AUTHORS CHANGES cmake CMakeLists.txt CommonAPI-SomeIP.pc.in include INSTALL LICENSE README.md src
capicxx-someip-runtime-master$ mkdir build
capicxx-someip-runtime-master$ cd build/
capicxx-someip-runtime-master/build$ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Project name: CommonAPI-SomeIP
-- USE_FILE is set to value: OFF
-- USE_CONSOLE is set to value: OFF
-- DEFAULT_SEND_TIMEOUT is set to value: 5000 ms
-- Setting build type to 'RelWithDebInfo' as none was specified.
-- MAX_LOG_LEVEL is set to value: DEBUG
-- CommonAPI_CONSIDERED_CONFIGS: /data/Workspace/SOA/capicxx-core-runtime-master/build/CommonAPIConfig.cmake
-- COMMONAPI_INCLUDE_DIRS: /data/Workspace/SOA/capicxx-core-runtime-master/include
-- CommonAPI Version: 3.2.0
-- Using vsomeip3 - v3.1.20
-- Configuring done
-- Generating done
-- Build files have been written to: /capicxx-someip-runtime-master/build
capicxx-someip-runtime-master/build$ make
Scanning dependencies of target CommonAPI-SomeIP
[ 5%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/Address.cpp.o
[ 10%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/AddressTranslator.cpp.o
[ 15%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/ClientId.cpp.o
[ 21%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/Connection.cpp.o
[ 26%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/DispatchSource.cpp.o
[ 31%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/Factory.cpp.o
[ 36%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/InputStream.cpp.o
[ 42%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/InstanceAvailabilityStatusChangedEvent.cpp.o
[ 47%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/Message.cpp.o
[ 52%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/OutputStream.cpp.o
[ 57%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/Proxy.cpp.o
[ 63%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/ProxyBase.cpp.o
[ 68%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/ProxyManager.cpp.o
[ 73%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/StringEncoder.cpp.o
[ 78%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/StubAdapter.cpp.o
[ 84%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/StubManager.cpp.o
[ 89%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/SubscriptionStatusWrapper.cpp.o
[ 94%] Building CXX object CMakeFiles/CommonAPI-SomeIP.dir/src/CommonAPI/SomeIP/Watch.cpp.o
[100%] Linking CXX shared library libCommonAPI-SomeIP.so
[100%] Built target CommonAPI-SomeIP
capicxx-someip-runtime-master/build$ ls
CMakeCache.txt cmake_install.cmake CommonAPI-SomeIPConfigVersion.cmake CommonAPI-SomeIPTargets.cmake libCommonAPI-SomeIP.so.3.2.0
CMakeFiles CommonAPI-SomeIPConfig.cmake CommonAPI-SomeIP.pc libCommonAPI-SomeIP.so Makefile
capicxx-core-tools
可以直接下载已编译好的成果物
https://github.com/COVESA/capicxx-core-tools/releases下的commonapi_core_generator.zip
capicxx-someip-tools
可以直接下载已编译好的成果物
https://github.com/COVESA/capicxx-someip-tools/releases下的
commonapi_someip_generator.zip
总结:
自从,我们已经完成了基于SOME/IP的CommonAPI的准备工作,接下来,我们会编写Helloworld完成一个简单的demo