From 02987671e5335cb767e0a0c64391dd44dec9e737 Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Tue, 2 Jun 2015 10:57:57 +0200 Subject: * Common-API 3 integration and fix for the asserts order in the router tests. Signed-off-by: Christian Linke --- AudioManagerDaemon/CMakeLists.txt | 36 +-- AudioManagerDaemon/fidls/NodeStateManager.fdepl | 2 +- .../include/CAmNodeStateCommunicatorCAPI.h | 59 +++-- .../src/CAmNodeStateCommunicatorCAPI.cpp | 67 ++--- .../CAmNodeStateCommunicatorTest.cpp | 3 +- .../AmNodeStateCommunicatorCAPITest/CMakeLists.txt | 15 +- .../test/AmNodeStateCommunicatorCAPITest/nsm.py | 188 ++++++------- .../AmNodeStateCommunicatorCAPITest/send2nsm.py | 10 +- .../test/AmRouterMapTest/CAmRouterMapTest.cpp | 34 ++- .../test/AmRouterTest/CAmRouterTest.cpp | 4 +- .../include/CAmCommonAPIWrapper.h | 235 +++++++++++++---- AudioManagerUtilities/include/CAmDltWrapper.h | 2 +- AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp | 110 ++++---- CMakeLists.txt | 7 +- cmake/CommonAPI.cmake | 291 +++++++++++++++++++++ cmake/CommonAPIGenerator.cmake | 205 --------------- cmake/FindCommonAPI.cmake | 72 ----- cmake/TargetArch.cmake | 134 ++++++++++ cmake/audiomanagerConfig.cmake.in | 2 + cmake/config.cmake.in | 2 + 20 files changed, 893 insertions(+), 585 deletions(-) create mode 100755 cmake/CommonAPI.cmake delete mode 100755 cmake/CommonAPIGenerator.cmake delete mode 100644 cmake/FindCommonAPI.cmake create mode 100644 cmake/TargetArch.cmake diff --git a/AudioManagerDaemon/CMakeLists.txt b/AudioManagerDaemon/CMakeLists.txt index 58c5929..b52e625 100644 --- a/AudioManagerDaemon/CMakeLists.txt +++ b/AudioManagerDaemon/CMakeLists.txt @@ -45,12 +45,13 @@ if (WITH_SYSTEMD_WATCHDOG) endif(SYSTEMD_FOUND) endif (WITH_SYSTEMD_WATCHDOG) -if(WITH_DBUS_WRAPPER) +if(WITH_DBUS_WRAPPER) find_package(DBUS REQUIRED) endif(WITH_DBUS_WRAPPER) if(WITH_CAPI_WRAPPER) - find_package(CommonAPI REQUIRED) + INCLUDE (CommonAPI) + LOAD_COMMONAPI(DBUS) endif(WITH_CAPI_WRAPPER) set (AM_LINK_LIBS @@ -103,15 +104,18 @@ if(WITH_DBUS_WRAPPER) ${DBUS_LIBRARY}) endif(WITH_DBUS_WRAPPER) +set (AM_LINK_LIBS + ${AM_LINK_LIBS} + ${DBUS_LIBRARY}) + if(WITH_CAPI_WRAPPER) set (AUDIOMAN_SRCS_CXX ${AUDIOMAN_SRCS_CXX} "${AUDIOMANAGER_UTILITIES_SRC}/CAmCommonAPIWrapper.cpp") set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DBUS_LIBRARY} - ${COMMON_API_LIBRARIES} - ${COMMON_API_DBUS_LIBRARIES}) + ${AM_LINK_LIBS} + ${CommonAPI-DBus_LIBRARY} + ${CommonAPI_LIBRARY}) endif(WITH_CAPI_WRAPPER) if(WITH_NSM) @@ -151,24 +155,22 @@ INCLUDE_DIRECTORIES( ) if(WITH_CAPI_WRAPPER) - if(WITH_NSM) - include (CommonAPIGenerator) COMMON_API_GENERATE_SOUCRES(TARGET COMMON_API - FIDLS fidls/NodeStateManager.fidl # a list with fidls - DESTINATION src-gen # a relative path to the build directory or an absolute path + FIDLS fidls/NodeStateManager.fdepl # a list with fidls + DESTINATION src-gen # a relative path to the build directory or an absolute path ALT_DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/src-gen # an alternative relative/absolute path with common-api sources, usually in the source tree - DBUS) + ) + set(AUDIOMAN_SRCS_CXX ${AUDIOMAN_SRCS_CXX} ${COMMON_API_GEN_SOURCES}) endif(WITH_NSM) INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} - ${COMMON_API_INCLUDE_DIRS} - ${COMMON_API_DBUS_INCLUDE_DIRS} - ${COMMON_API_GEN_INCLUDE_DIR}) - + ${COMMONAPI_DBUS_INCLUDE_DIRS} + ${COMMONAPI_INCLUDE_DIRS} + ${COMMON_API_GEN_INCLUDE_DIR}) endif(WITH_CAPI_WRAPPER) if(WITH_DLT) @@ -179,11 +181,11 @@ if(WITH_DLT) ${DLT_LIBRARIES}) endif(WITH_DLT) -if(WITH_DBUS_WRAPPER) +#if(WITH_DBUS_WRAPPER) INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${DBUS_ARCH_INCLUDE_DIR} ${DBUS_INCLUDE_DIR}) -endif(WITH_DBUS_WRAPPER) +#endif(WITH_DBUS_WRAPPER) ADD_EXECUTABLE(AudioManager ${AUDIOMAN_SRCS_CXX}) diff --git a/AudioManagerDaemon/fidls/NodeStateManager.fdepl b/AudioManagerDaemon/fidls/NodeStateManager.fdepl index e524417..489e85e 100644 --- a/AudioManagerDaemon/fidls/NodeStateManager.fdepl +++ b/AudioManagerDaemon/fidls/NodeStateManager.fdepl @@ -1,6 +1,6 @@ import "platform:/plugin/org.genivi.commonapi.dbus/deployment/CommonAPI-DBus_deployment.fdepl" import "NodeStateManager.fidl" -define org.genivi.commonapi.dbus.deployment.deployment for interface org.genivi.NodeStateManager.Consumer { +define org.genivi.commonapi.dbus.deployment for interface org.genivi.NodeStateManager.Consumer { PropertiesType=freedesktop } diff --git a/AudioManagerDaemon/include/CAmNodeStateCommunicatorCAPI.h b/AudioManagerDaemon/include/CAmNodeStateCommunicatorCAPI.h index 44c8149..ab89526 100644 --- a/AudioManagerDaemon/include/CAmNodeStateCommunicatorCAPI.h +++ b/AudioManagerDaemon/include/CAmNodeStateCommunicatorCAPI.h @@ -23,27 +23,37 @@ #ifndef CAMNODESTATECOMMUNICATORCAPI_H_ #define CAMNODESTATECOMMUNICATORCAPI_H_ -#include #include "CAmNodeStateCommunicator.h" -#include +#include "CAmCommonAPIWrapper.h" +#include +#include + namespace am { -using namespace CommonAPI; -using namespace org::genivi::NodeStateManager; + +#define am_nodestatemanager v1_0::org::genivi::NodeStateManager class CAmCommonAPIWrapper; /** communicates with the NSM - * The CAmNodeStateCommunicator communicates with the NodeStateManager via Dbus Common-API's wrapping mechanism. Only works, if CAmCommonAPIWrapper is enabled. + * The CAmNodeStateCommunicator communicates with the NodeStateManager via Common-API wrapping mechanism. It works only, if CAmCommonAPIWrapper is enabled. */ class CAmNodeStateCommunicatorCAPI : public CAmNodeStateCommunicator { + static const char * DEFAULT_DOMAIN_STRING; + static const char * CLIENT_INSTANCE_STRING; + static const char * CLIENT_INTERFACE_STRING; + static const char * LIFECYCLE_SERVICE_INSTANCE_STRING; + static const char * LIFECYCLE_SERVICE_INTERFACE_STRING; + static const char * OBJECT_NAME; + static const char * BUS_NAME; + /* A concrete implementation of the life cycle stub. * An object from this class is instantiated from the common-api factory. * It forwards the invocations to its delegate CAmNodeStateCommunicatorCAPI. */ - class CAmNodeStateCommunicatorServiceImpl : public LifeCycleConsumerStubDefault + class CAmNodeStateCommunicatorServiceImpl : public am_nodestatemanager::LifeCycleConsumerStubDefault { CAmNodeStateCommunicatorCAPI *mpDelegate; public: @@ -58,11 +68,29 @@ class CAmNodeStateCommunicatorCAPI : public CAmNodeStateCommunicator if(mpDelegate) mpDelegate->cbReceivedLifecycleRequest(Request, RequestId, ErrorCode); } + + void LifecycleRequest(const std::shared_ptr client, uint32_t Request, uint32_t RequestId, LifecycleRequestReply_t reply){ + int32_t ErrorCode; + LifecycleRequest(Request, RequestId, ErrorCode); + reply(ErrorCode); + } }; CAmCommonAPIWrapper *mpCAPIWrapper; - std::shared_ptr > mNSMProxy; + std::shared_ptr > mNSMProxy; std::shared_ptr mNSMStub; + + /* Client events */ + void onNodeStateEvent(const int32_t nodeState); + void onNodeApplicationModeEvent(const int32_t nodeApplicationMode); + void onSessionStateChangedEvent(const std::string & sessionName, const int32_t seatID, const int32_t sessionState); + void onServiceStatusEvent(const CommonAPI::AvailabilityStatus& serviceStatus); + /* Service callbacks */ + void cbReceivedLifecycleRequest(uint32_t Request, uint32_t RequestId, int32_t& ErrorCode); + +protected: + bool mIsServiceAvailable; + public: CAmNodeStateCommunicatorCAPI(CAmCommonAPIWrapper* iCAPIWrapper); virtual ~CAmNodeStateCommunicatorCAPI(); @@ -77,24 +105,7 @@ public: NsmErrorStatus_e nsmUnRegisterShutdownClient(const uint32_t shutdownMode) ; am_Error_e nsmGetInterfaceVersion(uint32_t& version) ; NsmErrorStatus_e nsmSendLifecycleRequestComplete(const uint32_t RequestId, const NsmErrorStatus_e status) ; - bool isServiceAvailable(); - - static const char * CLIENT_STRING; - static const char * SERVER_STRING; - static const char * OBJECT_NAME; - static const char * BUS_NAME; - -private: - /* Client events */ - void onNodeStateEvent(const int32_t nodeState); - void onNodeApplicationModeEvent(const int32_t nodeApplicationMode); - void onSessionStateChangedEvent(const std::string & sessionName, const int32_t seatID, const int32_t sessionState); - void onServiceStatusEvent(const CommonAPI::AvailabilityStatus& serviceStatus); - /* Service callbacks */ - void cbReceivedLifecycleRequest(uint32_t Request, uint32_t RequestId, int32_t& ErrorCode); -protected: - bool mIsServiceAvailable; }; } diff --git a/AudioManagerDaemon/src/CAmNodeStateCommunicatorCAPI.cpp b/AudioManagerDaemon/src/CAmNodeStateCommunicatorCAPI.cpp index 7081fe5..700c9c3 100644 --- a/AudioManagerDaemon/src/CAmNodeStateCommunicatorCAPI.cpp +++ b/AudioManagerDaemon/src/CAmNodeStateCommunicatorCAPI.cpp @@ -28,23 +28,28 @@ #include #include #include -#include #include "config.h" -#include "CAmCommonAPIWrapper.h" #include "CAmDltWrapper.h" #include "CAmNodeStateCommunicatorCAPI.h" #include "CAmControlSender.h" -#include +#include namespace am { -const char * CAmNodeStateCommunicatorCAPI::CLIENT_STRING = "local:org.genivi.NodeStateManager.Consumer:org.genivi.NodeStateManager"; -const char * CAmNodeStateCommunicatorCAPI::SERVER_STRING = "local:org.genivi.NodeStateManager.LifeCycleConsumer:org.genivi.audiomanager"; +#define LIFECYCLE_SERVICE_INTERFACE NSM_BUS_INTERFACE ".LifeCycleConsumer" -const char * CAmNodeStateCommunicatorCAPI::OBJECT_NAME = "/org/genivi/audiomanager/LifeCycleConsumer"; -const char * CAmNodeStateCommunicatorCAPI::BUS_NAME = "org.genivi.audiomanager"; +const char * CAmNodeStateCommunicatorCAPI::DEFAULT_DOMAIN_STRING = "local"; + +const char * CAmNodeStateCommunicatorCAPI::CLIENT_INSTANCE_STRING = NSM_BUS_INTERFACE; +const char * CAmNodeStateCommunicatorCAPI::CLIENT_INTERFACE_STRING = NSM_INTERFACE; + +const char * CAmNodeStateCommunicatorCAPI::LIFECYCLE_SERVICE_INSTANCE_STRING = DBUS_SERVICE_PREFIX; +const char * CAmNodeStateCommunicatorCAPI::LIFECYCLE_SERVICE_INTERFACE_STRING = LIFECYCLE_SERVICE_INTERFACE; + +const char * CAmNodeStateCommunicatorCAPI::OBJECT_NAME = DBUS_SERVICE_OBJECT_PATH; +const char * CAmNodeStateCommunicatorCAPI::BUS_NAME = LIFECYCLE_SERVICE_INTERFACE "_" DBUS_SERVICE_PREFIX; #define IF_NOT_AVAILABLE_RETURN(error) \ @@ -53,13 +58,13 @@ if(!mIsServiceAvailable) { logError(__PRETTY_FUNCTION__, "Node State Manager not /** * Retrieves the value from given attribute wrapper. */ -template am_Error_e getAttributeValue(Attribute* attribute, TValueReturnType & resultValue) +template am_Error_e getAttributeValue(CommonAPI::Attribute* attribute, TValueReturnType & resultValue) { - CallStatus status; - typename Attribute::ValueType value; + CommonAPI::CallStatus status; + typename CommonAPI::Attribute::ValueType value; attribute->getValue(status, value); std::cout << std::endl << "CallStatus : " << static_cast(status) << std::endl; - if( CallStatus::SUCCESS == status) + if( CommonAPI::CallStatus::SUCCESS == status) { resultValue = static_cast(value); return E_OK; @@ -77,9 +82,8 @@ CAmNodeStateCommunicatorCAPI::CAmNodeStateCommunicatorCAPI(CAmCommonAPIWrapper* logInfo("CAmNodeStateCommunicatorCAPI::CAmNodeStateCommunicatorCAPI started"); //Gets the factory pointer and build a proxy object - std::shared_ptr factory = iCAPIWrapper->factory(); - mNSMProxy = factory->buildProxy(CAmNodeStateCommunicatorCAPI::CLIENT_STRING); - + mNSMProxy = iCAPIWrapper->buildProxy( CAmNodeStateCommunicatorCAPI::DEFAULT_DOMAIN_STRING, + CAmNodeStateCommunicatorCAPI::CLIENT_INSTANCE_STRING); //Makes subscriptions to the following 3 events mNSMProxy->getNodeStateEvent().subscribe( std::bind(&CAmNodeStateCommunicatorCAPI::onNodeStateEvent, this, std::placeholders::_1) @@ -95,13 +99,16 @@ CAmNodeStateCommunicatorCAPI::CAmNodeStateCommunicatorCAPI(CAmCommonAPIWrapper* mNSMStub = std::make_shared(this); //Registers the service - iCAPIWrapper->registerStub(mNSMStub, CAmNodeStateCommunicatorCAPI::SERVER_STRING); + if(!iCAPIWrapper->registerService(mNSMStub,CAmNodeStateCommunicatorCAPI::DEFAULT_DOMAIN_STRING,CAmNodeStateCommunicatorCAPI::LIFECYCLE_SERVICE_INSTANCE_STRING)) + logError("AudioManager can't register service"); } CAmNodeStateCommunicatorCAPI::~CAmNodeStateCommunicatorCAPI() { mNSMProxy.reset(); - mpCAPIWrapper->unregisterStub(CAmNodeStateCommunicatorCAPI::SERVER_STRING); + mpCAPIWrapper->unregisterService(CAmNodeStateCommunicatorCAPI::DEFAULT_DOMAIN_STRING, + CAmNodeStateCommunicatorCAPI::LIFECYCLE_SERVICE_INTERFACE_STRING, + CAmNodeStateCommunicatorCAPI::LIFECYCLE_SERVICE_INSTANCE_STRING); mNSMStub->setDelegate(NULL); mNSMStub.reset(); mpCAPIWrapper = NULL; @@ -179,10 +186,10 @@ NsmErrorStatus_e CAmNodeStateCommunicatorCAPI::nsmGetNodeState(NsmNodeState_e& n //Check the service via the proxy object is available IF_NOT_AVAILABLE_RETURN(NsmErrorStatus_Error) - CallStatus callStatus; + CommonAPI::CallStatus callStatus; int32_t tmpNodeState = 0, errorCode = 0; mNSMProxy->GetNodeState(callStatus, tmpNodeState, errorCode); - if( CallStatus::SUCCESS == callStatus ) + if( CommonAPI::CallStatus::SUCCESS == callStatus ) { nsmNodeState = static_cast(tmpNodeState); return (static_cast(errorCode)); @@ -202,11 +209,11 @@ NsmErrorStatus_e CAmNodeStateCommunicatorCAPI::nsmGetSessionState(const std::str //Check the service via the proxy object is available IF_NOT_AVAILABLE_RETURN(NsmErrorStatus_Error) - CallStatus callStatus; + CommonAPI::CallStatus callStatus; int32_t tmpSessionState = 0 , errorCode = 0; mNSMProxy->GetSessionState(sessionName,seatID,callStatus, tmpSessionState, errorCode); - if( CallStatus::SUCCESS == callStatus) + if( CommonAPI::CallStatus::SUCCESS == callStatus) { sessionState = static_cast(tmpSessionState); return (static_cast(errorCode)); @@ -224,10 +231,10 @@ NsmErrorStatus_e CAmNodeStateCommunicatorCAPI::nsmGetApplicationMode(NsmApplicat //Check the service via the proxy object is available IF_NOT_AVAILABLE_RETURN(NsmErrorStatus_Error) - CallStatus callStatus; + CommonAPI::CallStatus callStatus; int32_t tmpAppMode = 0 , errorCode = 0; mNSMProxy->GetApplicationMode(callStatus, tmpAppMode, errorCode); - if( CallStatus::SUCCESS == callStatus) + if( CommonAPI::CallStatus::SUCCESS == callStatus) { applicationMode = static_cast(tmpAppMode); return (static_cast(errorCode)); @@ -246,12 +253,12 @@ NsmErrorStatus_e CAmNodeStateCommunicatorCAPI::nsmRegisterShutdownClient(const u //Check the service via the proxy object is available IF_NOT_AVAILABLE_RETURN(NsmErrorStatus_Error) - CallStatus callStatus; + CommonAPI::CallStatus callStatus; int32_t errorCode = 0; std::string objName = std::string(CAmNodeStateCommunicatorCAPI::OBJECT_NAME); std::string busName = std::string(CAmNodeStateCommunicatorCAPI::BUS_NAME); mNSMProxy->RegisterShutdownClient(busName, objName, shutdownMode, timeoutMs, callStatus, errorCode); - if( CallStatus::SUCCESS == callStatus) + if( CommonAPI::CallStatus::SUCCESS == callStatus) return (static_cast(errorCode)); return NsmErrorStatus_Dbus; @@ -267,12 +274,12 @@ NsmErrorStatus_e CAmNodeStateCommunicatorCAPI::nsmUnRegisterShutdownClient(const //Check the service via the proxy object is available IF_NOT_AVAILABLE_RETURN(NsmErrorStatus_Error) - CallStatus callStatus; + CommonAPI::CallStatus callStatus; int32_t errorCode = 0; std::string objName = std::string(CAmNodeStateCommunicatorCAPI::OBJECT_NAME); std::string busName = std::string(CAmNodeStateCommunicatorCAPI::BUS_NAME); mNSMProxy->UnRegisterShutdownClient(busName, objName, shutdownMode, callStatus, errorCode); - if( CallStatus::SUCCESS == callStatus) + if( CommonAPI::CallStatus::SUCCESS == callStatus) return (static_cast(errorCode)); return NsmErrorStatus_Dbus; } @@ -287,9 +294,9 @@ am_Error_e CAmNodeStateCommunicatorCAPI::nsmGetInterfaceVersion(uint32_t& versio //Check the service via the proxy object is available IF_NOT_AVAILABLE_RETURN(E_NOT_POSSIBLE) - CallStatus callStatus; + CommonAPI::CallStatus callStatus; mNSMProxy->GetInterfaceVersion(callStatus, version); - if( CallStatus::SUCCESS == callStatus) + if( CommonAPI::CallStatus::SUCCESS == callStatus) return E_OK; return E_UNKNOWN; } @@ -305,10 +312,10 @@ NsmErrorStatus_e CAmNodeStateCommunicatorCAPI::nsmSendLifecycleRequestComplete(c //Check the service via the proxy object is available IF_NOT_AVAILABLE_RETURN(NsmErrorStatus_Error) - CallStatus callStatus; + CommonAPI::CallStatus callStatus; int32_t errorCode = 0; mNSMProxy->LifecycleRequestComplete(RequestId, status, callStatus, errorCode); - if( CallStatus::SUCCESS == callStatus) + if( CommonAPI::CallStatus::SUCCESS == callStatus) { return (static_cast(errorCode)); } diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/CAmNodeStateCommunicatorTest.cpp b/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/CAmNodeStateCommunicatorTest.cpp index 9bb95e2..d9e0fd0 100644 --- a/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/CAmNodeStateCommunicatorTest.cpp +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/CAmNodeStateCommunicatorTest.cpp @@ -49,7 +49,8 @@ CAmNodeStateCommunicatorTest::~CAmNodeStateCommunicatorTest() */ void* nsmThread (void*) { - system("python nsm.py"); + if(-1 == system("python nsm.py")) + logError("Something went wrong with nsm.py!"); return (NULL); } diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/CMakeLists.txt b/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/CMakeLists.txt index 018d71a..9c2d1a2 100644 --- a/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/CMakeLists.txt +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/CMakeLists.txt @@ -22,7 +22,6 @@ project(AmNodeStateCommunicatorCAPITest) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1") find_package(Threads) -find_package(CommonAPI REQUIRED) find_package(PythonLibs REQUIRED) set (AM_LINK_LIBS @@ -43,9 +42,11 @@ INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_DIRS} ${GOOGLE_TEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} - ${COMMON_API_INCLUDE_DIRS} - ${COMMON_API_DBUS_INCLUDE_DIRS} + ${COMMONAPI_DBUS_INCLUDE_DIRS} + ${COMMONAPI_INCLUDE_DIRS} ${COMMON_API_GEN_INCLUDE_DIR} + ${DBUS_ARCH_INCLUDE_DIR} + ${DBUS_INCLUDE_DIR} ) if(WITH_DLT) @@ -77,8 +78,9 @@ TARGET_LINK_LIBRARIES(AmNodeStateCommunicatorCAPITest ${AM_LINK_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${PYTHON_LIBRARY} - ${COMMON_API_LIBRARIES} - ${COMMON_API_DBUS_LIBRARIES} + ${CommonAPI-DBus_LIBRARY} + ${CommonAPI_LIBRARY} + ${DBUS_LIBRARY} gtest gmock ) @@ -106,6 +108,7 @@ if(USE_BUILD_LIBS) COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/org.genivi.NodeStateManager.Consumer.xml" ${EXECUTABLE_OUTPUT_PATH}/org.genivi.NodeStateManager.Consumer.xml COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/nsm.py" ${EXECUTABLE_OUTPUT_PATH}/nsm.py COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/send2nsm.py" ${EXECUTABLE_OUTPUT_PATH}/send2nsm.py - COMMAND cp "${AUDIOMANAGER_DAEMON_FOLDER}/fidls/NodeStateManager_dbus.conf" ${EXECUTABLE_OUTPUT_PATH}/AmNodeStateCommunicatorCAPITest_dbus.conf) +# COMMAND cp "${AUDIOMANAGER_DAEMON_FOLDER}/fidls/NodeStateManager_dbus.conf" ${EXECUTABLE_OUTPUT_PATH}/AmNodeStateCommunicatorCAPITest_dbus.conf + ) endif(USE_BUILD_LIBS) diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/nsm.py b/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/nsm.py index 74dae54..c648484 100644 --- a/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/nsm.py +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/nsm.py @@ -31,7 +31,7 @@ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) class NodeStateManager(dbus.service.Object): def __init__(self, loop): - busName = dbus.service.BusName('org.genivi.NodeStateManager', bus = dbus.SessionBus()) + busName = dbus.service.BusName('org.genivi.NodeStateManager.Consumer_org.genivi.NodeStateManager', bus = dbus.SessionBus()) dbus.service.Object.__init__(self, busName, '/org/genivi/NodeStateManager') self.properties = {'RestartReason': 1, 'ShutdownReason': 2, 'WakeUpReason' :3, 'BootMode' :4} self.ABus="" @@ -40,140 +40,140 @@ class NodeStateManager(dbus.service.Object): @dbus.service.method(dbus_interface='org.freedesktop.DBus.Introspectable', out_signature = 's') def Introspect(self): - f = open('org.genivi.NodeStateManager.Consumer.xml', "r") - text = f.read() - return text + f = open('org.genivi.NodeStateManager.Consumer.xml', "r") + text = f.read() + return text @dbus.service.method(dbus_interface='org.genivi.NodeStateManager.Consumer', out_signature = 'ii') def GetNodeState(self): - NodeStateId=1 - ErrorCode=1 - print('[-----nsm-----] send out nodeState' + str(NodeStateId) + ' ErrorCode '+ str(1)) - return NodeStateId, ErrorCode - + NodeStateId=1 + ErrorCode=1 + print('[-----nsm-----] send out nodeState' + str(NodeStateId) + ' ErrorCode '+ str(1)) + return NodeStateId, ErrorCode + @dbus.service.method('org.genivi.NodeStateManager.Consumer', out_signature = 'ii') def GetApplicationMode(self): - ApplicationModeId=5 - ErrorCode=2 - print('[-----nsm-----] send out ApplicationMode' + str(ApplicationModeId) + ' ErrorCode '+ str(2)) - return ApplicationModeId, ErrorCode + ApplicationModeId=5 + ErrorCode=2 + print('[-----nsm-----] send out ApplicationMode' + str(ApplicationModeId) + ' ErrorCode '+ str(2)) + return ApplicationModeId, ErrorCode @dbus.service.method('org.genivi.NodeStateManager.Consumer', in_signature='si', out_signature = 'ii') def GetSessionState(self,SessionName,seatID): - SessionState=0 - ErrorCode=2 - - if SessionName=="mySession" and seatID==1: - SessionState=5 - ErrorCode=1 - - print('[-----nsm-----] GetSessionState for session ' + SessionName + ' seatID '+ str(seatID) + ' returnState ' + str (SessionState)) - return SessionState, ErrorCode - + SessionState=0 + ErrorCode=2 + + if SessionName=="mySession" and seatID==1: + SessionState=5 + ErrorCode=1 + + print('[-----nsm-----] GetSessionState for session ' + SessionName + ' seatID '+ str(seatID) + ' returnState ' + str (SessionState)) + return SessionState, ErrorCode + @dbus.service.method('org.genivi.NodeStateManager.Consumer', in_signature='ssuu', out_signature = 'i') def RegisterShutdownClient(self,BName,ObjName,ShutdownMode,TimeoutMs): - print('[-----nsm-----] Busname: ' + BName) - print('[-----nsm-----] ObjName: ' + ObjName) - print('[-----nsm-----] ShutdownMode: ' + str(ShutdownMode)) - print('[-----nsm-----] TimeoutMs: ' + str(TimeoutMs)) - ErrorCode=1 - if TimeoutMs!=100: - ErrorCode=3 - if BName!="org.genivi.audiomanager": - ErrorCode=4 - if ShutdownMode!=1: - ErrorCode=5 - if ObjName!="/org/genivi/audiomanager/LifeCycleConsumer": - ErrorCode=6 - self.ABus=BName - self.APath=ObjName - return ErrorCode - + print('[-----nsm-----] Busname: ' + BName) + print('[-----nsm-----] ObjName: ' + ObjName) + print('[-----nsm-----] ShutdownMode: ' + str(ShutdownMode)) + print('[-----nsm-----] TimeoutMs: ' + str(TimeoutMs)) + ErrorCode=1 + if TimeoutMs!=100: + ErrorCode=3 + if BName!="org.genivi.NodeStateManager.LifeCycleConsumer_org.genivi.audiomanager": + ErrorCode=4 + if ShutdownMode!=1: + ErrorCode=5 + if ObjName!="/org/genivi/audiomanager": + ErrorCode=6 + self.ABus=BName + self.APath=ObjName + return ErrorCode + @dbus.service.method('org.genivi.NodeStateManager.Consumer', in_signature='ssu', out_signature = 'i') def UnRegisterShutdownClient(self,BusName,ObjName,ShutdownMode): - print('[-----nsm-----] Busname: ' + str(BusName)) - print('[-----nsm-----] ObjName: ' + str(ObjName)) - print('[-----nsm-----] ShutdownMode: ' + str(ShutdownMode)) - ErrorCode=1 - if BusName!=self.ABus: - ErrorCode=2 - if ObjName!=self.APath: - ErrorCode=2 - if ShutdownMode!=1: - ErrorCode=2 - return ErrorCode - + print('[-----nsm-----] Busname: ' + str(BusName)) + print('[-----nsm-----] ObjName: ' + str(ObjName)) + print('[-----nsm-----] ShutdownMode: ' + str(ShutdownMode)) + ErrorCode=1 + if BusName!=self.ABus: + ErrorCode=2 + if ObjName!=self.APath: + ErrorCode=2 + if ShutdownMode!=1: + ErrorCode=2 + return ErrorCode + @dbus.service.method(dbus_interface='org.genivi.NodeStateManager.Consumer', out_signature = 'u') def GetInterfaceVersion(self): - version=23 - return version - + version=23 + return version + @dbus.service.method('org.genivi.NodeStateManager.Consumer', in_signature='ui', out_signature='i') def LifecycleRequestComplete(self,RequestID,Status): - print('[-----nsm-----] RequestId: ' + str(RequestID)) - print('[-----nsm-----] Status: ' + str(Status)) - ErrorCode=1 - if RequestID!=22: - ErrorCode=2 - if Status!=4: - ErrorCode=2 - return ErrorCode + print('[-----nsm-----] RequestId: ' + str(RequestID)) + print('[-----nsm-----] Status: ' + str(Status)) + ErrorCode=1 + if RequestID!=22: + ErrorCode=2 + if Status!=4: + ErrorCode=2 + return ErrorCode @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v') def Get(self, interface, prop): - if prop in self.properties: - print('[-----nsm-----] send out ' + str(self.properties[prop]) + ' for property '+ prop) - return self.properties[prop] - return 0 + if prop in self.properties: + print('[-----nsm-----] send out ' + str(self.properties[prop]) + ' for property '+ prop) + return self.properties[prop] + return 0 @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='ssv') def Set(self, interface, prop, value): - return 3 + return 3 @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}') def GetAll(self, interface): - return self.properties - + return self.properties + @dbus.service.signal(dbus_interface='org.genivi.NodeStateManager.Consumer', signature='i') def NodeApplicationMode(self, ApplicationModeId): - print "[-----nsm-----] Send out application mode ID %d" % (ApplicationModeId) - + print "[-----nsm-----] Send out application mode ID %d" % (ApplicationModeId) + @dbus.service.signal(dbus_interface='org.genivi.NodeStateManager.Consumer', signature='i') def NodeState(self, NodeState): - print "[-----nsm-----] Send out NodeState %d" % (NodeState) - + print "[-----nsm-----] Send out NodeState %d" % (NodeState) + @dbus.service.signal(dbus_interface='org.genivi.NodeStateManager.Consumer', signature='sii') def SessionStateChanged(self, SessionStateName,SeatID,SessionState): - print "[-----nsm-----] Send out SessionStateChanged " + SessionStateName - + print "[-----nsm-----] Send out SessionStateChanged " + SessionStateName + @dbus.service.method('org.genivi.NodeStateManager.Control', in_signature='i') def sendNodeApplicationMode(self, input): - self.NodeApplicationMode(input) - return input - + self.NodeApplicationMode(input) + return input + @dbus.service.method('org.genivi.NodeStateManager.Control', in_signature='i') def sendNodeState(self, input): - self.NodeState(input) - return input - + self.NodeState(input) + return input + @dbus.service.method('org.genivi.NodeStateManager.Control', in_signature='sii') def sendSessionState(self, SessionStateName,SeatID,SessionState): - self.SessionStateChanged (SessionStateName,SeatID,SessionState) - return SeatID - + self.SessionStateChanged (SessionStateName,SeatID,SessionState) + return SeatID + @dbus.service.method('org.genivi.NodeStateManager.Control', in_signature='uu', out_signature='i') def sendLifeCycleRequest(self, request, requestID): - bus = dbus.SessionBus() - remote_object = bus.get_object(self.ABus,self.APath) - iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.LifeCycleConsumer') - iface.LifecycleRequest(request,requestID) - return 42 - + bus = dbus.SessionBus() + remote_object = bus.get_object(self.ABus,self.APath) + iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.LifeCycleConsumer') + iface.LifecycleRequest(request,requestID) + return 42 + @dbus.service.method('org.genivi.NodeStateManager.Control') def finish(self): - print '[-----nsm-----] Going to exit now!' - self.loop.quit() - return 0 + print '[-----nsm-----] Going to exit now!' + self.loop.quit() + return 0 nsm = NodeStateManager(loop) loop.run() diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/send2nsm.py b/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/send2nsm.py index c7e8bf5..5ed6c0c 100644 --- a/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/send2nsm.py +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorCAPITest/send2nsm.py @@ -27,31 +27,31 @@ import dbus.service def nodeState (nodeState): bus = dbus.SessionBus() - remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + remote_object = bus.get_object('org.genivi.NodeStateManager.Consumer_org.genivi.NodeStateManager','/org/genivi/NodeStateManager') iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') iface.sendNodeState(int(nodeState)) def appMode (appMode): bus = dbus.SessionBus() - remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + remote_object = bus.get_object('org.genivi.NodeStateManager.Consumer_org.genivi.NodeStateManager','/org/genivi/NodeStateManager') iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') iface.sendNodeApplicationMode(int(appMode)) def sessionState (SessionStateName,SeatID,SessionState): bus = dbus.SessionBus() - remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + remote_object = bus.get_object('org.genivi.NodeStateManager.Consumer_org.genivi.NodeStateManager','/org/genivi/NodeStateManager') iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') iface.sendSessionState(SessionStateName,int(SeatID),int(SessionState)) def finish(): bus = dbus.SessionBus() - remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + remote_object = bus.get_object('org.genivi.NodeStateManager.Consumer_org.genivi.NodeStateManager','/org/genivi/NodeStateManager') iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') iface.finish() def LifecycleRequest(Request,RequestID): bus = dbus.SessionBus() - remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + remote_object = bus.get_object('org.genivi.NodeStateManager.Consumer_org.genivi.NodeStateManager','/org/genivi/NodeStateManager') iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') iface.sendLifeCycleRequest(dbus.UInt32(Request),dbus.UInt32(RequestID)) diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp index b592f39..3b10f13 100644 --- a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp +++ b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp @@ -2347,13 +2347,13 @@ TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink) ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink, listRoutes)); ASSERT_EQ(static_cast(2), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])||pCF.compareRoute(compareRoute1,listRoutes[1])); am_Route_s compareRoute2; compareRoute2.route = listRoutingElements2; compareRoute2.sinkID = sinkID; compareRoute2.sourceID = sourceID; - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1])); + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1])||pCF.compareRoute(compareRoute2,listRoutes[0])); } TEST_F(CAmRouterMapTest,route2Domains1Source1Sink) @@ -2559,7 +2559,6 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) compareRoute1.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); compareRoute1.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); compareRoute1.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); am_Route_s compareRoute2; compareRoute2.sinkID = sinkID; @@ -2569,8 +2568,6 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) compareRoute2.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); compareRoute2.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); compareRoute2.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1])); - am_Route_s compareRoute3; compareRoute3.sinkID = sinkID; @@ -2580,7 +2577,6 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) compareRoute3.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); compareRoute3.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); compareRoute3.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[2])); am_Route_s compareRoute4; compareRoute4.sinkID = sinkID; @@ -2590,7 +2586,23 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) compareRoute4.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); compareRoute4.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); compareRoute4.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute4,listRoutes[3])); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])|| + pCF.compareRoute(compareRoute1,listRoutes[1])|| + pCF.compareRoute(compareRoute1,listRoutes[2])|| + pCF.compareRoute(compareRoute1,listRoutes[3])); + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])|| + pCF.compareRoute(compareRoute2,listRoutes[1])|| + pCF.compareRoute(compareRoute2,listRoutes[2])|| + pCF.compareRoute(compareRoute2,listRoutes[3])); + ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[0])|| + pCF.compareRoute(compareRoute3,listRoutes[1])|| + pCF.compareRoute(compareRoute3,listRoutes[2])|| + pCF.compareRoute(compareRoute3,listRoutes[3])); + ASSERT_TRUE(pCF.compareRoute(compareRoute4,listRoutes[0])|| + pCF.compareRoute(compareRoute4,listRoutes[1])|| + pCF.compareRoute(compareRoute4,listRoutes[2])|| + pCF.compareRoute(compareRoute4,listRoutes[3])); } TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) @@ -2893,17 +2905,19 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2) compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); compareRoute1.route.push_back({coSourceID21, gwSinkID21, domainID2, CF_GENIVI_STEREO}); compareRoute1.route.push_back({gwSourceID12, sinkID, domainID1, CF_GENIVI_AUTO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); am_Route_s compareRoute2; compareRoute2.sinkID = sinkID; compareRoute2.sourceID = sourceID; compareRoute2.route.push_back({sourceID, coSinkID12, domainID1, CF_GENIVI_STEREO}); compareRoute2.route.push_back({coSourceID12, coSinkID13, domainID1, 6}); - compareRoute2.route.push_back({coSourceID13, gwSinkID21, domainID1, 5}); + compareRoute2.route.push_back({coSourceID13, gwSinkID11, domainID1, 5}); compareRoute2.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); + compareRoute2.route.push_back({coSourceID21, gwSinkID21, domainID2, CF_GENIVI_STEREO}); compareRoute2.route.push_back({gwSourceID12, sinkID, domainID1, CF_GENIVI_AUTO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])||pCF.compareRoute(compareRoute1,listRoutes[0])); + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])||pCF.compareRoute(compareRoute2,listRoutes[1])); } int main(int argc, char **argv) diff --git a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp index 36f487e..e88d54b 100644 --- a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp +++ b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp @@ -1253,8 +1253,8 @@ TEST_F(CAmRouterTest,simpleRoute4Domains2Routes) ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); ASSERT_EQ(static_cast(2), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]) || pCF.compareRoute(compareRoute,listRoutes[1]) ); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1]) || pCF.compareRoute(compareRoute1,listRoutes[0]) ); } //test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit. diff --git a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h index e756cc7..08823af 100644 --- a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h +++ b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h @@ -24,28 +24,82 @@ #include #include #include -#include +#include +#include +#ifndef COMMONAPI_INTERNAL_COMPILATION +#define COMMONAPI_INTERNAL_COMPILATION +#include +#undef COMMONAPI_INTERNAL_COMPILATION +#endif +#include #include "config.h" #include "CAmSocketHandler.h" /** - * A Common-API wrapper class, that loads the common-api runtime and instantiates all necessary other objects. Works with the CAmSocketHandler. - * It is implemented as singleton and usually once instantiated at the beginning with CAmSocketHandler. + * A Common-API wrapper class, which loads the common-api runtime and instantiates all necessary objects. + * It is implemented as singleton and usually instantiated at the beginning with CAmSocketHandler as parameter. * Example: CAmCommonAPIWrapper *pCAPIWrapper = CAmCommonAPIWrapper::instantiateOnce( aSocketHandlerPointer ); */ namespace am { -using namespace CommonAPI; class CAmSocketHandler; class CAmCommonAPIWrapper { + void commonPrepareCallback(const sh_pollHandle_t handle, void* userData); + TAmShPollPrepare pCommonPrepareCallback; + + bool commonDispatchCallback(const sh_pollHandle_t handle, void* userData); + TAmShPollDispatch pCommonDispatchCallback; + + void commonFireCallback(const pollfd pollfd, const sh_pollHandle_t, void*); + TAmShPollFired pCommonFireCallback; + + bool commonCheckCallback(const sh_pollHandle_t handle, void*); + TAmShPollCheck pCommonCheckCallback; + + void commonTimerCallback(sh_timerHandle_t handle, void* userData); + TAmShTimerCallBack pCommonTimerCallback; + + struct timerHandles + { + sh_timerHandle_t handle; + CommonAPI::Timeout* timeout; + }; + + CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler + + std::shared_ptr mRuntime; + std::shared_ptr mContext; + + CommonAPI::DispatchSourceListenerSubscription mDispatchSourceListenerSubscription; + CommonAPI::WatchListenerSubscription mWatchListenerSubscription; + CommonAPI::TimeoutSourceListenerSubscription mTimeoutSourceListenerSubscription; + CommonAPI::WakeupListenerSubscription mWakeupListenerSubscription; + std::multimap mRegisteredDispatchSources; + std::map mMapWatches; + CommonAPI::Watch* mWatchToCheck; + std::list mSourcesToDispatch; + std::vector mpListTimerhandles; + + void registerDispatchSource(CommonAPI::DispatchSource* dispatchSource, const CommonAPI::DispatchPriority dispatchPriority); + void deregisterDispatchSource(CommonAPI::DispatchSource* dispatchSource); + void registerWatch(CommonAPI::Watch* watch, const CommonAPI::DispatchPriority dispatchPriority); + void deregisterWatch(CommonAPI::Watch* watch); + void registerTimeout(CommonAPI::Timeout* timeout, const CommonAPI::DispatchPriority dispatchPriority); + void deregisterTimeout(CommonAPI::Timeout* timeout); + void wakeup(); + +protected: + CAmCommonAPIWrapper(CAmSocketHandler* socketHandler) ; + public: virtual ~CAmCommonAPIWrapper(); + /** * \brief Returns an already instantiated object. * @@ -54,6 +108,7 @@ public: * @return The common-api wrapper object. */ static CAmCommonAPIWrapper* getInstance(); + /** * \brief Creates a singleton instance attached to the provided socket handler object. * @@ -67,74 +122,142 @@ public: */ static CAmCommonAPIWrapper* instantiateOnce(CAmSocketHandler* socketHandler); - void registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority); - void deregisterDispatchSource(DispatchSource* dispatchSource); - void registerWatch(Watch* watch, const DispatchPriority dispatchPriority); - void deregisterWatch(Watch* watch); - void registerTimeout(Timeout* timeout, const DispatchPriority dispatchPriority); - void deregisterTimeout(Timeout* timeout); - void wakeup(); - std::shared_ptr factory() const; - std::shared_ptr runtime() const; - //Wraps the invitation to the service publisher - template bool registerStub(const std::shared_ptr & shStub, const std::string & aCommonAPIAddress) + /** + * \brief Getter for the socket handler. + * + * @return Pointer to the socket handler. + */ + CAmSocketHandler *getSocketHandler() const { return mpSocketHandler; } + + /** + * \brief Register stub objects. + * + * Example: std::shared_ptr aStub; + * registerService( aStub, "local", "com.your_company.instance_name"); + * + * @param shStub: Shared pointer to a stub instance + * @param domain: A string with the domain name, usually "local" + * @param instance: Common-api instance string as example "com.your_company.instance_name" + * + */ + template bool registerService(const std::shared_ptr & shStub, const std::string & domain, const std::string & instance) { - return runtime()->getServicePublisher()->registerService(shStub, aCommonAPIAddress, factory()); + return mRuntime->registerService(domain, instance, shStub, mContext); } - bool unregisterStub(const std::string & aCommonAPIAddress) - { - (void)aCommonAPIAddress; - /** Not implemented yet - todo: Check whether the appropriate method is available and uncomment... - return runtime()->getServicePublisher()->unregisterService(aCommonAPIAddress); - */ - return true; + /** + * \brief Unregister stub objects. + * + * @param domain: A string with the domain name, usually "local" + * @param interface: Common-api interface string as example "com.your_company.interface_name" + * @param instance: Common-api instance string as example "com.your_company.instance_name" + * + */ + bool unregisterService(const std::string &domain, const std::string &interface, const std::string &instance) + { + return mRuntime->unregisterService(domain, interface, instance); } + /** + * \brief Deprecated method. Instead you should use bool registerService(const std::shared_ptr & shStub, const std::string & domain, const std::string & instance). + * + * Register stub objects. + * + * Example: std::shared_ptr aStub; + * registerService( aStub, "local:com.your_company.interface_name:com.your_company.instance_name"); + * + * @param shStub: Shared pointer to a stub instance + * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name" + * + */ + template bool __attribute__((deprecated)) registerStub(const std::shared_ptr & shStub, const std::string & address) + { + std::vector parts = CommonAPI::split(address, ':'); + assert(parts.size()==3); -protected: - CAmCommonAPIWrapper(CAmSocketHandler* socketHandler) ; -private: - void commonPrepareCallback(const sh_pollHandle_t handle, void* userData); - TAmShPollPrepare pCommonPrepareCallback; + return registerService(shStub, parts[0], parts[2]); + } - bool commonDispatchCallback(const sh_pollHandle_t handle, void* userData); - TAmShPollDispatch pCommonDispatchCallback; + /** + * \brief Deprecated method. Instead you should use bool unregisterService(const std::string &domain, const std::string &interface, const std::string &instance). + * + * Unregister stub objects. + * + * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name" + * + */ + bool __attribute__((deprecated)) unregisterStub(const std::string & address) + { + std::vector parts = CommonAPI::split(address, ':'); + assert(parts.size()==3); - void commonFireCallback(const pollfd pollfd, const sh_pollHandle_t, void*); - TAmShPollFired pCommonFireCallback; + return unregisterService(parts[0], parts[1], parts[2]); + } - bool commonCheckCallback(const sh_pollHandle_t handle, void*); - TAmShPollCheck pCommonCheckCallback; - void commonTimerCallback(sh_timerHandle_t handle, void* userData); - TAmShTimerCallBack pCommonTimerCallback; + /** + * \brief Build proxy objects. + * + * Example: std::shared_ptr> aProxy = buildProxy("local", "com.your_company.instance_name"); + * + * @param domain: A string with the domain name, usually "local" + * @param instance: Common-api instance string as example "com.your_company.instance_name" + * + * @return A proxy object. + */ + template class ProxyClass, typename ... AttributeExtensions> + std::shared_ptr> buildProxy(const std::string &domain, const std::string &instance) + { + return mRuntime->buildProxy(domain, instance, mContext); + } - struct timerHandles - { - sh_timerHandle_t handle; - Timeout* timeout; - }; - //!< reference to the dbus instance - CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler - std::shared_ptr mFactory; - std::shared_ptr mContext; + /** + * \brief Deprecated method. Instead you should use buildProxy(const std::string &domain, const std::string &instance). + * + * Build proxy objects. + * Example: std::shared_ptr> aProxy = buildProxy("local:com.your_company.interface_name:com.your_company.instance_name"); + * + * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name" + * + * @return A proxy object. + */ + template class ProxyClass, typename ... AttributeExtensions> + std::shared_ptr> __attribute__((deprecated)) buildProxy(const std::string & address) + { + std::vector parts=CommonAPI::split(address, ':'); + assert(parts.size()==3); - DispatchSourceListenerSubscription mDispatchSourceListenerSubscription; - WatchListenerSubscription mWatchListenerSubscription; - TimeoutSourceListenerSubscription mTimeoutSourceListenerSubscription; - WakeupListenerSubscription mWakeupListenerSubscription; - std::multimap mRegisteredDispatchSources; - std::map mMapWatches; - Watch* mWatchToCheck; - std::list mSourcesToDispatch; - std::vector mpListTimerhandles; + return buildProxy(parts[0], parts[2]); + } + + /**The following code is deprecated and it might be unavailable in future versions! + * Compatibility to versions prior 3.0.0 + */ +private: + std::shared_ptr mFactory; +public: + std::shared_ptr __attribute__((deprecated)) factory() const { return mFactory; }; + std::shared_ptr __attribute__((deprecated)) runtime() const { return mRuntime; }; }; -#define Am_CAPI CAmCommonAPIWrapper::getInstance() + +//Alias +extern CAmCommonAPIWrapper* (*getCAPI)(); + +#ifndef AMCAPI + #define AMCAPI getCAPI() +#endif + +#ifndef AM_CAPI + #define AM_CAPI getCAPI() +#endif + +#ifndef CAPI + #define CAPI getCAPI() +#endif + } diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h index fb28f78..a7e464d 100644 --- a/AudioManagerUtilities/include/CAmDltWrapper.h +++ b/AudioManagerUtilities/include/CAmDltWrapper.h @@ -25,7 +25,7 @@ #include "audiomanagertypes.h" #ifdef WITH_DLT -#include +#include namespace am { #else diff --git a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp index f486920..9bfeadb 100644 --- a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp +++ b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp @@ -1,44 +1,48 @@ /** - * SPDX license identifier: MPL-2.0 + * SPDX license identifier: MPL-2.0 * - * Copyright (C) 2012, BMW AG - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * Copyright (C) 2012, BMW AG * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 * * \copyright * This Source Code Form is subject to the terms of the * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * - * \file CAmCommonAPIWrapper.cpp - * For further information see http://www.genivi.org/. + * \file CAmCommonAPIWrapper.cpp + * For further information see http://www.genivi.org/. */ #include #include #include -#include #include -#include #include #include #include #include +#include +#include #include "audiomanagertypes.h" #include "CAmSocketHandler.h" #include "CAmDltWrapper.h" #include "CAmCommonAPIWrapper.h" +#ifndef COMMONAPI_INTERNAL_COMPILATION +#define COMMONAPI_INTERNAL_COMPILATION +#include +#undef COMMONAPI_INTERNAL_COMPILATION +#endif + + namespace am { static CAmCommonAPIWrapper* pSingleCommonAPIInstance = NULL; -using namespace CommonAPI; - CAmCommonAPIWrapper::CAmCommonAPIWrapper(CAmSocketHandler* socketHandler): pCommonPrepareCallback(this,&CAmCommonAPIWrapper::commonPrepareCallback), // pCommonDispatchCallback(this, &CAmCommonAPIWrapper::commonDispatchCallback), // @@ -49,12 +53,29 @@ CAmCommonAPIWrapper::CAmCommonAPIWrapper(CAmSocketHandler* socketHandler): mWatchToCheck(NULL) { assert(NULL!=socketHandler); -//1. Load the runtime - std::shared_ptr runtime = CommonAPI::Runtime::load(); -//2. Get the context and store a pointer to it - mContext = runtime->getNewMainLoopContext(); -//3. Make subscriptions - mDispatchSourceListenerSubscription = mContext->subscribeForDispatchSources( +//Get the runtime +#if COMMONAPI_VERSION_NUMBER < 300 + mRuntime = CommonAPI::Runtime::load(); +#else + mRuntime = CommonAPI::Runtime::get(); +#endif + assert(NULL!=mRuntime); + +//Create the context + mContext = std::make_shared(); + assert(NULL!=mContext); + +#if COMMONAPI_VERSION_NUMBER < 300 + mFactory = runtime->createFactory(mContext); + assert(mFactory); +#else + mFactory = CommonAPI::DBus::Factory::get(); + assert(mFactory); + mRuntime->registerFactory("dbus", mFactory); +#endif + +//Make subscriptions + mDispatchSourceListenerSubscription = mContext->subscribeForDispatchSources( std::bind(&CAmCommonAPIWrapper::registerDispatchSource, this, std::placeholders::_1, std::placeholders::_2), std::bind(&CAmCommonAPIWrapper::deregisterDispatchSource, this, std::placeholders::_1)); mWatchListenerSubscription = mContext->subscribeForWatches( @@ -63,20 +84,6 @@ CAmCommonAPIWrapper::CAmCommonAPIWrapper(CAmSocketHandler* socketHandler): mTimeoutSourceListenerSubscription = mContext->subscribeForTimeouts( std::bind(&CAmCommonAPIWrapper::registerTimeout, this, std::placeholders::_1, std::placeholders::_2), std::bind(&CAmCommonAPIWrapper::deregisterTimeout, this, std::placeholders::_1)); -//4. Create the factory - std::shared_ptr factory = runtime->createFactory(mContext); - assert(factory); - logInfo(__PRETTY_FUNCTION__,"CommonAPI -> Factory created"); - mFactory = factory; -//5. Get the publisher V.2.1 -// std::shared_ptr servicePublisher = runtime->getServicePublisher(); -// assert(servicePublisher); -// logInfo(__PRETTY_FUNCTION__,"CommonAPI -> Publisher available"); -//6. Instantiate your concrete stub implementations -// std::shared_ptr theStub = std::make_shared(1); -//7. Register the services -// std::string capiAddress("local:org.genivi.audiomanager.sourcestate:de.bmw.infotainment.broadcast.ta"); -// registerStub(theStub, capiAddress); } CAmCommonAPIWrapper::~CAmCommonAPIWrapper() @@ -84,10 +91,9 @@ CAmCommonAPIWrapper::~CAmCommonAPIWrapper() mContext->unsubscribeForDispatchSources(mDispatchSourceListenerSubscription); mContext->unsubscribeForWatches(mWatchListenerSubscription); mContext->unsubscribeForTimeouts(mTimeoutSourceListenerSubscription); -//The following objects must be released in the given order. mFactory.reset(); mContext.reset(); - + mRuntime.reset(); mpSocketHandler = NULL; mWatchToCheck = NULL; } @@ -112,26 +118,15 @@ CAmCommonAPIWrapper* CAmCommonAPIWrapper::getInstance() return pSingleCommonAPIInstance; } -std::shared_ptr CAmCommonAPIWrapper::factory() const -{ - return mFactory; -} - - -std::shared_ptr CAmCommonAPIWrapper::runtime() const -{ - return mFactory->getRuntime(); -} - bool CAmCommonAPIWrapper::commonDispatchCallback(const sh_pollHandle_t handle, void *userData) { (void) handle; (void) userData; - std::list::iterator iterator(mSourcesToDispatch.begin()); + std::list::iterator iterator(mSourcesToDispatch.begin()); for(;iterator!=mSourcesToDispatch.end();) { - DispatchSource* source = *iterator; + CommonAPI::DispatchSource* source = *iterator; if (!source->dispatch()) { iterator=mSourcesToDispatch.erase(iterator); } @@ -146,7 +141,7 @@ bool CAmCommonAPIWrapper::commonDispatchCallback(const sh_pollHandle_t handle, v bool CAmCommonAPIWrapper::commonCheckCallback(const sh_pollHandle_t, void *) { - std::vector vecDispatch=mWatchToCheck->getDependentDispatchSources(); + std::vector vecDispatch=mWatchToCheck->getDependentDispatchSources(); mSourcesToDispatch.insert(mSourcesToDispatch.end(), vecDispatch.begin(), vecDispatch.end()); return (mWatchToCheck || !mSourcesToDispatch.empty()); @@ -173,7 +168,7 @@ void CAmCommonAPIWrapper::commonPrepareCallback(const sh_pollHandle_t, void*) dispatchSourceIterator != mRegisteredDispatchSources.end(); dispatchSourceIterator++) { - int64_t dispatchTimeout(TIMEOUT_INFINITE); + int64_t dispatchTimeout(CommonAPI::TIMEOUT_INFINITE); if(dispatchSourceIterator->second->prepare(dispatchTimeout)) { while (dispatchSourceIterator->second->dispatch()); @@ -181,12 +176,12 @@ void CAmCommonAPIWrapper::commonPrepareCallback(const sh_pollHandle_t, void*) } } -void CAmCommonAPIWrapper::registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority) +void CAmCommonAPIWrapper::registerDispatchSource(CommonAPI::DispatchSource* dispatchSource, const CommonAPI::DispatchPriority dispatchPriority) { mRegisteredDispatchSources.insert({dispatchPriority, dispatchSource}); } -void CAmCommonAPIWrapper::deregisterDispatchSource(DispatchSource* dispatchSource) +void CAmCommonAPIWrapper::deregisterDispatchSource(CommonAPI::DispatchSource* dispatchSource) { for(auto dispatchSourceIterator = mRegisteredDispatchSources.begin(); dispatchSourceIterator != mRegisteredDispatchSources.end(); @@ -199,10 +194,9 @@ void CAmCommonAPIWrapper::deregisterDispatchSource(DispatchSource* dispatchSourc } } -void CAmCommonAPIWrapper::deregisterWatch(Watch* watch) +void CAmCommonAPIWrapper::deregisterWatch(CommonAPI::Watch* watch) { - logInfo(__PRETTY_FUNCTION__); - for(std::map::iterator iter(mMapWatches.begin());iter!=mMapWatches.end();iter++) + for(std::map::iterator iter(mMapWatches.begin());iter!=mMapWatches.end();iter++) { if (iter->second == watch) { @@ -212,9 +206,8 @@ void CAmCommonAPIWrapper::deregisterWatch(Watch* watch) } } -void CAmCommonAPIWrapper::registerTimeout(Timeout* timeout, const DispatchPriority) +void CAmCommonAPIWrapper::registerTimeout(CommonAPI::Timeout* timeout, const CommonAPI::DispatchPriority) { - logInfo(__PRETTY_FUNCTION__); timespec pollTimeout; int64_t localTimeout = timeout->getTimeoutInterval(); @@ -233,9 +226,8 @@ void CAmCommonAPIWrapper::registerTimeout(Timeout* timeout, const DispatchPriori return; } -void CAmCommonAPIWrapper::deregisterTimeout(Timeout* timeout) +void CAmCommonAPIWrapper::deregisterTimeout(CommonAPI::Timeout* timeout) { - logInfo(__PRETTY_FUNCTION__); for( std::vector::iterator iter(mpListTimerhandles.begin());iter!=mpListTimerhandles.end();iter++) { if(iter->timeout==timeout) @@ -245,7 +237,7 @@ void CAmCommonAPIWrapper::deregisterTimeout(Timeout* timeout) } } -void CAmCommonAPIWrapper::registerWatch(Watch* watch, const DispatchPriority) +void CAmCommonAPIWrapper::registerWatch(CommonAPI::Watch* watch, const CommonAPI::DispatchPriority) { logInfo(__PRETTY_FUNCTION__); pollfd pollfd_ (watch->getAssociatedFileDescriptor()); @@ -271,4 +263,6 @@ void CAmCommonAPIWrapper::commonTimerCallback(sh_timerHandle_t handle, void *) } } +CAmCommonAPIWrapper* (*getCAPI)() = CAmCommonAPIWrapper::getInstance; + } diff --git a/CMakeLists.txt b/CMakeLists.txt index 079035f..45ffe41 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,7 @@ set(DOC_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/doc CACHE STRINGS "The doxygen documentation will be placed here") set(AM_SHARE_FOLDER ${CMAKE_INSTALL_PREFIX}/share - CACHE STRINGS "The share folder for the AM. Some DBus xmls will be placed here and so on") + CACHE STRINGS "The share folder for the AM. Some DBus xmls will be placed here and so on") set(AUDIOMANAGER_INCLUDE_FOLDER ${CMAKE_BINARY_DIR}/include) set(AUDIO_INCLUDE_FOLDER ${CMAKE_SOURCE_DIR}/include) @@ -167,8 +167,6 @@ else(USE_BUILD_LIBS) endif(NOT DEFINED CONTROLLER_PLUGIN) endif(USE_BUILD_LIBS) -configure_file( ${CMAKE_SOURCE_DIR}/AudioManagerDaemon/docx/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/DoxyFile ) -configure_file( ${CMAKE_SOURCE_DIR}/cmake/config.cmake.in ${CMAKE_BINARY_DIR}/include/config.h ) if (WITH_ENABLED_IPC STREQUAL "NONE") set (ENABLE_NSM OFF) @@ -269,3 +267,6 @@ add_custom_target(test-install "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=tests -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" ) + +configure_file( ${CMAKE_SOURCE_DIR}/AudioManagerDaemon/docx/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/DoxyFile ) +configure_file( ${CMAKE_SOURCE_DIR}/cmake/config.cmake.in ${CMAKE_BINARY_DIR}/include/config.h ) diff --git a/cmake/CommonAPI.cmake b/cmake/CommonAPI.cmake new file mode 100755 index 0000000..f98bcda --- /dev/null +++ b/cmake/CommonAPI.cmake @@ -0,0 +1,291 @@ +# +# Find common-api sources +# +# This module defines these variables: +# +# ${PARAMS_TARGET}_GEN_HEADERS +# A list with generated headers +# ${PARAMS_TARGET}_GEN_SOURCES +# A list with generated sources +# ${PARAMS_TARGET}_GEN_INCLUDE_DIR +# A list with include directories + +include(CMakeParseArguments) +include(TargetArch) + +MACRO(LOAD_COMMONAPI) + #parse the input parameters + set(options DBUS SOMEIP) + set(oneValueArgs "") + set(multiValueArgs "") + cmake_parse_arguments(PARAMS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # check the binding parameter ... + if(PARAMS_DBUS) + SET(COMMONAPI_USED_BINDING 0 CACHE INTERNAL "hide this!" FORCE) + elseif(PARAMS_SOMEIP) + SET(COMMONAPI_USED_BINDING 1 CACHE INTERNAL "hide this!" FORCE) + else() + SET(COMMONAPI_USED_BINDING 0 CACHE INTERNAL "hide this!" FORCE) + endif() + # load the proper libs ... + IF(NOT CommonAPI_FOUND) + FIND_PACKAGE(CommonAPI REQUIRED) + FIND_LIBRARY(CommonAPI_LIBRARY + REQUIRED + NAMES CommonAPI + PATHS + "/usr/local/lib" + "/usr/lib" + ) + ENDIF(NOT CommonAPI_FOUND) + message(STATUS "CommonAPI Version: ${CommonAPI_VERSION}") + + string(REPLACE "." "" COMMONAPI_VERSION_NUMBER ${CommonAPI_VERSION}) + SET(COMMONAPI_VERSION_NUMBER ${COMMONAPI_VERSION_NUMBER} CACHE INTERNAL "hide this!" FORCE) + SET(CommonAPI_VERSION ${CommonAPI_VERSION} PARENT_SCOPE) + + IF(${COMMONAPI_USED_BINDING} EQUAL 1) + IF(NOT CommonAPI-SomeIP_FOUND) + FIND_PACKAGE(CommonAPI-SomeIP REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) + FIND_LIBRARY(CommonAPI-SomeIP_LIBRARY + REQUIRED + NAMES CommonAPI-SomeIP + PATHS + "/usr/local/lib" + "/usr/lib" + ) + ENDIF(NOT CommonAPI-SomeIP_FOUND) + message(STATUS "CommonAPI-SomeIP Version: ${CommonAPI-SomeIP_VERSION}") + + string(REPLACE "." "" COMMONAPI_SOMEIP_VERSION_NUMBER ${CommonAPI-SomeIP_VERSION}) + SET(COMMONAPI_SOMEIP_VERSION_NUMBER ${COMMONAPI_SOMEIP_VERSION_NUMBER} CACHE INTERNAL "hide this!" FORCE) + ELSE() + SET(COMMONAPI_USED_BINDING 0 CACHE INTERNAL "hide this!" FORCE) + IF(NOT CommonAPI-DBus_FOUND) + FIND_PACKAGE(DBUS REQUIRED) + FIND_PACKAGE(CommonAPI-DBus REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) + FIND_LIBRARY(CommonAPI-DBus_LIBRARY + REQUIRED + NAMES CommonAPI-DBus + PATHS + "/usr/local/lib" + "/usr/lib" + ) + ENDIF(NOT CommonAPI-DBus_FOUND) + message(STATUS "CommonAPI-DBus Version: ${CommonAPI-DBus_VERSION}") + + string(REPLACE "." "" COMMONAPI_DBUS_VERSION_NUMBER ${CommonAPI-DBus_VERSION}) + SET(COMMONAPI_DBUS_VERSION_NUMBER ${COMMONAPI_DBUS_VERSION_NUMBER} CACHE INTERNAL "hide this!" FORCE) + ENDIF() + +ENDMACRO() + +# helper function giving a string with the current architecture +function(GET_TARGET_ARCH OUT_ARCH) + target_architecture(TARGET_ARCH) + IF("${TARGET_ARCH}" STREQUAL "i386") + SET(${OUT_ARCH} "x86" PARENT_SCOPE) + ELSEIF("${TARGET_ARCH}" STREQUAL "x86_64") + SET(${OUT_ARCH} "x86_64" PARENT_SCOPE) + ELSE() + SET(${OUT_ARCH} "x86_64" PARENT_SCOPE) + ENDIF() +endfunction() + +# helper function giving a string with the current host +function(GET_TARGET_HOST OUT_HOST) + IF(CMAKE_HOST_WIN32) + SET(${OUT_HOST} "windows" PARENT_SCOPE) + ELSE()#CMAKE_HOST_UNIX + SET(${OUT_HOST} "linux" PARENT_SCOPE) + ENDIF() +endfunction() + +# get lists with headers and sources after they has been generated +macro(GET_GENERATED_FILES GEN_DESTINATION) + + #searching for generated headers + execute_process(COMMAND find ${GEN_DESTINATION} -name *.hpp + RESULT_VARIABLE EXIT_CODE + OUTPUT_VARIABLE _CAPI_HEADERS + ERROR_VARIABLE CAPI_HEADERS_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + + IF(CAPI_HEADERS_ERROR) + MESSAGE(FATAL_ERROR "Can't find common-api generated headers!") + ENDIF() + string(REPLACE "\n" ";" CAPI_HEADERS ${_CAPI_HEADERS}) + + FOREACH(INCLUDE_ITER ${CAPI_HEADERS}) + GET_FILENAME_COMPONENT(TEMP_PATH ${INCLUDE_ITER} PATH) + SET(CAPI_INCLUDES ${CAPI_INCLUDES} ${TEMP_PATH}) + ENDFOREACH(INCLUDE_ITER ${CAPI_HEADERS}) + LIST(REMOVE_DUPLICATES CAPI_INCLUDES) + + #searching for generated sources + execute_process(COMMAND find ${GEN_DESTINATION} -name *.cpp + RESULT_VARIABLE EXIT_CODE + OUTPUT_VARIABLE _CAPI_SOURCES + ERROR_VARIABLE CAPI_SOURCES_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + IF(CAPI_SOURCES_ERROR) + MESSAGE(FATAL_ERROR "Can't find common-api generated sources!") + ENDIF() + string(REPLACE "\n" ";" CAPI_SOURCES ${_CAPI_SOURCES}) + LIST(REMOVE_DUPLICATES CAPI_SOURCES) + + set(${PARAMS_TARGET}_GEN_HEADERS ${CAPI_HEADERS} PARENT_SCOPE) + set(${PARAMS_TARGET}_GEN_SOURCES ${CAPI_SOURCES} PARENT_SCOPE) + + #add base path src-gen + SET(${PARAMS_TARGET}_GEN_INCLUDE_DIR ${CAPI_INCLUDES} ${GEN_DESTINATION} PARENT_SCOPE) +endmacro(GET_GENERATED_FILES) + +macro(FIND_AND_EXEC_GENERATOR GENERATOR_EXECUTABLE SHOULD_GENERATE_STUB_DEFAULT) + MESSAGE(STATUS "Searching for common-api generator executable ${GENERATOR_EXECUTABLE} ...") + # find the generator binary ... + execute_process(COMMAND find "/usr/local/share/CommonAPI-${CommonAPI_VERSION}" -name ${GENERATOR_EXECUTABLE} + RESULT_VARIABLE EXIT_CODE + OUTPUT_VARIABLE OUT_RESULT + ERROR_VARIABLE OUT_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + + IF(OUT_ERROR) + # in case of error just try to find the sources in the alternative folder + SET(TEMP_GEN_DST ${PARAMS_ALT_DESTINATION}) + message(STATUS "Common-api generator error / ${OUT_ERROR} /. Will try the alternative folder!") + ELSEIF(NOT OUT_RESULT) + # in case of error just try to find the sources in the alternative folder + SET(TEMP_GEN_DST ${PARAMS_ALT_DESTINATION}) + message(STATUS "Common-api generator can't be found. Will try the alternative folder!") + ELSE() + # the generator binary is found + MESSAGE(STATUS "Will execute common-api generator at path ${OUT_RESULT}") + function(mktmpdir OUTVAR) + while(NOT TEMP_DESTINATION OR EXISTS ${TEMP_DESTINATION}) + string(RANDOM LENGTH 16 TEMP_DESTINATION) + set(TEMP_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${TEMP_DESTINATION}") + endwhile() + + file(MAKE_DIRECTORY ${TEMP_DESTINATION}) + + set(${OUTVAR} ${TEMP_DESTINATION} PARENT_SCOPE) + endfunction() + # execute the generate command ... + IF(${SHOULD_GENERATE_STUB_DEFAULT} EQUAL 1) + execute_process(COMMAND ${OUT_RESULT} -sk Default -d ${PARAMS_DESTINATION} ${FIDLS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE EXIT_CODE + OUTPUT_VARIABLE GENERATOR_OUTPUT + ERROR_VARIABLE GENERATOR_ERR_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + ELSE() + execute_process(COMMAND ${OUT_RESULT} -d ${PARAMS_DESTINATION} ${FIDLS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE EXIT_CODE + OUTPUT_VARIABLE GENERATOR_OUTPUT + ERROR_VARIABLE GENERATOR_ERR_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + ENDIF() + if(EXIT_CODE) + message(FATAL_ERROR "Failed to generate files from FIDL:${GENERATOR_OUTPUT}") + elseif(GENERATOR_ERR_OUTPUT) + message(FATAL_ERROR "Common-API generator error:${GENERATOR_ERR_OUTPUT}") + endif() + SET(TEMP_GEN_DST ${PARAMS_DESTINATION}) + ENDIF() +endmacro(FIND_AND_EXEC_GENERATOR GENERATOR_EXECUTABLE ADDITIONAL_ARGS) + +# generate common-api sources and retreive a list with them +MACRO(EXECUTE_GENERATOR) + # construct the generator binary name... + GET_TARGET_HOST(_TARGET_HOST) + GET_TARGET_ARCH(_TARGET_ARCH) + SET(COMMONAPI_GENERATOR_EXECUTABLE commonapi-generator-${_TARGET_HOST}-${_TARGET_ARCH}) + IF(${COMMONAPI_USED_BINDING} EQUAL 1) + SET(COMMONAPI_BINDING_GENERATOR_EXECUTABLE commonapi-someip-generator-${_TARGET_HOST}-${_TARGET_ARCH}) + ELSE() + SET(COMMONAPI_BINDING_GENERATOR_EXECUTABLE commonapi-dbus-generator-${_TARGET_HOST}-${_TARGET_ARCH}) + ENDIF() + # prepare an additional compatibilty flag for generators prior 3.x.x ... + IF(${COMMONAPI_VERSION_NUMBER} GREATER 300 OR ${COMMONAPI_VERSION_NUMBER} EQUAL 300) + # >= 3.x.x the stubs are generated by the binding generator + SET(GENERATE_STUB 1) + ELSE() + # < 3.0.0 the stubs are generated by the genric generator + SET(GENERATE_STUB 0) + ENDIF() + # searching for common-api-generator executable ... + FIND_AND_EXEC_GENERATOR(${COMMONAPI_GENERATOR_EXECUTABLE} ${GENERATE_STUB}) + FIND_AND_EXEC_GENERATOR(${COMMONAPI_BINDING_GENERATOR_EXECUTABLE} FALSE) + # get the lists with the sources and headers + message(STATUS "Looking for generated common-api files...") + GET_GENERATED_FILES(${TEMP_GEN_DST}) +ENDMACRO(EXECUTE_GENERATOR) + +FUNCTION(COMMON_API_GENERATE_SOUCRES) + #parse the input parameters + set(options "") + set(oneValueArgs TARGET DESTINATION ALT_DESTINATION HEADER_TEMPLATE) + set(multiValueArgs FIDLS FIDL_DEPENDS) + + cmake_parse_arguments(PARAMS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT IS_ABSOLUTE ${PARAMS_DESTINATION}) + set(PARAMS_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${PARAMS_DESTINATION}) + endif() + + if(NOT IS_ABSOLUTE ${PARAMS_ALT_DESTINATION}) + set(PARAMS_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${PARAMS_ALT_DESTINATION}) + endif() + # check the cmake option, whether to use the generator or not ... + IF(NOT WITH_COMMON_API_GEN) + message(STATUS "Looking for generated common-api files...") + # check which of the given folders exists and get it as destination + IF(EXISTS ${PARAMS_DESTINATION}) + GET_GENERATED_FILES(${PARAMS_DESTINATION}) + ELSE() + GET_GENERATED_FILES(${PARAMS_ALT_DESTINATION}) + ENDIF() + ELSE() + + if(NOT PARAMS_FIDLS) + message(FATAL_ERROR "FIDLS must be specified") + endif() + + if(NOT PARAMS_TARGET) + message(FATAL_ERROR "TARGET must be specified") + endif() + + if(PARAMS_HEADER_TEMPLATE) + list(APPEND ARGS -pref ${PARAMS_HEADER_TEMPLATE}) + endif() + + foreach(FIDL ${PARAMS_FIDLS}) + get_filename_component(FIDL_PATH ${FIDL} ABSOLUTE) + + # Run configure_file on the .fidl - this forces cmake to reexecute its + # configure phase if the input file changes. + string(MD5 ${FIDL_PATH} FIDL_CHECKSUM) + configure_file(${FIDL_PATH} ${CMAKE_CURRENT_BINARY_DIR}/${FIDL_CHECKSUM}.fidl.done) + + list(APPEND FIDLS ${FIDL_PATH}) + endforeach() + + message(STATUS "Will generate common-api files for ${PARAMS_FIDLS} ...") + + foreach(FIDL_DEPEND ${PARAMS_FIDL_DEPENDS}) + string(MD5 ${FIDL_PATH} FIDL_CHECKSUM) + configure_file(${FIDL_PATH} ${CMAKE_CURRENT_BINARY_DIR}/${FIDL_CHECKSUM}.fidl.done) + endforeach() + # run the generator ... + EXECUTE_GENERATOR() + ENDIF() +ENDFUNCTION() + diff --git a/cmake/CommonAPIGenerator.cmake b/cmake/CommonAPIGenerator.cmake deleted file mode 100755 index 332f9e6..0000000 --- a/cmake/CommonAPIGenerator.cmake +++ /dev/null @@ -1,205 +0,0 @@ -# -# Find common-api sources -# -# This module defines these variables: -# -# ${PARAMS_TARGET}_GEN_HEADERS -# A list with generated headers -# ${PARAMS_TARGET}_GEN_SOURCES -# A list with generated sources -# ${PARAMS_TARGET}_GEN_INCLUDE_DIR -# A list with include directories - -include(CMakeParseArguments) - -IF(COMMON_API_FOUND AND COMMON_API_DBUS_FOUND) - # get lists with headers and sources after they has been generated - macro(SEARCH_FOR_COMMON_API_GEN_FILES GEN_DESTINATION) - - #searching for generated headers - execute_process(COMMAND find ${GEN_DESTINATION} -name *.h - RESULT_VARIABLE EXIT_CODE - OUTPUT_VARIABLE _CAPI_HEADERS - ERROR_VARIABLE CAPI_HEADERS_ERROR - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE) - - IF(CAPI_HEADERS_ERROR) - MESSAGE(FATAL_ERROR "Can't find common-api generated headers!") - ENDIF() - string(REPLACE "\n" ";" CAPI_HEADERS ${_CAPI_HEADERS}) - - FOREACH(INCLUDE_ITER ${CAPI_HEADERS}) - GET_FILENAME_COMPONENT(TEMP_PATH ${INCLUDE_ITER} PATH) - SET(CAPI_INCLUDES ${CAPI_INCLUDES} ${TEMP_PATH}) - ENDFOREACH(INCLUDE_ITER ${CAPI_HEADERS}) - LIST(REMOVE_DUPLICATES CAPI_INCLUDES) - - #searching for generated sources - execute_process(COMMAND find ${GEN_DESTINATION} -name *.cpp - RESULT_VARIABLE EXIT_CODE - OUTPUT_VARIABLE _CAPI_SOURCES - ERROR_VARIABLE CAPI_SOURCES_ERROR - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE) - IF(CAPI_SOURCES_ERROR) - MESSAGE(FATAL_ERROR "Can't find common-api generated sources!") - ENDIF() - string(REPLACE "\n" ";" CAPI_SOURCES ${_CAPI_SOURCES}) - LIST(REMOVE_DUPLICATES CAPI_SOURCES) - - set(${PARAMS_TARGET}_GEN_HEADERS ${CAPI_HEADERS} PARENT_SCOPE) - set(${PARAMS_TARGET}_GEN_SOURCES ${CAPI_SOURCES} PARENT_SCOPE) - - #add base path src-gen - SET(${PARAMS_TARGET}_GEN_INCLUDE_DIR ${CAPI_INCLUDES} ${GEN_DESTINATION} PARENT_SCOPE) - endmacro() - - # generate common-api sources and retreive a list with them - macro(GENERATE_FILES) - - - # searching for common-api-generator executable ... - FIND_PATH(COMMONAPI_GENERATOR_JAR - NAMES - "common-api-generator.jar" - PATH_SUFFIXES - CommonAPI-${COMMON_API_VERSION} - PATHS - "/usr/share" - "/usr/local/share") - - FIND_PATH(COMMONAPI_GENERATOR_EXE - NAMES - "commonapi_generator" - PATH_SUFFIXES - CommonAPI-${COMMON_API_VERSION} - PATHS - "~" - "/usr/share" - "/usr/local/share") - - if(COMMONAPI_GENERATOR_JAR) - # load java runtime ... - find_package(Java COMPONENTS Runtime REQUIRED QUIET) - function(mktmpdir OUTVAR) - while(NOT TEMP_DESTINATION OR EXISTS ${TEMP_DESTINATION}) - string(RANDOM LENGTH 16 TEMP_DESTINATION) - set(TEMP_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${TEMP_DESTINATION}") - endwhile() - - file(MAKE_DIRECTORY ${TEMP_DESTINATION}) - - set(${OUTVAR} ${TEMP_DESTINATION} PARENT_SCOPE) - endfunction() - # execute the generate command ... - execute_process(COMMAND ${Java_JAVA_EXECUTABLE} -jar "${COMMONAPI_GENERATOR_JAR}/common-api-generator.jar" -dest ${PARAMS_DESTINATION} ${ARGS} ${FIDLS} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE EXIT_CODE - OUTPUT_VARIABLE GENERATOR_OUTPUT - ERROR_VARIABLE GENERATOR_OUTPUT - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE) - if(EXIT_CODE) - message(FATAL_ERROR "Failed to generate files from FIDL:\n ${GENERATOR_OUTPUT}") - endif() - SET(TEMP_GEN_DST ${PARAMS_DESTINATION}) - elseif(COMMONAPI_GENERATOR_EXE) - # load executable - function(mktmpdir OUTVAR) - while(NOT TEMP_DESTINATION OR EXISTS ${TEMP_DESTINATION}) - string(RANDOM LENGTH 16 TEMP_DESTINATION) - set(TEMP_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${TEMP_DESTINATION}") - endwhile() - - file(MAKE_DIRECTORY ${TEMP_DESTINATION}) - - set(${OUTVAR} ${TEMP_DESTINATION} PARENT_SCOPE) - endfunction() - - # execute the generate command ... - execute_process(COMMAND ${COMMONAPI_GENERATOR_EXE}/commonapi_generator -dest ${PARAMS_DESTINATION} ${ARGS} ${FIDLS} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - RESULT_VARIABLE EXIT_CODE - OUTPUT_VARIABLE GENERATOR_OUTPUT - ERROR_VARIABLE GENERATOR_OUTPUT - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE) - if(EXIT_CODE) - message(FATAL_ERROR "Failed to generate files from FIDL:\n ${GENERATOR_OUTPUT}") - endif() - SET(TEMP_GEN_DST ${PARAMS_DESTINATION}) - else() - # if the generator is not found, try to find the sources in the alternative folder - SET(TEMP_GEN_DST ${PARAMS_ALT_DESTINATION}) - message(STATUS "Couldn't find a common-api generator...skiping generation!") - endif() - # get the lists with the sources and headers - message(STATUS "Looking for available common-api generated files...") - SEARCH_FOR_COMMON_API_GEN_FILES(${TEMP_GEN_DST}) - endmacro() - - function(COMMON_API_GENERATE_SOUCRES) - #parse the input parameters - set(options DBUS) - set(oneValueArgs TARGET DESTINATION ALT_DESTINATION HEADER_TEMPLATE) - set(multiValueArgs FIDLS FIDL_DEPENDS) - - cmake_parse_arguments(PARAMS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT IS_ABSOLUTE ${PARAMS_DESTINATION}) - set(PARAMS_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${PARAMS_DESTINATION}) - endif() - - if(NOT IS_ABSOLUTE ${PARAMS_ALT_DESTINATION}) - set(PARAMS_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${PARAMS_ALT_DESTINATION}) - endif() - # check the cmake option, whether to use the generator or not ... - IF(NOT WITH_COMMON_API_GEN) - message(STATUS "Looking for available common-api generated files...") - # check which of the given folders exists and get it as destination - IF(EXISTS ${PARAMS_DESTINATION}) - SEARCH_FOR_COMMON_API_GEN_FILES(${PARAMS_DESTINATION}) - ELSE() - SEARCH_FOR_COMMON_API_GEN_FILES(${PARAMS_ALT_DESTINATION}) - ENDIF() - ELSE() - message(STATUS "Will generate common-api files...") - if(NOT PARAMS_FIDLS) - message(FATAL_ERROR "FIDLS must be specified") - endif() - - if(NOT PARAMS_TARGET) - message(FATAL_ERROR "TARGET must be specified") - endif() - - if(PARAMS_DBUS) - list(APPEND ARGS -dbus) - endif() - - if(PARAMS_HEADER_TEMPLATE) - list(APPEND ARGS -pref ${PARAMS_HEADER_TEMPLATE}) - endif() - - foreach(FIDL ${PARAMS_FIDLS}) - get_filename_component(FIDL_PATH ${FIDL} ABSOLUTE) - - # Run configure_file on the .fidl - this forces cmake to reexecute its - # configure phase if the input file changes. - string(MD5 ${FIDL_PATH} FIDL_CHECKSUM) - configure_file(${FIDL_PATH} ${CMAKE_CURRENT_BINARY_DIR}/${FIDL_CHECKSUM}.fidl.done) - - list(APPEND FIDLS ${FIDL_PATH}) - endforeach() - - message(STATUS "Determining list of generated files for ${PARAMS_FIDLS}") - - foreach(FIDL_DEPEND ${PARAMS_FIDL_DEPENDS}) - string(MD5 ${FIDL_PATH} FIDL_CHECKSUM) - configure_file(${FIDL_PATH} ${CMAKE_CURRENT_BINARY_DIR}/${FIDL_CHECKSUM}.fidl.done) - endforeach() - GENERATE_FILES() - ENDIF() - endfunction() - -ENDIF(COMMON_API_FOUND AND COMMON_API_DBUS_FOUND) diff --git a/cmake/FindCommonAPI.cmake b/cmake/FindCommonAPI.cmake deleted file mode 100644 index 958b729..0000000 --- a/cmake/FindCommonAPI.cmake +++ /dev/null @@ -1,72 +0,0 @@ -# -# Copyright (C) 2012, BMW AG -# -# \author Christian Linke -# - -include(UsePkgConfig) - -pkg_check_modules(COMMON_API CommonAPI) -IF(COMMON_API_FOUND) - FIND_PATH(COMMON_API_INCLUDE_DIR - NAMES CommonAPI/Runtime.h CommonAPI/Proxy.h - PATH_SUFFIXES CommonAPI-${COMMON_API_VERSION} - PATHS - ${COMMON_API_INCLUDE_DIRS} - "/usr/local/include" - "/usr/include") - - FIND_LIBRARY(COMMON_API_LIBRARY - NAMES CommonAPI - PATHS - "/usr/local/lib" - "/usr/lib" - ) -ENDIF(COMMON_API_FOUND) - -pkg_check_modules(COMMON_API_DBUS CommonAPI-DBus) -IF(COMMON_API_DBUS_FOUND) - FIND_PATH(COMMON_API_DBUS_INCLUDE_DIR - NAMES CommonAPI/DBus/DBusRuntime.h CommonAPI/DBus/DBusProxy.h - PATH_SUFFIXES CommonAPI-${COMMON_API_VERSION} - PATHS - ${COMMON_API_DBUS_INCLUDE_DIRS} - "/usr/local/include" - "/usr/include") - - FIND_LIBRARY(COMMON_API_DBUS_LIBRARY - NAMES CommonAPI-DBus murmurhash-internal - PATHS - "/usr/local/lib" - "/usr/lib" - ) -ENDIF(COMMON_API_DBUS_FOUND) - - -SET(COMMON_API_LIBRARIES ${COMMON_API_LIBRARY}) - -IF(COMMON_API_INCLUDE_DIR AND COMMON_API_LIBRARY) - message(STATUS "Found CommonAPI ${COMMON_API_VERSION}") -ELSE(COMMON_API_LIBRARIES AND COMMON_API_LIBRARY) - message(STATUS " CommonAPI not found.") -ENDIF(COMMON_API_INCLUDE_DIR AND COMMON_API_LIBRARY) - -SET(COMMON_API_DBUS_LIBRARIES ${COMMON_API_DBUS_LIBRARY}) - -IF(COMMON_API_DBUS_INCLUDE_DIR AND COMMON_API_DBUS_LIBRARY) - message(STATUS "Found CommonAPI_DBUS") -ELSE(COMMON_API_DBUS_INCLUDE_DIR AND COMMON_API_DBUS_LIBRARY) - message(STATUS " CommonAPI_DBUS not found.") -ENDIF(COMMON_API_DBUS_INCLUDE_DIR AND COMMON_API_DBUS_LIBRARY) - -MARK_AS_ADVANCED( - COMMON_API_DBUS_LIBRARIES - COMMON_API_DBUS_INCLUDE_DIR -) - -MARK_AS_ADVANCED( - COMMON_API_LIBRARIES - COMMON_API_INCLUDE_DIR - COMMON_API_GEN_INCLUDE_DIR - COMMON_API_GEN_SOURCES -) diff --git a/cmake/TargetArch.cmake b/cmake/TargetArch.cmake new file mode 100644 index 0000000..3761e4d --- /dev/null +++ b/cmake/TargetArch.cmake @@ -0,0 +1,134 @@ +# Based on the Qt 5 processor detection code, so should be very accurate +# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h +# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64) + +# Regarding POWER/PowerPC, just as is noted in the Qt source, +# "There are many more known variants/revisions that we do not handle/detect." + +set(archdetect_c_code " +#if defined(__arm__) || defined(__TARGET_ARCH_ARM) + #if defined(__ARM_ARCH_7__) \\ + || defined(__ARM_ARCH_7A__) \\ + || defined(__ARM_ARCH_7R__) \\ + || defined(__ARM_ARCH_7M__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7) + #error cmake_ARCH armv7 + #elif defined(__ARM_ARCH_6__) \\ + || defined(__ARM_ARCH_6J__) \\ + || defined(__ARM_ARCH_6T2__) \\ + || defined(__ARM_ARCH_6Z__) \\ + || defined(__ARM_ARCH_6K__) \\ + || defined(__ARM_ARCH_6ZK__) \\ + || defined(__ARM_ARCH_6M__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6) + #error cmake_ARCH armv6 + #elif defined(__ARM_ARCH_5TEJ__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5) + #error cmake_ARCH armv5 + #else + #error cmake_ARCH arm + #endif +#elif defined(__i386) || defined(__i386__) || defined(_M_IX86) + #error cmake_ARCH i386 +#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) + #error cmake_ARCH x86_64 +#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) + #error cmake_ARCH ia64 +#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\ + || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\ + || defined(_M_MPPC) || defined(_M_PPC) + #if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__) + #error cmake_ARCH ppc64 + #else + #error cmake_ARCH ppc + #endif +#endif + +#error cmake_ARCH unknown +") + +# Set ppc_support to TRUE before including this file or ppc and ppc64 +# will be treated as invalid architectures since they are no longer supported by Apple + +function(target_architecture output_var) + if(APPLE AND CMAKE_OSX_ARCHITECTURES) + # On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set + # First let's normalize the order of the values + + # Note that it's not possible to compile PowerPC applications if you are using + # the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we + # disable it by default + # See this page for more information: + # http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4 + + # Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime. + # On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise. + + foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES}) + if("${osx_arch}" STREQUAL "ppc" AND ppc_support) + set(osx_arch_ppc TRUE) + elseif("${osx_arch}" STREQUAL "i386") + set(osx_arch_i386 TRUE) + elseif("${osx_arch}" STREQUAL "x86_64") + set(osx_arch_x86_64 TRUE) + elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support) + set(osx_arch_ppc64 TRUE) + else() + message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}") + endif() + endforeach() + + # Now add all the architectures in our normalized order + if(osx_arch_ppc) + list(APPEND ARCH ppc) + endif() + + if(osx_arch_i386) + list(APPEND ARCH i386) + endif() + + if(osx_arch_x86_64) + list(APPEND ARCH x86_64) + endif() + + if(osx_arch_ppc64) + list(APPEND ARCH ppc64) + endif() + else() + file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}") + + enable_language(C) + + # Detect the architecture in a rather creative way... + # This compiles a small C program which is a series of ifdefs that selects a + # particular #error preprocessor directive whose message string contains the + # target architecture. The program will always fail to compile (both because + # file is not a valid C program, and obviously because of the presence of the + # #error preprocessor directives... but by exploiting the preprocessor in this + # way, we can detect the correct target architecture even when cross-compiling, + # since the program itself never needs to be run (only the compiler/preprocessor) + try_run( + run_result_unused + compile_result_unused + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}/arch.c" + COMPILE_OUTPUT_VARIABLE ARCH + CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + ) + + # Parse the architecture name from the compiler output + string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}") + + # Get rid of the value marker leaving just the architecture name + string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}") + + # If we are compiling with an unknown architecture this variable should + # already be set to "unknown" but in the case that it's empty (i.e. due + # to a typo in the code), then set it to unknown + if (NOT ARCH) + set(ARCH unknown) + endif() + endif() + + set(${output_var} "${ARCH}" PARENT_SCOPE) +endfunction() diff --git a/cmake/audiomanagerConfig.cmake.in b/cmake/audiomanagerConfig.cmake.in index c51729e..fa992ce 100644 --- a/cmake/audiomanagerConfig.cmake.in +++ b/cmake/audiomanagerConfig.cmake.in @@ -32,6 +32,8 @@ set(AUDIOMANAGER_UTILITIES_SRC "@AUDIOMANAGER_UTILITIES_SRC@") set(WITH_COMMON_API_GEN "@WITH_COMMON_API_GEN@") set(WRITE_COMMONAPI_DBUS_CONFIG_FILE "@WRITE_COMMONAPI_DBUS_CONFIG_FILE@") set(TCLAP_INCLUDE_DIR "@TCLAP_INCLUDE_DIR@") +set(COMMONAPI_VERSION_NUMBER "@COMMONAPI_VERSION_NUMBER@") +set(COMMONAPI_DBUS_VERSION_NUMBER "@COMMONAPI_DBUS_VERSION_NUMBER@") IF(WITH_TESTS) diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index fcfdc7f..3e1095f 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -32,6 +32,8 @@ #cmakedefine NSM_INTERFACE "@NSM_INTERFACE@" #cmakedefine NSM_INTROSPECTION_FILE "@NSM_INTROSPECTION_FILE@" #cmakedefine AM_SHARE_FOLDER "@AM_SHARE_FOLDER@" +#cmakedefine COMMONAPI_VERSION_NUMBER @COMMONAPI_VERSION_NUMBER@ +#cmakedefine COMMONAPI_DBUS_VERSION_NUMBER @COMMONAPI_DBUS_VERSION_NUMBER@ enum { DYNAMIC_ID_BOUNDARY = @DYNAMIC_ID_BOUNDARY@ }; -- cgit v1.2.1