CommonAPI介紹
CommonAPI C++是一個(gè)標(biāo)準(zhǔn)化的C++ API規(guī)范圣絮,用于開發(fā)分布式的應(yīng)用程序。這些應(yīng)用程序通過進(jìn)程間通信的中間件進(jìn)行通信。其目的是封裝通信協(xié)議和相鄰的中間件,使C++接口與底層的IPC無關(guān)藻雪。
CommonAPI C++ 依賴Franca-IDL來描述靜態(tài)接口以及通信和協(xié)議配置參數(shù)。你可以用代碼生成器(CommonAPI-Tools)來生成proxy- 和stub- 代碼狸吞。然后通過生成的函數(shù)體實(shí)現(xiàn)stub函數(shù)勉耀,通過生成的proxy來實(shí)現(xiàn)接口的調(diào)用。
要獲得可執(zhí)行應(yīng)用程序(客戶端和服務(wù))捷绒,請(qǐng)使用特定的代碼生成器(DBus or SOME/IP)生成IPC框架特定的黏性代碼(glue-code)瑰排,然后與依賴的runtime庫一起編譯贯要。
- CommonAPI C++ 被劃分成與中間件無關(guān)的部分(CommonAPI C++ Core)暖侨,以及與中間件相關(guān)部分(CommonAPI C++ Binding)
- CommonAPI使用接口描述語言FrancaIDL來規(guī)范接口,F(xiàn)rancaIDL的代碼生成是CommonAPI的一個(gè)集成部分
-
CommonAPI C++ Binding代碼生成器需要特定的中間件參數(shù)崇渗,這個(gè)參數(shù)定義在Francal 部署文件中(*.fdepl)
CommonAPI C++ Overview - user API被分成了兩部分
基于FrancaIDL生成的部分字逗,其中包含與FrancaIDL文件的類型京郑、屬性和方法相關(guān)的API函數(shù)
“common”部分(Runtime API),其中包含用于加載Runtime環(huán)境葫掉、創(chuàng)建代理等的API函數(shù) - CommonAPI Core和IPC之間沒有直接關(guān)系
- 生成的CommonAPI Binding代碼與CommonAPI的其他部分都有接口
開發(fā)一個(gè)基于CommonAPI的應(yīng)用程序的基本流程如下:
- 創(chuàng)建一個(gè)FrancaIDL文件些举,其中指定了一個(gè)具有方法和屬性的接口
- 通過啟動(dòng)CommonAPI代碼生成器為客戶端和服務(wù)生成代碼
- 通過在生成的框架中實(shí)現(xiàn)方法來實(shí)現(xiàn)服務(wù)端
- 通過創(chuàng)建代理并使用代理調(diào)用這些方法來實(shí)現(xiàn)客戶端
CommonAPI用戶集成指南
CommonAPI是GENIVI開發(fā)的,可以在Linux平臺(tái)上運(yùn)行俭厚。此外户魏,出于測試和開發(fā)目的,也可以在Windows下運(yùn)行挪挤。
CommonAPI使用了許多C++11特性叼丑,如可變模板,std::bind扛门,std::function等鸠信。需要確保目標(biāo)平臺(tái)的編譯器能夠編譯(例如gcc 4.8)
CommonAPI依賴CMake編譯,需要確定你的編譯平臺(tái)已支持CMake论寨,并且CMake版本大于2.8.12
代碼生成器的構(gòu)建工具鏈?zhǔn)荕aven,確保你的編譯平臺(tái)的Maven3是有效的
模塊 | 鏈接 | Comment |
---|---|---|
capicxx-core-runtime | https://github.com/COVESA/capicxx-core-runtime | CommonAPI runtime庫星立,包含用于構(gòu)建runtime庫的源代碼 |
capicxx-someip-runtime | https://github.com/COVESA/capicxx-someip-runtime | CommonAPI SOME/IP runtime庫和源代碼,用于構(gòu)建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
總結(jié):
自從,我們已經(jīng)完成了基于SOME/IP的CommonAPI的準(zhǔn)備工作荐健,接下來酱畅,我們會(huì)編寫Helloworld完成一個(gè)簡單的demo