CommonAPI入門

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++ Overview

  • 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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市江场,隨后出現(xiàn)的幾起案子纺酸,更是在濱河造成了極大的恐慌,老刑警劉巖址否,帶你破解...
    沈念sama閱讀 219,270評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件餐蔬,死亡現(xiàn)場離奇詭異,居然都是意外死亡佑附,警方通過查閱死者的電腦和手機(jī)樊诺,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,489評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來音同,“玉大人词爬,你說我怎么就攤上這事∪ň” “怎么了顿膨?”我有些...
    開封第一講書人閱讀 165,630評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵锅锨,是天一觀的道長。 經(jīng)常有香客問我恋沃,道長必搞,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,906評(píng)論 1 295
  • 正文 為了忘掉前任囊咏,我火速辦了婚禮恕洲,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘梅割。我一直安慰自己研侣,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,928評(píng)論 6 392
  • 文/花漫 我一把揭開白布炮捧。 她就那樣靜靜地躺著庶诡,像睡著了一般。 火紅的嫁衣襯著肌膚如雪咆课。 梳的紋絲不亂的頭發(fā)上末誓,一...
    開封第一講書人閱讀 51,718評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音书蚪,去河邊找鬼喇澡。 笑死,一個(gè)胖子當(dāng)著我的面吹牛殊校,可吹牛的內(nèi)容都是我干的晴玖。 我是一名探鬼主播,決...
    沈念sama閱讀 40,442評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼为流,長吁一口氣:“原來是場噩夢啊……” “哼呕屎!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起敬察,我...
    開封第一講書人閱讀 39,345評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤秀睛,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后莲祸,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體蹂安,經(jīng)...
    沈念sama閱讀 45,802評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,984評(píng)論 3 337
  • 正文 我和宋清朗相戀三年锐帜,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了田盈。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,117評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡缴阎,死狀恐怖允瞧,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤瓷式,帶...
    沈念sama閱讀 35,810評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站语泽,受9級(jí)特大地震影響贸典,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜踱卵,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,462評(píng)論 3 331
  • 文/蒙蒙 一廊驼、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧惋砂,春花似錦妒挎、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至眷柔,卻和暖如春期虾,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背驯嘱。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評(píng)論 1 272
  • 我被黑心中介騙來泰國打工镶苞, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人鞠评。 一個(gè)月前我還...
    沈念sama閱讀 48,377評(píng)論 3 373
  • 正文 我出身青樓茂蚓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親剃幌。 傳聞我的和親對(duì)象是個(gè)殘疾皇子聋涨,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,060評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容