summaryrefslogtreecommitdiff
path: root/AudioManagerCore/src/CAmCommandReceiver.cpp
blob: 8b60c66ef9296f4a027dd712d972d38d9abecaa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
 * SPDX license identifier: MPL-2.0
 *
 * Copyright (C) 2012, BMW AG
 *
 * This file is part of GENIVI Project AudioManager.
 *
 * Contributions are licensed to the GENIVI Alliance under one or more
 * Contribution License Agreements.
 *
 * \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/.
 *
 *
 * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012
 *
 * \file CAmCommandReceiver.cpp
 * For further information see http://www.genivi.org/.
 *
 */

#include "CAmCommandReceiver.h"
#include <cassert>
#include <algorithm>
#include "IAmDatabaseHandler.h"
#include "CAmControlSender.h"
#include "CAmDltWrapper.h"
#include "CAmSocketHandler.h"

#define __METHOD_NAME__ std::string (std::string("CAmCommandReceiver::") + __func__)

namespace am
{

CAmCommandReceiver::CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) :
        mDatabaseHandler(iDatabaseHandler),
        mControlSender(iControlSender),
        mDBusWrapper(NULL),
        mSocketHandler(iSocketHandler),
        handleCount(0),
        mListStartupHandles(),
        mListRundownHandles(),
        mWaitStartup(false),
        mWaitRundown(false),
        mLastErrorStartup(E_OK),
        mLastErrorRundown(E_OK)

{
    assert(mDatabaseHandler!=NULL);
    assert(mSocketHandler!=NULL);
    assert(mControlSender!=NULL);
}

CAmCommandReceiver::CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) :
        mDatabaseHandler(iDatabaseHandler),
        mControlSender(iControlSender),
        mDBusWrapper(iDBusWrapper),
        mSocketHandler(iSocketHandler),
        handleCount(0),
        mListStartupHandles(),
        mListRundownHandles(),
        mWaitStartup(false),
        mWaitRundown(false),
        mLastErrorStartup(E_UNKNOWN),
        mLastErrorRundown(E_UNKNOWN)
{
    assert(mDatabaseHandler!=NULL);
    assert(mSocketHandler!=NULL);
    assert(mControlSender!=NULL);
    assert(mDBusWrapper!=NULL);
}

CAmCommandReceiver::~CAmCommandReceiver()
{
}

am_Error_e CAmCommandReceiver::connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID)
{
    logInfo(__METHOD_NAME__,"sourceID=", sourceID, "sinkID=", sinkID);
    return (mControlSender->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID));
}

am_Error_e CAmCommandReceiver::disconnect(const am_mainConnectionID_t mainConnectionID)
{
    logInfo(__METHOD_NAME__,"mainConnectionID=", mainConnectionID);
    return (mControlSender->hookUserDisconnectionRequest(mainConnectionID));
}

am_Error_e CAmCommandReceiver::setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume)
{
    logInfo(__METHOD_NAME__,"sinkID=", sinkID, "volume=", volume);
    return (mControlSender->hookUserVolumeChange(sinkID, volume));
}

am_Error_e CAmCommandReceiver::volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep)
{
    logInfo(__METHOD_NAME__,"sinkID=", sinkID, "volumeStep=", volumeStep);
    return (mControlSender->hookUserVolumeStep(sinkID, volumeStep));
}

am_Error_e CAmCommandReceiver::setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState)
{
    logInfo(__METHOD_NAME__,"sinkID=", sinkID, "muteState=", muteState);
    return (mControlSender->hookUserSetSinkMuteState(sinkID, muteState));
}

