* AmMapHanlderTest - added tests for the callbacks in CAmDatabaseObserver.
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / include / CAmNodeStateCommunicatorCAPI.h
1 /**
2  * Copyright (C) 2012, BMW AG
3  *
4  * This file is part of GENIVI Project AudioManager.
5  *
6  * Contributions are licensed to the GENIVI Alliance under one or more
7  * Contribution License Agreements.
8  *
9  * \copyright
10  * This Source Code Form is subject to the terms of the
11  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
12  * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  *
15  * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
16  *
17  * \file CAmNodeStateCommunicatorCAPI.h
18  * For further information see http://www.genivi.org/.
19  *
20  */
21 #ifndef CAMNODESTATECOMMUNICATORCAPI_H_
22 #define CAMNODESTATECOMMUNICATORCAPI_H_
23
24 #include <org/genivi/NodeStateManager/Consumer/ConsumerProxy.h>
25 #include "CAmNodeStateCommunicator.h"
26 #include "LifeCycleConsumerStubDefault.h"
27
28 namespace am
29 {
30 using namespace CommonAPI;
31 using namespace org::genivi::NodeStateManager::Consumer;
32 using namespace org::genivi::NodeStateManager::LifeCycleConsumer;
33
34
35 class CAmCommonAPIWrapper;
36 /** communicates with the NSM
37  *  The CAmNodeStateCommunicator communicates with the NodeStateManager via Dbus Common-API's wrapping mechanism. Only works, if CAmCommonAPIWrapper is enabled.
38  */
39 class CAmNodeStateCommunicatorCAPI : public CAmNodeStateCommunicator
40 {
41         /* A concrete implementation of the life cycle stub.
42          * An object from this class is instantiated from the common-api factory.
43          * It forwards the invocations to its delegate CAmNodeStateCommunicatorCAPI.
44         */
45         class CAmNodeStateCommunicatorServiceImpl : public LifeCycleConsumerStubDefault
46         {
47                 CAmNodeStateCommunicatorCAPI *mpDelegate;
48         public:
49                 CAmNodeStateCommunicatorServiceImpl ():mpDelegate(NULL) {}
50                 CAmNodeStateCommunicatorServiceImpl (CAmNodeStateCommunicatorCAPI *aNSCommunicator):mpDelegate(aNSCommunicator) {}
51                 ~CAmNodeStateCommunicatorServiceImpl() { mpDelegate = NULL; }
52
53                 CAmNodeStateCommunicatorCAPI *getDelegate() { return mpDelegate; };
54                 void setDelegate(CAmNodeStateCommunicatorCAPI *aDelegate) { mpDelegate = aDelegate; };
55
56                 void LifecycleRequest(uint32_t Request, uint32_t RequestId, int32_t& ErrorCode) {
57                    if(mpDelegate)
58                            mpDelegate->cbReceivedLifecycleRequest(Request, RequestId, ErrorCode);
59                 }
60         };
61
62         CAmCommonAPIWrapper *mpCAPIWrapper;
63         std::shared_ptr<ConsumerProxy<> > mNSMProxy;
64         std::shared_ptr<CAmNodeStateCommunicatorCAPI::CAmNodeStateCommunicatorServiceImpl> mNSMStub;
65 public:
66         CAmNodeStateCommunicatorCAPI(CAmCommonAPIWrapper* iCAPIWrapper);
67     virtual ~CAmNodeStateCommunicatorCAPI();
68
69     am_Error_e nsmGetRestartReasonProperty(NsmRestartReason_e& restartReason) ;
70     am_Error_e nsmGetShutdownReasonProperty(NsmShutdownReason_e& ShutdownReason) ;
71     am_Error_e nsmGetRunningReasonProperty(NsmRunningReason_e& nsmRunningReason) ;
72     NsmErrorStatus_e nsmGetNodeState(NsmNodeState_e& nsmNodeState) ;
73     NsmErrorStatus_e nsmGetSessionState(const std::string& sessionName, const NsmSeat_e& seatID, NsmSessionState_e& sessionState) ;
74     NsmErrorStatus_e nsmGetApplicationMode(NsmApplicationMode_e& applicationMode) ;
75     NsmErrorStatus_e nsmRegisterShutdownClient(const uint32_t shutdownMode, const uint32_t timeoutMs) ;
76     NsmErrorStatus_e nsmUnRegisterShutdownClient(const uint32_t shutdownMode) ;
77     am_Error_e nsmGetInterfaceVersion(uint32_t& version) ;
78     NsmErrorStatus_e nsmSendLifecycleRequestComplete(const uint32_t RequestId, const NsmErrorStatus_e status) ;
79
80     bool isServiceAvailable();
81
82     static const char * CLIENT_STRING;
83     static const char * SERVER_STRING;
84     static const char * OBJECT_NAME;
85     static const char * BUS_NAME;
86
87 private:
88     /* Client events */
89     void onNodeStateEvent(const int32_t nodeState);
90     void onNodeApplicationModeEvent(const int32_t nodeApplicationMode);
91     void onSessionStateChangedEvent(const std::string & sessionName, const int32_t seatID, const int32_t sessionState);
92     void onServiceStatusEvent(const CommonAPI::AvailabilityStatus& serviceStatus);
93     /* Service callbacks */
94     void cbReceivedLifecycleRequest(uint32_t Request, uint32_t RequestId, int32_t& ErrorCode);
95 protected:
96     bool mIsServiceAvailable;
97 };
98
99 }
100 /* namespace am */
101 #endif /* CAMNODESTATECOMMUNICATORCAPI_H_ */