2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file Databasehandler.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG Christian Mueller Christian.ei.mueller@bmw.de
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
25 #include "DatabaseHandler.h"
26 #include "DatabaseObserver.h"
35 #define DOMAIN_TABLE "Domains"
36 #define SOURCE_CLASS_TABLE "SourceClasses"
37 #define SINK_CLASS_TABLE "SinkClasses"
38 #define SOURCE_TABLE "Sources"
39 #define SINK_TABLE "Sinks"
40 #define GATEWAY_TABLE "Gateways"
41 #define CROSSFADER_TABLE "Crossfaders"
42 #define CONNECTION_TABLE "Connections"
43 #define MAINCONNECTION_TABLE "MainConnections"
44 #define INTERRUPT_TABLE "Interrupts"
45 #define MAIN_TABLE "MainTable"
46 #define SYSTEM_TABLE "SystemProperties"
48 DLT_IMPORT_CONTEXT(AudioManager)
52 const std::string databaseTables[] =
54 " Domains (domainID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), busname VARCHAR(50), nodename VARCHAR(50), early BOOL, complete BOOL, state INTEGER, reserved BOOL);", " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));",
55 " Sources (sourceID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, domainID INTEGER, name VARCHAR(50), sourceClassID INTEGER, sourceState INTEGER, volume INTEGER, visible BOOL, availability INTEGER, availabilityReason INTEGER, interruptState INTEGER, reserved BOOL);", //
56 " Sinks (sinkID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), domainID INTEGER, sinkClassID INTEGER, volume INTEGER, visible BOOL, availability INTEGER, availabilityReason INTEGER, muteState INTEGER, mainVolume INTEGER, reserved BOOL);", " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER, inUse BOOL);", " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);",
57 " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);", //
58 " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);", " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);" };
61 * template to converts T to std::string
62 * @param i the value to be converted
66 inline std::string i2s(T const& x)
73 DatabaseHandler::DatabaseHandler(std::string databasePath) :
75 mPath(databasePath), //
76 mDatabaseObserver(NULL), //
77 mFirstStaticSink(true), //
78 mFirstStaticSource(true), //
79 mFirstStaticGateway(true), //
80 mFirstStaticSinkClass(true), //
81 mFirstStaticSourceClass(true), //
82 mListConnectionFormat()
86 *\todo: this erases the database. just for testing!
88 std::ifstream infile(mPath.c_str());
92 remove(mPath.c_str());
93 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::DatabaseHandler Knocked down database"));
96 bool dbOpen = openDatabase();
99 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::DatabaseHandler problems opening the database!"));
106 DatabaseHandler::~DatabaseHandler()
108 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("Closed Database"));
109 sqlite3_close(mDatabase);
112 am_Error_e DatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
114 assert(domainData.domainID==0);
115 assert(!domainData.name.empty());
116 assert(!domainData.busname.empty());
117 assert(domainData.state>=DS_CONTROLLED && domainData.state<=DS_INDEPENDENT_RUNDOWN);
119 //first check for a reserved domain
120 sqlite3_stmt* query = NULL, *queryFinal;
122 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
123 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
124 sqlite3_bind_text(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC);
125 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
127 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" + i2s(sqlite3_column_int(query, 0));
129 else if (eCode == SQLITE_DONE)
132 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)";
136 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Step error code:"), DLT_INT(eCode));
137 return E_DATABASE_ERROR;
140 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
142 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Finalize error code:"), DLT_INT(eCode));
143 return E_DATABASE_ERROR;
146 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
147 sqlite3_bind_text(queryFinal, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC);
148 sqlite3_bind_text(queryFinal, 2, domainData.busname.c_str(), domainData.busname.size(), SQLITE_STATIC);
149 sqlite3_bind_text(queryFinal, 3, domainData.nodename.c_str(), domainData.nodename.size(), SQLITE_STATIC);
150 sqlite3_bind_int(queryFinal, 4, domainData.early);
151 sqlite3_bind_int(queryFinal, 5, domainData.complete);
152 sqlite3_bind_int(queryFinal, 6, domainData.state);
153 sqlite3_bind_int(queryFinal, 7, 0);
155 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
157 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Step error code:"), DLT_INT(eCode));
158 return E_DATABASE_ERROR;
161 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
163 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Finalize error code:"), DLT_INT(eCode));
164 return E_DATABASE_ERROR;
167 domainID = sqlite3_last_insert_rowid(mDatabase);
168 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterDomainDB entered new domain with name"), DLT_STRING(domainData.name.c_str()), DLT_STRING("busname:"), DLT_STRING(domainData.busname.c_str()), DLT_STRING("nodename:"), DLT_STRING(domainData.nodename.c_str()), DLT_STRING("early:"), DLT_BOOL(domainData.early), DLT_STRING("complete:"), DLT_BOOL(domainData.complete), DLT_STRING("state:"), DLT_INT(domainData.state), DLT_STRING("assigned ID:"), DLT_INT16(domainID));
170 am_Domain_s domain = domainData;
171 domain.domainID = domainID;
172 if (mDatabaseObserver)
173 mDatabaseObserver->newDomain(domain);
178 am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
180 assert(mainConnectionData.connectionID==0);
181 assert(mainConnectionData.connectionState>=CS_CONNECTING && mainConnectionData.connectionState<=CS_SUSPENDED);
182 assert(mainConnectionData.route.sinkID!=0);
183 assert(mainConnectionData.route.sourceID!=0);
185 sqlite3_stmt* query = NULL;
187 std::string command = "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)";
188 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
189 sqlite3_bind_int(query, 1, mainConnectionData.route.sourceID);
190 sqlite3_bind_int(query, 2, mainConnectionData.route.sinkID);
191 sqlite3_bind_int(query, 3, mainConnectionData.connectionState);
193 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
195 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"), DLT_INT(eCode));
196 return E_DATABASE_ERROR;
199 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
201 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"), DLT_INT(eCode));
202 return E_DATABASE_ERROR;
205 connectionID = sqlite3_last_insert_rowid(mDatabase);
207 //now check the connectionTable for all connections in the route. IF a particular route is not found, we return with error
208 std::vector<uint16_t> listOfConnections;
210 command = "SELECT connectionID, delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
211 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
212 std::vector<am_RoutingElement_s>::const_iterator elementIterator = mainConnectionData.route.route.begin();
213 for (; elementIterator < mainConnectionData.route.route.end(); ++elementIterator)
215 sqlite3_bind_int(query, 1, elementIterator->sourceID);
216 sqlite3_bind_int(query, 2, elementIterator->sinkID);
217 sqlite3_bind_int(query, 3, elementIterator->connectionFormat);
219 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
221 listOfConnections.push_back(sqlite3_column_int(query, 0));
222 int16_t temp_delay = sqlite3_column_int(query, 1);
223 if (temp_delay != -1 && delay != -1)
230 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:"), DLT_INT(eCode));
231 return E_DATABASE_ERROR;
233 sqlite3_reset(query);
236 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
238 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"), DLT_INT(eCode));
239 return E_DATABASE_ERROR;
242 //now we create a table with references to the connections;
243 command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
244 assert(this->sqQuery(command));
246 command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
247 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
248 std::vector<uint16_t>::iterator listConnectionIterator = listOfConnections.begin();
249 for (; listConnectionIterator < listOfConnections.end(); ++listConnectionIterator)
251 sqlite3_bind_int(query, 1, *listConnectionIterator);
252 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
254 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"), DLT_INT(eCode));
255 return E_DATABASE_ERROR;
257 sqlite3_reset(query);
260 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
262 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"), DLT_INT(eCode));
263 return E_DATABASE_ERROR;
266 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID"), DLT_INT(mainConnectionData.route.sourceID), DLT_STRING("sinkID:"), DLT_INT16(mainConnectionData.route.sinkID), DLT_STRING("delay:"), DLT_INT16(delay), DLT_STRING("assigned ID:"), DLT_INT16(connectionID));
268 if (mDatabaseObserver)
270 mDatabaseObserver->numberOfMainConnectionsChanged();
271 mDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState);
274 //finally, we update the delay value for the maintable
277 return changeDelayMainConnection(delay, connectionID);
280 am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
282 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
283 assert(sinkData.domainID!=0);
284 assert(!sinkData.name.empty());
285 assert(sinkData.sinkClassID!=0);
286 // \todo: need to check if class exists?
287 assert(!sinkData.listConnectionFormats.empty());
288 assert(sinkData.muteState>=MS_MUTED && sinkData.muteState<=MS_UNMUTED);
290 sqlite3_stmt *query = NULL, *queryFinal = NULL;
292 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
294 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
295 sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
297 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
299 command = "UPDATE " + std::string(SINK_TABLE) + " SET name=?, domainID=?, sinkClassID=?, volume=?, visible=?, availability=?, availabilityReason=?, muteState=?, mainVolume=?, reserved=? WHERE sinkID=" + i2s(sqlite3_column_int(query, 0));
301 else if (eCode == SQLITE_DONE)
303 //if sinkID is zero and the first Static Sink was already entered, the ID is created
304 if (sinkData.sinkID == 0 && !mFirstStaticSink && !existSinkName(sinkData.name))
306 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
310 //check if the ID already exists
311 if (existSinkNameOrID(sinkData.sinkID, sinkData.name))
313 sqlite3_finalize(query);
314 return E_ALREADY_EXISTS;
316 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
321 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
322 sqlite3_finalize(query);
323 return E_DATABASE_ERROR;
326 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
328 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"), DLT_INT(eCode));
329 return E_DATABASE_ERROR;
332 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
333 sqlite3_bind_text(queryFinal, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
334 sqlite3_bind_int(queryFinal, 2, sinkData.domainID);
335 sqlite3_bind_int(queryFinal, 3, sinkData.sinkClassID);
336 sqlite3_bind_int(queryFinal, 4, sinkData.volume);
337 sqlite3_bind_int(queryFinal, 5, sinkData.visible);
338 sqlite3_bind_int(queryFinal, 6, sinkData.available.availability);
339 sqlite3_bind_int(queryFinal, 7, sinkData.available.availabilityReason);
340 sqlite3_bind_int(queryFinal, 8, sinkData.muteState);
341 sqlite3_bind_int(queryFinal, 9, sinkData.mainVolume);
342 sqlite3_bind_int(queryFinal, 10, 0);
344 //if the ID is not created, we add it to the query
345 if (sinkData.sinkID != 0)
347 sqlite3_bind_int(queryFinal, 11, sinkData.sinkID);
350 //if the first static sink is entered, we need to set it onto the boundary
351 else if (mFirstStaticSink)
353 sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY);
354 mFirstStaticSink = false;
357 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
359 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
360 sqlite3_finalize(queryFinal);
361 return E_DATABASE_ERROR;
364 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
366 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"), DLT_INT(eCode));
367 return E_DATABASE_ERROR;
370 //now read back the sinkID
371 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
372 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
373 sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
374 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
376 sinkID = sqlite3_column_int(query, 0);
381 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
382 sqlite3_finalize(query);
383 return E_DATABASE_ERROR;
385 sqlite3_finalize(query);
387 //now we need to create the additional tables:
388 command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
389 assert(this->sqQuery(command));
390 command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
391 assert(this->sqQuery(command));
392 command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
393 assert(this->sqQuery(command));
395 //fill ConnectionFormats
396 command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
397 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
398 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin();
399 for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator)
401 sqlite3_bind_int(query, 1, *connectionFormatIterator);
402 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
404 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
405 sqlite3_finalize(query);
406 return E_DATABASE_ERROR;
408 sqlite3_reset(query);
411 //Fill MainSinkSoundProperties
412 command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
413 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
414 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin();
415 for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
417 sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type);
418 sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value);
419 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
421 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
422 sqlite3_finalize(query);
423 return E_DATABASE_ERROR;
425 sqlite3_reset(query);
428 //Fill SinkSoundProperties
429 command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
430 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
431 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin();
432 for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator)
434 sqlite3_bind_int(query, 1, SoundPropertyIterator->type);
435 sqlite3_bind_int(query, 2, SoundPropertyIterator->value);
436 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
438 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
439 sqlite3_finalize(query);
440 return E_DATABASE_ERROR;
442 sqlite3_reset(query);
445 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkDB entered new sink with name"), DLT_STRING(sinkData.name.c_str()), DLT_STRING("domainID:"), DLT_INT(sinkData.domainID), DLT_STRING("classID:"), DLT_INT(sinkData.sinkClassID), DLT_STRING("volume:"), DLT_INT(sinkData.volume), DLT_STRING("visible:"), DLT_BOOL(sinkData.visible), DLT_STRING("available.availability:"), DLT_INT(sinkData.available.availability), DLT_STRING("available.availabilityReason:"), DLT_INT(sinkData.available.availabilityReason), DLT_STRING("muteState:"), DLT_INT(sinkData.muteState), DLT_STRING("mainVolume:"), DLT_INT(sinkData.mainVolume), DLT_STRING("assigned ID:"), DLT_INT16(sinkID));
447 am_Sink_s sink = sinkData;
448 sink.sinkID = sinkID;
449 if (mDatabaseObserver != NULL)
450 mDatabaseObserver->newSink(sink);
455 am_Error_e DatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
457 //todo: implement crossfader
458 (void) crossfaderData;
463 am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
465 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
466 assert(gatewayData.sinkID!=0);
467 assert(gatewayData.sourceID!=0);
468 assert(gatewayData.controlDomainID!=0);
469 assert(gatewayData.domainSinkID!=0);
470 assert(gatewayData.domainSourceID!=0);
471 assert(!gatewayData.name.empty());
472 assert(!gatewayData.convertionMatrix.empty());
473 assert(!gatewayData.listSinkFormats.empty());
474 assert(!gatewayData.listSourceFormats.empty());
476 sqlite3_stmt* query = NULL;
480 //if sinkID is zero and the first Static Sink was already entered, the ID is created
481 if (gatewayData.gatewayID == 0 && !mFirstStaticGateway)
483 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, inUse) VALUES (?,?,?,?,?,?,0)";
487 //check if the ID already exists
488 if (existGateway(gatewayData.gatewayID))
489 return E_ALREADY_EXISTS;
490 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID, inUse) VALUES (?,?,?,?,?,?,?,0)";
493 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
494 sqlite3_bind_text(query, 1, gatewayData.name.c_str(), gatewayData.name.size(), SQLITE_STATIC);
495 sqlite3_bind_int(query, 2, gatewayData.sinkID);
496 sqlite3_bind_int(query, 3, gatewayData.sourceID);
497 sqlite3_bind_int(query, 4, gatewayData.domainSinkID);
498 sqlite3_bind_int(query, 5, gatewayData.domainSourceID);
499 sqlite3_bind_int(query, 6, gatewayData.controlDomainID);
501 //if the ID is not created, we add it to the query
502 if (gatewayData.gatewayID != 0)
504 sqlite3_bind_int(query, 7, gatewayData.gatewayID);
507 //if the first static sink is entered, we need to set it onto the boundary
508 else if (mFirstStaticGateway)
510 sqlite3_bind_int(query, 7, DYNAMIC_ID_BOUNDARY);
511 mFirstStaticGateway = false;
514 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
516 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"), DLT_INT(eCode));
517 return E_DATABASE_ERROR;
520 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
522 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Finalize error code:"), DLT_INT(eCode));
523 return E_DATABASE_ERROR;
526 gatewayID = sqlite3_last_insert_rowid(mDatabase);
528 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
529 mListConnectionFormat.insert(std::make_pair(gatewayID, gatewayData.convertionMatrix));
531 command = "CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
532 assert(this->sqQuery(command));
533 command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
534 assert(this->sqQuery(command));
536 //fill ConnectionFormats
537 command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
538 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
539 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin();
540 for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator)
542 sqlite3_bind_int(query, 1, *connectionFormatIterator);
543 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
545 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"), DLT_INT(eCode));
546 return E_DATABASE_ERROR;
548 sqlite3_reset(query);
551 command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
552 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
553 connectionFormatIterator = gatewayData.listSinkFormats.begin();
554 for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator)
556 sqlite3_bind_int(query, 1, *connectionFormatIterator);
557 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
559 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"), DLT_INT(eCode));
560 return E_DATABASE_ERROR;
562 sqlite3_reset(query);
565 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterGatewayDB entered new gateway with name"), DLT_STRING(gatewayData.name.c_str()), DLT_STRING("sourceID:"), DLT_INT(gatewayData.sourceID), DLT_STRING("sinkID:"), DLT_INT(gatewayData.sinkID), DLT_STRING("domainSinkID:"), DLT_INT(gatewayData.domainSinkID), DLT_STRING("domainSourceID:"), DLT_BOOL(gatewayData.domainSourceID), DLT_STRING("controlDomainID:"), DLT_INT(gatewayData.controlDomainID), DLT_STRING("assigned ID:"), DLT_INT16(gatewayID));
567 am_Gateway_s gateway = gatewayData;
568 gateway.gatewayID = gatewayID;
569 if (mDatabaseObserver)
570 mDatabaseObserver->newGateway(gateway);
574 am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
576 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
577 assert(sourceData.domainID!=0);
578 assert(!sourceData.name.empty());
579 assert(sourceData.sourceClassID!=0);
580 // \todo: need to check if class exists?
581 assert(!sourceData.listConnectionFormats.empty());
582 assert(sourceData.sourceState>=SS_ON && sourceData.sourceState<=SS_PAUSED);
584 sqlite3_stmt* query = NULL, *queryFinal = NULL;
587 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
589 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
590 sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
592 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
594 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET name=?, domainID=?, sourceClassID=?, sourceState=?, volume=?, visible=?, availability=?, availabilityReason=?, interruptState=?, reserved=? WHERE sourceID=" + i2s(sqlite3_column_int(query, 0));
596 else if (eCode == SQLITE_DONE)
598 //if sinkID is zero and the first Static Sink was already entered, the ID is created
599 if (sourceData.sourceID == 0 && !mFirstStaticSource && !existSourceName(sourceData.name))
601 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
605 //check if the ID already exists
606 if (existSourceNameOrID(sourceData.sourceID, sourceData.name))
608 sqlite3_finalize(query);
609 return E_ALREADY_EXISTS;
611 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
616 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"), DLT_INT(eCode));
617 sqlite3_finalize(query);
618 return E_DATABASE_ERROR;
621 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
623 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"), DLT_INT(eCode));
624 return E_DATABASE_ERROR;
626 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
627 sqlite3_bind_text(queryFinal, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
628 sqlite3_bind_int(queryFinal, 2, sourceData.domainID);
629 sqlite3_bind_int(queryFinal, 3, sourceData.sourceClassID);
630 sqlite3_bind_int(queryFinal, 4, sourceData.sourceState);
631 sqlite3_bind_int(queryFinal, 5, sourceData.volume);
632 sqlite3_bind_int(queryFinal, 6, sourceData.visible);
633 sqlite3_bind_int(queryFinal, 7, sourceData.available.availability);
634 sqlite3_bind_int(queryFinal, 8, sourceData.available.availabilityReason);
635 sqlite3_bind_int(queryFinal, 9, sourceData.interruptState);
636 sqlite3_bind_int(queryFinal, 10, 0);
638 //if the ID is not created, we add it to the query
639 if (sourceData.sourceID != 0)
641 sqlite3_bind_int(queryFinal, 11, sourceData.sourceID);
644 //if the first static sink is entered, we need to set it onto the boundary
645 else if (mFirstStaticSource)
647 sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY);
648 mFirstStaticSource = false;
651 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
653 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"), DLT_INT(eCode));
654 sqlite3_finalize(queryFinal);
655 return E_DATABASE_ERROR;
658 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
660 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"), DLT_INT(eCode));
661 sqlite3_finalize(queryFinal);
662 return E_DATABASE_ERROR;
665 //now read back the sinkID
666 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
667 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
668 sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
669 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
671 sourceID = sqlite3_column_int(query, 0);
676 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
677 sqlite3_finalize(query);
678 return E_DATABASE_ERROR;
680 sqlite3_finalize(query);
682 //now we need to create the additional tables:
683 command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
684 assert(this->sqQuery(command));
685 command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
686 assert(this->sqQuery(command));
687 command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
688 assert(this->sqQuery(command));
690 //fill ConnectionFormats
691 command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
692 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
693 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin();
694 for (; connectionFormatIterator < sourceData.listConnectionFormats.end(); ++connectionFormatIterator)
696 sqlite3_bind_int(query, 1, *connectionFormatIterator);
697 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
699 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"), DLT_INT(eCode));
700 sqlite3_finalize(query);
701 return E_DATABASE_ERROR;
703 sqlite3_reset(query);
706 //Fill MainSinkSoundProperties
707 command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
708 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
709 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin();
710 for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
712 sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type);
713 sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value);
714 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
716 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"), DLT_INT(eCode));
717 sqlite3_finalize(query);
718 return E_DATABASE_ERROR;
720 sqlite3_reset(query);
723 //Fill SinkSoundProperties
724 command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
725 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
726 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin();
727 for (; SoundPropertyIterator < sourceData.listSoundProperties.end(); ++SoundPropertyIterator)
729 sqlite3_bind_int(query, 1, SoundPropertyIterator->type);
730 sqlite3_bind_int(query, 2, SoundPropertyIterator->value);
731 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
733 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
734 sqlite3_finalize(query);
735 return E_DATABASE_ERROR;
737 sqlite3_reset(query);
740 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkDB entered new source with name"), DLT_STRING(sourceData.name.c_str()), DLT_STRING("domainID:"), DLT_INT(sourceData.domainID), DLT_STRING("classID:"), DLT_INT(sourceData.sourceClassID), DLT_STRING("volume:"), DLT_INT(sourceData.volume), DLT_STRING("visible:"), DLT_BOOL(sourceData.visible), DLT_STRING("available.availability:"), DLT_INT(sourceData.available.availability), DLT_STRING("available.availabilityReason:"), DLT_INT(sourceData.available.availabilityReason), DLT_STRING("interruptState:"), DLT_INT(sourceData.interruptState), DLT_STRING("assigned ID:"), DLT_INT16(sourceID));
742 am_Source_s source = sourceData;
743 source.sourceID = sourceID;
744 if (mDatabaseObserver)
745 mDatabaseObserver->newSource(source);
749 am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
751 assert(mainconnectionID!=0);
752 if (!existMainConnection(mainconnectionID))
754 return E_NON_EXISTENT;
756 sqlite3_stmt* query = NULL;
760 std::vector<uint16_t> listOfConnections;
762 command = "SELECT connectionID, delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
763 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
764 std::vector<am_RoutingElement_s>::const_iterator elementIterator = route.route.begin();
765 for (; elementIterator < route.route.end(); ++elementIterator)
767 sqlite3_bind_int(query, 1, elementIterator->sourceID);
768 sqlite3_bind_int(query, 2, elementIterator->sinkID);
769 sqlite3_bind_int(query, 3, elementIterator->connectionFormat);
771 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
773 listOfConnections.push_back(sqlite3_column_int(query, 0));
774 int16_t temp_delay = sqlite3_column_int(query, 1);
775 if (temp_delay != -1 && delay != -1)
782 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:"), DLT_INT(eCode));
783 return E_DATABASE_ERROR;
785 sqlite3_reset(query);
788 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
790 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"), DLT_INT(eCode));
791 return E_DATABASE_ERROR;
794 //now we delete the data in the table
795 command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID);
796 assert(this->sqQuery(command));
798 command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
799 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
800 std::vector<uint16_t>::iterator listConnectionIterator = listOfConnections.begin();
801 for (; listConnectionIterator < listOfConnections.end(); ++listConnectionIterator)
803 sqlite3_bind_int(query, 1, *listConnectionIterator);
804 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
806 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:"), DLT_INT(eCode));
807 return E_DATABASE_ERROR;
809 sqlite3_reset(query);
812 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
814 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"), DLT_INT(eCode));
815 return E_DATABASE_ERROR;
816 }DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB entered new route:"), DLT_INT(mainconnectionID));
820 am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
822 assert(mainconnectionID!=0);
824 sqlite3_stmt* query = NULL;
828 if (!existMainConnection(mainconnectionID))
830 return E_NON_EXISTENT;
832 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
833 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
834 sqlite3_bind_int(query, 1, connectionState);
835 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
837 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:"), DLT_INT(eCode));
838 return E_DATABASE_ERROR;
840 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
842 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:"), DLT_INT(eCode));
843 return E_DATABASE_ERROR;
844 }DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:"), DLT_INT(mainconnectionID), DLT_STRING("to:"), DLT_INT(connectionState));
846 if (mDatabaseObserver)
847 mDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState);
851 am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
855 sqlite3_stmt* query = NULL;
859 if (!existSink(sinkID))
861 return E_NON_EXISTENT;
863 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
864 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
865 sqlite3_bind_int(query, 1, mainVolume);
866 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
868 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:"), DLT_INT(eCode));
869 return E_DATABASE_ERROR;
871 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
873 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:"), DLT_INT(eCode));
874 return E_DATABASE_ERROR;
877 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:"), DLT_INT(sinkID), DLT_STRING("to:"), DLT_INT(mainVolume));
879 if (mDatabaseObserver)
880 mDatabaseObserver->volumeChanged(sinkID, mainVolume);
885 am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
889 sqlite3_stmt* query = NULL;
893 if (!existSink(sinkID))
895 return E_NON_EXISTENT;
897 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
898 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
899 sqlite3_bind_int(query, 1, availability.availability);
900 sqlite3_bind_int(query, 2, availability.availabilityReason);
901 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
903 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:"), DLT_INT(eCode));
904 return E_DATABASE_ERROR;
907 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
909 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:"), DLT_INT(eCode));
910 return E_DATABASE_ERROR;
913 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:"), DLT_INT(sinkID), DLT_STRING("to:"), DLT_INT(availability.availability), DLT_STRING("Reason:"), DLT_INT(availability.availabilityReason));
915 if (mDatabaseObserver && sourceVisible(sinkID))
916 mDatabaseObserver->sinkAvailabilityChanged(sinkID, availability);
920 am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
924 sqlite3_stmt* query = NULL;
928 if (!existDomain(domainID))
930 return E_NON_EXISTENT;
932 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
933 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
934 sqlite3_bind_int(query, 1, domainState);
935 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
937 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Step error code:"), DLT_INT(eCode));
938 return E_DATABASE_ERROR;
941 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
943 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:"), DLT_INT(eCode));
944 return E_DATABASE_ERROR;
947 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changDomainStateDB changed domainState of domain:"), DLT_INT(domainID), DLT_STRING("to:"), DLT_INT(domainState));
951 am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
955 sqlite3_stmt* query = NULL;
959 if (!existSink(sinkID))
961 return E_NON_EXISTENT;
963 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
964 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
965 sqlite3_bind_int(query, 1, muteState);
966 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
968 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:"), DLT_INT(eCode));
969 return E_DATABASE_ERROR;
972 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
974 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:"), DLT_INT(eCode));
975 return E_DATABASE_ERROR;
978 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:"), DLT_INT(sinkID), DLT_STRING("to:"), DLT_INT(muteState));
980 if (mDatabaseObserver)
981 mDatabaseObserver->sinkMuteStateChanged(sinkID, muteState);
986 am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
988 //todo: add checks if soundproperty exists!
991 sqlite3_stmt* query = NULL;
995 if (!existSink(sinkID))
997 return E_NON_EXISTENT;
999 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1000 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1001 sqlite3_bind_int(query, 1, soundProperty.value);
1002 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1004 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
1005 return E_DATABASE_ERROR;
1008 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1010 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
1011 return E_DATABASE_ERROR;
1014 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:"), DLT_INT(sinkID), DLT_STRING("type:"), DLT_INT(soundProperty.type), DLT_STRING("to:"), DLT_INT(soundProperty.value));
1015 if (mDatabaseObserver)
1016 mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty);
1020 am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1022 //todo: add checks if soundproperty exists!
1023 assert(sourceID!=0);
1025 sqlite3_stmt* query = NULL;
1027 std::string command;
1029 if (!existSource(sourceID))
1031 return E_NON_EXISTENT;
1033 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1034 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1035 sqlite3_bind_int(query, 1, soundProperty.value);
1036 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1038 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
1039 return E_DATABASE_ERROR;
1042 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1044 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
1045 return E_DATABASE_ERROR;
1048 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:"), DLT_INT(sourceID), DLT_STRING("type:"), DLT_INT(soundProperty.type), DLT_STRING("to:"), DLT_INT(soundProperty.value));
1050 if (mDatabaseObserver)
1051 mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty);
1055 am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1057 assert(sourceID!=0);
1059 sqlite3_stmt* query = NULL;
1061 std::string command;
1063 if (!existSource(sourceID))
1065 return E_NON_EXISTENT;
1067 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1068 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1069 sqlite3_bind_int(query, 1, availability.availability);
1070 sqlite3_bind_int(query, 2, availability.availabilityReason);
1071 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1073 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:"), DLT_INT(eCode));
1074 return E_DATABASE_ERROR;
1077 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1079 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:"), DLT_INT(eCode));
1080 return E_DATABASE_ERROR;
1083 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:"), DLT_INT(sourceID), DLT_STRING("to:"), DLT_INT(availability.availability), DLT_STRING("Reason:"), DLT_INT(availability.availabilityReason));
1085 if (mDatabaseObserver && sourceVisible(sourceID))
1086 mDatabaseObserver->sourceAvailabilityChanged(sourceID, availability);
1090 am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1092 sqlite3_stmt* query = NULL;
1094 std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1096 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1097 sqlite3_bind_int(query, 1, property.value);
1098 sqlite3_bind_int(query, 2, property.type);
1100 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1102 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
1103 return E_DATABASE_ERROR;
1106 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1108 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
1109 return E_DATABASE_ERROR;
1112 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSystemPropertyDB changed system property"));
1114 if (mDatabaseObserver)
1115 mDatabaseObserver->systemPropertyChanged(property);
1120 am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1122 assert(mainConnectionID!=0);
1124 if (!existMainConnection(mainConnectionID))
1126 return E_NON_EXISTENT;
1128 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1129 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1130 if (!sqQuery(command))
1131 return E_DATABASE_ERROR;
1132 if (!sqQuery(command1))
1133 return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeMainConnectionDB removed:"), DLT_INT(mainConnectionID));
1134 if (mDatabaseObserver)
1136 mDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED);
1137 mDatabaseObserver->numberOfMainConnectionsChanged();
1142 am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1146 if (!existSink(sinkID))
1148 return E_NON_EXISTENT;
1150 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1151 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1152 std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1153 std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID);
1154 if (!sqQuery(command))
1155 return E_DATABASE_ERROR;
1156 if (!sqQuery(command1))
1157 return E_DATABASE_ERROR;
1158 if (!sqQuery(command2))
1159 return E_DATABASE_ERROR;
1160 if (!sqQuery(command3))
1161 return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkDB removed:"), DLT_INT(sinkID));
1163 if (mDatabaseObserver != NULL)
1164 mDatabaseObserver->removedSink(sinkID);
1169 am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1171 assert(sourceID!=0);
1173 if (!existSource(sourceID))
1175 return E_NON_EXISTENT;
1177 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1178 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1179 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1180 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1181 if (!sqQuery(command))
1182 return E_DATABASE_ERROR;
1183 if (!sqQuery(command1))
1184 return E_DATABASE_ERROR;
1185 if (!sqQuery(command2))
1186 return E_DATABASE_ERROR;
1187 if (!sqQuery(command3))
1188 return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceDB removed:"), DLT_INT(sourceID));
1189 if (mDatabaseObserver)
1190 mDatabaseObserver->removedSource(sourceID);
1194 am_Error_e DatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1196 assert(gatewayID!=0);
1198 if (!existGateway(gatewayID))
1200 return E_NON_EXISTENT;
1202 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1203 if (!sqQuery(command))
1204 return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeGatewayDB removed:"), DLT_INT(gatewayID));
1205 if (mDatabaseObserver)
1206 mDatabaseObserver->removeGateway(gatewayID);
1210 am_Error_e DatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1212 //todo: implement crossdfader
1213 (void) crossfaderID;
1217 am_Error_e DatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1219 assert(domainID!=0);
1221 if (!existDomain(domainID))
1223 return E_NON_EXISTENT;
1225 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1226 if (!sqQuery(command))
1227 return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeDomainDB removed:"), DLT_INT(domainID));
1228 if (mDatabaseObserver)
1229 mDatabaseObserver->removeDomain(domainID);
1233 am_Error_e DatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1235 assert(sinkClassID!=0);
1237 if (!existSinkClass(sinkClassID))
1239 return E_NON_EXISTENT;
1241 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1242 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1243 if (!sqQuery(command))
1244 return E_DATABASE_ERROR;
1245 if (!sqQuery(command1))
1246 return E_DATABASE_ERROR;
1248 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkClassDB removed:"), DLT_INT(sinkClassID));
1249 if (mDatabaseObserver)
1250 mDatabaseObserver->numberOfSinkClassesChanged();
1255 am_Error_e DatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1257 assert(sourceClassID!=0);
1259 if (!existSourceClass(sourceClassID))
1261 return E_NON_EXISTENT;
1263 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1264 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1265 if (!sqQuery(command))
1266 return E_DATABASE_ERROR;
1267 if (!sqQuery(command1))
1268 return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceClassDB removed:"), DLT_INT(sourceClassID));
1270 if (mDatabaseObserver)
1271 mDatabaseObserver->numberOfSourceClassesChanged();
1275 am_Error_e DatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1277 assert(connectionID!=0);
1279 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1280 std::string command1 = "DROP table SourceClassProperties" + i2s(connectionID);
1281 if (!sqQuery(command))
1282 return E_DATABASE_ERROR;
1283 if (!sqQuery(command1))
1284 return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeConnection removed:"), DLT_INT(connectionID));
1289 am_Error_e DatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1291 assert(sourceID!=0);
1293 if (!existSource(sourceID))
1295 return E_NON_EXISTENT;
1297 sqlite3_stmt* query = NULL;
1299 am_ClassProperty_s propertyTemp;
1300 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + (i2s(sourceID));
1301 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1303 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1305 classInfo.sourceClassID = sqlite3_column_int(query, 0);
1308 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1310 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1311 return E_DATABASE_ERROR;
1314 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1316 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1317 return E_DATABASE_ERROR;
1320 command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1321 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1323 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1325 classInfo.name = std::string((const char*) sqlite3_column_text(query, 0));
1328 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1330 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1331 return E_DATABASE_ERROR;
1334 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1336 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1337 return E_DATABASE_ERROR;
1340 //read out Properties
1341 command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID);
1342 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1343 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1345 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1346 propertyTemp.value = sqlite3_column_int(query, 1);
1347 classInfo.listClassProperties.push_back(propertyTemp);
1350 if (eCode != SQLITE_DONE)
1352 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1353 return E_DATABASE_ERROR;
1356 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1358 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1359 return E_DATABASE_ERROR;
1364 am_Error_e DatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1366 assert(sinkClass.sinkClassID!=0);
1367 assert(!sinkClass.listClassProperties.empty());
1369 sqlite3_stmt* query = NULL;
1372 //check if the ID already exists
1373 if (!existSinkClass(sinkClass.sinkClassID))
1374 return E_NON_EXISTENT;
1376 //fill ConnectionFormats
1377 std::string command = "UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1378 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1379 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
1380 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
1382 sqlite3_bind_int(query, 1, Iterator->value);
1383 sqlite3_bind_int(query, 2, Iterator->classProperty);
1384 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1386 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"), DLT_INT(eCode));
1387 return E_DATABASE_ERROR;
1389 sqlite3_reset(query);
1392 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1394 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1395 return E_DATABASE_ERROR;
1398 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1402 am_Error_e DatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1404 assert(sourceClass.sourceClassID!=0);
1405 assert(!sourceClass.listClassProperties.empty());
1407 sqlite3_stmt* query = NULL;
1410 //check if the ID already exists
1411 if (!existSourceClass(sourceClass.sourceClassID))
1412 return E_NON_EXISTENT;
1414 //fill ConnectionFormats
1415 std::string command = "UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1416 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1417 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
1418 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
1420 sqlite3_bind_int(query, 1, Iterator->value);
1421 sqlite3_bind_int(query, 2, Iterator->classProperty);
1422 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1424 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"), DLT_INT(eCode));
1425 return E_DATABASE_ERROR;
1427 sqlite3_reset(query);
1430 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1432 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1433 return E_DATABASE_ERROR;
1436 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1440 am_Error_e DatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1444 if (!existSink(sinkID))
1446 return E_NON_EXISTENT;
1448 sqlite3_stmt* query = NULL;
1450 am_ClassProperty_s propertyTemp;
1451 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + (i2s(sinkID));
1452 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1454 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1456 sinkClass.sinkClassID = sqlite3_column_int(query, 0);
1459 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1461 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1462 return E_DATABASE_ERROR;
1465 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1467 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1468 return E_DATABASE_ERROR;
1471 command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1472 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1474 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1476 sinkClass.name = std::string((const char*) sqlite3_column_text(query, 0));
1479 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1481 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1482 return E_DATABASE_ERROR;
1485 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1487 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1488 return E_DATABASE_ERROR;
1491 //read out Properties
1492 command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID);
1493 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1494 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1496 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1497 propertyTemp.value = sqlite3_column_int(query, 1);
1498 sinkClass.listClassProperties.push_back(propertyTemp);
1501 if (eCode != SQLITE_DONE)
1503 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1504 return E_DATABASE_ERROR;
1507 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1509 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1510 return E_DATABASE_ERROR;
1515 am_Error_e DatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1517 assert(gatewayID!=0);
1518 if (!existGateway(gatewayID))
1520 return E_NON_EXISTENT;
1522 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
1524 am_ConnectionFormat_e tempConnectionFormat;
1525 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1526 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1528 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1530 gatewayData.name = std::string((const char*) sqlite3_column_text(query, 0));
1531 gatewayData.sinkID = sqlite3_column_int(query, 1);
1532 gatewayData.sourceID = sqlite3_column_int(query, 2);
1533 gatewayData.domainSinkID = sqlite3_column_int(query, 3);
1534 gatewayData.domainSourceID = sqlite3_column_int(query, 4);
1535 gatewayData.controlDomainID = sqlite3_column_int(query, 5);
1536 gatewayData.gatewayID = sqlite3_column_int(query, 6);
1539 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
1540 iter = mListConnectionFormat.find(gatewayData.gatewayID);
1541 if (iter == mListConnectionFormat.end())
1543 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB database error with convertionFormat"));
1544 return E_DATABASE_ERROR;
1546 gatewayData.convertionMatrix = iter->second;
1548 //read out the connectionFormats
1549 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
1550 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL);
1551 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
1553 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
1554 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
1557 if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK)
1559 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1560 return E_DATABASE_ERROR;
1563 //read out sound properties
1564 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
1565 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL);
1566 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
1568 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
1569 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
1572 if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK)
1574 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1575 return E_DATABASE_ERROR;
1580 if (eCode != SQLITE_DONE)
1582 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE error code:"), DLT_INT(eCode));
1583 return E_DATABASE_ERROR;
1586 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1588 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1589 return E_DATABASE_ERROR;
1596 am_Error_e DatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
1598 //todo: implement crossfader
1599 (void) crossfaderID;
1600 (void) crossfaderData;
1604 am_Error_e DatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
1606 assert(domainID!=0);
1608 if (!existDomain(domainID))
1610 return E_NON_EXISTENT;
1612 sqlite3_stmt* query = NULL;
1615 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND domainID=" + (i2s(domainID));
1616 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1618 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1620 temp = sqlite3_column_int(query, 0);
1621 listSinkID.push_back(temp);
1624 if (eCode != SQLITE_DONE)
1626 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE error code:"), DLT_INT(eCode));
1627 return E_DATABASE_ERROR;
1630 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1632 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:"), DLT_INT(eCode));
1633 return E_DATABASE_ERROR;
1639 am_Error_e DatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
1641 assert(domainID!=0);
1642 listSourceID.clear();
1643 if (!existDomain(domainID))
1645 return E_NON_EXISTENT;
1647 sqlite3_stmt* query = NULL;
1650 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
1652 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1654 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1656 temp = sqlite3_column_int(query, 0);
1657 listSourceID.push_back(temp);
1660 if (eCode != SQLITE_DONE)
1662 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE error code:"), DLT_INT(eCode));
1663 return E_DATABASE_ERROR;
1666 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1668 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:"), DLT_INT(eCode));
1669 return E_DATABASE_ERROR;
1675 am_Error_e DatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listGatewaysID) const
1677 //todo: implement crossfader
1678 (void) listGatewaysID;
1684 am_Error_e DatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
1686 assert(domainID!=0);
1687 listGatewaysID.clear();
1688 if (!existDomain(domainID))
1690 return E_NON_EXISTENT;
1692 sqlite3_stmt* query = NULL;
1694 am_gatewayID_t temp;
1696 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" + i2s(domainID);
1697 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1699 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1701 temp = sqlite3_column_int(query, 0);
1702 listGatewaysID.push_back(temp);
1705 if (eCode != SQLITE_DONE)
1707 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:"), DLT_INT(eCode));
1708 return E_DATABASE_ERROR;
1711 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1713 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:"), DLT_INT(eCode));
1714 return E_DATABASE_ERROR;
1720 am_Error_e DatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
1722 listMainConnections.clear();
1723 sqlite3_stmt *query = NULL, *query1 = NULL, *query2 = NULL;
1725 am_MainConnection_s temp;
1726 am_RoutingElement_s tempRoute;
1728 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
1729 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
1730 std::string command2 = "SELECT sourceID, sinkID, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=?";
1731 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1732 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &query2, NULL);
1734 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1736 temp.connectionID = sqlite3_column_int(query, 0);
1737 temp.route.sourceID = sqlite3_column_int(query, 1);
1738 temp.route.sinkID = sqlite3_column_int(query, 2);
1739 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
1740 temp.delay = sqlite3_column_int(query, 4);
1741 std::string statement = command1 + i2s(temp.connectionID);
1742 sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL);
1743 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW) //todo: check results of eCode1, eCode2
1745 int k = sqlite3_column_int(query1, 0);
1746 sqlite3_bind_int(query2, 1, k);
1747 while ((eCode = sqlite3_step(query2)) == SQLITE_ROW)
1749 tempRoute.sourceID = sqlite3_column_int(query2, 0);
1750 tempRoute.sinkID = sqlite3_column_int(query2, 1);
1751 tempRoute.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query2, 2);
1752 getDomainOfSource(tempRoute.sourceID, tempRoute.domainID);
1753 temp.route.route.push_back(tempRoute);
1755 sqlite3_reset(query2);
1757 listMainConnections.push_back(temp);
1760 if (eCode != SQLITE_DONE)
1762 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE error code:"), DLT_INT(eCode));
1763 return E_DATABASE_ERROR;
1766 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1768 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE Finalize error code:"), DLT_INT(eCode));
1769 return E_DATABASE_ERROR;
1775 am_Error_e DatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
1777 listDomains.clear();
1778 sqlite3_stmt* query = NULL;
1781 std::string command = "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
1782 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1784 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1786 temp.domainID = sqlite3_column_int(query, 0);
1787 temp.name = std::string((const char*) sqlite3_column_text(query, 1));
1788 temp.busname = std::string((const char*) sqlite3_column_text(query, 2));
1789 temp.nodename = std::string((const char*) sqlite3_column_text(query, 3));
1790 temp.early = sqlite3_column_int(query, 4);
1791 temp.complete = sqlite3_column_int(query, 5);
1792 temp.state = (am_DomainState_e) sqlite3_column_int(query, 6);
1793 listDomains.push_back(temp);
1796 if (eCode != SQLITE_DONE)
1798 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE error code:"), DLT_INT(eCode));
1799 return E_DATABASE_ERROR;
1802 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1804 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE Finalize error code:"), DLT_INT(eCode));
1805 return E_DATABASE_ERROR;
1811 am_Error_e DatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
1813 listConnections.clear();
1814 sqlite3_stmt* query = NULL;
1816 am_Connection_s temp;
1817 std::string command = "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE reserved=0";
1818 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1820 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1822 temp.connectionID = sqlite3_column_int(query, 0);
1823 temp.sourceID = sqlite3_column_int(query, 1);
1824 temp.sinkID = sqlite3_column_int(query, 2);
1825 temp.delay = sqlite3_column_int(query, 3);
1826 temp.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query, 4);
1827 listConnections.push_back(temp);
1830 if (eCode != SQLITE_DONE)
1832 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE error code:"), DLT_INT(eCode));
1833 return E_DATABASE_ERROR;
1836 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1838 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE Finalize error code:"), DLT_INT(eCode));
1839 return E_DATABASE_ERROR;
1845 am_Error_e DatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
1848 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
1851 am_ConnectionFormat_e tempConnectionFormat;
1852 am_SoundProperty_s tempSoundProperty;
1853 am_MainSoundProperty_s tempMainSoundProperty;
1854 std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0";
1855 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1857 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1859 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
1860 temp.domainID = sqlite3_column_int(query, 1);
1861 temp.sinkClassID = sqlite3_column_int(query, 2);
1862 temp.volume = sqlite3_column_int(query, 3);
1863 temp.visible = sqlite3_column_int(query, 4);
1864 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5);
1865 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
1866 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
1867 temp.mainVolume = sqlite3_column_int(query, 8);
1868 temp.sinkID = sqlite3_column_int(query, 9);
1870 //read out the connectionFormats
1871 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID);
1872 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
1873 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1875 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1876 temp.listConnectionFormats.push_back(tempConnectionFormat);
1879 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
1881 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
1882 return E_DATABASE_ERROR;
1885 //read out sound properties
1886 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
1887 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
1888 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1890 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1891 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1892 temp.listSoundProperties.push_back(tempSoundProperty);
1895 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
1897 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
1898 return E_DATABASE_ERROR;
1901 //read out MainSoundProperties
1902 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID);
1903 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
1904 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1906 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1907 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1908 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
1911 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
1913 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
1914 return E_DATABASE_ERROR;
1916 listSinks.push_back(temp);
1917 temp.listConnectionFormats.clear();
1918 temp.listMainSoundProperties.clear();
1919 temp.listSoundProperties.clear();
1922 if (eCode != SQLITE_DONE)
1924 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"), DLT_INT(eCode));
1925 return E_DATABASE_ERROR;
1928 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1930 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
1931 return E_DATABASE_ERROR;
1937 am_Error_e DatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
1939 listSources.clear();
1940 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
1943 am_ConnectionFormat_e tempConnectionFormat;
1944 am_SoundProperty_s tempSoundProperty;
1945 am_MainSoundProperty_s tempMainSoundProperty;
1946 std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0";
1947 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1949 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1951 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
1952 temp.domainID = sqlite3_column_int(query, 1);
1953 temp.sourceClassID = sqlite3_column_int(query, 2);
1954 temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
1955 temp.volume = sqlite3_column_int(query, 4);
1956 temp.visible = sqlite3_column_int(query, 5);
1957 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6);
1958 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
1959 temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
1960 temp.sourceID = sqlite3_column_int(query, 9);
1962 //read out the connectionFormats
1963 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID);
1964 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
1965 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1967 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1968 temp.listConnectionFormats.push_back(tempConnectionFormat);
1971 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
1973 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
1974 return E_DATABASE_ERROR;
1977 //read out sound properties
1978 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
1979 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
1980 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1982 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1983 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1984 temp.listSoundProperties.push_back(tempSoundProperty);
1987 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
1989 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
1990 return E_DATABASE_ERROR;
1993 //read out MainSoundProperties
1994 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID);
1995 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
1996 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1998 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1999 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2000 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2003 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
2005 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
2006 return E_DATABASE_ERROR;
2008 listSources.push_back(temp);
2009 temp.listConnectionFormats.clear();
2010 temp.listMainSoundProperties.clear();
2011 temp.listSoundProperties.clear();
2014 if (eCode != SQLITE_DONE)
2016 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"), DLT_INT(eCode));
2017 return E_DATABASE_ERROR;
2020 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2022 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
2023 return E_DATABASE_ERROR;
2029 am_Error_e DatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
2031 listSourceClasses.clear();
2033 sqlite3_stmt* query = NULL, *subQuery = NULL;
2034 int eCode = 0, eCode1;
2035 am_SourceClass_s classTemp;
2036 am_ClassProperty_s propertyTemp;
2038 std::string command = "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
2039 std::string command2;
2040 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2042 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2044 classTemp.sourceClassID = sqlite3_column_int(query, 0);
2045 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2047 //read out Properties
2048 command2 = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classTemp.sourceClassID);
2049 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL);
2051 while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW)
2053 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2054 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2055 classTemp.listClassProperties.push_back(propertyTemp);
2058 if (eCode1 != SQLITE_DONE)
2060 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"), DLT_INT(eCode1));
2061 return E_DATABASE_ERROR;
2064 if ((eCode1 = sqlite3_finalize(subQuery)) != SQLITE_OK)
2066 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"), DLT_INT(eCode1));
2067 return E_DATABASE_ERROR;
2069 listSourceClasses.push_back(classTemp);
2072 if (eCode != SQLITE_DONE)
2074 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"), DLT_INT(eCode));
2075 return E_DATABASE_ERROR;
2078 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2080 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"), DLT_INT(eCode));
2081 return E_DATABASE_ERROR;
2087 am_Error_e DatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2089 //todo: implement crossfaders
2090 (void) listCrossfaders;
2094 am_Error_e DatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2096 listGateways.clear();
2097 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
2100 am_ConnectionFormat_e tempConnectionFormat;
2102 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2103 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2105 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2107 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2108 temp.sinkID = sqlite3_column_int(query, 1);
2109 temp.sourceID = sqlite3_column_int(query, 2);
2110 temp.domainSinkID = sqlite3_column_int(query, 3);
2111 temp.domainSourceID = sqlite3_column_int(query, 4);
2112 temp.controlDomainID = sqlite3_column_int(query, 5);
2113 temp.gatewayID = sqlite3_column_int(query, 6);
2116 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2117 iter = mListConnectionFormat.find(temp.gatewayID);
2118 if (iter == mListConnectionFormat.end())
2120 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways database error with convertionFormat"));
2121 return E_DATABASE_ERROR;
2123 temp.convertionMatrix = iter->second;
2125 //read out the connectionFormats
2126 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2127 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL);
2128 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
2130 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
2131 temp.listSourceFormats.push_back(tempConnectionFormat);
2134 if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK)
2136 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"), DLT_INT(eCode));
2137 return E_DATABASE_ERROR;
2140 //read out sound properties
2141 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2142 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL);
2143 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
2145 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
2146 temp.listSinkFormats.push_back(tempConnectionFormat);
2149 if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK)
2151 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"), DLT_INT(eCode));
2152 return E_DATABASE_ERROR;
2155 listGateways.push_back(temp);
2156 temp.listSinkFormats.clear();
2157 temp.listSourceFormats.clear();
2160 if (eCode != SQLITE_DONE)
2162 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE error code:"), DLT_INT(eCode));
2163 return E_DATABASE_ERROR;
2166 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2168 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"), DLT_INT(eCode));
2169 return E_DATABASE_ERROR;
2175 am_Error_e DatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2177 listSinkClasses.clear();
2179 sqlite3_stmt* query = NULL, *subQuery = NULL;
2181 am_SinkClass_s classTemp;
2182 am_ClassProperty_s propertyTemp;
2184 std::string command = "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2185 std::string command2;
2186 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2188 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2190 classTemp.sinkClassID = sqlite3_column_int(query, 0);
2191 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2193 //read out Properties
2194 command2 = "SELECT classProperty, value FROM SinkClassProperties" + i2s(classTemp.sinkClassID);
2195 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL);
2197 while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW)
2199 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2200 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2201 classTemp.listClassProperties.push_back(propertyTemp);
2204 if (eCode != SQLITE_DONE)
2206 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"), DLT_INT(eCode));
2207 return E_DATABASE_ERROR;
2210 if ((eCode = sqlite3_finalize(subQuery)) != SQLITE_OK)
2212 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"), DLT_INT(eCode));
2213 return E_DATABASE_ERROR;
2215 listSinkClasses.push_back(classTemp);
2218 if (eCode != SQLITE_DONE)
2220 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"), DLT_INT(eCode));
2221 return E_DATABASE_ERROR;
2224 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2226 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"), DLT_INT(eCode));
2227 return E_DATABASE_ERROR;
2233 am_Error_e DatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2235 listConnections.clear();
2236 sqlite3_stmt *query = NULL;
2238 am_MainConnectionType_s temp;
2240 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2241 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2243 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2245 temp.mainConnectionID = sqlite3_column_int(query, 0);
2246 temp.sourceID = sqlite3_column_int(query, 1);
2247 temp.sinkID = sqlite3_column_int(query, 2);
2248 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2249 temp.delay = sqlite3_column_int(query, 4);
2250 listConnections.push_back(temp);
2253 if (eCode != SQLITE_DONE)
2255 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE error code:"), DLT_INT(eCode));
2256 return E_DATABASE_ERROR;
2259 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2261 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:"), DLT_INT(eCode));
2262 return E_DATABASE_ERROR;
2268 am_Error_e DatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2270 listMainSinks.clear();
2271 sqlite3_stmt* query = NULL;
2275 std::string command = "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2276 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2278 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2280 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2281 temp.sinkID = sqlite3_column_int(query, 1);
2282 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2283 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2284 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 4);
2285 temp.volume = sqlite3_column_int(query, 5);
2286 temp.sinkClassID = sqlite3_column_int(query, 6);
2287 listMainSinks.push_back(temp);
2290 if (eCode != SQLITE_DONE)
2292 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"), DLT_INT(eCode));
2293 return E_DATABASE_ERROR;
2296 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2298 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
2299 return E_DATABASE_ERROR;
2305 am_Error_e DatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2307 listMainSources.clear();
2308 sqlite3_stmt* query = NULL;
2310 am_SourceType_s temp;
2311 std::string command = "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2312 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2314 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2316 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2317 temp.sourceClassID = sqlite3_column_int(query, 1);
2318 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2319 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2320 temp.sourceID = sqlite3_column_int(query, 4);
2322 listMainSources.push_back(temp);
2325 if (eCode != SQLITE_DONE)
2327 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"), DLT_INT(eCode));
2328 return E_DATABASE_ERROR;
2331 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2333 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
2334 return E_DATABASE_ERROR;
2340 am_Error_e DatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2343 if (!existSink(sinkID))
2344 return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2345 listSoundProperties.clear();
2347 sqlite3_stmt* query = NULL;
2349 am_MainSoundProperty_s temp;
2350 std::string command = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2351 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2353 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2355 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2356 temp.value = sqlite3_column_int(query, 1);
2357 listSoundProperties.push_back(temp);
2360 if (eCode != SQLITE_DONE)
2362 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"), DLT_INT(eCode));
2363 return E_DATABASE_ERROR;
2366 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2368 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"), DLT_INT(eCode));
2369 return E_DATABASE_ERROR;
2375 am_Error_e DatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2377 assert(sourceID!=0);
2378 if (!existSource(sourceID))
2379 return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2380 listSourceProperties.clear();
2382 sqlite3_stmt* query = NULL;
2384 am_MainSoundProperty_s temp;
2385 std::string command = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2386 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2388 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2390 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2391 temp.value = sqlite3_column_int(query, 1);
2392 listSourceProperties.push_back(temp);
2395 if (eCode != SQLITE_DONE)
2397 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"), DLT_INT(eCode));
2398 return E_DATABASE_ERROR;
2401 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2403 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"), DLT_INT(eCode));
2404 return E_DATABASE_ERROR;
2410 am_Error_e DatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2412 listSystemProperties.clear();
2414 sqlite3_stmt* query = NULL;
2416 am_SystemProperty_s temp;
2417 std::string command = "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2418 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2420 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2422 temp.type = (am_SystemPropertyType_e) sqlite3_column_int(query, 0);
2423 temp.value = sqlite3_column_int(query, 1);
2424 listSystemProperties.push_back(temp);
2427 if (eCode != SQLITE_DONE)
2429 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE error code:"), DLT_INT(eCode));
2430 return E_DATABASE_ERROR;
2433 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2435 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:"), DLT_INT(eCode));
2436 return E_DATABASE_ERROR;
2442 am_Error_e am::DatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2444 listConnectionFormats.clear();
2445 sqlite3_stmt *qConnectionFormat = NULL;
2447 am_ConnectionFormat_e tempConnectionFormat;
2448 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
2449 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2450 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2452 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2453 listConnectionFormats.push_back(tempConnectionFormat);
2456 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2458 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinkConnectionFormats SQLITE Finalize error code:"), DLT_INT(eCode));
2459 return E_DATABASE_ERROR;
2465 am_Error_e am::DatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2467 listConnectionFormats.clear();
2468 sqlite3_stmt* qConnectionFormat = NULL;
2470 am_ConnectionFormat_e tempConnectionFormat;
2472 //read out the connectionFormats
2473 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
2474 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2475 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2477 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2478 listConnectionFormats.push_back(tempConnectionFormat);
2481 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2483 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
2484 return E_DATABASE_ERROR;
2490 am_Error_e am::DatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const
2492 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2493 iter = mListConnectionFormat.find(gatewayID);
2494 if (iter == mListConnectionFormat.end())
2496 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat"));
2497 return (E_DATABASE_ERROR);
2499 listConnectionFormat = iter->second;
2504 am_Error_e DatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2506 assert(mainConnectionID!=0);
2508 sqlite3_stmt *query = NULL;
2511 std::string command = "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2512 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2514 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2516 delay = sqlite3_column_int(query, 0);
2519 if (eCode != SQLITE_DONE)
2521 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE error code:"), DLT_INT(eCode));
2522 return E_DATABASE_ERROR;
2525 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2527 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE Finalize error code:"), DLT_INT(eCode));
2528 return E_DATABASE_ERROR;
2532 return E_NOT_POSSIBLE;
2537 bool DatabaseHandler::sqQuery(const std::string& query)
2539 sqlite3_stmt* statement;
2541 if ((eCode = sqlite3_exec(mDatabase, query.c_str(), NULL, &statement, NULL)) != SQLITE_OK)
2543 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sqQuery SQL Query failed:"), DLT_STRING(query.c_str()), DLT_STRING("error code:"), DLT_INT(eCode));
2549 bool DatabaseHandler::openDatabase()
2551 if (sqlite3_open_v2(mPath.c_str(), &mDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
2553 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::openDatabase opened database"));
2555 }DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::openDatabase failed to open database"));
2559 am_Error_e DatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
2561 assert(connectionID!=0);
2563 sqlite3_stmt* query = NULL;
2565 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE delay=? AND mainConnectionID=?";
2566 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2567 sqlite3_bind_int(query, 1, delay);
2568 sqlite3_bind_int(query, 2, connectionID);
2569 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2571 sqlite3_finalize(query);
2574 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
2575 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2576 sqlite3_bind_int(query, 1, delay);
2577 sqlite3_bind_int(query, 2, connectionID);
2579 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2581 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:"), DLT_INT(eCode));
2582 return E_DATABASE_ERROR;
2585 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2587 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:"), DLT_INT(eCode));
2588 return E_DATABASE_ERROR;
2591 if (mDatabaseObserver)
2592 mDatabaseObserver->timingInformationChanged(connectionID, delay);
2597 am_Error_e DatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
2599 assert(connection.connectionID==0);
2600 assert(connection.sinkID!=0);
2601 assert(connection.sourceID!=0);
2602 //connection format is not checked, because it's project specific
2604 sqlite3_stmt* query = NULL;
2606 std::string command = "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
2608 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2609 sqlite3_bind_int(query, 1, connection.sinkID);
2610 sqlite3_bind_int(query, 2, connection.sourceID);
2611 sqlite3_bind_int(query, 3, connection.delay);
2612 sqlite3_bind_int(query, 4, connection.connectionFormat);
2613 sqlite3_bind_int(query, 5, true);
2615 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2617 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Step error code:"), DLT_INT(eCode));
2618 return E_DATABASE_ERROR;
2621 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2623 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:"), DLT_INT(eCode));
2624 return E_DATABASE_ERROR;
2627 connectionID = sqlite3_last_insert_rowid(mDatabase);
2629 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterConnectionDB entered new connection sourceID:"), DLT_INT16(connection.sourceID), DLT_STRING("sinkID:"), DLT_INT16(connection.sinkID), DLT_STRING("sourceID:"), DLT_INT16(connection.sourceID), DLT_STRING("delay:"), DLT_INT16(connection.delay), DLT_STRING("connectionFormat:"), DLT_INT16(connection.connectionFormat), DLT_STRING("assigned ID:"), DLT_INT16(connectionID));
2633 am_Error_e DatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
2635 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
2636 assert(!sinkClass.listClassProperties.empty());
2637 assert(!sinkClass.name.empty());
2639 sqlite3_stmt* query = NULL;
2641 std::string command;
2643 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2644 if (sinkClass.sinkClassID == 0 && !mFirstStaticSinkClass)
2646 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
2650 //check if the ID already exists
2651 if (existSinkClass(sinkClass.sinkClassID))
2652 return E_ALREADY_EXISTS;
2653 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
2656 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2657 sqlite3_bind_text(query, 1, sinkClass.name.c_str(), sinkClass.name.size(), SQLITE_STATIC);
2659 //if the ID is not created, we add it to the query
2660 if (sinkClass.sinkClassID != 0)
2662 sqlite3_bind_int(query, 2, sinkClass.sinkClassID);
2665 //if the first static sink is entered, we need to set it onto the boundary
2666 else if (mFirstStaticSinkClass)
2668 sqlite3_bind_int(query, 2, DYNAMIC_ID_BOUNDARY);
2669 mFirstStaticSinkClass = false;
2672 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2674 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"), DLT_INT(eCode));
2675 return E_DATABASE_ERROR;
2678 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2680 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"), DLT_INT(eCode));
2681 return E_DATABASE_ERROR;
2684 sinkClassID = sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2686 //now we need to create the additional tables:
2687 command = "CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2688 assert(this->sqQuery(command));
2690 //fill ConnectionFormats
2691 command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
2692 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2693 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
2694 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
2696 sqlite3_bind_int(query, 1, Iterator->classProperty);
2697 sqlite3_bind_int(query, 2, Iterator->value);
2698 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2700 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"), DLT_INT(eCode));
2701 return E_DATABASE_ERROR;
2703 sqlite3_reset(query);
2706 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2708 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"), DLT_INT(eCode));
2709 return E_DATABASE_ERROR;
2712 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkClassDB entered new sinkClass"));
2713 if (mDatabaseObserver)
2714 mDatabaseObserver->numberOfSinkClassesChanged();
2718 am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
2720 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
2721 assert(!sourceClass.listClassProperties.empty());
2722 assert(!sourceClass.name.empty());
2724 sqlite3_stmt* query = NULL;
2726 std::string command;
2728 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2729 if (sourceClass.sourceClassID == 0 && !mFirstStaticSourceClass)
2731 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
2735 //check if the ID already exists
2736 if (existSourceClass(sourceClass.sourceClassID))
2737 return E_ALREADY_EXISTS;
2738 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
2741 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2742 sqlite3_bind_text(query, 1, sourceClass.name.c_str(), sourceClass.name.size(), SQLITE_STATIC);
2744 //if the ID is not created, we add it to the query
2745 if (sourceClass.sourceClassID != 0)
2747 sqlite3_bind_int(query, 2, sourceClass.sourceClassID);
2750 //if the first static sink is entered, we need to set it onto the boundary
2751 else if (mFirstStaticSourceClass)
2753 sqlite3_bind_int(query, 2, DYNAMIC_ID_BOUNDARY);
2754 mFirstStaticSourceClass = false;
2757 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2759 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"), DLT_INT(eCode));
2760 return E_DATABASE_ERROR;
2763 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2765 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"), DLT_INT(eCode));
2766 return E_DATABASE_ERROR;
2769 sourceClassID = sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2771 //now we need to create the additional tables:
2772 command = "CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2773 assert(sqQuery(command));
2775 //fill ConnectionFormats
2776 command = "INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
2777 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2778 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
2779 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
2781 sqlite3_bind_int(query, 1, Iterator->classProperty);
2782 sqlite3_bind_int(query, 2, Iterator->value);
2783 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2785 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"), DLT_INT(eCode));
2786 return E_DATABASE_ERROR;
2788 sqlite3_reset(query);
2791 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2793 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"), DLT_INT(eCode));
2794 return E_DATABASE_ERROR;
2797 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSourceClassDB entered new sourceClass"));
2799 if (mDatabaseObserver)
2800 mDatabaseObserver->numberOfSourceClassesChanged();
2804 am_Error_e DatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
2806 sqlite3_stmt* query = NULL;
2808 std::vector<am_SystemProperty_s>::const_iterator listIterator = listSystemProperties.begin();
2809 std::string command = "DELETE * FROM " + std::string(SYSTEM_TABLE);
2812 command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
2814 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2815 for (; listIterator < listSystemProperties.end(); ++listIterator)
2817 sqlite3_bind_int(query, 1, listIterator->type);
2818 sqlite3_bind_int(query, 2, listIterator->value);
2820 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2822 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Step error code:"), DLT_INT(eCode));
2823 return E_DATABASE_ERROR;
2826 sqlite3_reset(query);
2829 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2831 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:"), DLT_INT(eCode));
2832 return E_DATABASE_ERROR;
2835 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSystemProperties entered system properties"));
2839 bool DatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
2841 sqlite3_stmt* query = NULL;
2842 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2844 bool returnVal = true;
2845 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2846 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2848 else if (eCode != SQLITE_ROW)
2851 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
2853 sqlite3_finalize(query);
2857 bool DatabaseHandler::existSource(const am_sourceID_t sourceID) const
2859 sqlite3_stmt* query = NULL;
2860 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
2862 bool returnVal = true;
2863 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2864 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2866 else if (eCode != SQLITE_ROW)
2869 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2871 sqlite3_finalize(query);
2875 bool DatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
2877 sqlite3_stmt* query = NULL;
2878 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
2880 bool returnVal = true;
2881 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2882 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
2883 sqlite3_bind_int(query, 2, sourceID);
2884 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2886 else if (eCode != SQLITE_ROW)
2889 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2891 sqlite3_finalize(query);
2895 bool DatabaseHandler::existSourceName(const std::string & name) const
2897 sqlite3_stmt* query = NULL;
2898 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
2900 bool returnVal = true;
2901 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2902 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
2903 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2905 else if (eCode != SQLITE_ROW)
2908 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2910 sqlite3_finalize(query);
2914 bool DatabaseHandler::existSink(const am_sinkID_t sinkID) const
2916 sqlite3_stmt* query = NULL;
2917 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
2919 bool returnVal = true;
2920 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2921 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2923 else if (eCode != SQLITE_ROW)
2926 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2928 sqlite3_finalize(query);
2932 bool DatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
2934 sqlite3_stmt* query = NULL;
2935 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
2937 bool returnVal = true;
2938 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2939 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
2940 sqlite3_bind_int(query, 2, sinkID);
2941 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2943 else if (eCode != SQLITE_ROW)
2946 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2948 sqlite3_finalize(query);
2952 bool DatabaseHandler::existSinkName(const std::string & name) const
2954 sqlite3_stmt* query = NULL;
2955 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
2957 bool returnVal = true;
2958 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2959 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
2960 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2962 else if (eCode != SQLITE_ROW)
2965 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2967 sqlite3_finalize(query);
2971 bool DatabaseHandler::existDomain(const am_domainID_t domainID) const
2973 sqlite3_stmt* query = NULL;
2974 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
2976 bool returnVal = true;
2977 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2978 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2980 else if (eCode != SQLITE_ROW)
2983 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existDomain database error!:"), DLT_INT(eCode))
2985 sqlite3_finalize(query);
2989 bool DatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
2991 sqlite3_stmt* query = NULL;
2992 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
2994 bool returnVal = true;
2995 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2996 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2998 else if (eCode != SQLITE_ROW)
3001 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existGateway database error!:"), DLT_INT(eCode))
3003 sqlite3_finalize(query);
3007 am_Error_e DatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
3009 assert(sourceID!=0);
3011 sqlite3_stmt* query = NULL;
3012 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3014 am_Error_e returnVal = E_DATABASE_ERROR;
3015 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3016 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3018 domainID = sqlite3_column_int(query, 0);
3023 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainOfSource database error!:"), DLT_INT(eCode))
3025 sqlite3_finalize(query);
3029 am_Error_e am::DatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const
3033 sqlite3_stmt* query = NULL;
3034 std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3036 am_Error_e returnVal = E_DATABASE_ERROR;
3037 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3038 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3040 domainID = sqlite3_column_int(query, 0);
3045 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainOfSink database error!:"), DLT_INT(eCode))
3047 sqlite3_finalize(query);
3051 bool DatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3053 sqlite3_stmt* query = NULL;
3054 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
3056 bool returnVal = true;
3057 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3058 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3060 else if (eCode != SQLITE_ROW)
3063 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3065 sqlite3_finalize(query);
3069 bool DatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3071 sqlite3_stmt* query = NULL;
3072 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
3074 bool returnVal = true;
3075 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3076 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3078 else if (eCode != SQLITE_ROW)
3081 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3083 sqlite3_finalize(query);
3087 am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3089 assert(connectionID!=0);
3091 sqlite3_stmt *query = NULL, *queryMainConnections, *queryMainConnectionSubIDs;
3092 int eCode = 0, eCode1 = 0;
3093 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3095 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3096 sqlite3_bind_int(query, 1, delay);
3097 sqlite3_bind_int(query, 2, connectionID);
3099 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3101 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:"), DLT_INT(eCode));
3102 return E_DATABASE_ERROR;
3105 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3107 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"), DLT_INT(eCode));
3108 return E_DATABASE_ERROR;
3111 //now we need to find all mainConnections that use the changed connection and update their timing
3113 int tempMainConnectionID;
3114 //first get all route tables for all mainconnections
3115 command = "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'";
3116 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryMainConnections, NULL);
3118 while ((eCode = sqlite3_step(queryMainConnections)) == SQLITE_ROW)
3120 //now check if the connection ID is in this table
3121 std::string tablename = std::string((const char*) sqlite3_column_text(queryMainConnections, 0));
3122 std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID);
3123 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &queryMainConnectionSubIDs, NULL);
3124 if ((eCode1 = sqlite3_step(queryMainConnectionSubIDs)) == SQLITE_ROW)
3126 //if the connection ID is in, recalculate the mainconnection delay
3127 std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID;
3128 changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID), tempMainConnectionID);
3130 else if (eCode1 != SQLITE_DONE)
3132 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"), DLT_INT(eCode1));
3133 return E_DATABASE_ERROR;
3137 if (eCode != SQLITE_DONE)
3139 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"), DLT_INT(eCode));
3140 return E_DATABASE_ERROR;
3143 if ((eCode = sqlite3_finalize(queryMainConnections)) != SQLITE_OK)
3145 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"), DLT_INT(eCode));
3146 return E_DATABASE_ERROR;
3152 am_Error_e DatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3154 assert(connectionID!=0);
3156 sqlite3_stmt *query = NULL;
3158 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3160 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3161 sqlite3_bind_int(query, 1, connectionID);
3163 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3165 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Step error code:"), DLT_INT(eCode));
3166 return E_DATABASE_ERROR;
3169 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3171 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:"), DLT_INT(eCode));
3172 return E_DATABASE_ERROR;
3177 am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3179 assert(mainConnectionID!=0);
3180 sqlite3_stmt* query = NULL;
3181 std::string command = "SELECT sum(Connections.delay),min(Connections.delay) FROM " + std::string(CONNECTION_TABLE) + ",MainConnectionRoute" + i2s(mainConnectionID) + " WHERE MainConnectionRoute" + i2s(mainConnectionID) + ".connectionID = Connections.connectionID";
3183 am_timeSync_t delay = 0;
3184 am_timeSync_t min = 0;
3185 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3186 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3188 delay = sqlite3_column_int(query, 0);
3189 min = sqlite3_column_int(query, 1);
3191 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3193 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:"), DLT_INT(eCode));
3194 return E_DATABASE_ERROR;
3197 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3199 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:"), DLT_INT(eCode));
3200 return E_DATABASE_ERROR;
3208 void DatabaseHandler::registerObserver(DatabaseObserver *iObserver)
3210 assert(iObserver!=NULL);
3211 mDatabaseObserver = iObserver;
3214 bool DatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3216 assert(sourceID!=0);
3217 sqlite3_stmt* query = NULL;
3218 std::string command = "SELECT visible FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3220 bool returnVal = false;
3221 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3222 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3224 returnVal = (bool) sqlite3_column_int(query, 0);
3226 else if (eCode != SQLITE_ROW)
3229 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sourceVisible database error!:"), DLT_INT(eCode))
3231 sqlite3_finalize(query);
3235 bool DatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3237 sqlite3_stmt* query = NULL;
3238 std::string command = "SELECT visible FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3240 bool returnVal = false;
3241 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3242 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3244 returnVal = sqlite3_column_int(query, 0);
3246 else if (eCode != SQLITE_ROW)
3249 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sinkVisible database error!:"), DLT_INT(eCode))
3251 sqlite3_finalize(query);
3255 bool DatabaseHandler::existConnection(const am_Connection_s connection)
3257 sqlite3_stmt* query = NULL;
3258 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3260 bool returnVal = true;
3261 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3262 sqlite3_bind_int(query, 1, connection.sinkID);
3263 sqlite3_bind_int(query, 2, connection.sourceID);
3264 sqlite3_bind_int(query, 3, connection.connectionFormat);
3265 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3267 else if (eCode != SQLITE_ROW)
3270 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3272 sqlite3_finalize(query);
3276 bool DatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3278 sqlite3_stmt* query = NULL;
3279 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3281 bool returnVal = true;
3282 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3283 sqlite3_bind_int(query, 1, connectionID);
3284 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3286 else if (eCode != SQLITE_ROW)
3289 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3291 sqlite3_finalize(query);
3295 bool DatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3297 sqlite3_stmt* query = NULL;
3298 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3300 bool returnVal = true;
3301 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3302 sqlite3_bind_int(query, 1, crossfaderID);
3303 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3305 else if (eCode != SQLITE_ROW)
3308 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3310 sqlite3_finalize(query);
3314 am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3316 assert(sourceID!=0);
3317 sqlite3_stmt* query = NULL;
3318 sourceState = SS_MIN;
3319 std::string command = "SELECT sourceState FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3321 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3322 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3324 sourceState = (am_SourceState_e) sqlite3_column_int(query, 0);
3326 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3328 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSoureState database error!:"), DLT_INT(eCode))
3331 sqlite3_finalize(query);
3335 am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3337 assert(sourceID!=0);
3338 sqlite3_stmt* query = NULL;
3339 std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID);
3341 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3342 sqlite3_bind_int(query, 1, sourceState);
3343 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3345 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Step error code:"), DLT_INT(eCode));
3346 return E_DATABASE_ERROR;
3349 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3351 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Finalize error code:"), DLT_INT(eCode));
3352 return E_DATABASE_ERROR;
3357 am_Error_e DatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3360 sqlite3_stmt* query = NULL;
3362 std::string command = "SELECT volume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3364 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3365 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3367 volume = sqlite3_column_int(query, 0);
3369 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3371 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkVolume database error!:"), DLT_INT(eCode))
3374 sqlite3_finalize(query);
3378 am_Error_e DatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
3380 assert(sourceID!=0);
3381 sqlite3_stmt* query = NULL;
3383 std::string command = "SELECT volume FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3385 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3386 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3388 volume = sqlite3_column_int(query, 0);
3390 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3392 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceVolume database error!:"), DLT_INT(eCode))
3394 sqlite3_finalize(query);
3398 am_Error_e DatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3401 if (!existSink(sinkID))
3402 return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3404 sqlite3_stmt* query = NULL;
3406 std::string command = "SELECT value FROM SinkSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType);
3407 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3409 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3411 value = sqlite3_column_int(query, 0);
3414 if (eCode != SQLITE_DONE)
3416 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"), DLT_INT(eCode));
3417 return E_DATABASE_ERROR;
3420 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3422 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"), DLT_INT(eCode));
3423 return E_DATABASE_ERROR;
3429 am_Error_e DatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3431 assert(sourceID!=0);
3432 if (!existSource(sourceID))
3433 return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3435 sqlite3_stmt* query = NULL;
3437 std::string command = "SELECT value FROM SourceSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType);
3438 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3440 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3442 value = sqlite3_column_int(query, 0);
3445 if (eCode != SQLITE_DONE)
3447 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"), DLT_INT(eCode));
3448 return E_DATABASE_ERROR;
3451 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3453 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"), DLT_INT(eCode));
3454 return E_DATABASE_ERROR;
3460 am_Error_e DatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
3462 assert(domainID!=0);
3463 sqlite3_stmt* query = NULL;
3465 std::string command = "SELECT domainState FROM " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
3467 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3468 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3470 state = (am_DomainState_e) sqlite3_column_int(query, 0);
3472 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3474 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainState database error!:"), DLT_INT(eCode))
3477 sqlite3_finalize(query);
3482 am_Error_e DatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
3484 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3485 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
3486 int eCode = 0, eCode1 = 0;
3487 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3488 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3489 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3491 domainID = sqlite3_column_int(query, 0);
3493 else if (eCode != SQLITE_DONE)
3495 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain database error!:"), DLT_INT(eCode))
3496 return E_DATABASE_ERROR;
3500 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
3501 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3502 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3503 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3504 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3506 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Step error code:"), DLT_INT(eCode1));
3507 return E_DATABASE_ERROR;
3510 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3512 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"), DLT_INT(eCode1));
3513 return E_DATABASE_ERROR;
3515 domainID = sqlite3_last_insert_rowid(mDatabase);
3517 sqlite3_finalize(query);
3521 am_Error_e DatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
3523 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3524 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
3525 int eCode = 0, eCode1 = 0;
3526 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3527 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3528 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3530 sinkID = sqlite3_column_int(query, 0);
3532 else if (eCode != SQLITE_DONE)
3534 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3535 return E_DATABASE_ERROR;
3539 if (mFirstStaticSink)
3541 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3542 mFirstStaticSink = false;
3546 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
3548 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3549 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3550 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3551 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3553 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"), DLT_INT(eCode1));
3554 return E_DATABASE_ERROR;
3557 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3559 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"), DLT_INT(eCode1));
3560 return E_DATABASE_ERROR;
3562 sinkID = sqlite3_last_insert_rowid(mDatabase);
3564 sqlite3_finalize(query);
3568 am_Error_e DatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
3570 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3571 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
3572 int eCode = 0, eCode1 = 0;
3573 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3574 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3575 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3577 sourceID = sqlite3_column_int(query, 0);
3579 else if (eCode != SQLITE_DONE)
3581 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3582 return E_DATABASE_ERROR;
3586 if (mFirstStaticSource)
3588 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3589 mFirstStaticSource = false;
3593 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
3595 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3596 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3597 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3598 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3600 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"), DLT_INT(eCode1));
3601 return E_DATABASE_ERROR;
3604 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3606 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"), DLT_INT(eCode1));
3607 return E_DATABASE_ERROR;
3609 sourceID = sqlite3_last_insert_rowid(mDatabase);
3611 sqlite3_finalize(query);
3615 am_Error_e DatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
3619 sqlite3_stmt* query = NULL;
3621 std::string command;
3623 if (!existSink(sinkID))
3625 return E_NON_EXISTENT;
3627 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
3628 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3629 sqlite3_bind_int(query, 1, volume);
3630 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3632 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Step error code:"), DLT_INT(eCode));
3633 return E_DATABASE_ERROR;
3635 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3637 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:"), DLT_INT(eCode));
3638 return E_DATABASE_ERROR;
3641 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkVolume changed volume of sink:"), DLT_INT(sinkID), DLT_STRING("to:"), DLT_INT(volume));
3646 am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
3648 assert(sourceID!=0);
3650 sqlite3_stmt* query = NULL;
3652 std::string command;
3654 if (!existSource(sourceID))
3656 return E_NON_EXISTENT;
3658 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
3659 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3660 sqlite3_bind_int(query, 1, volume);
3661 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3663 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Step error code:"), DLT_INT(eCode));
3664 return E_DATABASE_ERROR;
3666 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3668 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:"), DLT_INT(eCode));
3669 return E_DATABASE_ERROR;
3672 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceVolume changed volume of source=:"), DLT_INT(sourceID), DLT_STRING("to:"), DLT_INT(volume));
3677 am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
3679 //todo: add checks if soundproperty exists!
3680 assert(sourceID!=0);
3682 sqlite3_stmt* query = NULL;
3684 std::string command;
3686 if (!existSource(sourceID))
3688 return E_NON_EXISTENT;
3690 command = "UPDATE SourceSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3691 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3692 sqlite3_bind_int(query, 1, soundProperty.value);
3693 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3695 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
3696 return E_DATABASE_ERROR;
3699 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3701 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
3702 return E_DATABASE_ERROR;
3705 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:"), DLT_INT(sourceID), DLT_STRING("type:"), DLT_INT(soundProperty.type), DLT_STRING("to:"), DLT_INT(soundProperty.value));
3710 am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
3712 //todo: add checks if soundproperty exists!
3715 sqlite3_stmt* query = NULL;
3717 std::string command;
3719 if (!existSink(sinkID))
3721 return E_NON_EXISTENT;
3723 command = "UPDATE SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3724 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3725 sqlite3_bind_int(query, 1, soundProperty.value);
3726 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3728 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
3729 return E_DATABASE_ERROR;
3732 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3734 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
3735 return E_DATABASE_ERROR;
3738 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB changed MainSinkSoundProperty of sink:"), DLT_INT(sinkID), DLT_STRING("type:"), DLT_INT(soundProperty.type), DLT_STRING("to:"), DLT_INT(soundProperty.value));
3743 am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
3745 assert(crossfaderID!=0);
3747 sqlite3_stmt* query = NULL;
3749 std::string command;
3751 if (!existcrossFader(crossfaderID))
3753 return E_NON_EXISTENT;
3755 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
3756 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3757 sqlite3_bind_int(query, 1, hotsink);
3758 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3760 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:"), DLT_INT(eCode));
3761 return E_DATABASE_ERROR;
3763 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3765 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:"), DLT_INT(eCode));
3766 return E_DATABASE_ERROR;
3769 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader="), DLT_INT(crossfaderID), DLT_STRING("to:"), DLT_INT(hotsink));
3774 am_Error_e DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree& tree, std::vector<RoutingTreeItem*>& flatTree)
3776 sqlite3_stmt* query = NULL;
3779 std::string command;
3780 am_domainID_t rootID = tree.returnRootDomainID();
3781 RoutingTreeItem *parent = tree.returnRootItem();
3783 command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=? AND inUse=?";
3789 parent = flatTree.at(i - 1);
3790 rootID = parent->returnDomainID();
3792 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3793 sqlite3_bind_int(query, 1, rootID);
3794 sqlite3_bind_int(query, 2, onlyfree);
3796 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3798 flatTree.push_back(tree.insertItem(sqlite3_column_int(query, 0), sqlite3_column_int(query, 1), parent));
3801 if (eCode != SQLITE_DONE)
3803 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getRoutingTree SQLITE error code:"), DLT_INT(eCode));
3804 return (E_DATABASE_ERROR);
3807 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3809 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getRoutingTree SQLITE Finalize error code:"), DLT_INT(eCode));
3810 return (E_DATABASE_ERROR);
3813 } while (flatTree.size() > (i - 1));
3818 void DatabaseHandler::createTables()
3820 for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++)
3822 assert(sqQuery("CREATE TABLE " + databaseTables[i]));