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) mDatabaseObserver->newDomain(domain);
177 am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
179 assert(mainConnectionData.connectionID==0);
180 assert(mainConnectionData.connectionState>=CS_CONNECTING && mainConnectionData.connectionState<=CS_SUSPENDED);
181 assert(mainConnectionData.route.sinkID!=0);
182 assert(mainConnectionData.route.sourceID!=0);
184 sqlite3_stmt* query = NULL;
186 std::string command = "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)";
187 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
188 sqlite3_bind_int(query, 1, mainConnectionData.route.sourceID);
189 sqlite3_bind_int(query, 2, mainConnectionData.route.sinkID);
190 sqlite3_bind_int(query, 3, mainConnectionData.connectionState);
192 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
194 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"), DLT_INT(eCode));
195 return E_DATABASE_ERROR;
198 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
200 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"), DLT_INT(eCode));
201 return E_DATABASE_ERROR;
204 connectionID = sqlite3_last_insert_rowid(mDatabase);
206 //now check the connectionTable for all connections in the route. IF a particular route is not found, we return with error
207 std::vector<uint16_t> listOfConnections;
209 command = "SELECT connectionID, delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
210 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
211 std::vector<am_RoutingElement_s>::const_iterator elementIterator = mainConnectionData.route.route.begin();
212 for (; elementIterator < mainConnectionData.route.route.end(); ++elementIterator)
214 sqlite3_bind_int(query, 1, elementIterator->sourceID);
215 sqlite3_bind_int(query, 2, elementIterator->sinkID);
216 sqlite3_bind_int(query, 3, elementIterator->connectionFormat);
218 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
220 listOfConnections.push_back(sqlite3_column_int(query, 0));
221 int16_t temp_delay = sqlite3_column_int(query, 1);
222 if (temp_delay != -1 && delay != -1)
229 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:"), DLT_INT(eCode));
230 return E_DATABASE_ERROR;
232 sqlite3_reset(query);
235 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
237 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"), DLT_INT(eCode));
238 return E_DATABASE_ERROR;
241 //now we create a table with references to the connections;
242 command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
243 assert(this->sqQuery(command));
245 command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
246 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
247 std::vector<uint16_t>::iterator listConnectionIterator = listOfConnections.begin();
248 for (; listConnectionIterator < listOfConnections.end(); ++listConnectionIterator)
250 sqlite3_bind_int(query, 1, *listConnectionIterator);
251 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
253 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"), DLT_INT(eCode));
254 return E_DATABASE_ERROR;
256 sqlite3_reset(query);
259 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
261 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"), DLT_INT(eCode));
262 return E_DATABASE_ERROR;
265 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));
267 if (mDatabaseObserver)
269 mDatabaseObserver->numberOfMainConnectionsChanged();
270 mDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState);
273 //finally, we update the delay value for the maintable
274 if (delay == 0) delay = -1;
275 return changeDelayMainConnection(delay, connectionID);
278 am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
280 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
281 assert(sinkData.domainID!=0);
282 assert(!sinkData.name.empty());
283 assert(sinkData.sinkClassID!=0);
284 // \todo: need to check if class exists?
285 assert(!sinkData.listConnectionFormats.empty());
286 assert(sinkData.muteState>=MS_MUTED && sinkData.muteState<=MS_UNMUTED);
288 sqlite3_stmt *query = NULL, *queryFinal = NULL;
290 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
292 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
293 sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
295 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
297 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));
299 else if (eCode == SQLITE_DONE)
301 //if sinkID is zero and the first Static Sink was already entered, the ID is created
302 if (sinkData.sinkID == 0 && !mFirstStaticSink && !existSinkName(sinkData.name))
304 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
308 //check if the ID already exists
309 if (existSinkNameOrID(sinkData.sinkID, sinkData.name))
311 sqlite3_finalize(query);
312 return E_ALREADY_EXISTS;
314 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
319 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
320 sqlite3_finalize(query);
321 return E_DATABASE_ERROR;
324 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
326 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"), DLT_INT(eCode));
327 return E_DATABASE_ERROR;
330 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
331 sqlite3_bind_text(queryFinal, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
332 sqlite3_bind_int(queryFinal, 2, sinkData.domainID);
333 sqlite3_bind_int(queryFinal, 3, sinkData.sinkClassID);
334 sqlite3_bind_int(queryFinal, 4, sinkData.volume);
335 sqlite3_bind_int(queryFinal, 5, sinkData.visible);
336 sqlite3_bind_int(queryFinal, 6, sinkData.available.availability);
337 sqlite3_bind_int(queryFinal, 7, sinkData.available.availabilityReason);
338 sqlite3_bind_int(queryFinal, 8, sinkData.muteState);
339 sqlite3_bind_int(queryFinal, 9, sinkData.mainVolume);
340 sqlite3_bind_int(queryFinal, 10, 0);
342 //if the ID is not created, we add it to the query
343 if (sinkData.sinkID != 0)
345 sqlite3_bind_int(queryFinal, 11, sinkData.sinkID);
348 //if the first static sink is entered, we need to set it onto the boundary
349 else if (mFirstStaticSink)
351 sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY);
352 mFirstStaticSink = false;
355 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
357 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
358 sqlite3_finalize(queryFinal);
359 return E_DATABASE_ERROR;
362 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
364 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"), DLT_INT(eCode));
365 return E_DATABASE_ERROR;
368 //now read back the sinkID
369 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
370 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
371 sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
372 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
374 sinkID = sqlite3_column_int(query, 0);
379 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
380 sqlite3_finalize(query);
381 return E_DATABASE_ERROR;
383 sqlite3_finalize(query);
385 //now we need to create the additional tables:
386 command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
387 assert(this->sqQuery(command));
388 command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
389 assert(this->sqQuery(command));
390 command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
391 assert(this->sqQuery(command));
393 //fill ConnectionFormats
394 command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
395 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
396 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin();
397 for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator)
399 sqlite3_bind_int(query, 1, *connectionFormatIterator);
400 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
402 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
403 sqlite3_finalize(query);
404 return E_DATABASE_ERROR;
406 sqlite3_reset(query);
409 //Fill MainSinkSoundProperties
410 command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
411 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
412 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin();
413 for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
415 sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type);
416 sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value);
417 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
419 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
420 sqlite3_finalize(query);
421 return E_DATABASE_ERROR;
423 sqlite3_reset(query);
426 //Fill SinkSoundProperties
427 command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
428 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
429 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin();
430 for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator)
432 sqlite3_bind_int(query, 1, SoundPropertyIterator->type);
433 sqlite3_bind_int(query, 2, SoundPropertyIterator->value);
434 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
436 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
437 sqlite3_finalize(query);
438 return E_DATABASE_ERROR;
440 sqlite3_reset(query);
443 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));
445 am_Sink_s sink = sinkData;
446 sink.sinkID = sinkID;
447 if (mDatabaseObserver != NULL) mDatabaseObserver->newSink(sink);
452 am_Error_e DatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
454 //todo: implement crossfader
455 (void) crossfaderData;
460 am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
462 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
463 assert(gatewayData.sinkID!=0);
464 assert(gatewayData.sourceID!=0);
465 assert(gatewayData.controlDomainID!=0);
466 assert(gatewayData.domainSinkID!=0);
467 assert(gatewayData.domainSourceID!=0);
468 assert(!gatewayData.name.empty());
469 assert(!gatewayData.convertionMatrix.empty());
470 assert(!gatewayData.listSinkFormats.empty());
471 assert(!gatewayData.listSourceFormats.empty());
473 sqlite3_stmt* query = NULL;
477 //if sinkID is zero and the first Static Sink was already entered, the ID is created
478 if (gatewayData.gatewayID == 0 && !mFirstStaticGateway)
480 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, inUse) VALUES (?,?,?,?,?,?,0)";
484 //check if the ID already exists
485 if (existGateway(gatewayData.gatewayID)) return E_ALREADY_EXISTS;
486 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID, inUse) VALUES (?,?,?,?,?,?,?,0)";
489 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
490 sqlite3_bind_text(query, 1, gatewayData.name.c_str(), gatewayData.name.size(), SQLITE_STATIC);
491 sqlite3_bind_int(query, 2, gatewayData.sinkID);
492 sqlite3_bind_int(query, 3, gatewayData.sourceID);
493 sqlite3_bind_int(query, 4, gatewayData.domainSinkID);
494 sqlite3_bind_int(query, 5, gatewayData.domainSourceID);
495 sqlite3_bind_int(query, 6, gatewayData.controlDomainID);
497 //if the ID is not created, we add it to the query
498 if (gatewayData.gatewayID != 0)
500 sqlite3_bind_int(query, 7, gatewayData.gatewayID);
503 //if the first static sink is entered, we need to set it onto the boundary
504 else if (mFirstStaticGateway)
506 sqlite3_bind_int(query, 7, DYNAMIC_ID_BOUNDARY);
507 mFirstStaticGateway = false;
510 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
512 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"), DLT_INT(eCode));
513 return E_DATABASE_ERROR;
516 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
518 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Finalize error code:"), DLT_INT(eCode));
519 return E_DATABASE_ERROR;
522 gatewayID = sqlite3_last_insert_rowid(mDatabase);
524 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
525 mListConnectionFormat.insert(std::make_pair(gatewayID, gatewayData.convertionMatrix));
527 command = "CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
528 assert(this->sqQuery(command));
529 command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
530 assert(this->sqQuery(command));
532 //fill ConnectionFormats
533 command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
534 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
535 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin();
536 for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator)
538 sqlite3_bind_int(query, 1, *connectionFormatIterator);
539 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
541 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"), DLT_INT(eCode));
542 return E_DATABASE_ERROR;
544 sqlite3_reset(query);
547 command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
548 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
549 connectionFormatIterator = gatewayData.listSinkFormats.begin();
550 for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator)
552 sqlite3_bind_int(query, 1, *connectionFormatIterator);
553 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
555 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"), DLT_INT(eCode));
556 return E_DATABASE_ERROR;
558 sqlite3_reset(query);
561 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));
563 am_Gateway_s gateway = gatewayData;
564 gateway.gatewayID = gatewayID;
565 if (mDatabaseObserver) mDatabaseObserver->newGateway(gateway);
569 am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
571 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
572 assert(sourceData.domainID!=0);
573 assert(!sourceData.name.empty());
574 assert(sourceData.sourceClassID!=0);
575 // \todo: need to check if class exists?
576 assert(!sourceData.listConnectionFormats.empty());
577 assert(sourceData.sourceState>=SS_ON && sourceData.sourceState<=SS_PAUSED);
579 sqlite3_stmt* query = NULL, *queryFinal = NULL;
582 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
584 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
585 sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
587 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
589 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));
591 else if (eCode == SQLITE_DONE)
593 //if sinkID is zero and the first Static Sink was already entered, the ID is created
594 if (sourceData.sourceID == 0 && !mFirstStaticSource && !existSourceName(sourceData.name))
596 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
600 //check if the ID already exists
601 if (existSourceNameOrID(sourceData.sourceID, sourceData.name))
603 sqlite3_finalize(query);
604 return E_ALREADY_EXISTS;
606 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
611 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"), DLT_INT(eCode));
612 sqlite3_finalize(query);
613 return E_DATABASE_ERROR;
616 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
618 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"), DLT_INT(eCode));
619 return E_DATABASE_ERROR;
621 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
622 sqlite3_bind_text(queryFinal, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
623 sqlite3_bind_int(queryFinal, 2, sourceData.domainID);
624 sqlite3_bind_int(queryFinal, 3, sourceData.sourceClassID);
625 sqlite3_bind_int(queryFinal, 4, sourceData.sourceState);
626 sqlite3_bind_int(queryFinal, 5, sourceData.volume);
627 sqlite3_bind_int(queryFinal, 6, sourceData.visible);
628 sqlite3_bind_int(queryFinal, 7, sourceData.available.availability);
629 sqlite3_bind_int(queryFinal, 8, sourceData.available.availabilityReason);
630 sqlite3_bind_int(queryFinal, 9, sourceData.interruptState);
631 sqlite3_bind_int(queryFinal, 10, 0);
633 //if the ID is not created, we add it to the query
634 if (sourceData.sourceID != 0)
636 sqlite3_bind_int(queryFinal, 11, sourceData.sourceID);
639 //if the first static sink is entered, we need to set it onto the boundary
640 else if (mFirstStaticSource)
642 sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY);
643 mFirstStaticSource = false;
646 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
648 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"), DLT_INT(eCode));
649 sqlite3_finalize(queryFinal);
650 return E_DATABASE_ERROR;
653 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
655 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"), DLT_INT(eCode));
656 sqlite3_finalize(queryFinal);
657 return E_DATABASE_ERROR;
660 //now read back the sinkID
661 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
662 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
663 sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
664 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
666 sourceID = sqlite3_column_int(query, 0);
671 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
672 sqlite3_finalize(query);
673 return E_DATABASE_ERROR;
675 sqlite3_finalize(query);
677 //now we need to create the additional tables:
678 command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
679 assert(this->sqQuery(command));
680 command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
681 assert(this->sqQuery(command));
682 command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
683 assert(this->sqQuery(command));
685 //fill ConnectionFormats
686 command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
687 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
688 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin();
689 for (; connectionFormatIterator < sourceData.listConnectionFormats.end(); ++connectionFormatIterator)
691 sqlite3_bind_int(query, 1, *connectionFormatIterator);
692 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
694 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"), DLT_INT(eCode));
695 sqlite3_finalize(query);
696 return E_DATABASE_ERROR;
698 sqlite3_reset(query);
701 //Fill MainSinkSoundProperties
702 command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
703 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
704 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin();
705 for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
707 sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type);
708 sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value);
709 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
711 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"), DLT_INT(eCode));
712 sqlite3_finalize(query);
713 return E_DATABASE_ERROR;
715 sqlite3_reset(query);
718 //Fill SinkSoundProperties
719 command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
720 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
721 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin();
722 for (; SoundPropertyIterator < sourceData.listSoundProperties.end(); ++SoundPropertyIterator)
724 sqlite3_bind_int(query, 1, SoundPropertyIterator->type);
725 sqlite3_bind_int(query, 2, SoundPropertyIterator->value);
726 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
728 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"), DLT_INT(eCode));
729 sqlite3_finalize(query);
730 return E_DATABASE_ERROR;
732 sqlite3_reset(query);
735 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));
737 am_Source_s source = sourceData;
738 source.sourceID = sourceID;
739 if (mDatabaseObserver) mDatabaseObserver->newSource(source);
743 am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
745 assert(mainconnectionID!=0);
746 if (!existMainConnection(mainconnectionID))
748 return E_NON_EXISTENT;
750 sqlite3_stmt* query = NULL;
754 std::vector<uint16_t> listOfConnections;
756 command = "SELECT connectionID, delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
757 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
758 std::vector<am_RoutingElement_s>::const_iterator elementIterator = route.route.begin();
759 for (; elementIterator < route.route.end(); ++elementIterator)
761 sqlite3_bind_int(query, 1, elementIterator->sourceID);
762 sqlite3_bind_int(query, 2, elementIterator->sinkID);
763 sqlite3_bind_int(query, 3, elementIterator->connectionFormat);
765 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
767 listOfConnections.push_back(sqlite3_column_int(query, 0));
768 int16_t temp_delay = sqlite3_column_int(query, 1);
769 if (temp_delay != -1 && delay != -1)
776 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:"), DLT_INT(eCode));
777 return E_DATABASE_ERROR;
779 sqlite3_reset(query);
782 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
784 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"), DLT_INT(eCode));
785 return E_DATABASE_ERROR;
788 //now we delete the data in the table
789 command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID);
790 assert(this->sqQuery(command));
792 command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
793 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
794 std::vector<uint16_t>::iterator listConnectionIterator = listOfConnections.begin();
795 for (; listConnectionIterator < listOfConnections.end(); ++listConnectionIterator)
797 sqlite3_bind_int(query, 1, *listConnectionIterator);
798 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
800 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:"), DLT_INT(eCode));
801 return E_DATABASE_ERROR;
803 sqlite3_reset(query);
806 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
808 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"), DLT_INT(eCode));
809 return E_DATABASE_ERROR;
810 }DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB entered new route:"), DLT_INT(mainconnectionID));
814 am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
816 assert(mainconnectionID!=0);
818 sqlite3_stmt* query = NULL;
822 if (!existMainConnection(mainconnectionID))
824 return E_NON_EXISTENT;
826 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
827 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
828 sqlite3_bind_int(query, 1, connectionState);
829 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
831 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:"), DLT_INT(eCode));
832 return E_DATABASE_ERROR;
834 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
836 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:"), DLT_INT(eCode));
837 return E_DATABASE_ERROR;
838 }DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:"), DLT_INT(mainconnectionID), DLT_STRING("to:"), DLT_INT(connectionState));
840 if (mDatabaseObserver) mDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState);
844 am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
848 sqlite3_stmt* query = NULL;
852 if (!existSink(sinkID))
854 return E_NON_EXISTENT;
856 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
857 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
858 sqlite3_bind_int(query, 1, mainVolume);
859 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
861 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:"), DLT_INT(eCode));
862 return E_DATABASE_ERROR;
864 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
866 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:"), DLT_INT(eCode));
867 return E_DATABASE_ERROR;
870 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:"), DLT_INT(sinkID), DLT_STRING("to:"), DLT_INT(mainVolume));
872 if (mDatabaseObserver) mDatabaseObserver->volumeChanged(sinkID, mainVolume);
877 am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
881 sqlite3_stmt* query = NULL;
885 if (!existSink(sinkID))
887 return E_NON_EXISTENT;
889 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
890 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
891 sqlite3_bind_int(query, 1, availability.availability);
892 sqlite3_bind_int(query, 2, availability.availabilityReason);
893 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
895 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:"), DLT_INT(eCode));
896 return E_DATABASE_ERROR;
899 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
901 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:"), DLT_INT(eCode));
902 return E_DATABASE_ERROR;
905 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));
907 if (mDatabaseObserver && sourceVisible(sinkID)) mDatabaseObserver->sinkAvailabilityChanged(sinkID, availability);
911 am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
915 sqlite3_stmt* query = NULL;
919 if (!existDomain(domainID))
921 return E_NON_EXISTENT;
923 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
924 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
925 sqlite3_bind_int(query, 1, domainState);
926 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
928 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Step error code:"), DLT_INT(eCode));
929 return E_DATABASE_ERROR;
932 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
934 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:"), DLT_INT(eCode));
935 return E_DATABASE_ERROR;
938 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changDomainStateDB changed domainState of domain:"), DLT_INT(domainID), DLT_STRING("to:"), DLT_INT(domainState));
942 am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
946 sqlite3_stmt* query = NULL;
950 if (!existSink(sinkID))
952 return E_NON_EXISTENT;
954 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
955 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
956 sqlite3_bind_int(query, 1, muteState);
957 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
959 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:"), DLT_INT(eCode));
960 return E_DATABASE_ERROR;
963 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
965 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:"), DLT_INT(eCode));
966 return E_DATABASE_ERROR;
969 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:"), DLT_INT(sinkID), DLT_STRING("to:"), DLT_INT(muteState));
971 if (mDatabaseObserver) mDatabaseObserver->sinkMuteStateChanged(sinkID, muteState);
976 am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
978 //todo: add checks if soundproperty exists!
981 sqlite3_stmt* query = NULL;
985 if (!existSink(sinkID))
987 return E_NON_EXISTENT;
989 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
990 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
991 sqlite3_bind_int(query, 1, soundProperty.value);
992 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
994 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
995 return E_DATABASE_ERROR;
998 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1000 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
1001 return E_DATABASE_ERROR;
1004 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));
1005 if (mDatabaseObserver) mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty);
1009 am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1011 //todo: add checks if soundproperty exists!
1012 assert(sourceID!=0);
1014 sqlite3_stmt* query = NULL;
1016 std::string command;
1018 if (!existSource(sourceID))
1020 return E_NON_EXISTENT;
1022 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1023 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1024 sqlite3_bind_int(query, 1, soundProperty.value);
1025 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1027 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
1028 return E_DATABASE_ERROR;
1031 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1033 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
1034 return E_DATABASE_ERROR;
1037 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));
1039 if (mDatabaseObserver) mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty);
1043 am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1045 assert(sourceID!=0);
1047 sqlite3_stmt* query = NULL;
1049 std::string command;
1051 if (!existSource(sourceID))
1053 return E_NON_EXISTENT;
1055 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1056 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1057 sqlite3_bind_int(query, 1, availability.availability);
1058 sqlite3_bind_int(query, 2, availability.availabilityReason);
1059 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1061 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:"), DLT_INT(eCode));
1062 return E_DATABASE_ERROR;
1065 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1067 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:"), DLT_INT(eCode));
1068 return E_DATABASE_ERROR;
1071 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));
1073 if (mDatabaseObserver && sourceVisible(sourceID)) mDatabaseObserver->sourceAvailabilityChanged(sourceID, availability);
1077 am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1079 sqlite3_stmt* query = NULL;
1081 std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1083 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1084 sqlite3_bind_int(query, 1, property.value);
1085 sqlite3_bind_int(query, 2, property.type);
1087 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1089 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
1090 return E_DATABASE_ERROR;
1093 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1095 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
1096 return E_DATABASE_ERROR;
1099 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSystemPropertyDB changed system property"));
1101 if (mDatabaseObserver) mDatabaseObserver->systemPropertyChanged(property);
1106 am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1108 assert(mainConnectionID!=0);
1110 if (!existMainConnection(mainConnectionID))
1112 return E_NON_EXISTENT;
1114 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1115 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1116 if (!sqQuery(command)) return E_DATABASE_ERROR;
1117 if (!sqQuery(command1)) return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeMainConnectionDB removed:"), DLT_INT(mainConnectionID));
1118 if (mDatabaseObserver)
1120 mDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED);
1121 mDatabaseObserver->numberOfMainConnectionsChanged();
1126 am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1130 if (!existSink(sinkID))
1132 return E_NON_EXISTENT;
1134 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1135 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1136 std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1137 std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID);
1138 if (!sqQuery(command)) return E_DATABASE_ERROR;
1139 if (!sqQuery(command1)) return E_DATABASE_ERROR;
1140 if (!sqQuery(command2)) return E_DATABASE_ERROR;
1141 if (!sqQuery(command3)) return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkDB removed:"), DLT_INT(sinkID));
1143 if (mDatabaseObserver != NULL) mDatabaseObserver->removedSink(sinkID);
1148 am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1150 assert(sourceID!=0);
1152 if (!existSource(sourceID))
1154 return E_NON_EXISTENT;
1156 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1157 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1158 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1159 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1160 if (!sqQuery(command)) return E_DATABASE_ERROR;
1161 if (!sqQuery(command1)) return E_DATABASE_ERROR;
1162 if (!sqQuery(command2)) return E_DATABASE_ERROR;
1163 if (!sqQuery(command3)) return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceDB removed:"), DLT_INT(sourceID));
1164 if (mDatabaseObserver) mDatabaseObserver->removedSource(sourceID);
1168 am_Error_e DatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1170 assert(gatewayID!=0);
1172 if (!existGateway(gatewayID))
1174 return E_NON_EXISTENT;
1176 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1177 if (!sqQuery(command)) return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeGatewayDB removed:"), DLT_INT(gatewayID));
1178 if (mDatabaseObserver) mDatabaseObserver->removeGateway(gatewayID);
1182 am_Error_e DatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1184 //todo: implement crossdfader
1185 (void) crossfaderID;
1189 am_Error_e DatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1191 assert(domainID!=0);
1193 if (!existDomain(domainID))
1195 return E_NON_EXISTENT;
1197 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1198 if (!sqQuery(command)) return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeDomainDB removed:"), DLT_INT(domainID));
1199 if (mDatabaseObserver) mDatabaseObserver->removeDomain(domainID);
1203 am_Error_e DatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1205 assert(sinkClassID!=0);
1207 if (!existSinkClass(sinkClassID))
1209 return E_NON_EXISTENT;
1211 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1212 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1213 if (!sqQuery(command)) return E_DATABASE_ERROR;
1214 if (!sqQuery(command1)) return E_DATABASE_ERROR;
1216 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkClassDB removed:"), DLT_INT(sinkClassID));
1217 if (mDatabaseObserver) mDatabaseObserver->numberOfSinkClassesChanged();
1222 am_Error_e DatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1224 assert(sourceClassID!=0);
1226 if (!existSourceClass(sourceClassID))
1228 return E_NON_EXISTENT;
1230 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1231 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1232 if (!sqQuery(command)) return E_DATABASE_ERROR;
1233 if (!sqQuery(command1)) return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceClassDB removed:"), DLT_INT(sourceClassID));
1235 if (mDatabaseObserver) mDatabaseObserver->numberOfSourceClassesChanged();
1239 am_Error_e DatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1241 assert(connectionID!=0);
1243 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1244 std::string command1 = "DROP table SourceClassProperties" + i2s(connectionID);
1245 if (!sqQuery(command)) return E_DATABASE_ERROR;
1246 if (!sqQuery(command1)) return E_DATABASE_ERROR;DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeConnection removed:"), DLT_INT(connectionID));
1251 am_Error_e DatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1253 assert(sourceID!=0);
1255 if (!existSource(sourceID))
1257 return E_NON_EXISTENT;
1259 sqlite3_stmt* query = NULL;
1261 am_ClassProperty_s propertyTemp;
1262 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + (i2s(sourceID));
1263 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1265 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1267 classInfo.sourceClassID = sqlite3_column_int(query, 0);
1270 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1272 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1273 return E_DATABASE_ERROR;
1276 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1278 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1279 return E_DATABASE_ERROR;
1282 command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1283 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1285 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1287 classInfo.name = std::string((const char*) sqlite3_column_text(query, 0));
1290 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1292 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1293 return E_DATABASE_ERROR;
1296 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1298 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1299 return E_DATABASE_ERROR;
1302 //read out Properties
1303 command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID);
1304 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1305 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1307 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1308 propertyTemp.value = sqlite3_column_int(query, 1);
1309 classInfo.listClassProperties.push_back(propertyTemp);
1312 if (eCode != SQLITE_DONE)
1314 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1315 return E_DATABASE_ERROR;
1318 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1320 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1321 return E_DATABASE_ERROR;
1326 am_Error_e DatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1328 assert(sinkClass.sinkClassID!=0);
1329 assert(!sinkClass.listClassProperties.empty());
1331 sqlite3_stmt* query = NULL;
1334 //check if the ID already exists
1335 if (!existSinkClass(sinkClass.sinkClassID)) return E_NON_EXISTENT;
1337 //fill ConnectionFormats
1338 std::string command = "UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1339 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1340 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
1341 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
1343 sqlite3_bind_int(query, 1, Iterator->value);
1344 sqlite3_bind_int(query, 2, Iterator->classProperty);
1345 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1347 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"), DLT_INT(eCode));
1348 return E_DATABASE_ERROR;
1350 sqlite3_reset(query);
1353 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1355 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1356 return E_DATABASE_ERROR;
1359 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1363 am_Error_e DatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1365 assert(sourceClass.sourceClassID!=0);
1366 assert(!sourceClass.listClassProperties.empty());
1368 sqlite3_stmt* query = NULL;
1371 //check if the ID already exists
1372 if (!existSourceClass(sourceClass.sourceClassID)) return E_NON_EXISTENT;
1374 //fill ConnectionFormats
1375 std::string command = "UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1376 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1377 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
1378 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
1380 sqlite3_bind_int(query, 1, Iterator->value);
1381 sqlite3_bind_int(query, 2, Iterator->classProperty);
1382 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1384 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"), DLT_INT(eCode));
1385 return E_DATABASE_ERROR;
1387 sqlite3_reset(query);
1390 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1392 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1393 return E_DATABASE_ERROR;
1396 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1400 am_Error_e DatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1404 if (!existSink(sinkID))
1406 return E_NON_EXISTENT;
1408 sqlite3_stmt* query = NULL;
1410 am_ClassProperty_s propertyTemp;
1411 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + (i2s(sinkID));
1412 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1414 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1416 sinkClass.sinkClassID = sqlite3_column_int(query, 0);
1419 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1421 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1422 return E_DATABASE_ERROR;
1425 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1427 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1428 return E_DATABASE_ERROR;
1431 command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1432 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1434 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1436 sinkClass.name = std::string((const char*) sqlite3_column_text(query, 0));
1439 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1441 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1442 return E_DATABASE_ERROR;
1445 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1447 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1448 return E_DATABASE_ERROR;
1451 //read out Properties
1452 command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID);
1453 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1454 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1456 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1457 propertyTemp.value = sqlite3_column_int(query, 1);
1458 sinkClass.listClassProperties.push_back(propertyTemp);
1461 if (eCode != SQLITE_DONE)
1463 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"), DLT_INT(eCode));
1464 return E_DATABASE_ERROR;
1467 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1469 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1470 return E_DATABASE_ERROR;
1475 am_Error_e DatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1477 assert(gatewayID!=0);
1478 if (!existGateway(gatewayID))
1480 return E_NON_EXISTENT;
1482 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
1484 am_ConnectionFormat_e tempConnectionFormat;
1485 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1486 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1488 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1490 gatewayData.name = std::string((const char*) sqlite3_column_text(query, 0));
1491 gatewayData.sinkID = sqlite3_column_int(query, 1);
1492 gatewayData.sourceID = sqlite3_column_int(query, 2);
1493 gatewayData.domainSinkID = sqlite3_column_int(query, 3);
1494 gatewayData.domainSourceID = sqlite3_column_int(query, 4);
1495 gatewayData.controlDomainID = sqlite3_column_int(query, 5);
1496 gatewayData.gatewayID = sqlite3_column_int(query, 6);
1499 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
1500 iter = mListConnectionFormat.find(gatewayData.gatewayID);
1501 if (iter == mListConnectionFormat.end())
1503 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB database error with convertionFormat"));
1504 return E_DATABASE_ERROR;
1506 gatewayData.convertionMatrix = iter->second;
1508 //read out the connectionFormats
1509 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
1510 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL);
1511 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
1513 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
1514 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
1517 if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK)
1519 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1520 return E_DATABASE_ERROR;
1523 //read out sound properties
1524 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
1525 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL);
1526 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
1528 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
1529 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
1532 if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK)
1534 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1535 return E_DATABASE_ERROR;
1540 if (eCode != SQLITE_DONE)
1542 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE error code:"), DLT_INT(eCode));
1543 return E_DATABASE_ERROR;
1546 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1548 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"), DLT_INT(eCode));
1549 return E_DATABASE_ERROR;
1556 am_Error_e DatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
1558 //todo: implement crossfader
1559 (void) crossfaderID;
1560 (void) crossfaderData;
1564 am_Error_e DatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
1566 assert(domainID!=0);
1568 if (!existDomain(domainID))
1570 return E_NON_EXISTENT;
1572 sqlite3_stmt* query = NULL;
1575 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND domainID=" + (i2s(domainID));
1576 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1578 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1580 temp = sqlite3_column_int(query, 0);
1581 listSinkID.push_back(temp);
1584 if (eCode != SQLITE_DONE)
1586 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE error code:"), DLT_INT(eCode));
1587 return E_DATABASE_ERROR;
1590 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1592 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:"), DLT_INT(eCode));
1593 return E_DATABASE_ERROR;
1599 am_Error_e DatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
1601 assert(domainID!=0);
1602 listSourceID.clear();
1603 if (!existDomain(domainID))
1605 return E_NON_EXISTENT;
1607 sqlite3_stmt* query = NULL;
1610 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
1612 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1614 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1616 temp = sqlite3_column_int(query, 0);
1617 listSourceID.push_back(temp);
1620 if (eCode != SQLITE_DONE)
1622 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE error code:"), DLT_INT(eCode));
1623 return E_DATABASE_ERROR;
1626 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1628 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:"), DLT_INT(eCode));
1629 return E_DATABASE_ERROR;
1635 am_Error_e DatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listGatewaysID) const
1637 //todo: implement crossfader
1638 (void) listGatewaysID;
1644 am_Error_e DatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
1646 assert(domainID!=0);
1647 listGatewaysID.clear();
1648 if (!existDomain(domainID))
1650 return E_NON_EXISTENT;
1652 sqlite3_stmt* query = NULL;
1654 am_gatewayID_t temp;
1656 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" + i2s(domainID);
1657 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1659 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1661 temp = sqlite3_column_int(query, 0);
1662 listGatewaysID.push_back(temp);
1665 if (eCode != SQLITE_DONE)
1667 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:"), DLT_INT(eCode));
1668 return E_DATABASE_ERROR;
1671 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1673 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:"), DLT_INT(eCode));
1674 return E_DATABASE_ERROR;
1680 am_Error_e DatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
1682 listMainConnections.clear();
1683 sqlite3_stmt *query = NULL, *query1 = NULL, *query2 = NULL;
1685 am_MainConnection_s temp;
1686 am_RoutingElement_s tempRoute;
1688 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
1689 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
1690 std::string command2 = "SELECT sourceID, sinkID, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=?";
1691 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1692 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &query2, NULL);
1694 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1696 temp.connectionID = sqlite3_column_int(query, 0);
1697 temp.route.sourceID = sqlite3_column_int(query, 1);
1698 temp.route.sinkID = sqlite3_column_int(query, 2);
1699 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
1700 temp.delay = sqlite3_column_int(query, 4);
1701 std::string statement = command1 + i2s(temp.connectionID);
1702 sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL);
1703 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW) //todo: check results of eCode1, eCode2
1705 int k = sqlite3_column_int(query1, 0);
1706 sqlite3_bind_int(query2, 1, k);
1707 while ((eCode = sqlite3_step(query2)) == SQLITE_ROW)
1709 tempRoute.sourceID = sqlite3_column_int(query2, 0);
1710 tempRoute.sinkID = sqlite3_column_int(query2, 1);
1711 tempRoute.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query2, 2);
1712 getDomainOfSource(tempRoute.sourceID, tempRoute.domainID);
1713 temp.route.route.push_back(tempRoute);
1715 sqlite3_reset(query2);
1717 listMainConnections.push_back(temp);
1720 if (eCode != SQLITE_DONE)
1722 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE error code:"), DLT_INT(eCode));
1723 return E_DATABASE_ERROR;
1726 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1728 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE Finalize error code:"), DLT_INT(eCode));
1729 return E_DATABASE_ERROR;
1735 am_Error_e DatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
1737 listDomains.clear();
1738 sqlite3_stmt* query = NULL;
1741 std::string command = "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
1742 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1744 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1746 temp.domainID = sqlite3_column_int(query, 0);
1747 temp.name = std::string((const char*) sqlite3_column_text(query, 1));
1748 temp.busname = std::string((const char*) sqlite3_column_text(query, 2));
1749 temp.nodename = std::string((const char*) sqlite3_column_text(query, 3));
1750 temp.early = sqlite3_column_int(query, 4);
1751 temp.complete = sqlite3_column_int(query, 5);
1752 temp.state = (am_DomainState_e) sqlite3_column_int(query, 6);
1753 listDomains.push_back(temp);
1756 if (eCode != SQLITE_DONE)
1758 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE error code:"), DLT_INT(eCode));
1759 return E_DATABASE_ERROR;
1762 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1764 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE Finalize error code:"), DLT_INT(eCode));
1765 return E_DATABASE_ERROR;
1771 am_Error_e DatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
1773 listConnections.clear();
1774 sqlite3_stmt* query = NULL;
1776 am_Connection_s temp;
1777 std::string command = "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE reserved=0";
1778 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1780 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1782 temp.connectionID = sqlite3_column_int(query, 0);
1783 temp.sourceID = sqlite3_column_int(query, 1);
1784 temp.sinkID = sqlite3_column_int(query, 2);
1785 temp.delay = sqlite3_column_int(query, 3);
1786 temp.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query, 4);
1787 listConnections.push_back(temp);
1790 if (eCode != SQLITE_DONE)
1792 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE error code:"), DLT_INT(eCode));
1793 return E_DATABASE_ERROR;
1796 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1798 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE Finalize error code:"), DLT_INT(eCode));
1799 return E_DATABASE_ERROR;
1805 am_Error_e DatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
1808 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
1811 am_ConnectionFormat_e tempConnectionFormat;
1812 am_SoundProperty_s tempSoundProperty;
1813 am_MainSoundProperty_s tempMainSoundProperty;
1814 std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0";
1815 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1817 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1819 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
1820 temp.domainID = sqlite3_column_int(query, 1);
1821 temp.sinkClassID = sqlite3_column_int(query, 2);
1822 temp.volume = sqlite3_column_int(query, 3);
1823 temp.visible = sqlite3_column_int(query, 4);
1824 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5);
1825 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
1826 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
1827 temp.mainVolume = sqlite3_column_int(query, 8);
1828 temp.sinkID = sqlite3_column_int(query, 9);
1830 //read out the connectionFormats
1831 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID);
1832 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
1833 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1835 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1836 temp.listConnectionFormats.push_back(tempConnectionFormat);
1839 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
1841 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
1842 return E_DATABASE_ERROR;
1845 //read out sound properties
1846 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
1847 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
1848 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1850 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1851 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1852 temp.listSoundProperties.push_back(tempSoundProperty);
1855 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
1857 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
1858 return E_DATABASE_ERROR;
1861 //read out MainSoundProperties
1862 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID);
1863 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
1864 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1866 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1867 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1868 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
1871 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
1873 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
1874 return E_DATABASE_ERROR;
1876 listSinks.push_back(temp);
1877 temp.listConnectionFormats.clear();
1878 temp.listMainSoundProperties.clear();
1879 temp.listSoundProperties.clear();
1882 if (eCode != SQLITE_DONE)
1884 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"), DLT_INT(eCode));
1885 return E_DATABASE_ERROR;
1888 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1890 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
1891 return E_DATABASE_ERROR;
1897 am_Error_e DatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
1899 listSources.clear();
1900 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
1903 am_ConnectionFormat_e tempConnectionFormat;
1904 am_SoundProperty_s tempSoundProperty;
1905 am_MainSoundProperty_s tempMainSoundProperty;
1906 std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0";
1907 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1909 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1911 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
1912 temp.domainID = sqlite3_column_int(query, 1);
1913 temp.sourceClassID = sqlite3_column_int(query, 2);
1914 temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
1915 temp.volume = sqlite3_column_int(query, 4);
1916 temp.visible = sqlite3_column_int(query, 5);
1917 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6);
1918 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
1919 temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
1920 temp.sourceID = sqlite3_column_int(query, 9);
1922 //read out the connectionFormats
1923 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID);
1924 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
1925 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1927 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1928 temp.listConnectionFormats.push_back(tempConnectionFormat);
1931 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
1933 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
1934 return E_DATABASE_ERROR;
1937 //read out sound properties
1938 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
1939 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
1940 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1942 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1943 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1944 temp.listSoundProperties.push_back(tempSoundProperty);
1947 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
1949 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
1950 return E_DATABASE_ERROR;
1953 //read out MainSoundProperties
1954 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID);
1955 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
1956 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1958 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1959 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1960 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
1963 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
1965 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
1966 return E_DATABASE_ERROR;
1968 listSources.push_back(temp);
1969 temp.listConnectionFormats.clear();
1970 temp.listMainSoundProperties.clear();
1971 temp.listSoundProperties.clear();
1974 if (eCode != SQLITE_DONE)
1976 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"), DLT_INT(eCode));
1977 return E_DATABASE_ERROR;
1980 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1982 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
1983 return E_DATABASE_ERROR;
1989 am_Error_e DatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
1991 listSourceClasses.clear();
1993 sqlite3_stmt* query = NULL, *subQuery = NULL;
1994 int eCode = 0, eCode1;
1995 am_SourceClass_s classTemp;
1996 am_ClassProperty_s propertyTemp;
1998 std::string command = "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
1999 std::string command2;
2000 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2002 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2004 classTemp.sourceClassID = sqlite3_column_int(query, 0);
2005 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2007 //read out Properties
2008 command2 = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classTemp.sourceClassID);
2009 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL);
2011 while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW)
2013 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2014 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2015 classTemp.listClassProperties.push_back(propertyTemp);
2018 if (eCode1 != SQLITE_DONE)
2020 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"), DLT_INT(eCode1));
2021 return E_DATABASE_ERROR;
2024 if ((eCode1 = sqlite3_finalize(subQuery)) != SQLITE_OK)
2026 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"), DLT_INT(eCode1));
2027 return E_DATABASE_ERROR;
2029 listSourceClasses.push_back(classTemp);
2032 if (eCode != SQLITE_DONE)
2034 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"), DLT_INT(eCode));
2035 return E_DATABASE_ERROR;
2038 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2040 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"), DLT_INT(eCode));
2041 return E_DATABASE_ERROR;
2047 am_Error_e DatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2049 //todo: implement crossfaders
2050 (void) listCrossfaders;
2054 am_Error_e DatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2056 listGateways.clear();
2057 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
2060 am_ConnectionFormat_e tempConnectionFormat;
2062 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2063 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2065 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2067 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2068 temp.sinkID = sqlite3_column_int(query, 1);
2069 temp.sourceID = sqlite3_column_int(query, 2);
2070 temp.domainSinkID = sqlite3_column_int(query, 3);
2071 temp.domainSourceID = sqlite3_column_int(query, 4);
2072 temp.controlDomainID = sqlite3_column_int(query, 5);
2073 temp.gatewayID = sqlite3_column_int(query, 6);
2076 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2077 iter = mListConnectionFormat.find(temp.gatewayID);
2078 if (iter == mListConnectionFormat.end())
2080 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways database error with convertionFormat"));
2081 return E_DATABASE_ERROR;
2083 temp.convertionMatrix = iter->second;
2085 //read out the connectionFormats
2086 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2087 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL);
2088 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
2090 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
2091 temp.listSourceFormats.push_back(tempConnectionFormat);
2094 if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK)
2096 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"), DLT_INT(eCode));
2097 return E_DATABASE_ERROR;
2100 //read out sound properties
2101 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2102 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL);
2103 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
2105 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
2106 temp.listSinkFormats.push_back(tempConnectionFormat);
2109 if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK)
2111 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"), DLT_INT(eCode));
2112 return E_DATABASE_ERROR;
2115 listGateways.push_back(temp);
2116 temp.listSinkFormats.clear();
2117 temp.listSourceFormats.clear();
2120 if (eCode != SQLITE_DONE)
2122 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE error code:"), DLT_INT(eCode));
2123 return E_DATABASE_ERROR;
2126 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2128 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"), DLT_INT(eCode));
2129 return E_DATABASE_ERROR;
2135 am_Error_e DatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2137 listSinkClasses.clear();
2139 sqlite3_stmt* query = NULL, *subQuery = NULL;
2141 am_SinkClass_s classTemp;
2142 am_ClassProperty_s propertyTemp;
2144 std::string command = "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2145 std::string command2;
2146 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2148 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2150 classTemp.sinkClassID = sqlite3_column_int(query, 0);
2151 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2153 //read out Properties
2154 command2 = "SELECT classProperty, value FROM SinkClassProperties" + i2s(classTemp.sinkClassID);
2155 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL);
2157 while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW)
2159 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2160 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2161 classTemp.listClassProperties.push_back(propertyTemp);
2164 if (eCode != SQLITE_DONE)
2166 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"), DLT_INT(eCode));
2167 return E_DATABASE_ERROR;
2170 if ((eCode = sqlite3_finalize(subQuery)) != SQLITE_OK)
2172 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"), DLT_INT(eCode));
2173 return E_DATABASE_ERROR;
2175 listSinkClasses.push_back(classTemp);
2178 if (eCode != SQLITE_DONE)
2180 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"), DLT_INT(eCode));
2181 return E_DATABASE_ERROR;
2184 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2186 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"), DLT_INT(eCode));
2187 return E_DATABASE_ERROR;
2193 am_Error_e DatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2195 listConnections.clear();
2196 sqlite3_stmt *query = NULL;
2198 am_MainConnectionType_s temp;
2200 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2201 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2203 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2205 temp.mainConnectionID = sqlite3_column_int(query, 0);
2206 temp.sourceID = sqlite3_column_int(query, 1);
2207 temp.sinkID = sqlite3_column_int(query, 2);
2208 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2209 temp.delay = sqlite3_column_int(query, 4);
2210 listConnections.push_back(temp);
2213 if (eCode != SQLITE_DONE)
2215 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE error code:"), DLT_INT(eCode));
2216 return E_DATABASE_ERROR;
2219 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2221 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:"), DLT_INT(eCode));
2222 return E_DATABASE_ERROR;
2228 am_Error_e DatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2230 listMainSinks.clear();
2231 sqlite3_stmt* query = NULL;
2235 std::string command = "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2236 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2238 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2240 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2241 temp.sinkID = sqlite3_column_int(query, 1);
2242 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2243 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2244 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 4);
2245 temp.volume = sqlite3_column_int(query, 5);
2246 temp.sinkClassID = sqlite3_column_int(query, 6);
2247 listMainSinks.push_back(temp);
2250 if (eCode != SQLITE_DONE)
2252 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"), DLT_INT(eCode));
2253 return E_DATABASE_ERROR;
2256 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2258 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"), DLT_INT(eCode));
2259 return E_DATABASE_ERROR;
2265 am_Error_e DatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2267 listMainSources.clear();
2268 sqlite3_stmt* query = NULL;
2270 am_SourceType_s temp;
2271 std::string command = "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2272 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2274 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2276 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2277 temp.sourceClassID = sqlite3_column_int(query, 1);
2278 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2279 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2280 temp.sourceID = sqlite3_column_int(query, 4);
2282 listMainSources.push_back(temp);
2285 if (eCode != SQLITE_DONE)
2287 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"), DLT_INT(eCode));
2288 return E_DATABASE_ERROR;
2291 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2293 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
2294 return E_DATABASE_ERROR;
2300 am_Error_e DatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2303 if (!existSink(sinkID)) return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2304 listSoundProperties.clear();
2306 sqlite3_stmt* query = NULL;
2308 am_MainSoundProperty_s temp;
2309 std::string command = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2310 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2312 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2314 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2315 temp.value = sqlite3_column_int(query, 1);
2316 listSoundProperties.push_back(temp);
2319 if (eCode != SQLITE_DONE)
2321 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"), DLT_INT(eCode));
2322 return E_DATABASE_ERROR;
2325 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2327 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"), DLT_INT(eCode));
2328 return E_DATABASE_ERROR;
2334 am_Error_e DatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2336 assert(sourceID!=0);
2337 if (!existSource(sourceID)) return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2338 listSourceProperties.clear();
2340 sqlite3_stmt* query = NULL;
2342 am_MainSoundProperty_s temp;
2343 std::string command = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2344 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2346 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2348 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2349 temp.value = sqlite3_column_int(query, 1);
2350 listSourceProperties.push_back(temp);
2353 if (eCode != SQLITE_DONE)
2355 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"), DLT_INT(eCode));
2356 return E_DATABASE_ERROR;
2359 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2361 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"), DLT_INT(eCode));
2362 return E_DATABASE_ERROR;
2368 am_Error_e DatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2370 listSystemProperties.clear();
2372 sqlite3_stmt* query = NULL;
2374 am_SystemProperty_s temp;
2375 std::string command = "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2376 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2378 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2380 temp.type = (am_SystemPropertyType_e) sqlite3_column_int(query, 0);
2381 temp.value = sqlite3_column_int(query, 1);
2382 listSystemProperties.push_back(temp);
2385 if (eCode != SQLITE_DONE)
2387 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE error code:"), DLT_INT(eCode));
2388 return E_DATABASE_ERROR;
2391 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2393 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:"), DLT_INT(eCode));
2394 return E_DATABASE_ERROR;
2400 am_Error_e am::DatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2402 listConnectionFormats.clear();
2403 sqlite3_stmt *qConnectionFormat = NULL;
2405 am_ConnectionFormat_e tempConnectionFormat;
2406 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
2407 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2408 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2410 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2411 listConnectionFormats.push_back(tempConnectionFormat);
2414 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2416 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinkConnectionFormats SQLITE Finalize error code:"), DLT_INT(eCode));
2417 return E_DATABASE_ERROR;
2423 am_Error_e am::DatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2425 listConnectionFormats.clear();
2426 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
2428 am_ConnectionFormat_e tempConnectionFormat;
2430 //read out the connectionFormats
2431 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
2432 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2433 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2435 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2436 listConnectionFormats.push_back(tempConnectionFormat);
2439 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2441 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"), DLT_INT(eCode));
2442 return E_DATABASE_ERROR;
2448 am_Error_e am::DatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const
2450 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2451 iter = mListConnectionFormat.find(gatewayID);
2452 if (iter == mListConnectionFormat.end())
2454 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat"));
2455 return (E_DATABASE_ERROR);
2457 listConnectionFormat = iter->second;
2462 am_Error_e DatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2464 assert(mainConnectionID!=0);
2466 sqlite3_stmt *query = NULL;
2469 std::string command = "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2470 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2472 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2474 delay = sqlite3_column_int(query, 0);
2477 if (eCode != SQLITE_DONE)
2479 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE error code:"), DLT_INT(eCode));
2480 return E_DATABASE_ERROR;
2483 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2485 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE Finalize error code:"), DLT_INT(eCode));
2486 return E_DATABASE_ERROR;
2489 if (delay == -1) return E_NOT_POSSIBLE;
2494 bool DatabaseHandler::sqQuery(const std::string& query)
2496 sqlite3_stmt* statement;
2498 if ((eCode = sqlite3_exec(mDatabase, query.c_str(), NULL, &statement, NULL)) != SQLITE_OK)
2500 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));
2506 bool DatabaseHandler::openDatabase()
2508 if (sqlite3_open_v2(mPath.c_str(), &mDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
2510 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::openDatabase opened database"));
2512 }DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::openDatabase failed to open database"));
2516 am_Error_e DatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
2518 assert(connectionID!=0);
2520 sqlite3_stmt* query = NULL;
2522 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE delay=? AND mainConnectionID=?";
2523 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2524 sqlite3_bind_int(query, 1, delay);
2525 sqlite3_bind_int(query, 2, connectionID);
2526 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2528 sqlite3_finalize(query);
2531 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
2532 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2533 sqlite3_bind_int(query, 1, delay);
2534 sqlite3_bind_int(query, 2, connectionID);
2536 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2538 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:"), DLT_INT(eCode));
2539 return E_DATABASE_ERROR;
2542 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2544 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:"), DLT_INT(eCode));
2545 return E_DATABASE_ERROR;
2548 if (mDatabaseObserver) mDatabaseObserver->timingInformationChanged(connectionID, delay);
2553 am_Error_e DatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
2555 assert(connection.connectionID==0);
2556 assert(connection.sinkID!=0);
2557 assert(connection.sourceID!=0);
2558 //connection format is not checked, because it's project specific
2560 sqlite3_stmt* query = NULL;
2562 std::string command = "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
2564 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2565 sqlite3_bind_int(query, 1, connection.sinkID);
2566 sqlite3_bind_int(query, 2, connection.sourceID);
2567 sqlite3_bind_int(query, 3, connection.delay);
2568 sqlite3_bind_int(query, 4, connection.connectionFormat);
2569 sqlite3_bind_int(query, 5, true);
2571 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2573 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Step error code:"), DLT_INT(eCode));
2574 return E_DATABASE_ERROR;
2577 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2579 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:"), DLT_INT(eCode));
2580 return E_DATABASE_ERROR;
2583 connectionID = sqlite3_last_insert_rowid(mDatabase);
2585 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));
2589 am_Error_e DatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
2591 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
2592 assert(!sinkClass.listClassProperties.empty());
2593 assert(!sinkClass.name.empty());
2595 sqlite3_stmt* query = NULL;
2597 std::string command;
2599 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2600 if (sinkClass.sinkClassID == 0 && !mFirstStaticSinkClass)
2602 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
2606 //check if the ID already exists
2607 if (existSinkClass(sinkClass.sinkClassID)) return E_ALREADY_EXISTS;
2608 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
2611 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2612 sqlite3_bind_text(query, 1, sinkClass.name.c_str(), sinkClass.name.size(), SQLITE_STATIC);
2614 //if the ID is not created, we add it to the query
2615 if (sinkClass.sinkClassID != 0)
2617 sqlite3_bind_int(query, 2, sinkClass.sinkClassID);
2620 //if the first static sink is entered, we need to set it onto the boundary
2621 else if (mFirstStaticSinkClass)
2623 sqlite3_bind_int(query, 2, DYNAMIC_ID_BOUNDARY);
2624 mFirstStaticSinkClass = false;
2627 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2629 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"), DLT_INT(eCode));
2630 return E_DATABASE_ERROR;
2633 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2635 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"), DLT_INT(eCode));
2636 return E_DATABASE_ERROR;
2639 sinkClassID = sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2641 //now we need to create the additional tables:
2642 command = "CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2643 assert(this->sqQuery(command));
2645 //fill ConnectionFormats
2646 command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
2647 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2648 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
2649 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
2651 sqlite3_bind_int(query, 1, Iterator->classProperty);
2652 sqlite3_bind_int(query, 2, Iterator->value);
2653 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2655 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"), DLT_INT(eCode));
2656 return E_DATABASE_ERROR;
2658 sqlite3_reset(query);
2661 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2663 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"), DLT_INT(eCode));
2664 return E_DATABASE_ERROR;
2667 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkClassDB entered new sinkClass"));
2668 if (mDatabaseObserver) mDatabaseObserver->numberOfSinkClassesChanged();
2672 am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
2674 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
2675 assert(!sourceClass.listClassProperties.empty());
2676 assert(!sourceClass.name.empty());
2678 sqlite3_stmt* query = NULL;
2680 std::string command;
2682 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2683 if (sourceClass.sourceClassID == 0 && !mFirstStaticSourceClass)
2685 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
2689 //check if the ID already exists
2690 if (existSourceClass(sourceClass.sourceClassID)) return E_ALREADY_EXISTS;
2691 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
2694 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2695 sqlite3_bind_text(query, 1, sourceClass.name.c_str(), sourceClass.name.size(), SQLITE_STATIC);
2697 //if the ID is not created, we add it to the query
2698 if (sourceClass.sourceClassID != 0)
2700 sqlite3_bind_int(query, 2, sourceClass.sourceClassID);
2703 //if the first static sink is entered, we need to set it onto the boundary
2704 else if (mFirstStaticSourceClass)
2706 sqlite3_bind_int(query, 2, DYNAMIC_ID_BOUNDARY);
2707 mFirstStaticSourceClass = false;
2710 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2712 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"), DLT_INT(eCode));
2713 return E_DATABASE_ERROR;
2716 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2718 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"), DLT_INT(eCode));
2719 return E_DATABASE_ERROR;
2722 sourceClassID = sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2724 //now we need to create the additional tables:
2725 command = "CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2726 assert(sqQuery(command));
2728 //fill ConnectionFormats
2729 command = "INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
2730 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2731 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
2732 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
2734 sqlite3_bind_int(query, 1, Iterator->classProperty);
2735 sqlite3_bind_int(query, 2, Iterator->value);
2736 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2738 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"), DLT_INT(eCode));
2739 return E_DATABASE_ERROR;
2741 sqlite3_reset(query);
2744 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2746 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"), DLT_INT(eCode));
2747 return E_DATABASE_ERROR;
2750 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSourceClassDB entered new sourceClass"));
2752 if (mDatabaseObserver) mDatabaseObserver->numberOfSourceClassesChanged();
2756 am_Error_e DatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
2758 sqlite3_stmt* query = NULL;
2760 std::vector<am_SystemProperty_s>::const_iterator listIterator = listSystemProperties.begin();
2761 std::string command = "DELETE * FROM " + std::string(SYSTEM_TABLE);
2764 command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
2766 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2767 for (; listIterator < listSystemProperties.end(); ++listIterator)
2769 sqlite3_bind_int(query, 1, listIterator->type);
2770 sqlite3_bind_int(query, 2, listIterator->value);
2772 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2774 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Step error code:"), DLT_INT(eCode));
2775 return E_DATABASE_ERROR;
2778 sqlite3_reset(query);
2781 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2783 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:"), DLT_INT(eCode));
2784 return E_DATABASE_ERROR;
2787 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSystemProperties entered system properties"));
2791 bool DatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
2793 sqlite3_stmt* query = NULL;
2794 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2796 bool returnVal = true;
2797 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2798 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2800 else if (eCode != SQLITE_ROW)
2803 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
2805 sqlite3_finalize(query);
2809 bool DatabaseHandler::existSource(const am_sourceID_t sourceID) const
2811 sqlite3_stmt* query = NULL;
2812 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
2814 bool returnVal = true;
2815 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2816 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2818 else if (eCode != SQLITE_ROW)
2821 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2823 sqlite3_finalize(query);
2827 bool DatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
2829 sqlite3_stmt* query = NULL;
2830 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
2832 bool returnVal = true;
2833 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2834 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
2835 sqlite3_bind_int(query, 2, sourceID);
2836 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2838 else if (eCode != SQLITE_ROW)
2841 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2843 sqlite3_finalize(query);
2847 bool DatabaseHandler::existSourceName(const std::string & name) const
2849 sqlite3_stmt* query = NULL;
2850 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
2852 bool returnVal = true;
2853 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2854 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
2855 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2857 else if (eCode != SQLITE_ROW)
2860 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2862 sqlite3_finalize(query);
2866 bool DatabaseHandler::existSink(const am_sinkID_t sinkID) const
2868 sqlite3_stmt* query = NULL;
2869 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
2871 bool returnVal = true;
2872 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2873 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2875 else if (eCode != SQLITE_ROW)
2878 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2880 sqlite3_finalize(query);
2884 bool DatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
2886 sqlite3_stmt* query = NULL;
2887 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
2889 bool returnVal = true;
2890 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2891 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
2892 sqlite3_bind_int(query, 2, sinkID);
2893 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2895 else if (eCode != SQLITE_ROW)
2898 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2900 sqlite3_finalize(query);
2904 bool DatabaseHandler::existSinkName(const std::string & name) const
2906 sqlite3_stmt* query = NULL;
2907 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
2909 bool returnVal = true;
2910 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2911 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
2912 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2914 else if (eCode != SQLITE_ROW)
2917 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2919 sqlite3_finalize(query);
2923 bool DatabaseHandler::existDomain(const am_domainID_t domainID) const
2925 sqlite3_stmt* query = NULL;
2926 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
2928 bool returnVal = true;
2929 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2930 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2932 else if (eCode != SQLITE_ROW)
2935 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existDomain database error!:"), DLT_INT(eCode))
2937 sqlite3_finalize(query);
2941 bool DatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
2943 sqlite3_stmt* query = NULL;
2944 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
2946 bool returnVal = true;
2947 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2948 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
2950 else if (eCode != SQLITE_ROW)
2953 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existGateway database error!:"), DLT_INT(eCode))
2955 sqlite3_finalize(query);
2959 am_Error_e DatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
2961 assert(sourceID!=0);
2963 sqlite3_stmt* query = NULL;
2964 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
2966 am_Error_e returnVal = E_DATABASE_ERROR;
2967 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2968 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2970 domainID = sqlite3_column_int(query, 0);
2975 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainOfSource database error!:"), DLT_INT(eCode))
2977 sqlite3_finalize(query);
2981 am_Error_e am::DatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const
2985 sqlite3_stmt* query = NULL;
2986 std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
2988 am_Error_e returnVal = E_DATABASE_ERROR;
2989 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2990 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2992 domainID = sqlite3_column_int(query, 0);
2997 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainOfSink database error!:"), DLT_INT(eCode))
2999 sqlite3_finalize(query);
3003 bool DatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3005 sqlite3_stmt* query = NULL;
3006 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
3008 bool returnVal = true;
3009 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3010 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3012 else if (eCode != SQLITE_ROW)
3015 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3017 sqlite3_finalize(query);
3021 bool DatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3023 sqlite3_stmt* query = NULL;
3024 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
3026 bool returnVal = true;
3027 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3028 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3030 else if (eCode != SQLITE_ROW)
3033 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3035 sqlite3_finalize(query);
3039 am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3041 assert(connectionID!=0);
3043 sqlite3_stmt *query = NULL, *queryMainConnections, *queryMainConnectionSubIDs;
3044 int eCode = 0, eCode1 = 0;
3045 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3047 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3048 sqlite3_bind_int(query, 1, delay);
3049 sqlite3_bind_int(query, 2, connectionID);
3051 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3053 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:"), DLT_INT(eCode));
3054 return E_DATABASE_ERROR;
3057 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3059 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"), DLT_INT(eCode));
3060 return E_DATABASE_ERROR;
3063 //now we need to find all mainConnections that use the changed connection and update their timing
3064 am_timeSync_t tempDelay = 0;
3067 int tempMainConnectionID;
3068 //first get all route tables for all mainconnections
3069 command = "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'";
3070 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryMainConnections, NULL);
3072 while ((eCode = sqlite3_step(queryMainConnections)) == SQLITE_ROW)
3074 //now check if the connection ID is in this table
3075 std::string tablename = std::string((const char*) sqlite3_column_text(queryMainConnections, 0));
3076 std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID);
3077 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &queryMainConnectionSubIDs, NULL);
3078 if ((eCode1 = sqlite3_step(queryMainConnectionSubIDs)) == SQLITE_ROW)
3080 //if the connection ID is in, recalculate the mainconnection delay
3081 std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID;
3082 changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID), tempMainConnectionID);
3084 else if (eCode1 != SQLITE_DONE)
3086 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"), DLT_INT(eCode1));
3087 return E_DATABASE_ERROR;
3091 if (eCode != SQLITE_DONE)
3093 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"), DLT_INT(eCode));
3094 return E_DATABASE_ERROR;
3097 if ((eCode = sqlite3_finalize(queryMainConnections)) != SQLITE_OK)
3099 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"), DLT_INT(eCode));
3100 return E_DATABASE_ERROR;
3106 am_Error_e DatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3108 assert(connectionID!=0);
3110 sqlite3_stmt *query = NULL;
3112 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3114 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3115 sqlite3_bind_int(query, 1, connectionID);
3117 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3119 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Step error code:"), DLT_INT(eCode));
3120 return E_DATABASE_ERROR;
3123 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3125 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:"), DLT_INT(eCode));
3126 return E_DATABASE_ERROR;
3131 am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3133 assert(mainConnectionID!=0);
3134 sqlite3_stmt* query = NULL;
3135 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";
3137 am_timeSync_t delay = 0;
3138 am_timeSync_t min = 0;
3139 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3140 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3142 delay = sqlite3_column_int(query, 0);
3143 min = sqlite3_column_int(query, 1);
3145 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3147 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:"), DLT_INT(eCode));
3148 return E_DATABASE_ERROR;
3151 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3153 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:"), DLT_INT(eCode));
3154 return E_DATABASE_ERROR;
3156 if (min < 0) delay = -1;
3161 void DatabaseHandler::registerObserver(DatabaseObserver *iObserver)
3163 assert(iObserver!=NULL);
3164 mDatabaseObserver = iObserver;
3167 bool DatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3169 assert(sourceID!=0);
3170 sqlite3_stmt* query = NULL;
3171 std::string command = "SELECT visible FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3173 bool returnVal = false;
3174 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3175 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3177 returnVal = (bool) sqlite3_column_int(query, 0);
3179 else if (eCode != SQLITE_ROW)
3182 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sourceVisible database error!:"), DLT_INT(eCode))
3184 sqlite3_finalize(query);
3188 bool DatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3190 sqlite3_stmt* query = NULL;
3191 std::string command = "SELECT visible FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3193 bool returnVal = false;
3194 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3195 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3197 returnVal = sqlite3_column_int(query, 0);
3199 else if (eCode != SQLITE_ROW)
3202 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sinkVisible database error!:"), DLT_INT(eCode))
3204 sqlite3_finalize(query);
3208 bool DatabaseHandler::existConnection(const am_Connection_s connection)
3210 sqlite3_stmt* query = NULL;
3211 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3213 bool returnVal = true;
3214 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3215 sqlite3_bind_int(query, 1, connection.sinkID);
3216 sqlite3_bind_int(query, 2, connection.sourceID);
3217 sqlite3_bind_int(query, 3, connection.connectionFormat);
3218 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3220 else if (eCode != SQLITE_ROW)
3223 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3225 sqlite3_finalize(query);
3229 bool DatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3231 sqlite3_stmt* query = NULL;
3232 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3234 bool returnVal = true;
3235 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3236 sqlite3_bind_int(query, 1, connectionID);
3237 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3239 else if (eCode != SQLITE_ROW)
3242 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3244 sqlite3_finalize(query);
3248 bool DatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3250 sqlite3_stmt* query = NULL;
3251 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3253 bool returnVal = true;
3254 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3255 sqlite3_bind_int(query, 1, crossfaderID);
3256 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3258 else if (eCode != SQLITE_ROW)
3261 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3263 sqlite3_finalize(query);
3267 am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3269 assert(sourceID!=0);
3270 sqlite3_stmt* query = NULL;
3271 sourceState = SS_MIN;
3272 std::string command = "SELECT sourceState FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3274 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3275 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3277 sourceState = (am_SourceState_e) sqlite3_column_int(query, 0);
3279 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3281 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSoureState database error!:"), DLT_INT(eCode))
3284 sqlite3_finalize(query);
3288 am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3290 assert(sourceID!=0);
3291 sqlite3_stmt* query = NULL;
3292 std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID);
3294 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3295 sqlite3_bind_int(query, 1, sourceState);
3296 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3298 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Step error code:"), DLT_INT(eCode));
3299 return E_DATABASE_ERROR;
3302 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3304 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Finalize error code:"), DLT_INT(eCode));
3305 return E_DATABASE_ERROR;
3310 am_Error_e DatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3313 sqlite3_stmt* query = NULL;
3315 std::string command = "SELECT volume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3317 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3318 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3320 volume = sqlite3_column_int(query, 0);
3322 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3324 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkVolume database error!:"), DLT_INT(eCode))
3327 sqlite3_finalize(query);
3331 am_Error_e DatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
3333 assert(sourceID!=0);
3334 sqlite3_stmt* query = NULL;
3336 std::string command = "SELECT volume FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3338 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3339 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3341 volume = sqlite3_column_int(query, 0);
3343 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3345 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceVolume database error!:"), DLT_INT(eCode))
3347 sqlite3_finalize(query);
3351 am_Error_e DatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3354 if (!existSink(sinkID)) return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3356 sqlite3_stmt* query = NULL;
3358 std::string command = "SELECT value FROM SinkSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType);
3359 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3361 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3363 value = sqlite3_column_int(query, 0);
3366 if (eCode != SQLITE_DONE)
3368 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"), DLT_INT(eCode));
3369 return E_DATABASE_ERROR;
3372 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3374 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"), DLT_INT(eCode));
3375 return E_DATABASE_ERROR;
3381 am_Error_e DatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3383 assert(sourceID!=0);
3384 if (!existSource(sourceID)) return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3386 sqlite3_stmt* query = NULL;
3388 std::string command = "SELECT value FROM SourceSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType);
3389 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3391 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3393 value = sqlite3_column_int(query, 0);
3396 if (eCode != SQLITE_DONE)
3398 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"), DLT_INT(eCode));
3399 return E_DATABASE_ERROR;
3402 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3404 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"), DLT_INT(eCode));
3405 return E_DATABASE_ERROR;
3411 am_Error_e DatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
3413 assert(domainID!=0);
3414 sqlite3_stmt* query = NULL;
3416 std::string command = "SELECT domainState FROM " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
3418 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3419 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3421 state = (am_DomainState_e) sqlite3_column_int(query, 0);
3423 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3425 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainState database error!:"), DLT_INT(eCode))
3428 sqlite3_finalize(query);
3433 am_Error_e DatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
3435 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3436 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
3437 int eCode = 0, eCode1 = 0;
3438 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3439 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3440 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3442 domainID = sqlite3_column_int(query, 0);
3444 else if (eCode != SQLITE_DONE)
3446 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain database error!:"), DLT_INT(eCode))
3447 return E_DATABASE_ERROR;
3451 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
3452 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3453 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3454 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3455 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3457 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Step error code:"), DLT_INT(eCode1));
3458 return E_DATABASE_ERROR;
3461 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3463 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"), DLT_INT(eCode1));
3464 return E_DATABASE_ERROR;
3466 domainID = sqlite3_last_insert_rowid(mDatabase);
3468 sqlite3_finalize(query);
3472 am_Error_e DatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
3474 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3475 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
3476 int eCode = 0, eCode1 = 0;
3477 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3478 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3479 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3481 sinkID = sqlite3_column_int(query, 0);
3483 else if (eCode != SQLITE_DONE)
3485 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3486 return E_DATABASE_ERROR;
3490 if (mFirstStaticSink)
3492 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3493 mFirstStaticSink = false;
3497 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
3499 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3500 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3501 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3502 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3504 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"), DLT_INT(eCode1));
3505 return E_DATABASE_ERROR;
3508 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3510 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"), DLT_INT(eCode1));
3511 return E_DATABASE_ERROR;
3513 sinkID = sqlite3_last_insert_rowid(mDatabase);
3515 sqlite3_finalize(query);
3519 am_Error_e DatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
3521 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3522 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
3523 int eCode = 0, eCode1 = 0;
3524 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3525 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3526 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3528 sourceID = sqlite3_column_int(query, 0);
3530 else if (eCode != SQLITE_DONE)
3532 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3533 return E_DATABASE_ERROR;
3537 if (mFirstStaticSource)
3539 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3540 mFirstStaticSource = false;
3544 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
3546 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3547 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3548 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3549 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3551 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"), DLT_INT(eCode1));
3552 return E_DATABASE_ERROR;
3555 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3557 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"), DLT_INT(eCode1));
3558 return E_DATABASE_ERROR;
3560 sourceID = sqlite3_last_insert_rowid(mDatabase);
3562 sqlite3_finalize(query);
3566 am_Error_e DatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
3570 sqlite3_stmt* query = NULL;
3572 std::string command;
3574 if (!existSink(sinkID))
3576 return E_NON_EXISTENT;
3578 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
3579 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3580 sqlite3_bind_int(query, 1, volume);
3581 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3583 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Step error code:"), DLT_INT(eCode));
3584 return E_DATABASE_ERROR;
3586 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3588 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:"), DLT_INT(eCode));
3589 return E_DATABASE_ERROR;
3592 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkVolume changed volume of sink:"), DLT_INT(sinkID), DLT_STRING("to:"), DLT_INT(volume));
3597 am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
3599 assert(sourceID!=0);
3601 sqlite3_stmt* query = NULL;
3603 std::string command;
3605 if (!existSource(sourceID))
3607 return E_NON_EXISTENT;
3609 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
3610 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3611 sqlite3_bind_int(query, 1, volume);
3612 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3614 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Step error code:"), DLT_INT(eCode));
3615 return E_DATABASE_ERROR;
3617 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3619 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:"), DLT_INT(eCode));
3620 return E_DATABASE_ERROR;
3623 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceVolume changed volume of source=:"), DLT_INT(sourceID), DLT_STRING("to:"), DLT_INT(volume));
3628 am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
3630 //todo: add checks if soundproperty exists!
3631 assert(sourceID!=0);
3633 sqlite3_stmt* query = NULL;
3635 std::string command;
3637 if (!existSource(sourceID))
3639 return E_NON_EXISTENT;
3641 command = "UPDATE SourceSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3642 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3643 sqlite3_bind_int(query, 1, soundProperty.value);
3644 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3646 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
3647 return E_DATABASE_ERROR;
3650 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3652 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
3653 return E_DATABASE_ERROR;
3656 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));
3661 am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
3663 //todo: add checks if soundproperty exists!
3666 sqlite3_stmt* query = NULL;
3668 std::string command;
3670 if (!existSink(sinkID))
3672 return E_NON_EXISTENT;
3674 command = "UPDATE SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3675 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3676 sqlite3_bind_int(query, 1, soundProperty.value);
3677 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3679 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:"), DLT_INT(eCode));
3680 return E_DATABASE_ERROR;
3683 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3685 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:"), DLT_INT(eCode));
3686 return E_DATABASE_ERROR;
3689 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));
3694 am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
3696 assert(crossfaderID!=0);
3698 sqlite3_stmt* query = NULL;
3700 std::string command;
3702 if (!existcrossFader(crossfaderID))
3704 return E_NON_EXISTENT;
3706 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
3707 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3708 sqlite3_bind_int(query, 1, hotsink);
3709 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3711 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:"), DLT_INT(eCode));
3712 return E_DATABASE_ERROR;
3714 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3716 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:"), DLT_INT(eCode));
3717 return E_DATABASE_ERROR;
3720 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader="), DLT_INT(crossfaderID), DLT_STRING("to:"), DLT_INT(hotsink));
3725 am_Error_e am::DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree *tree, std::vector<RoutingTreeItem*> *flatTree)
3727 sqlite3_stmt* query = NULL;
3730 std::string command;
3731 am_domainID_t rootID = tree->returnRootDomainID();
3732 RoutingTreeItem *parent = tree->returnRootItem();
3734 command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=? AND inUse=?";
3736 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3739 sqlite3_bind_int(query, 1, rootID);
3740 sqlite3_bind_int(query, 2, onlyfree);
3741 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3743 flatTree->push_back(tree->insertItem(sqlite3_column_int(query, 0), sqlite3_column_int(query, 1), parent));
3746 if (eCode != SQLITE_DONE)
3748 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getRoutingTree SQLITE error code:"), DLT_INT(eCode));
3749 return (E_DATABASE_ERROR);
3751 parent = flatTree->at(i);
3752 rootID = parent->returnDomainID();
3754 } while (flatTree->size() > i);
3756 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3758 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getRoutingTree SQLITE Finalize error code:"), DLT_INT(eCode));
3759 return (E_DATABASE_ERROR);
3765 void DatabaseHandler::createTables()
3767 for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++)
3769 assert(sqQuery("CREATE TABLE " + databaseTables[i]));