CommonAPI入門

CommonAPI介紹

CommonAPI C++是一個(gè)標(biāo)準(zhǔn)化的C++ API規(guī)范,用于開發(fā)分布式的應(yīng)用程序。這些應(yīng)用程序通過進(jìn)程間通信的中間件進(jìn)行通信。其目的是封裝通信協(xié)議和相鄰的中間件,使C++接口與底層的IPC無(wú)關(guān)。
CommonAPI C++ 依賴Franca-IDL來(lái)描述靜態(tài)接口以及通信和協(xié)議配置參數(shù)。你可以用代碼生成器(CommonAPI-Tools)來(lái)生成proxy- 和stub- 代碼。然后通過生成的函數(shù)體實(shí)現(xiàn)stub函數(shù),通過生成的proxy來(lái)實(shí)現(xiàn)接口的調(diào)用。
要獲得可執(zhí)行應(yīng)用程序(客戶端和服務(wù)),請(qǐng)使用特定的代碼生成器(DBus or SOME/IP)生成IPC框架特定的黏性代碼(glue-code),然后與依賴的runtime庫(kù)一起編譯。

CommonAPI C++ Overview

  • CommonAPI C++ 被劃分成與中間件無(wú)關(guān)的部分(CommonAPI C++ Core),以及與中間件相關(guān)部分(CommonAPI C++ Binding)
  • CommonAPI使用接口描述語(yǔ)言FrancaIDL來(lái)規(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)方法來(lái)實(shí)現(xiàn)服務(wù)端
  • 通過創(chuàng)建代理并使用代理調(diào)用這些方法來(lái)實(shí)現(xiàn)客戶端

CommonAPI用戶集成指南

CommonAPI是GENIVI開發(fā)的,可以在Linux平臺(tái)上運(yùn)行。此外,出于測(cè)試和開發(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庫(kù),包含用于構(gòu)建runtime庫(kù)的源代碼
capicxx-someip-runtime https://github.com/COVESA/capicxx-someip-runtime CommonAPI SOME/IP runtime庫(kù)和源代碼,用于構(gòu)建SOME/IP binding的runtime庫(kù)
capicxx-core-tools https://github.com/COVESA/capicxx-core-tools
Release版本
https://github.com/COVESA/capicxx-core-tools/releases
CommonAPI 代碼生成器庫(kù),包含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代碼生成器庫(kù),其中包含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)備工作,接下來(lái),我們會(huì)編寫Helloworld完成一個(gè)簡(jiǎn)單的demo

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容