am_Error_e CAmCommandReceiver::setMainSinkSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
{
    logInfo(__METHOD_NAME__,"sinkID=", sinkID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
    return (mControlSender->hookUserSetMainSinkSoundProperty(sinkID, soundProperty));
}

am_Error_e CAmCommandReceiver::setMainSourceSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
{
    logInfo(__METHOD_NAME__,"sourceID=", sourceID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
    return (mControlSender->hookUserSetMainSourceSoundProperty(sourceID, soundProperty));
}

am_Error_e CAmCommandReceiver::setSystemProperty(const am_SystemProperty_s & property)
{
    logInfo(__METHOD_NAME__,"type=", property.type, "systemPropertyValue=", property.value);
    return (mControlSender->hookUserSetSystemProperty(property));
}

am_Error_e CAmCommandReceiver::getVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const
{
    return (mDatabaseHandler->getSinkMainVolume(sinkID, mainVolume));
}

am_Error_e CAmCommandReceiver::getListMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
{
    return (mDatabaseHandler->getListVisibleMainConnections(listConnections));
}

am_Error_e CAmCommandReceiver::getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const
{
    return (mDatabaseHandler->getListMainSinks(listMainSinks));
}

am_Error_e CAmCommandReceiver::getListMainSources(std::vector<am_SourceType_s>& listMainSources) const
{
    return (mDatabaseHandler->getListMainSources(listMainSources));
}

am_Error_e CAmCommandReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
{
    return (mDatabaseHandler->getListMainSinkSoundProperties(sinkID, listSoundProperties));
}

am_Error_e CAmCommandReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
{
    return (mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSourceProperties));
}

am_Error_e CAmCommandReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
{
    return (mDatabaseHandler->getListSourceClasses(listSourceClasses));
}

am_Error_e CAmCommandReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
{
    return (mDatabaseHandler->getListSinkClasses(listSinkClasses));
}

am_Error_e CAmCommandReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
{
    return (mDatabaseHandler->getListSystemProperties(listSystemProperties));
}

am_Error_e CAmCommandReceiver::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
{
    return (mDatabaseHandler->getTimingInformation(mainConnectionID, delay));
}

am_Error_e CAmCommandReceiver::getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const
{
#ifdef WITH_DBUS_WRAPPER
    dbusConnectionWrapper = mDBusWrapper;
    return (E_OK);
#else
    dbusConnectionWrapper = NULL;
    return (E_UNKNOWN);
#endif /*WITH_DBUS_WRAPPER*/
}

am_Error_e CAmCommandReceiver::getSocketHandler(CAmSocketHandler *& socketHandler) const
{
    socketHandler = mSocketHandler;
    return (E_OK);
}

void CAmCommandReceiver::getInterfaceVersion(std::string & version) const
{
    version = CommandVersion;
}

void CAmCommandReceiver::confirmCommandReady(const uint16_t handle, const am_Error_e error)
{
	if (error !=E_OK)
		mLastErrorStartup=error;
    mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end());
    if (mWaitStartup && mListStartupHandles.empty())
        mControlSender->confirmCommandReady(mLastErrorStartup);
}

void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle, const am_Error_e error)
{
	if (error !=E_OK)
		mLastErrorRundown=error;
    mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end());
    if (mWaitRundown && mListRundownHandles.empty())
        mControlSender->confirmCommandRundown(mLastErrorRundown);
}

uint16_t CAmCommandReceiver::getStartupHandle()
{
    uint16_t handle = ++handleCount; //todo: handle overflow
    mListStartupHandles.push_back(handle);
    return (handle);
}

uint16_t CAmCommandReceiver::getRundownHandle()
{
    uint16_t handle = ++handleCount; //todo: handle overflow
    mListRundownHandles.push_back(handle);
    return (handle);
}

void CAmCommandReceiver::waitOnStartup(bool startup)
{
    mWaitStartup = startup;
    mLastErrorStartup=E_OK;
}

am_Error_e CAmCommandReceiver::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const
{
    return (mDatabaseHandler->getListMainSinkNotificationConfigurations(sinkID,listMainNotificationConfigurations));
}

am_Error_e CAmCommandReceiver::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const
{
    return (mDatabaseHandler->getListMainSourceNotificationConfigurations(sourceID,listMainNotificationConfigurations));
}

am_Error_e CAmCommandReceiver::setMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration)
{
    logInfo(__METHOD_NAME__,"sinkID=", sinkID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status);
    return (mControlSender->hookUserSetMainSinkNotificationConfiguration(sinkID,mainNotificationConfiguration));
}

am_Error_e CAmCommandReceiver::setMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration)
{
    logInfo(__METHOD_NAME__,"sourceID=", sourceID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status);
    return (mControlSender->hookUserSetMainSourceNotificationConfiguration(sourceID,mainNotificationConfiguration));
}

void CAmCommandReceiver::waitOnRundown(bool rundown)
{
    mWaitRundown = rundown;
    mLastErrorStartup=E_OK;
}

}