Contents copied from the project homepage and from powerpoint slides presented at the
Genivi All Members Meeting in Barcelona by Manfred Barthelt, BMW Group, EG-SI Topic Lead
CommonAPI C++ is an Inter Process Communication (IPC) language binding API for C++, which enables applications to use different IPC middleware as backend without any changes to the application code.
The intention is to make the IPC interface for application development independent from the underlying IPC middleware.
IPC CommonAPI C++ is availlable as open source project on the GENIVI project homepage.
CommonAPI C++ can be used to easily adapt and optimize applications to different deployment environments, e.g. to exchange an applications communication from CAN to D-Bus or SomeIP, while retaining the application code as a generic component.
Architecture for D-Bus IPC
Architecture for any IPC
package com.harman.test
interface Calculator {
version { major 1 minor 0 }
method add {
in { Int32 value1 Int32 value2 }
out { Int32 summary }
}
}
Example: Client
#include <iostream>
#include <CommonAPI/DBus/DBusRuntime.h>
#include <CommonAPI/Factory.h>
#include <com/harman/test/CalculatorProxy.h>
using namespace std;
int main() {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
std::string serviceAddress_ = "local:com.harman.test.CalculatorService:com.harman.test.CalculatorInstance";
auto proxy = factory->buildProxy<com::harman::test::CalculatorProxy>(serviceAddress_);
CommonAPI::CallStatus status;
int32_t result;
int32_t s1;
int32_t s2;
while(true) {
cout << "Enter value1: ";
cin >> s1;
cout << "Enter value2: ";
cin >> s2;
proxy->add(s1, s2, status, result);
cout << "Result: " << result << endl;
}
return 0;
}
Example: Service
void CalculatorServiceImpl::add(int32_t value1, int32_t value2, int32_t& summary) {
summary = value1 + value2;
cout << "Adding:" << value1 << " + " << value2 << " = " << summary << endl;
}
int main() {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
"domain:service:instance"
std::string serviceAddress_ = "local:com.harman.test.CalculatorService:com.harman.test.CalculatorInstance";
auto myStub = std::make_shared<CalculatorServiceImpl>();
bool success = factory->registerService(myStub, serviceAddress_);
if(success) {
cout << "Registered Service" << endl;
// Run forever....
while(true) {
}
}
return 0;
}