2 * Copyright (C) 2012, BMW AG
4 * This file is part of GENIVI Project AudioManager.
6 * Contributions are licensed to the GENIVI Alliance under one or more
7 * Contribution License Agreements.
10 * This Source Code Form is subject to the terms of the
11 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
12 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
17 * \file CAmDatabaseHandler.cpp
18 * For further information see http://www.genivi.org/.
22 #include "CAmDatabaseHandler.h"
28 #include "CAmDatabaseObserver.h"
29 #include "CAmRouter.h"
30 #include "shared/CAmDltWrapper.h"
36 * Macro to handle SQLITE errors on prepare
38 #define MY_SQLITE_PREPARE_V2(db,zSql,nByte,ppStmt,pzTail) \
39 if ((eCode = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail))) \
41 logError("CAmDatabaseHandler::my_sqlite_prepare_v2 on Command",zSql,"failed with errorCode:", eCode); \
42 return (E_DATABASE_ERROR); \
45 #define MY_SQLITE_PREPARE_V2_BOOL(db,zSql,nByte,ppStmt,pzTail) \
46 if ((eCode = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail))) \
48 logError("CAmDatabaseHandler::my_sqlite_prepare_v2_bool on Command",zSql,"failed with errorCode:", eCode); \
53 * Macro to handle SQLITE errors bind text
55 #define MY_SQLITE_BIND_TEXT(query,index,text,size,static_) \
56 if ((eCode = sqlite3_bind_text(query, index, text, size, static_))) \
58 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode); \
59 return (E_DATABASE_ERROR); \
63 * Macro to handle SQLITE errors on bind int
65 #define MY_SQLITE_BIND_INT(query, index, data) \
66 if((eCode = sqlite3_bind_int(query, index, data))) \
68 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); \
69 return (E_DATABASE_ERROR); \
73 * Macro to handle SQLITE errors on reset
75 #define MY_SQLITE_RESET(query) \
76 if((eCode = sqlite3_reset(query))) \
78 logError("CAmDatabaseHandler::sqlite3_reset failed with errorCode:", eCode); \
79 return (E_DATABASE_ERROR); \
83 * Macro to handle SQLITE finalize
85 #define MY_SQLITE_FINALIZE(query) \
86 if((eCode = sqlite3_finalize(query))) \
88 logError("CAmDatabaseHandler::sqlite3_finalize failed with errorCode:", eCode); \
89 return (E_DATABASE_ERROR); \
92 #define MY_SQLITE_FINALIZE_BOOL(query) \
93 if((eCode = sqlite3_finalize(query))) \
95 logError("CAmDatabaseHandler::sqlite3_finalize failed with errorCode:", eCode); \
99 #define DOMAIN_TABLE "Domains" //!< domain table
100 #define SOURCE_CLASS_TABLE "SourceClasses" //!< source class table
101 #define SINK_CLASS_TABLE "SinkClasses" //!< sink class table
102 #define SOURCE_TABLE "Sources" //!< source table
103 #define SINK_TABLE "Sinks" //!< sink table
104 #define GATEWAY_TABLE "Gateways" //!< gateway table
105 #define CROSSFADER_TABLE "Crossfaders" //!< crossfader table
106 #define CONNECTION_TABLE "Connections" //!< connection table
107 #define MAINCONNECTION_TABLE "MainConnections" //!< main connection table
108 #define SYSTEM_TABLE "SystemProperties" //!< system properties table
110 * table that holds table informations
112 const std::string databaseTables[] =
113 { " 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);", //
114 " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", //
115 " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", //
116 " 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);", //
117 " 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);", //
118 " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER);", //
119 " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);", //
120 " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);", //
121 " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);", //
122 " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);" };
125 * template to converts T to std::string
130 inline std::string i2s(T const& x)
132 std::ostringstream o;
137 CAmDatabaseHandler::CAmDatabaseHandler(std::string databasePath) :
139 mPath(databasePath), //
140 mpDatabaseObserver(NULL), //
141 mFirstStaticSink(true), //
142 mFirstStaticSource(true), //
143 mFirstStaticGateway(true), //
144 mFirstStaticSinkClass(true), //
145 mFirstStaticSourceClass(true), //
146 mFirstStaticCrossfader(true), //
147 mListConnectionFormat()
150 std::ifstream infile(mPath.c_str());
154 remove(mPath.c_str());
155 logInfo("DatabaseHandler::DatabaseHandler Knocked down database");
158 bool dbOpen = openDatabase();
161 logInfo("DatabaseHandler::DatabaseHandler problems opening the database!");
167 CAmDatabaseHandler::~CAmDatabaseHandler()
169 logInfo("Closed Database");
170 sqlite3_close(mpDatabase);
173 am_Error_e CAmDatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
175 assert(domainData.domainID==0);
176 assert(!domainData.name.empty());
177 assert(!domainData.busname.empty());
178 assert(domainData.state>=DS_UNKNOWN && domainData.state<=DS_MAX);
180 //first check for a reserved domain
181 sqlite3_stmt* query = NULL;
183 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
184 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
185 MY_SQLITE_BIND_TEXT(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC)
186 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
188 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" + i2s(sqlite3_column_int(query, 0));
190 else if (eCode == SQLITE_DONE)
193 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)";
197 logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode);
198 return (E_DATABASE_ERROR);
201 MY_SQLITE_FINALIZE(query)
203 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
204 MY_SQLITE_BIND_TEXT(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC)
205 MY_SQLITE_BIND_TEXT(query, 2, domainData.busname.c_str(), domainData.busname.size(), SQLITE_STATIC)
206 MY_SQLITE_BIND_TEXT(query, 3, domainData.nodename.c_str(), domainData.nodename.size(), SQLITE_STATIC)
207 MY_SQLITE_BIND_INT(query, 4, domainData.early)
208 MY_SQLITE_BIND_INT(query, 5, domainData.complete)
209 MY_SQLITE_BIND_INT(query, 6, domainData.state)
210 MY_SQLITE_BIND_INT(query, 7, 0)
212 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
214 logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode);
215 MY_SQLITE_FINALIZE(query)
216 return (E_DATABASE_ERROR);
218 MY_SQLITE_FINALIZE(query)
220 domainID = sqlite3_last_insert_rowid(mpDatabase);
221 logInfo("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID);
223 am_Domain_s domain = domainData;
224 domain.domainID = domainID;
225 if (mpDatabaseObserver)
226 mpDatabaseObserver->newDomain(domain);
231 am_Error_e CAmDatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
233 assert(mainConnectionData.mainConnectionID==0);
234 assert(mainConnectionData.connectionState>=CS_UNKNOWN && mainConnectionData.connectionState<=CS_MAX);
235 assert(mainConnectionData.sinkID!=0);
236 assert(mainConnectionData.sourceID!=0);
238 sqlite3_stmt* query = NULL;
241 std::string command = "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)";
242 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
243 MY_SQLITE_BIND_INT(query, 1, mainConnectionData.sourceID)
244 MY_SQLITE_BIND_INT(query, 2, mainConnectionData.sinkID)
245 MY_SQLITE_BIND_INT(query, 3, mainConnectionData.connectionState)
247 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
249 logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode);
250 MY_SQLITE_FINALIZE(query)
251 return (E_DATABASE_ERROR);
254 MY_SQLITE_FINALIZE(query)
256 connectionID = sqlite3_last_insert_rowid(mpDatabase);
258 //now check the connectionTable for all connections in the route. IF connectionID exist
259 command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?");
260 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
261 std::vector<am_connectionID_t>::const_iterator elementIterator = mainConnectionData.listConnectionID.begin();
262 for (; elementIterator < mainConnectionData.listConnectionID.end(); ++elementIterator)
264 MY_SQLITE_BIND_INT(query, 1, *elementIterator)
266 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
268 int16_t temp_delay = sqlite3_column_int(query, 1);
269 if (temp_delay != -1 && delay != -1)
276 logError("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:", eCode);
277 MY_SQLITE_FINALIZE(query)
278 return (E_DATABASE_ERROR);
280 MY_SQLITE_RESET(query)
282 MY_SQLITE_FINALIZE(query)
284 //now we create a table with references to the connections;
285 command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
286 if (!this->sqQuery(command))
287 return (E_DATABASE_ERROR);
289 command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
290 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
291 std::vector<am_connectionID_t>::const_iterator listConnectionIterator(mainConnectionData.listConnectionID.begin());
292 for (; listConnectionIterator < mainConnectionData.listConnectionID.end(); ++listConnectionIterator)
294 MY_SQLITE_BIND_INT(query, 1, *listConnectionIterator)
295 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
297 logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode);
298 MY_SQLITE_FINALIZE(query)
299 return (E_DATABASE_ERROR);
301 MY_SQLITE_RESET(query)
304 MY_SQLITE_FINALIZE(query)
305 logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID);
307 if (mpDatabaseObserver)
309 am_MainConnectionType_s mainConnection;
310 mainConnection.mainConnectionID = connectionID;
311 mainConnection.connectionState = mainConnectionData.connectionState;
312 mainConnection.delay = delay;
313 mainConnection.sinkID = mainConnectionData.sinkID;
314 mainConnection.sourceID = mainConnectionData.sourceID;
315 mpDatabaseObserver->newMainConnection(mainConnection);
316 mpDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState);
319 //finally, we update the delay value for the maintable
322 return (changeDelayMainConnection(delay, connectionID));
325 am_Error_e CAmDatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
327 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
328 assert(sinkData.domainID!=0);
329 assert(!sinkData.name.empty());
330 assert(sinkData.sinkClassID!=0);
331 //todo: need to check if class exists?
332 assert(!sinkData.listConnectionFormats.empty());
333 assert(sinkData.muteState>=MS_UNKNOWN && sinkData.muteState<=MS_MAX);
335 sqlite3_stmt *query = NULL;
337 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
339 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
340 MY_SQLITE_BIND_TEXT(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC)
342 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
344 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));
346 else if (eCode == SQLITE_DONE)
348 //if sinkID is zero and the first Static Sink was already entered, the ID is created
349 if (sinkData.sinkID == 0 && !mFirstStaticSink && !existSinkName(sinkData.name))
351 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
355 //check if the ID already exists
356 if (existSinkNameOrID(sinkData.sinkID, sinkData.name))
358 MY_SQLITE_FINALIZE(query)
359 return (E_ALREADY_EXISTS);
361 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
366 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
367 MY_SQLITE_FINALIZE(query)
368 return (E_DATABASE_ERROR);
371 MY_SQLITE_FINALIZE(query)
373 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
374 MY_SQLITE_BIND_TEXT(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC)
375 MY_SQLITE_BIND_INT(query, 2, sinkData.domainID)
376 MY_SQLITE_BIND_INT(query, 3, sinkData.sinkClassID)
377 MY_SQLITE_BIND_INT(query, 4, sinkData.volume)
378 MY_SQLITE_BIND_INT(query, 5, sinkData.visible)
379 MY_SQLITE_BIND_INT(query, 6, sinkData.available.availability)
380 MY_SQLITE_BIND_INT(query, 7, sinkData.available.availabilityReason)
381 MY_SQLITE_BIND_INT(query, 8, sinkData.muteState)
382 MY_SQLITE_BIND_INT(query, 9, sinkData.mainVolume)
383 MY_SQLITE_BIND_INT(query, 10, 0)
385 //if the ID is not created, we add it to the query
386 if (sinkData.sinkID != 0)
388 MY_SQLITE_BIND_INT(query, 11, sinkData.sinkID)
391 //if the first static sink is entered, we need to set it onto the boundary
392 else if (mFirstStaticSink)
394 MY_SQLITE_BIND_INT(query, 11, DYNAMIC_ID_BOUNDARY)
395 mFirstStaticSink = false;
398 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
400 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
401 MY_SQLITE_FINALIZE(query)
402 return (E_DATABASE_ERROR);
405 MY_SQLITE_FINALIZE(query)
407 //now read back the sinkID
408 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
409 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
410 MY_SQLITE_BIND_TEXT(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC)
411 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
413 sinkID = sqlite3_column_int(query, 0);
418 logError("DatabaseHandler::existSink database error!:", eCode);
419 MY_SQLITE_FINALIZE(query)
420 return (E_DATABASE_ERROR);
422 MY_SQLITE_FINALIZE(query)
424 //now we need to create the additional tables:
425 command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
426 if (!this->sqQuery(command))
427 return (E_DATABASE_ERROR);
428 command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
429 if (!this->sqQuery(command))
430 return (E_DATABASE_ERROR);
432 //fill ConnectionFormats
433 command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
434 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
435 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin();
436 for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator)
438 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
439 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
441 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
442 MY_SQLITE_FINALIZE(query)
443 return (E_DATABASE_ERROR);
445 MY_SQLITE_RESET(query)
448 //Fill SinkSoundProperties
449 command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
450 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
451 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin();
452 for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator)
454 MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type)
455 MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value)
456 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
458 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
459 MY_SQLITE_FINALIZE(query)
460 return (E_DATABASE_ERROR);
462 MY_SQLITE_RESET(query)
465 if (sinkData.visible == true)
467 command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
468 if (!this->sqQuery(command))
469 return (E_DATABASE_ERROR);
471 //Fill MainSinkSoundProperties
472 command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
473 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
474 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin();
475 for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
477 MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type)
478 MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value)
479 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
481 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
482 MY_SQLITE_FINALIZE(query)
483 return (E_DATABASE_ERROR);
485 MY_SQLITE_RESET(query)
487 MY_SQLITE_FINALIZE(query)
490 logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sinkData.name, "domainID:", sinkData.domainID, "classID:", sinkData.sinkClassID, "volume:", sinkData.volume, "assigned ID:", sinkID);
491 am_Sink_s sink = sinkData;
492 sink.sinkID = sinkID;
493 if (mpDatabaseObserver != NULL)
494 mpDatabaseObserver->newSink(sink);
498 am_Error_e CAmDatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
500 assert(crossfaderData.crossfaderID<DYNAMIC_ID_BOUNDARY);
501 assert(crossfaderData.hotSink>=HS_UNKNOWN && crossfaderData.hotSink<=HS_MAX);
502 assert(!crossfaderData.name.empty());
503 assert(existSink(crossfaderData.sinkID_A));
504 assert(existSink(crossfaderData.sinkID_B));
505 assert(existSource(crossfaderData.sourceID));
507 sqlite3_stmt* query = NULL;
511 //if gatewayData is zero and the first Static Sink was already entered, the ID is created
512 if (crossfaderData.crossfaderID == 0 && !mFirstStaticCrossfader)
514 command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink) VALUES (?,?,?,?,?)";
518 //check if the ID already exists
519 if (existcrossFader(crossfaderData.crossfaderID))
520 return (E_ALREADY_EXISTS);
521 command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink, crossfaderID) VALUES (?,?,?,?,?,?)";
524 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
526 MY_SQLITE_BIND_TEXT(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC)
527 MY_SQLITE_BIND_INT(query, 2, crossfaderData.sinkID_A)
528 MY_SQLITE_BIND_INT(query, 3, crossfaderData.sinkID_B)
529 MY_SQLITE_BIND_INT(query, 4, crossfaderData.sourceID)
530 MY_SQLITE_BIND_INT(query, 5, crossfaderData.hotSink)
532 //if the ID is not created, we add it to the query
533 if (crossfaderData.crossfaderID != 0)
535 MY_SQLITE_BIND_INT(query, 6, crossfaderData.crossfaderID)
538 //if the first static sink is entered, we need to set it onto the boundary
539 else if (mFirstStaticCrossfader)
541 MY_SQLITE_BIND_INT(query, 6, DYNAMIC_ID_BOUNDARY)
542 mFirstStaticCrossfader = false;
545 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
547 logError("DatabaseHandler::enterCrossfaderDB SQLITE Step error code:", eCode);
548 MY_SQLITE_FINALIZE(query)
549 return (E_DATABASE_ERROR);
552 MY_SQLITE_FINALIZE(query)
554 //now read back the crossfaderID
555 command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE name=?";
556 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
557 MY_SQLITE_BIND_TEXT(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC)
558 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
560 crossfaderID = sqlite3_column_int(query, 0);
565 logError("DatabaseHandler::enterCrossfaderDB database error!:", eCode);
566 MY_SQLITE_FINALIZE(query)
567 return (E_DATABASE_ERROR);
569 MY_SQLITE_FINALIZE(query)
571 logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID);
573 am_Crossfader_s crossfader(crossfaderData);
574 crossfader.crossfaderID = crossfaderID;
575 if (mpDatabaseObserver)
576 mpDatabaseObserver->newCrossfader(crossfader);
580 am_Error_e CAmDatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
582 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
583 assert(gatewayData.sinkID!=0);
584 assert(gatewayData.sourceID!=0);
585 assert(gatewayData.controlDomainID!=0);
586 assert(gatewayData.domainSinkID!=0);
587 assert(gatewayData.domainSourceID!=0);
588 assert(!gatewayData.name.empty());
589 assert(!gatewayData.convertionMatrix.empty());
590 assert(!gatewayData.listSinkFormats.empty());
591 assert(!gatewayData.listSourceFormats.empty());
592 assert(existSink(gatewayData.sinkID));
593 assert(existSource(gatewayData.sourceID));
595 sqlite3_stmt* query = NULL;
599 //if gatewayData is zero and the first Static Sink was already entered, the ID is created
600 if (gatewayData.gatewayID == 0 && !mFirstStaticGateway)
602 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID) VALUES (?,?,?,?,?,?)";
606 //check if the ID already exists
607 if (existGateway(gatewayData.gatewayID))
608 return (E_ALREADY_EXISTS);
609 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID) VALUES (?,?,?,?,?,?,?)";
612 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
613 MY_SQLITE_BIND_TEXT(query, 1, gatewayData.name.c_str(), gatewayData.name.size(), SQLITE_STATIC)
614 MY_SQLITE_BIND_INT(query, 2, gatewayData.sinkID)
615 MY_SQLITE_BIND_INT(query, 3, gatewayData.sourceID)
616 MY_SQLITE_BIND_INT(query, 4, gatewayData.domainSinkID)
617 MY_SQLITE_BIND_INT(query, 5, gatewayData.domainSourceID)
618 MY_SQLITE_BIND_INT(query, 6, gatewayData.controlDomainID)
620 //if the ID is not created, we add it to the query
621 if (gatewayData.gatewayID != 0)
623 MY_SQLITE_BIND_INT(query, 7, gatewayData.gatewayID)
626 //if the first static sink is entered, we need to set it onto the boundary
627 else if (mFirstStaticGateway)
629 MY_SQLITE_BIND_INT(query, 7, DYNAMIC_ID_BOUNDARY)
630 mFirstStaticGateway = false;
633 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
635 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
636 MY_SQLITE_FINALIZE(query)
637 return (E_DATABASE_ERROR);
640 MY_SQLITE_FINALIZE(query)
642 gatewayID = sqlite3_last_insert_rowid(mpDatabase);
644 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
645 mListConnectionFormat.insert(std::make_pair(gatewayID, gatewayData.convertionMatrix));
647 command = "CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
648 if (!this->sqQuery(command))
649 return (E_DATABASE_ERROR);
650 command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
651 if (!this->sqQuery(command))
652 return (E_DATABASE_ERROR);
654 //fill ConnectionFormats
655 command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
656 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
657 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin();
658 for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator)
660 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
661 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
663 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
664 MY_SQLITE_FINALIZE(query)
665 return (E_DATABASE_ERROR);
667 MY_SQLITE_RESET(query)
669 MY_SQLITE_FINALIZE(query)
671 command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
672 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
673 connectionFormatIterator = gatewayData.listSinkFormats.begin();
674 for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator)
676 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
677 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
679 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
680 MY_SQLITE_FINALIZE(query)
681 return (E_DATABASE_ERROR);
683 MY_SQLITE_RESET(query)
685 MY_SQLITE_FINALIZE(query)
687 logInfo("DatabaseHandler::enterGatewayDB entered new gateway with name", gatewayData.name, "sourceID:", gatewayData.sourceID, "sinkID:", gatewayData.sinkID, "assigned ID:", gatewayID);
688 am_Gateway_s gateway = gatewayData;
689 gateway.gatewayID = gatewayID;
690 if (mpDatabaseObserver)
691 mpDatabaseObserver->newGateway(gateway);
695 am_Error_e CAmDatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
697 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
698 assert(sourceData.domainID!=0);
699 assert(!sourceData.name.empty());
700 assert(sourceData.sourceClassID!=0);
701 // \todo: need to check if class exists?
702 assert(!sourceData.listConnectionFormats.empty());
703 assert(sourceData.sourceState>=SS_UNKNNOWN && sourceData.sourceState<=SS_MAX);
705 sqlite3_stmt* query = NULL;
708 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
710 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
711 MY_SQLITE_BIND_TEXT(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC)
713 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
715 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));
717 else if (eCode == SQLITE_DONE)
719 //if sinkID is zero and the first Static Sink was already entered, the ID is created
720 if (sourceData.sourceID == 0 && !mFirstStaticSource && !existSourceName(sourceData.name))
722 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
726 //check if the ID already exists
727 if (existSourceNameOrID(sourceData.sourceID, sourceData.name))
729 MY_SQLITE_FINALIZE(query)
730 return (E_ALREADY_EXISTS);
732 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
737 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
738 MY_SQLITE_FINALIZE(query)
739 return (E_DATABASE_ERROR);
742 MY_SQLITE_FINALIZE(query)
744 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
745 MY_SQLITE_BIND_TEXT(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC)
746 MY_SQLITE_BIND_INT(query, 2, sourceData.domainID)
747 MY_SQLITE_BIND_INT(query, 3, sourceData.sourceClassID)
748 MY_SQLITE_BIND_INT(query, 4, sourceData.sourceState)
749 MY_SQLITE_BIND_INT(query, 5, sourceData.volume)
750 MY_SQLITE_BIND_INT(query, 6, sourceData.visible)
751 MY_SQLITE_BIND_INT(query, 7, sourceData.available.availability)
752 MY_SQLITE_BIND_INT(query, 8, sourceData.available.availabilityReason)
753 MY_SQLITE_BIND_INT(query, 9, sourceData.interruptState)
754 MY_SQLITE_BIND_INT(query, 10, 0)
756 //if the ID is not created, we add it to the query
757 if (sourceData.sourceID != 0)
759 MY_SQLITE_BIND_INT(query, 11, sourceData.sourceID)
762 //if the first static sink is entered, we need to set it onto the boundary
763 else if (mFirstStaticSource)
765 MY_SQLITE_BIND_INT(query, 11, DYNAMIC_ID_BOUNDARY)
766 mFirstStaticSource = false;
769 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
771 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
772 MY_SQLITE_FINALIZE(query)
773 return (E_DATABASE_ERROR);
776 MY_SQLITE_FINALIZE(query)
778 //now read back the sinkID
779 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
780 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
781 MY_SQLITE_BIND_TEXT(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC)
782 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
784 sourceID = sqlite3_column_int(query, 0);
789 logError("DatabaseHandler::existSink database error!:", eCode);
790 MY_SQLITE_FINALIZE(query)
791 return (E_DATABASE_ERROR);
793 MY_SQLITE_FINALIZE(query)
795 //now we need to create the additional tables:
796 command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
797 if (!this->sqQuery(command))
798 return (E_DATABASE_ERROR);
799 command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
800 if (!this->sqQuery(command))
801 return (E_DATABASE_ERROR);
803 //fill ConnectionFormats
804 command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
805 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
806 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin();
807 for (; connectionFormatIterator < sourceData.listConnectionFormats.end(); ++connectionFormatIterator)
809 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
810 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
812 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
813 MY_SQLITE_FINALIZE(query)
814 return (E_DATABASE_ERROR);
816 MY_SQLITE_RESET(query)
818 MY_SQLITE_FINALIZE(query)
820 //Fill SinkSoundProperties
821 command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
822 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
823 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin();
824 for (; SoundPropertyIterator < sourceData.listSoundProperties.end(); ++SoundPropertyIterator)
826 MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type)
827 MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value)
828 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
830 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
831 MY_SQLITE_FINALIZE(query)
832 return (E_DATABASE_ERROR);
834 MY_SQLITE_RESET(query)
837 MY_SQLITE_FINALIZE(query)
839 if (sourceData.visible == true)
841 command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
842 if (!this->sqQuery(command))
843 return (E_DATABASE_ERROR);
845 //Fill MainSinkSoundProperties
846 command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
847 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
848 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin();
849 for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
851 MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type)
852 MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value)
853 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
855 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
856 MY_SQLITE_FINALIZE(query)
857 return (E_DATABASE_ERROR);
859 MY_SQLITE_RESET(query)
861 MY_SQLITE_FINALIZE(query)
864 logInfo("DatabaseHandler::enterSourceDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID);
866 am_Source_s source = sourceData;
867 source.sourceID = sourceID;
868 if (mpDatabaseObserver)
869 mpDatabaseObserver->newSource(source);
873 am_Error_e CAmDatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector<am_connectionID_t>& listConnectionID)
875 assert(mainconnectionID!=0);
876 if (!existMainConnection(mainconnectionID))
878 return (E_NON_EXISTENT);
880 sqlite3_stmt* query = NULL;
885 command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?");
886 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
887 std::vector<am_connectionID_t>::const_iterator elementIterator = listConnectionID.begin();
888 for (; elementIterator < listConnectionID.end(); ++elementIterator)
890 MY_SQLITE_BIND_INT(query, 1, *elementIterator)
892 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
894 int16_t temp_delay = sqlite3_column_int(query, 1);
895 if (temp_delay != -1 && delay != -1)
902 logError("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:", eCode);
903 MY_SQLITE_FINALIZE(query)
904 return (E_DATABASE_ERROR);
906 MY_SQLITE_RESET(query)
909 MY_SQLITE_FINALIZE(query)
911 //now we delete the data in the table
912 command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID);
913 if (!this->sqQuery(command))
914 return (E_DATABASE_ERROR);
916 command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
917 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
918 std::vector<am_connectionID_t>::const_iterator listConnectionIterator(listConnectionID.begin());
919 for (; listConnectionIterator != listConnectionID.end(); ++listConnectionIterator)
921 MY_SQLITE_BIND_INT(query, 1, *listConnectionIterator)
922 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
924 logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:", eCode);
925 MY_SQLITE_FINALIZE(query)
926 return (E_DATABASE_ERROR);
928 MY_SQLITE_RESET(query)
931 MY_SQLITE_FINALIZE(query)
932 logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID);
936 am_Error_e CAmDatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
938 assert(mainconnectionID!=0);
939 assert(connectionState>=CS_UNKNOWN && connectionState<=CS_MAX);
941 sqlite3_stmt* query = NULL;
945 if (!existMainConnection(mainconnectionID))
947 return (E_NON_EXISTENT);
949 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
950 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
951 MY_SQLITE_BIND_INT(query, 1, connectionState)
952 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
954 logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:", eCode);
955 MY_SQLITE_FINALIZE(query)
956 return (E_DATABASE_ERROR);
958 MY_SQLITE_FINALIZE(query)
959 logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState);
961 if (mpDatabaseObserver)
962 mpDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState);
966 am_Error_e CAmDatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
970 sqlite3_stmt* query = NULL;
974 if (!existSink(sinkID))
976 return (E_NON_EXISTENT);
978 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
979 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
980 MY_SQLITE_BIND_INT(query, 1, mainVolume)
981 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
983 logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:", eCode);
984 MY_SQLITE_FINALIZE(query)
985 return (E_DATABASE_ERROR);
988 MY_SQLITE_FINALIZE(query)
989 logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume);
991 if (mpDatabaseObserver)
992 mpDatabaseObserver->volumeChanged(sinkID, mainVolume);
997 am_Error_e CAmDatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
1000 assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX);
1001 assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX);
1003 sqlite3_stmt* query = NULL;
1005 std::string command;
1007 if (!existSink(sinkID))
1009 return (E_NON_EXISTENT);
1011 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
1012 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1013 MY_SQLITE_BIND_INT(query, 1, availability.availability)
1014 MY_SQLITE_BIND_INT(query, 2, availability.availabilityReason)
1015 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1017 logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:", eCode);
1018 MY_SQLITE_FINALIZE(query)
1019 return (E_DATABASE_ERROR);
1022 MY_SQLITE_FINALIZE(query)
1023 logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason);
1025 if (mpDatabaseObserver && sourceVisible(sinkID))
1026 mpDatabaseObserver->sinkAvailabilityChanged(sinkID, availability);
1030 am_Error_e CAmDatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
1032 assert(domainID!=0);
1033 assert(domainState>=DS_UNKNOWN && domainState<=DS_MAX);
1035 sqlite3_stmt* query = NULL;
1037 std::string command;
1039 if (!existDomain(domainID))
1041 return (E_NON_EXISTENT);
1043 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
1044 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1045 MY_SQLITE_BIND_INT(query, 1, domainState)
1046 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1048 logError("DatabaseHandler::changDomainStateDB SQLITE Step error code:", eCode);
1049 MY_SQLITE_FINALIZE(query)
1050 return (E_DATABASE_ERROR);
1053 MY_SQLITE_FINALIZE(query)
1055 logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState);
1059 am_Error_e CAmDatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
1062 assert(muteState>=MS_UNKNOWN && muteState<=MS_MAX);
1064 sqlite3_stmt* query = NULL;
1066 std::string command;
1068 if (!existSink(sinkID))
1070 return (E_NON_EXISTENT);
1072 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
1073 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1074 MY_SQLITE_BIND_INT(query, 1, muteState)
1075 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1077 logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:", eCode);
1078 MY_SQLITE_FINALIZE(query)
1079 return (E_DATABASE_ERROR);
1082 MY_SQLITE_FINALIZE(query)
1083 logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState);
1085 if (mpDatabaseObserver)
1086 mpDatabaseObserver->sinkMuteStateChanged(sinkID, muteState);
1091 am_Error_e CAmDatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
1093 assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX);
1096 sqlite3_stmt* query = NULL;
1098 std::string command;
1100 if (!existSink(sinkID))
1102 return (E_NON_EXISTENT);
1104 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1105 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1106 MY_SQLITE_BIND_INT(query, 1, soundProperty.value)
1107 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1109 logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:", eCode);
1110 MY_SQLITE_FINALIZE(query)
1111 return (E_DATABASE_ERROR);
1114 MY_SQLITE_FINALIZE(query)
1115 logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value);
1116 if (mpDatabaseObserver)
1117 mpDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty);
1121 am_Error_e CAmDatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1123 assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX);
1124 assert(sourceID!=0);
1126 sqlite3_stmt* query = NULL;
1128 std::string command;
1130 if (!existSource(sourceID))
1132 return (E_NON_EXISTENT);
1134 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1135 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1136 MY_SQLITE_BIND_INT(query, 1, soundProperty.value)
1137 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1139 logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:", eCode);
1140 MY_SQLITE_FINALIZE(query)
1141 return (E_DATABASE_ERROR);
1143 MY_SQLITE_FINALIZE(query)
1145 logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value);
1147 if (mpDatabaseObserver)
1148 mpDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty);
1152 am_Error_e CAmDatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1154 assert(sourceID!=0);
1155 assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX);
1156 assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX);
1158 sqlite3_stmt* query = NULL;
1160 std::string command;
1162 if (!existSource(sourceID))
1164 return (E_NON_EXISTENT);
1166 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1167 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1168 MY_SQLITE_BIND_INT(query, 1, availability.availability)
1169 MY_SQLITE_BIND_INT(query, 2, availability.availabilityReason)
1170 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1172 logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:", eCode);
1173 MY_SQLITE_FINALIZE(query)
1174 return (E_DATABASE_ERROR);
1177 MY_SQLITE_FINALIZE(query)
1179 logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason);
1181 if (mpDatabaseObserver && sourceVisible(sourceID))
1182 mpDatabaseObserver->sourceAvailabilityChanged(sourceID, availability);
1186 am_Error_e CAmDatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1188 assert(property.type>=SYP_UNKNOWN && property.type<=SYP_MAX);
1189 sqlite3_stmt* query = NULL;
1191 std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1193 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1194 MY_SQLITE_BIND_INT(query, 1, property.value)
1195 MY_SQLITE_BIND_INT(query, 2, property.type)
1197 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1199 logError("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:", eCode);
1200 MY_SQLITE_FINALIZE(query)
1201 return (E_DATABASE_ERROR);
1204 MY_SQLITE_FINALIZE(query)
1206 logInfo("DatabaseHandler::changeSystemPropertyDB changed system property");
1208 if (mpDatabaseObserver)
1209 mpDatabaseObserver->systemPropertyChanged(property);
1214 am_Error_e CAmDatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1216 assert(mainConnectionID!=0);
1218 if (!existMainConnection(mainConnectionID))
1220 return (E_NON_EXISTENT);
1222 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1223 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1224 if (!sqQuery(command))
1225 return (E_DATABASE_ERROR);
1226 if (!sqQuery(command1))
1227 return (E_DATABASE_ERROR);
1228 logInfo("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID);
1229 if (mpDatabaseObserver)
1231 mpDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED);
1232 mpDatabaseObserver->removedMainConnection(mainConnectionID);
1237 am_Error_e CAmDatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1241 if (!existSink(sinkID))
1243 return (E_NON_EXISTENT);
1246 bool visible = sinkVisible(sinkID);
1248 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1249 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1250 std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1251 std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID);
1252 if (!sqQuery(command))
1253 return (E_DATABASE_ERROR);
1254 if (!sqQuery(command1))
1255 return (E_DATABASE_ERROR);
1256 if (!sqQuery(command2))
1257 return (E_DATABASE_ERROR);
1258 if (!sqQuery(command3))
1259 return (E_DATABASE_ERROR);
1260 logInfo("DatabaseHandler::removeSinkDB removed:", sinkID);
1262 if (mpDatabaseObserver != NULL)
1263 mpDatabaseObserver->removedSink(sinkID, visible);
1268 am_Error_e CAmDatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1270 assert(sourceID!=0);
1272 if (!existSource(sourceID))
1274 return (E_NON_EXISTENT);
1277 bool visible = sourceVisible(sourceID);
1279 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1280 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1281 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1282 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1283 if (!sqQuery(command))
1284 return (E_DATABASE_ERROR);
1285 if (!sqQuery(command1))
1286 return (E_DATABASE_ERROR);
1287 if (!sqQuery(command2))
1288 return (E_DATABASE_ERROR);
1289 if (!sqQuery(command3))
1290 return (E_DATABASE_ERROR);
1291 logInfo("DatabaseHandler::removeSourceDB removed:", sourceID);
1292 if (mpDatabaseObserver)
1293 mpDatabaseObserver->removedSource(sourceID, visible);
1297 am_Error_e CAmDatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1299 assert(gatewayID!=0);
1301 if (!existGateway(gatewayID))
1303 return (E_NON_EXISTENT);
1305 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1306 if (!sqQuery(command))
1307 return (E_DATABASE_ERROR);
1308 logInfo("DatabaseHandler::removeGatewayDB removed:", gatewayID);
1309 if (mpDatabaseObserver)
1310 mpDatabaseObserver->removeGateway(gatewayID);
1314 am_Error_e CAmDatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1316 assert(crossfaderID!=0);
1318 if (!existcrossFader(crossfaderID))
1320 return (E_NON_EXISTENT);
1322 std::string command = "DELETE from " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID);
1323 if (!sqQuery(command))
1324 return (E_DATABASE_ERROR);
1325 logInfo("DatabaseHandler::removeDomainDB removed:", crossfaderID);
1326 if (mpDatabaseObserver)
1327 mpDatabaseObserver->removeCrossfader(crossfaderID);
1331 am_Error_e CAmDatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1333 assert(domainID!=0);
1335 if (!existDomain(domainID))
1337 return (E_NON_EXISTENT);
1339 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1340 if (!sqQuery(command))
1341 return (E_DATABASE_ERROR);
1342 logInfo("DatabaseHandler::removeDomainDB removed:", domainID);
1343 if (mpDatabaseObserver)
1344 mpDatabaseObserver->removeDomain(domainID);
1348 am_Error_e CAmDatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1350 assert(sinkClassID!=0);
1352 if (!existSinkClass(sinkClassID))
1354 return (E_NON_EXISTENT);
1356 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1357 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1358 if (!sqQuery(command))
1359 return (E_DATABASE_ERROR);
1360 if (!sqQuery(command1))
1361 return (E_DATABASE_ERROR);
1363 logInfo("DatabaseHandler::removeSinkClassDB removed:", sinkClassID);
1364 if (mpDatabaseObserver)
1365 mpDatabaseObserver->numberOfSinkClassesChanged();
1370 am_Error_e CAmDatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1372 assert(sourceClassID!=0);
1374 if (!existSourceClass(sourceClassID))
1376 return (E_NON_EXISTENT);
1378 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1379 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1380 if (!sqQuery(command))
1381 return (E_DATABASE_ERROR);
1382 if (!sqQuery(command1))
1383 return (E_DATABASE_ERROR);
1384 logInfo("DatabaseHandler::removeSourceClassDB removed:", sourceClassID);
1385 if (mpDatabaseObserver)
1386 mpDatabaseObserver->numberOfSourceClassesChanged();
1390 am_Error_e CAmDatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1392 assert(connectionID!=0);
1394 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1395 if (!sqQuery(command))
1396 return (E_DATABASE_ERROR);
1397 logInfo("DatabaseHandler::removeConnection removed:", connectionID);
1401 am_Error_e CAmDatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1403 assert(sourceID!=0);
1405 if (!existSource(sourceID))
1407 return (E_NON_EXISTENT);
1409 sqlite3_stmt* query = NULL;
1411 am_ClassProperty_s propertyTemp;
1412 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + (i2s(sourceID));
1413 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1415 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1417 classInfo.sourceClassID = sqlite3_column_int(query, 0);
1420 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1422 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1423 MY_SQLITE_FINALIZE(query)
1424 return (E_DATABASE_ERROR);
1427 MY_SQLITE_FINALIZE(query)
1429 command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1430 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1432 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1434 classInfo.name = std::string((const char*) sqlite3_column_text(query, 0));
1437 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1439 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1440 MY_SQLITE_FINALIZE(query)
1441 return (E_DATABASE_ERROR);
1444 MY_SQLITE_FINALIZE(query)
1446 //read out Properties
1447 command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID);
1448 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1449 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1451 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1452 propertyTemp.value = sqlite3_column_int(query, 1);
1453 classInfo.listClassProperties.push_back(propertyTemp);
1456 if (eCode != SQLITE_DONE)
1458 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1459 MY_SQLITE_FINALIZE(query)
1460 return (E_DATABASE_ERROR);
1463 MY_SQLITE_FINALIZE(query)
1467 am_Error_e CAmDatabaseHandler::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const
1472 if (!existSink(sinkID))
1474 return (E_NON_EXISTENT);
1477 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
1479 am_ConnectionFormat_e tempConnectionFormat;
1480 am_SoundProperty_s tempSoundProperty;
1481 am_MainSoundProperty_s tempMainSoundProperty;
1482 std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 and sinkID=" + i2s(sinkID);
1483 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1485 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1487 sinkData.name = std::string((const char*) sqlite3_column_text(query, 0));
1488 sinkData.domainID = sqlite3_column_int(query, 1);
1489 sinkData.sinkClassID = sqlite3_column_int(query, 2);
1490 sinkData.volume = sqlite3_column_int(query, 3);
1491 sinkData.visible = sqlite3_column_int(query, 4);
1492 sinkData.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5);
1493 sinkData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
1494 sinkData.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
1495 sinkData.mainVolume = sqlite3_column_int(query, 8);
1496 sinkData.sinkID = sqlite3_column_int(query, 9);
1498 //read out the connectionFormats
1499 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
1500 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
1501 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1503 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1504 sinkData.listConnectionFormats.push_back(tempConnectionFormat);
1507 MY_SQLITE_FINALIZE(qConnectionFormat)
1509 //read out sound properties
1510 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(sinkID);
1511 MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
1512 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1514 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1515 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1516 sinkData.listSoundProperties.push_back(tempSoundProperty);
1519 MY_SQLITE_FINALIZE(qSoundProperty)
1521 //read out MainSoundProperties
1522 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
1523 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
1524 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1526 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1527 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1528 sinkData.listMainSoundProperties.push_back(tempMainSoundProperty);
1531 MY_SQLITE_FINALIZE(qMAinSoundProperty)
1534 else if (eCode != SQLITE_DONE)
1536 logError("DatabaseHandler::getSinkInfoDB SQLITE error code:", eCode);
1537 MY_SQLITE_FINALIZE(query)
1538 return (E_DATABASE_ERROR);
1541 MY_SQLITE_FINALIZE(query)
1546 am_Error_e CAmDatabaseHandler::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const
1548 assert(sourceID!=0);
1550 if (!existSource(sourceID))
1552 return (E_NON_EXISTENT);
1555 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
1557 am_ConnectionFormat_e tempConnectionFormat;
1558 am_SoundProperty_s tempSoundProperty;
1559 am_MainSoundProperty_s tempMainSoundProperty;
1560 std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
1561 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1563 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1565 sourceData.name = std::string((const char*) sqlite3_column_text(query, 0));
1566 sourceData.domainID = sqlite3_column_int(query, 1);
1567 sourceData.sourceClassID = sqlite3_column_int(query, 2);
1568 sourceData.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
1569 sourceData.volume = sqlite3_column_int(query, 4);
1570 sourceData.visible = sqlite3_column_int(query, 5);
1571 sourceData.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6);
1572 sourceData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
1573 sourceData.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
1574 sourceData.sourceID = sqlite3_column_int(query, 9);
1576 //read out the connectionFormats
1577 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
1578 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
1579 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1581 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1582 sourceData.listConnectionFormats.push_back(tempConnectionFormat);
1585 MY_SQLITE_FINALIZE(qConnectionFormat)
1587 //read out sound properties
1588 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(sourceID);
1589 MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
1590 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1592 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1593 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1594 sourceData.listSoundProperties.push_back(tempSoundProperty);
1597 MY_SQLITE_FINALIZE(qSoundProperty)
1599 //read out MainSoundProperties
1600 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
1601 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
1602 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1604 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1605 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1606 sourceData.listMainSoundProperties.push_back(tempMainSoundProperty);
1609 MY_SQLITE_FINALIZE(qMAinSoundProperty)
1611 else if (eCode != SQLITE_DONE)
1613 logError("DatabaseHandler::getSourceInfoDB SQLITE error code:", eCode);
1614 MY_SQLITE_FINALIZE(query)
1615 return (E_DATABASE_ERROR);
1618 MY_SQLITE_FINALIZE(query)
1623 am_Error_e am::CAmDatabaseHandler::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const
1625 assert(mainConnectionID!=0);
1626 if (!existMainConnection(mainConnectionID))
1628 return (E_NON_EXISTENT);
1630 sqlite3_stmt *query = NULL, *query1 = NULL;
1632 am_MainConnection_s temp;
1633 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1634 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
1635 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1637 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1639 mainConnectionData.mainConnectionID = sqlite3_column_int(query, 0);
1640 mainConnectionData.sourceID = sqlite3_column_int(query, 1);
1641 mainConnectionData.sinkID = sqlite3_column_int(query, 2);
1642 mainConnectionData.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
1643 mainConnectionData.delay = sqlite3_column_int(query, 4);
1644 std::string statement = command1 + i2s(mainConnectionID);
1645 MY_SQLITE_PREPARE_V2(mpDatabase, statement.c_str(), -1, &query1, NULL)
1646 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW)
1648 mainConnectionData.listConnectionID.push_back(sqlite3_column_int(query1, 0));
1650 MY_SQLITE_FINALIZE(query1)
1653 if (eCode != SQLITE_DONE)
1655 logError("DatabaseHandler::getMainConnectionInfoDB SQLITE error code:", eCode);
1656 MY_SQLITE_FINALIZE(query)
1657 return (E_DATABASE_ERROR);
1660 MY_SQLITE_FINALIZE(query)
1665 am_Error_e CAmDatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1667 assert(sinkClass.sinkClassID!=0);
1668 assert(!sinkClass.listClassProperties.empty());
1670 sqlite3_stmt* query = NULL;
1673 //check if the ID already exists
1674 if (!existSinkClass(sinkClass.sinkClassID))
1675 return (E_NON_EXISTENT);
1677 //fill ConnectionFormats
1678 std::string command = "UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1679 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1680 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
1681 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
1683 MY_SQLITE_BIND_INT(query, 1, Iterator->value)
1684 MY_SQLITE_BIND_INT(query, 2, Iterator->classProperty)
1685 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1687 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode);
1688 MY_SQLITE_FINALIZE(query)
1689 return (E_DATABASE_ERROR);
1691 MY_SQLITE_RESET(query)
1694 MY_SQLITE_FINALIZE(query)
1696 logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo");
1700 am_Error_e CAmDatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1702 assert(sourceClass.sourceClassID!=0);
1703 assert(!sourceClass.listClassProperties.empty());
1705 sqlite3_stmt* query = NULL;
1708 //check if the ID already exists
1709 if (!existSourceClass(sourceClass.sourceClassID))
1710 return (E_NON_EXISTENT);
1712 //fill ConnectionFormats
1713 std::string command = "UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1714 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1715 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
1716 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
1718 MY_SQLITE_BIND_INT(query, 1, Iterator->value)
1719 MY_SQLITE_BIND_INT(query, 2, Iterator->classProperty)
1720 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1722 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode);
1723 MY_SQLITE_FINALIZE(query)
1724 return (E_DATABASE_ERROR);
1726 MY_SQLITE_RESET(query)
1729 MY_SQLITE_FINALIZE(query)
1731 logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo");
1735 am_Error_e CAmDatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1739 if (!existSink(sinkID))
1741 return (E_NON_EXISTENT);
1743 sqlite3_stmt* query = NULL;
1745 am_ClassProperty_s propertyTemp;
1746 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + (i2s(sinkID));
1747 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1749 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1751 sinkClass.sinkClassID = sqlite3_column_int(query, 0);
1754 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1756 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1757 MY_SQLITE_FINALIZE(query)
1758 return (E_DATABASE_ERROR);
1761 MY_SQLITE_FINALIZE(query)
1763 command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1764 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1766 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1768 sinkClass.name = std::string((const char*) sqlite3_column_text(query, 0));
1771 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1773 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1774 MY_SQLITE_FINALIZE(query)
1775 return (E_DATABASE_ERROR);
1778 MY_SQLITE_FINALIZE(query)
1780 //read out Properties
1781 command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID);
1782 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1783 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1785 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1786 propertyTemp.value = sqlite3_column_int(query, 1);
1787 sinkClass.listClassProperties.push_back(propertyTemp);
1790 if (eCode != SQLITE_DONE)
1792 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1793 MY_SQLITE_FINALIZE(query)
1794 return (E_DATABASE_ERROR);
1797 MY_SQLITE_FINALIZE(query)
1801 am_Error_e CAmDatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1803 assert(gatewayID!=0);
1804 if (!existGateway(gatewayID))
1806 return (E_NON_EXISTENT);
1808 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
1810 am_ConnectionFormat_e tempConnectionFormat;
1811 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1812 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1814 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1816 gatewayData.name = std::string((const char*) sqlite3_column_text(query, 0));
1817 gatewayData.sinkID = sqlite3_column_int(query, 1);
1818 gatewayData.sourceID = sqlite3_column_int(query, 2);
1819 gatewayData.domainSinkID = sqlite3_column_int(query, 3);
1820 gatewayData.domainSourceID = sqlite3_column_int(query, 4);
1821 gatewayData.controlDomainID = sqlite3_column_int(query, 5);
1822 gatewayData.gatewayID = sqlite3_column_int(query, 6);
1825 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
1826 iter = mListConnectionFormat.find(gatewayData.gatewayID);
1827 if (iter == mListConnectionFormat.end())
1829 logError("DatabaseHandler::getGatewayInfoDB database error with convertionFormat");
1830 MY_SQLITE_FINALIZE(query)
1831 return (E_DATABASE_ERROR);
1833 gatewayData.convertionMatrix = iter->second;
1835 //read out the connectionFormats
1836 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
1837 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL)
1838 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
1840 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
1841 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
1844 MY_SQLITE_FINALIZE(qSourceConnectionFormat)
1846 //read out sound properties
1847 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
1848 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL)
1849 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
1851 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
1852 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
1855 MY_SQLITE_FINALIZE(qSinkConnectionFormat)
1859 if (eCode != SQLITE_DONE)
1861 logError("DatabaseHandler::getGatewayInfoDB SQLITE error code:", eCode);
1862 MY_SQLITE_FINALIZE(query)
1863 return (E_DATABASE_ERROR);
1866 MY_SQLITE_FINALIZE(query)
1872 am_Error_e CAmDatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
1874 assert(crossfaderID!=0);
1875 if (!existcrossFader(crossfaderID))
1877 return (E_NON_EXISTENT);
1879 sqlite3_stmt* query = NULL;
1881 std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID);
1882 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1884 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1886 crossfaderData.name = std::string((const char*) sqlite3_column_text(query, 0));
1887 crossfaderData.sinkID_A = sqlite3_column_int(query, 1);
1888 crossfaderData.sinkID_B = sqlite3_column_int(query, 2);
1889 crossfaderData.sourceID = sqlite3_column_int(query, 3);
1890 crossfaderData.hotSink = static_cast<am_HotSink_e>(sqlite3_column_int(query, 4));
1891 crossfaderData.crossfaderID = sqlite3_column_int(query, 5);
1894 if (eCode != SQLITE_DONE)
1896 logError("DatabaseHandler::getCrossfaderInfoDB SQLITE error code:", eCode);
1897 MY_SQLITE_FINALIZE(query)
1898 return (E_DATABASE_ERROR);
1901 MY_SQLITE_FINALIZE(query)
1906 am_Error_e CAmDatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
1908 assert(domainID!=0);
1910 if (!existDomain(domainID))
1912 return (E_NON_EXISTENT);
1914 sqlite3_stmt* query = NULL;
1917 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND domainID=" + (i2s(domainID));
1918 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1920 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1922 temp = sqlite3_column_int(query, 0);
1923 listSinkID.push_back(temp);
1926 if (eCode != SQLITE_DONE)
1928 logError("DatabaseHandler::getListSinksOfDomain SQLITE error code:", eCode);
1929 MY_SQLITE_FINALIZE(query)
1930 return (E_DATABASE_ERROR);
1933 MY_SQLITE_FINALIZE(query)
1937 am_Error_e CAmDatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
1939 assert(domainID!=0);
1940 listSourceID.clear();
1941 if (!existDomain(domainID))
1943 return (E_NON_EXISTENT);
1945 sqlite3_stmt* query = NULL;
1948 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
1950 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1952 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1954 temp = sqlite3_column_int(query, 0);
1955 listSourceID.push_back(temp);
1958 if (eCode != SQLITE_DONE)
1960 logError("DatabaseHandler::getListSourcesOfDomain SQLITE error code:", eCode);
1961 MY_SQLITE_FINALIZE(query)
1962 return (E_DATABASE_ERROR);
1965 MY_SQLITE_FINALIZE(query)
1970 am_Error_e CAmDatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listCrossfader) const
1972 assert(domainID!=0);
1973 listCrossfader.clear();
1974 if (!existDomain(domainID))
1976 return (E_NON_EXISTENT);
1978 sqlite3_stmt* query = NULL;
1980 am_crossfaderID_t temp;
1982 std::string command = "SELECT c.crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " c," + std::string(SOURCE_TABLE) + " s WHERE c.sourceID=s.sourceID AND s.domainID=" + i2s(domainID);
1983 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1985 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1987 temp = sqlite3_column_int(query, 0);
1988 listCrossfader.push_back(temp);
1991 if (eCode != SQLITE_DONE)
1993 logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE error code:", eCode);
1994 MY_SQLITE_FINALIZE(query)
1995 return (E_DATABASE_ERROR);
1998 MY_SQLITE_FINALIZE(query)
2004 am_Error_e CAmDatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
2006 assert(domainID!=0);
2007 listGatewaysID.clear();
2008 if (!existDomain(domainID))
2010 return (E_NON_EXISTENT);
2012 sqlite3_stmt* query = NULL;
2014 am_gatewayID_t temp;
2016 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" + i2s(domainID);
2017 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2019 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2021 temp = sqlite3_column_int(query, 0);
2022 listGatewaysID.push_back(temp);
2025 if (eCode != SQLITE_DONE)
2027 logError("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:", eCode);
2028 MY_SQLITE_FINALIZE(query)
2029 return (E_DATABASE_ERROR);
2032 MY_SQLITE_FINALIZE(query)
2037 am_Error_e CAmDatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
2039 listMainConnections.clear();
2040 sqlite3_stmt *query = NULL, *query1 = NULL;
2042 am_MainConnection_s temp;
2043 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2044 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
2045 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2047 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2049 temp.mainConnectionID = sqlite3_column_int(query, 0);
2050 temp.sourceID = sqlite3_column_int(query, 1);
2051 temp.sinkID = sqlite3_column_int(query, 2);
2052 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2053 temp.delay = sqlite3_column_int(query, 4);
2054 std::string statement = command1 + i2s(temp.mainConnectionID);
2055 MY_SQLITE_PREPARE_V2(mpDatabase, statement.c_str(), -1, &query1, NULL)
2056 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW)
2058 temp.listConnectionID.push_back(sqlite3_column_int(query1, 0));
2060 listMainConnections.push_back(temp);
2061 MY_SQLITE_FINALIZE(query1)
2064 if (eCode != SQLITE_DONE)
2066 logError("DatabaseHandler::getListMainConnections SQLITE error code:", eCode);
2067 MY_SQLITE_FINALIZE(query)
2068 return (E_DATABASE_ERROR);
2071 MY_SQLITE_FINALIZE(query)
2076 am_Error_e CAmDatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
2078 listDomains.clear();
2079 sqlite3_stmt* query = NULL;
2082 std::string command = "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
2083 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2085 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2087 temp.domainID = sqlite3_column_int(query, 0);
2088 temp.name = std::string((const char*) sqlite3_column_text(query, 1));
2089 temp.busname = std::string((const char*) sqlite3_column_text(query, 2));
2090 temp.nodename = std::string((const char*) sqlite3_column_text(query, 3));
2091 temp.early = sqlite3_column_int(query, 4);
2092 temp.complete = sqlite3_column_int(query, 5);
2093 temp.state = (am_DomainState_e) sqlite3_column_int(query, 6);
2094 listDomains.push_back(temp);
2097 if (eCode != SQLITE_DONE)
2099 logError("DatabaseHandler::getListDomains SQLITE error code:", eCode);
2100 MY_SQLITE_FINALIZE(query)
2101 return (E_DATABASE_ERROR);
2104 MY_SQLITE_FINALIZE(query)
2109 am_Error_e CAmDatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
2111 listConnections.clear();
2112 sqlite3_stmt* query = NULL;
2114 am_Connection_s temp;
2115 std::string command = "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE reserved=0";
2116 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2118 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2120 temp.connectionID = sqlite3_column_int(query, 0);
2121 temp.sourceID = sqlite3_column_int(query, 1);
2122 temp.sinkID = sqlite3_column_int(query, 2);
2123 temp.delay = sqlite3_column_int(query, 3);
2124 temp.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query, 4);
2125 listConnections.push_back(temp);
2128 if (eCode != SQLITE_DONE)
2130 logError("DatabaseHandler::getListConnections SQLITE error code:", eCode);
2131 MY_SQLITE_FINALIZE(query)
2132 return (E_DATABASE_ERROR);
2135 MY_SQLITE_FINALIZE(query)
2140 am_Error_e CAmDatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
2143 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
2146 am_ConnectionFormat_e tempConnectionFormat;
2147 am_SoundProperty_s tempSoundProperty;
2148 am_MainSoundProperty_s tempMainSoundProperty;
2149 std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0";
2150 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2152 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2154 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2155 temp.domainID = sqlite3_column_int(query, 1);
2156 temp.sinkClassID = sqlite3_column_int(query, 2);
2157 temp.volume = sqlite3_column_int(query, 3);
2158 temp.visible = sqlite3_column_int(query, 4);
2159 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5);
2160 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
2161 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
2162 temp.mainVolume = sqlite3_column_int(query, 8);
2163 temp.sinkID = sqlite3_column_int(query, 9);
2165 //read out the connectionFormats
2166 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID);
2167 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
2168 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2170 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2171 temp.listConnectionFormats.push_back(tempConnectionFormat);
2174 MY_SQLITE_FINALIZE(qConnectionFormat)
2176 //read out sound properties
2177 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
2178 MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
2179 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
2181 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
2182 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
2183 temp.listSoundProperties.push_back(tempSoundProperty);
2186 MY_SQLITE_FINALIZE(qSoundProperty)
2188 //read out MainSoundProperties
2189 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID);
2190 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
2191 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
2193 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
2194 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2195 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2198 MY_SQLITE_FINALIZE(qMAinSoundProperty)
2200 listSinks.push_back(temp);
2201 temp.listConnectionFormats.clear();
2202 temp.listMainSoundProperties.clear();
2203 temp.listSoundProperties.clear();
2206 if (eCode != SQLITE_DONE)
2208 logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
2209 MY_SQLITE_FINALIZE(query)
2210 return (E_DATABASE_ERROR);
2213 MY_SQLITE_FINALIZE(query)
2218 am_Error_e CAmDatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
2220 listSources.clear();
2221 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
2224 am_ConnectionFormat_e tempConnectionFormat;
2225 am_SoundProperty_s tempSoundProperty;
2226 am_MainSoundProperty_s tempMainSoundProperty;
2227 std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0";
2228 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2230 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2232 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2233 temp.domainID = sqlite3_column_int(query, 1);
2234 temp.sourceClassID = sqlite3_column_int(query, 2);
2235 temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
2236 temp.volume = sqlite3_column_int(query, 4);
2237 temp.visible = sqlite3_column_int(query, 5);
2238 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6);
2239 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
2240 temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
2241 temp.sourceID = sqlite3_column_int(query, 9);
2243 //read out the connectionFormats
2244 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID);
2245 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
2246 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2248 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2249 temp.listConnectionFormats.push_back(tempConnectionFormat);
2252 MY_SQLITE_FINALIZE(qConnectionFormat)
2254 //read out sound properties
2255 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
2256 MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
2257 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
2259 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
2260 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
2261 temp.listSoundProperties.push_back(tempSoundProperty);
2264 MY_SQLITE_FINALIZE(qSoundProperty)
2266 //read out MainSoundProperties
2267 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID);
2268 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
2269 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
2271 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
2272 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2273 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2276 MY_SQLITE_FINALIZE(qMAinSoundProperty)
2278 listSources.push_back(temp);
2279 temp.listConnectionFormats.clear();
2280 temp.listMainSoundProperties.clear();
2281 temp.listSoundProperties.clear();
2284 if (eCode != SQLITE_DONE)
2286 logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
2287 MY_SQLITE_FINALIZE(query)
2288 return (E_DATABASE_ERROR);
2291 MY_SQLITE_FINALIZE(query)
2296 am_Error_e CAmDatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
2298 listSourceClasses.clear();
2300 sqlite3_stmt* query = NULL, *subQuery = NULL;
2301 int eCode = 0, eCode1;
2302 am_SourceClass_s classTemp;
2303 am_ClassProperty_s propertyTemp;
2305 std::string command = "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
2306 std::string command2;
2307 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2309 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2311 classTemp.sourceClassID = sqlite3_column_int(query, 0);
2312 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2314 //read out Properties
2315 command2 = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classTemp.sourceClassID);
2316 MY_SQLITE_PREPARE_V2(mpDatabase, command2.c_str(), -1, &subQuery, NULL)
2318 while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW)
2320 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2321 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2322 classTemp.listClassProperties.push_back(propertyTemp);
2325 if (eCode1 != SQLITE_DONE)
2327 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode1);
2328 MY_SQLITE_FINALIZE(query)
2329 MY_SQLITE_FINALIZE(subQuery)
2330 return (E_DATABASE_ERROR);
2333 MY_SQLITE_FINALIZE(subQuery)
2335 listSourceClasses.push_back(classTemp);
2338 if (eCode != SQLITE_DONE)
2340 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2341 MY_SQLITE_FINALIZE(subQuery)
2342 return (E_DATABASE_ERROR);
2345 MY_SQLITE_FINALIZE(query)
2350 am_Error_e CAmDatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2352 listCrossfaders.clear();
2353 sqlite3_stmt* query = NULL;
2355 am_Crossfader_s tempData;
2356 std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE);
2357 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2359 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2361 tempData.name = std::string((const char*) sqlite3_column_text(query, 0));
2362 tempData.sinkID_A = sqlite3_column_int(query, 1);
2363 tempData.sinkID_B = sqlite3_column_int(query, 2);
2364 tempData.sourceID = sqlite3_column_int(query, 3);
2365 tempData.hotSink = static_cast<am_HotSink_e>(sqlite3_column_int(query, 4));
2366 tempData.crossfaderID = sqlite3_column_int(query, 5);
2367 listCrossfaders.push_back(tempData);
2370 if (eCode != SQLITE_DONE)
2372 logError("DatabaseHandler::getListCrossfaders SQLITE error code:", eCode);
2373 MY_SQLITE_FINALIZE(query)
2374 return (E_DATABASE_ERROR);
2377 MY_SQLITE_FINALIZE(query)
2382 am_Error_e CAmDatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2384 listGateways.clear();
2385 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
2388 am_ConnectionFormat_e tempConnectionFormat;
2390 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2391 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2393 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2395 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2396 temp.sinkID = sqlite3_column_int(query, 1);
2397 temp.sourceID = sqlite3_column_int(query, 2);
2398 temp.domainSinkID = sqlite3_column_int(query, 3);
2399 temp.domainSourceID = sqlite3_column_int(query, 4);
2400 temp.controlDomainID = sqlite3_column_int(query, 5);
2401 temp.gatewayID = sqlite3_column_int(query, 6);
2404 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2405 iter = mListConnectionFormat.find(temp.gatewayID);
2406 if (iter == mListConnectionFormat.end())
2408 logError("DatabaseHandler::getListGateways database error with convertionFormat");
2410 return (E_DATABASE_ERROR);
2412 temp.convertionMatrix = iter->second;
2414 //read out the connectionFormats
2415 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2416 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL)
2417 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
2419 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
2420 temp.listSourceFormats.push_back(tempConnectionFormat);
2423 MY_SQLITE_FINALIZE(qSourceConnectionFormat)
2425 //read out sound properties
2426 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2427 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL)
2428 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
2430 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
2431 temp.listSinkFormats.push_back(tempConnectionFormat);
2434 MY_SQLITE_FINALIZE(qSinkConnectionFormat)
2436 listGateways.push_back(temp);
2437 temp.listSinkFormats.clear();
2438 temp.listSourceFormats.clear();
2441 if (eCode != SQLITE_DONE)
2443 logError("DatabaseHandler::getListGateways SQLITE error code:", eCode);
2444 MY_SQLITE_FINALIZE(query)
2445 return (E_DATABASE_ERROR);
2448 MY_SQLITE_FINALIZE(query)
2453 am_Error_e CAmDatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2455 listSinkClasses.clear();
2457 sqlite3_stmt* query = NULL, *subQuery = NULL;
2459 am_SinkClass_s classTemp;
2460 am_ClassProperty_s propertyTemp;
2462 std::string command = "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2463 std::string command2;
2464 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2466 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2468 classTemp.sinkClassID = sqlite3_column_int(query, 0);
2469 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2471 //read out Properties
2472 command2 = "SELECT classProperty, value FROM SinkClassProperties" + i2s(classTemp.sinkClassID);
2473 MY_SQLITE_PREPARE_V2(mpDatabase, command2.c_str(), -1, &subQuery, NULL)
2475 while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW)
2477 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2478 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2479 classTemp.listClassProperties.push_back(propertyTemp);
2482 if (eCode != SQLITE_DONE)
2484 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2486 return (E_DATABASE_ERROR);
2489 MY_SQLITE_FINALIZE(subQuery)
2491 listSinkClasses.push_back(classTemp);
2494 if (eCode != SQLITE_DONE)
2496 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2497 MY_SQLITE_FINALIZE(query)
2498 return (E_DATABASE_ERROR);
2501 MY_SQLITE_FINALIZE(query)
2506 am_Error_e CAmDatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2508 listConnections.clear();
2509 sqlite3_stmt *query = NULL;
2511 am_MainConnectionType_s temp;
2513 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2514 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2516 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2518 temp.mainConnectionID = sqlite3_column_int(query, 0);
2519 temp.sourceID = sqlite3_column_int(query, 1);
2520 temp.sinkID = sqlite3_column_int(query, 2);
2521 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2522 temp.delay = sqlite3_column_int(query, 4);
2523 listConnections.push_back(temp);
2526 if (eCode != SQLITE_DONE)
2528 logError("DatabaseHandler::getListVisibleMainConnections SQLITE error code:", eCode);
2529 MY_SQLITE_FINALIZE(query)
2530 return (E_DATABASE_ERROR);
2533 MY_SQLITE_FINALIZE(query)
2538 am_Error_e CAmDatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2540 listMainSinks.clear();
2541 sqlite3_stmt* query = NULL;
2545 std::string command = "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2546 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2548 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2550 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2551 temp.sinkID = sqlite3_column_int(query, 1);
2552 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2553 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2554 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 4);
2555 temp.volume = sqlite3_column_int(query, 5);
2556 temp.sinkClassID = sqlite3_column_int(query, 6);
2557 listMainSinks.push_back(temp);
2560 if (eCode != SQLITE_DONE)
2562 logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
2563 MY_SQLITE_FINALIZE(query)
2564 return (E_DATABASE_ERROR);
2567 MY_SQLITE_FINALIZE(query)
2572 am_Error_e CAmDatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2574 listMainSources.clear();
2575 sqlite3_stmt* query = NULL;
2577 am_SourceType_s temp;
2578 std::string command = "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2579 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2581 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2583 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2584 temp.sourceClassID = sqlite3_column_int(query, 1);
2585 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2586 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2587 temp.sourceID = sqlite3_column_int(query, 4);
2589 listMainSources.push_back(temp);
2592 if (eCode != SQLITE_DONE)
2594 logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
2595 MY_SQLITE_FINALIZE(query)
2596 return (E_DATABASE_ERROR);
2599 MY_SQLITE_FINALIZE(query)
2604 am_Error_e CAmDatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2607 if (!existSink(sinkID))
2608 return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences
2609 listSoundProperties.clear();
2611 sqlite3_stmt* query = NULL;
2613 am_MainSoundProperty_s temp;
2614 std::string command = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2615 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2617 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2619 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2620 temp.value = sqlite3_column_int(query, 1);
2621 listSoundProperties.push_back(temp);
2624 if (eCode != SQLITE_DONE)
2626 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode);
2627 MY_SQLITE_FINALIZE(query)
2628 return (E_DATABASE_ERROR);
2631 MY_SQLITE_FINALIZE(query)
2636 am_Error_e CAmDatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2638 assert(sourceID!=0);
2639 if (!existSource(sourceID))
2640 return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences
2641 listSourceProperties.clear();
2643 sqlite3_stmt* query = NULL;
2645 am_MainSoundProperty_s temp;
2646 std::string command = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2647 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2649 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2651 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2652 temp.value = sqlite3_column_int(query, 1);
2653 listSourceProperties.push_back(temp);
2656 if (eCode != SQLITE_DONE)
2658 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode);
2659 MY_SQLITE_FINALIZE(query)
2660 return (E_DATABASE_ERROR);
2663 MY_SQLITE_FINALIZE(query)
2668 am_Error_e CAmDatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2670 listSystemProperties.clear();
2672 sqlite3_stmt* query = NULL;
2674 am_SystemProperty_s temp;
2675 std::string command = "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2676 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2678 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2680 temp.type = (am_SystemPropertyType_e) sqlite3_column_int(query, 0);
2681 temp.value = sqlite3_column_int(query, 1);
2682 listSystemProperties.push_back(temp);
2685 if (eCode != SQLITE_DONE)
2687 logError("DatabaseHandler::getListSystemProperties SQLITE error code:", eCode);
2688 MY_SQLITE_FINALIZE(query)
2689 return (E_DATABASE_ERROR);
2692 MY_SQLITE_FINALIZE(query)
2697 am_Error_e am::CAmDatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2699 listConnectionFormats.clear();
2700 sqlite3_stmt *qConnectionFormat = NULL;
2702 am_ConnectionFormat_e tempConnectionFormat;
2703 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
2704 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
2705 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2707 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2708 listConnectionFormats.push_back(tempConnectionFormat);
2711 MY_SQLITE_FINALIZE(qConnectionFormat)
2716 am_Error_e am::CAmDatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2718 listConnectionFormats.clear();
2719 sqlite3_stmt* qConnectionFormat = NULL;
2721 am_ConnectionFormat_e tempConnectionFormat;
2723 //read out the connectionFormats
2724 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
2725 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
2726 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2728 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2729 listConnectionFormats.push_back(tempConnectionFormat);
2732 MY_SQLITE_FINALIZE(qConnectionFormat)
2737 am_Error_e am::CAmDatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const
2739 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2740 iter = mListConnectionFormat.find(gatewayID);
2741 if (iter == mListConnectionFormat.end())
2743 logError("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat");
2745 return (E_DATABASE_ERROR);
2747 listConnectionFormat = iter->second;
2752 am_Error_e CAmDatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2754 assert(mainConnectionID!=0);
2756 sqlite3_stmt *query = NULL;
2759 std::string command = "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2760 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2762 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2764 delay = sqlite3_column_int(query, 0);
2767 if (eCode != SQLITE_DONE)
2769 logError("DatabaseHandler::getTimingInformation SQLITE error code:", eCode);
2770 MY_SQLITE_FINALIZE(query)
2771 return (E_DATABASE_ERROR);
2774 MY_SQLITE_FINALIZE(query)
2777 return (E_NOT_POSSIBLE);
2782 bool CAmDatabaseHandler::sqQuery(const std::string& query)
2784 sqlite3_stmt* statement;
2786 if ((eCode = sqlite3_exec(mpDatabase, query.c_str(), NULL, &statement, NULL)) != SQLITE_OK)
2788 logError("DatabaseHandler::sqQuery SQL Query failed:", query.c_str(), "error code:", eCode);
2794 bool CAmDatabaseHandler::openDatabase()
2796 if (sqlite3_open_v2(mPath.c_str(), &mpDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
2798 logInfo("DatabaseHandler::openDatabase opened database");
2801 logError("DatabaseHandler::openDatabase failed to open database");
2805 am_Error_e CAmDatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
2807 assert(connectionID!=0);
2809 sqlite3_stmt* query = NULL;
2811 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE delay=? AND mainConnectionID=?";
2812 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2813 MY_SQLITE_BIND_INT(query, 1, delay)
2814 MY_SQLITE_BIND_INT(query, 2, connectionID)
2815 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2817 MY_SQLITE_FINALIZE(query)
2820 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
2821 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2822 MY_SQLITE_BIND_INT(query, 1, delay)
2823 MY_SQLITE_BIND_INT(query, 2, connectionID)
2825 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2827 logError("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:", eCode);
2829 MY_SQLITE_FINALIZE(query)
2830 return (E_DATABASE_ERROR);
2833 if (mpDatabaseObserver)
2834 mpDatabaseObserver->timingInformationChanged(connectionID, delay);
2836 MY_SQLITE_FINALIZE(query)
2840 am_Error_e CAmDatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
2842 assert(connection.connectionID==0);
2843 assert(connection.sinkID!=0);
2844 assert(connection.sourceID!=0);
2845 //connection format is not checked, because it's project specific
2847 sqlite3_stmt* query = NULL;
2849 std::string command = "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
2851 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2852 MY_SQLITE_BIND_INT(query, 1, connection.sinkID)
2853 MY_SQLITE_BIND_INT(query, 2, connection.sourceID)
2854 MY_SQLITE_BIND_INT(query, 3, connection.delay)
2855 MY_SQLITE_BIND_INT(query, 4, connection.connectionFormat)
2856 MY_SQLITE_BIND_INT(query, 5, true)
2858 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2860 logError("DatabaseHandler::enterConnectionDB SQLITE Step error code:", eCode);
2861 MY_SQLITE_FINALIZE(query)
2862 return (E_DATABASE_ERROR);
2865 MY_SQLITE_FINALIZE(query)
2867 connectionID = sqlite3_last_insert_rowid(mpDatabase);
2869 logInfo("DatabaseHandler::enterConnectionDB entered new connection sourceID=", connection.sourceID, "sinkID=", connection.sinkID, "sourceID=", connection.sourceID, "connectionFormat=", connection.connectionFormat, "assigned ID=", connectionID);
2873 am_Error_e CAmDatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
2875 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
2876 assert(!sinkClass.name.empty());
2878 sqlite3_stmt* query = NULL;
2880 std::string command;
2882 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2883 if (sinkClass.sinkClassID == 0 && !mFirstStaticSinkClass)
2885 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
2889 //check if the ID already exists
2890 if (existSinkClass(sinkClass.sinkClassID))
2891 return (E_ALREADY_EXISTS);
2892 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
2895 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2896 MY_SQLITE_BIND_TEXT(query, 1, sinkClass.name.c_str(), sinkClass.name.size(), SQLITE_STATIC)
2898 //if the ID is not created, we add it to the query
2899 if (sinkClass.sinkClassID != 0)
2901 MY_SQLITE_BIND_INT(query, 2, sinkClass.sinkClassID)
2904 //if the first static sink is entered, we need to set it onto the boundary
2905 else if (mFirstStaticSinkClass)
2907 MY_SQLITE_BIND_INT(query, 2, DYNAMIC_ID_BOUNDARY)
2908 mFirstStaticSinkClass = false;
2911 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2913 logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode);
2914 MY_SQLITE_FINALIZE(query)
2915 return (E_DATABASE_ERROR);
2918 MY_SQLITE_FINALIZE(query)
2920 sinkClassID = sqlite3_last_insert_rowid(mpDatabase); //todo:change last_insert implementations for mulithread usage...
2922 //now we need to create the additional tables:
2923 command = "CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2924 if (!this->sqQuery(command))
2925 return (E_DATABASE_ERROR);
2927 //fill ConnectionFormats
2928 command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
2929 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2930 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
2931 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
2933 MY_SQLITE_BIND_INT(query, 1, Iterator->classProperty)
2934 MY_SQLITE_BIND_INT(query, 2, Iterator->value)
2935 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2937 logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode);
2938 MY_SQLITE_FINALIZE(query)
2939 return (E_DATABASE_ERROR);
2941 MY_SQLITE_RESET(query)
2944 MY_SQLITE_FINALIZE(query)
2946 logInfo("DatabaseHandler::enterSinkClassDB entered new sinkClass");
2947 if (mpDatabaseObserver)
2948 mpDatabaseObserver->numberOfSinkClassesChanged();
2952 am_Error_e CAmDatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
2954 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
2955 assert(!sourceClass.name.empty());
2957 sqlite3_stmt* query = NULL;
2959 std::string command;
2961 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2962 if (sourceClass.sourceClassID == 0 && !mFirstStaticSourceClass)
2964 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
2968 //check if the ID already exists
2969 if (existSourceClass(sourceClass.sourceClassID))
2970 return (E_ALREADY_EXISTS);
2971 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
2974 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2975 MY_SQLITE_BIND_TEXT(query, 1, sourceClass.name.c_str(), sourceClass.name.size(), SQLITE_STATIC)
2977 //if the ID is not created, we add it to the query
2978 if (sourceClass.sourceClassID != 0)
2980 MY_SQLITE_BIND_INT(query, 2, sourceClass.sourceClassID)
2983 //if the first static sink is entered, we need to set it onto the boundary
2984 else if (mFirstStaticSourceClass)
2986 MY_SQLITE_BIND_INT(query, 2, DYNAMIC_ID_BOUNDARY)
2987 mFirstStaticSourceClass = false;
2990 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2992 logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode);
2993 MY_SQLITE_FINALIZE(query)
2994 return (E_DATABASE_ERROR);
2997 MY_SQLITE_FINALIZE(query)
2999 sourceClassID = sqlite3_last_insert_rowid(mpDatabase); //todo:change last_insert implementations for mulithread usage...
3001 //now we need to create the additional tables:
3002 command = "CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
3003 assert(sqQuery(command));
3005 //fill ConnectionFormats
3006 command = "INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
3007 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3008 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
3009 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
3011 MY_SQLITE_BIND_INT(query, 1, Iterator->classProperty)
3012 MY_SQLITE_BIND_INT(query, 2, Iterator->value)
3013 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3015 logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode);
3016 MY_SQLITE_FINALIZE(query)
3017 return (E_DATABASE_ERROR);
3019 MY_SQLITE_RESET(query)
3022 MY_SQLITE_FINALIZE(query)
3024 logInfo("DatabaseHandler::enterSourceClassDB entered new sourceClass");
3026 if (mpDatabaseObserver)
3027 mpDatabaseObserver->numberOfSourceClassesChanged();
3031 am_Error_e CAmDatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
3033 assert(!listSystemProperties.empty());
3034 sqlite3_stmt* query = NULL;
3036 std::vector<am_SystemProperty_s>::const_iterator listIterator = listSystemProperties.begin();
3037 std::string command = "DELETE FROM " + std::string(SYSTEM_TABLE);
3038 if (!this->sqQuery(command))
3039 return (E_DATABASE_ERROR);
3041 command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
3043 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3044 for (; listIterator < listSystemProperties.end(); ++listIterator)
3046 MY_SQLITE_BIND_INT(query, 1, listIterator->type)
3047 MY_SQLITE_BIND_INT(query, 2, listIterator->value)
3049 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3051 logError("DatabaseHandler::enterSystemProperties SQLITE Step error code:", eCode);
3052 MY_SQLITE_FINALIZE(query)
3053 return (E_DATABASE_ERROR);
3056 MY_SQLITE_RESET(query)
3059 MY_SQLITE_FINALIZE(query)
3061 logInfo("DatabaseHandler::enterSystemProperties entered system properties");
3066 * checks for a certain mainConnection
3067 * @param mainConnectionID to be checked for
3068 * @return true if it exists
3070 bool CAmDatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
3072 sqlite3_stmt* query = NULL;
3073 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
3075 bool returnVal = true;
3076 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3077 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3079 else if (eCode != SQLITE_ROW)
3082 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3085 MY_SQLITE_FINALIZE_BOOL(query)
3090 * checks for a certain Source
3091 * @param sourceID to be checked for
3092 * @return true if it exists
3094 bool CAmDatabaseHandler::existSource(const am_sourceID_t sourceID) const
3096 sqlite3_stmt* query = NULL;
3097 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
3099 bool returnVal = true;
3100 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3101 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3103 else if (eCode != SQLITE_ROW)
3106 logError("DatabaseHandler::existSource database error!:", eCode);
3108 MY_SQLITE_FINALIZE_BOOL(query)
3113 * checks if a source name or ID exists
3114 * @param sourceID the sourceID
3115 * @param name the name
3116 * @return true if it exits
3118 bool CAmDatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
3120 sqlite3_stmt* query = NULL;
3121 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
3123 bool returnVal = true;
3124 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3126 if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC)))
3128 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode);
3132 if ((eCode = sqlite3_bind_int(query, 2, sourceID)))
3134 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3138 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3140 else if (eCode != SQLITE_ROW)
3143 logError("DatabaseHandler::existSource database error!:", eCode);
3145 MY_SQLITE_FINALIZE_BOOL(query)
3150 * checks if a name exits
3151 * @param name the name
3152 * @return true if it exits
3154 bool CAmDatabaseHandler::existSourceName(const std::string & name) const
3156 sqlite3_stmt* query = NULL;
3157 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
3159 bool returnVal = true;
3160 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3162 if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC)))
3164 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode);
3168 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3170 else if (eCode != SQLITE_ROW)
3173 logError("DatabaseHandler::existSource database error!:", eCode);
3176 MY_SQLITE_FINALIZE_BOOL(query)
3181 * checks for a certain Sink
3182 * @param sinkID to be checked for
3183 * @return true if it exists
3185 bool CAmDatabaseHandler::existSink(const am_sinkID_t sinkID) const
3187 sqlite3_stmt* query = NULL;
3188 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3190 bool returnVal = true;
3191 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3193 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3195 else if (eCode != SQLITE_ROW)
3198 logError("DatabaseHandler::existSink database error!:", eCode);
3200 MY_SQLITE_FINALIZE_BOOL(query)
3205 * checks if a sink with the ID or the name exists
3206 * @param sinkID the ID
3207 * @param name the name
3208 * @return true if it exists.
3210 bool CAmDatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
3212 sqlite3_stmt* query = NULL;
3213 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
3215 bool returnVal = true;
3216 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3218 if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC)))
3220 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode);
3224 if ((eCode = sqlite3_bind_int(query, 2, sinkID)))
3226 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3230 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3232 else if (eCode != SQLITE_ROW)
3235 logError("DatabaseHandler::existSink database error!:", eCode);
3238 MY_SQLITE_FINALIZE_BOOL(query)
3243 * checks if a sink with the name exists
3244 * @param name the name
3245 * @return true if it exists
3247 bool CAmDatabaseHandler::existSinkName(const std::string & name) const
3249 sqlite3_stmt* query = NULL;
3250 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
3252 bool returnVal = true;
3253 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3255 if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC)))
3257 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode);
3261 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3263 else if (eCode != SQLITE_ROW)
3266 logError("DatabaseHandler::existSink database error!:", eCode);
3269 MY_SQLITE_FINALIZE_BOOL(query)
3274 * checks for a certain domain
3275 * @param domainID to be checked for
3276 * @return true if it exists
3278 bool CAmDatabaseHandler::existDomain(const am_domainID_t domainID) const
3280 sqlite3_stmt* query = NULL;
3281 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
3283 bool returnVal = true;
3284 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3286 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3288 else if (eCode != SQLITE_ROW)
3291 logError("DatabaseHandler::existDomain database error!:", eCode);
3294 MY_SQLITE_FINALIZE_BOOL(query)
3299 * checks for certain gateway
3300 * @param gatewayID to be checked for
3301 * @return true if it exists
3303 bool CAmDatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
3305 sqlite3_stmt* query = NULL;
3306 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
3308 bool returnVal = true;
3309 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3311 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3313 else if (eCode != SQLITE_ROW)
3316 logError("DatabaseHandler::existGateway database error!:", eCode);
3319 MY_SQLITE_FINALIZE_BOOL(query)
3323 am_Error_e CAmDatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
3325 assert(sourceID!=0);
3327 sqlite3_stmt* query = NULL;
3328 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3330 am_Error_e returnVal = E_DATABASE_ERROR;
3331 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3332 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3334 domainID = sqlite3_column_int(query, 0);
3339 logError("DatabaseHandler::getDomainOfSource database error!:", eCode);
3342 MY_SQLITE_FINALIZE(query)
3346 am_Error_e am::CAmDatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const
3350 sqlite3_stmt* query = NULL;
3351 std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3353 am_Error_e returnVal = E_DATABASE_ERROR;
3354 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3356 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3358 domainID = sqlite3_column_int(query, 0);
3363 logError("DatabaseHandler::getDomainOfSink database error!:", eCode);
3366 MY_SQLITE_FINALIZE(query)
3371 * checks for certain SinkClass
3372 * @param sinkClassID
3373 * @return true if it exists
3375 bool CAmDatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3377 sqlite3_stmt* query = NULL;
3378 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
3380 bool returnVal = true;
3381 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3382 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3384 else if (eCode != SQLITE_ROW)
3387 logError("DatabaseHandler::existSinkClass database error!:", eCode);
3390 MY_SQLITE_FINALIZE_BOOL(query)
3395 * checks for certain sourceClass
3396 * @param sourceClassID
3397 * @return true if it exists
3399 bool CAmDatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3401 sqlite3_stmt* query = NULL;
3402 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
3404 bool returnVal = true;
3405 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3407 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3409 else if (eCode != SQLITE_ROW)
3412 logError("DatabaseHandler::existSinkClass database error!:", eCode);
3415 MY_SQLITE_FINALIZE_BOOL(query)
3419 am_Error_e CAmDatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3421 assert(connectionID!=0);
3423 sqlite3_stmt *query = NULL, *queryMainConnectionSubIDs = NULL;
3424 int eCode = 0, eCode1 = 0;
3425 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3427 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3428 MY_SQLITE_BIND_INT(query, 1, delay)
3429 MY_SQLITE_BIND_INT(query, 2, connectionID)
3431 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3433 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:", eCode);
3434 MY_SQLITE_FINALIZE(query)
3435 return (E_DATABASE_ERROR);
3438 MY_SQLITE_FINALIZE(query)
3440 //now we need to find all mainConnections that use the changed connection and update their timing
3442 int tempMainConnectionID;
3443 //first get all route tables for all mainconnections
3444 command = "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'";
3445 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3447 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3449 //now check if the connection ID is in this table
3450 std::string tablename = std::string((const char*) sqlite3_column_text(query, 0));
3451 std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID);
3452 MY_SQLITE_PREPARE_V2(mpDatabase, command2.c_str(), -1, &queryMainConnectionSubIDs, NULL)
3453 if ((eCode1 = sqlite3_step(queryMainConnectionSubIDs)) == SQLITE_ROW)
3455 //if the connection ID is in, recalculate the mainconnection delay
3456 std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID;
3457 changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID), tempMainConnectionID);
3459 else if (eCode1 != SQLITE_DONE)
3461 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode1);
3463 return (E_DATABASE_ERROR);
3465 MY_SQLITE_FINALIZE(queryMainConnectionSubIDs)
3468 if (eCode != SQLITE_DONE)
3470 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode);
3471 MY_SQLITE_FINALIZE(query)
3472 return (E_DATABASE_ERROR);
3475 MY_SQLITE_FINALIZE(query)
3480 am_Error_e CAmDatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3482 assert(connectionID!=0);
3484 sqlite3_stmt *query = NULL;
3486 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3488 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3489 MY_SQLITE_BIND_INT(query, 1, connectionID)
3491 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3493 logError("DatabaseHandler::changeConnectionFinal SQLITE Step error code:", eCode);
3494 MY_SQLITE_FINALIZE(query)
3495 return (E_DATABASE_ERROR);
3498 MY_SQLITE_FINALIZE(query)
3502 am_timeSync_t CAmDatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3504 assert(mainConnectionID!=0);
3505 sqlite3_stmt* query = NULL;
3506 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";
3508 am_timeSync_t delay = 0;
3509 am_timeSync_t min = 0;
3510 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3511 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3513 delay = sqlite3_column_int(query, 0);
3514 min = sqlite3_column_int(query, 1);
3516 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3518 logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:", eCode);
3519 MY_SQLITE_FINALIZE(query)
3520 return (E_DATABASE_ERROR);
3523 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3525 logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:", eCode);
3526 MY_SQLITE_FINALIZE(query)
3527 return (E_DATABASE_ERROR);
3536 * registers the Observer at the Database
3537 * @param iObserver pointer to the observer
3539 void CAmDatabaseHandler::registerObserver(CAmDatabaseObserver *iObserver)
3541 assert(iObserver!=NULL);
3542 mpDatabaseObserver = iObserver;
3546 * gives information about the visibility of a source
3547 * @param sourceID the sourceID
3548 * @return true if source is visible
3550 bool CAmDatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3552 assert(sourceID!=0);
3553 sqlite3_stmt* query = NULL;
3554 std::string command = "SELECT visible FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3556 bool returnVal = false;
3557 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3559 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3561 returnVal = (bool) sqlite3_column_int(query, 0);
3563 else if (eCode != SQLITE_ROW)
3566 logError("DatabaseHandler::sourceVisible database error!:", eCode);
3569 MY_SQLITE_FINALIZE_BOOL(query)
3574 * gives information about the visibility of a sink
3575 * @param sinkID the sinkID
3576 * @return true if source is visible
3578 bool CAmDatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3580 sqlite3_stmt* query = NULL;
3581 std::string command = "SELECT visible FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3583 bool returnVal = false;
3584 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3585 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3587 returnVal = sqlite3_column_int(query, 0);
3589 else if (eCode != SQLITE_ROW)
3592 logError("DatabaseHandler::sinkVisible database error!:", eCode);
3595 MY_SQLITE_FINALIZE_BOOL(query)
3600 * checks if a connection already exists.
3601 * Only takes sink, source and format information for search!
3602 * @param connection the connection to be checked
3603 * @return true if connections exists
3605 bool CAmDatabaseHandler::existConnection(const am_Connection_s connection)
3607 sqlite3_stmt* query = NULL;
3608 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3610 bool returnVal = true;
3611 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3613 if ((eCode = sqlite3_bind_int(query, 1, connection.sinkID)))
3615 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3619 if ((eCode = sqlite3_bind_int(query, 2, connection.sourceID)))
3621 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3625 if ((eCode = sqlite3_bind_int(query, 3, connection.connectionFormat)))
3627 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3631 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3633 else if (eCode != SQLITE_ROW)
3636 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3639 MY_SQLITE_FINALIZE_BOOL(query)
3644 * checks if a connection with the given ID exists
3645 * @param connectionID
3646 * @return true if connection exits
3648 bool CAmDatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3650 sqlite3_stmt* query = NULL;
3651 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3653 bool returnVal = true;
3654 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3656 if ((eCode = sqlite3_bind_int(query, 1, connectionID)))
3658 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3662 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3664 else if (eCode != SQLITE_ROW)
3667 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3670 MY_SQLITE_FINALIZE_BOOL(query)
3675 * checks if a CrossFader exists
3676 * @param crossfaderID the ID of the crossfader to be checked
3677 * @return true if exists
3679 bool CAmDatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3681 sqlite3_stmt* query = NULL;
3682 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3684 bool returnVal = true;
3685 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3687 if ((eCode = sqlite3_bind_int(query, 1, crossfaderID)))
3689 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3693 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3695 else if (eCode != SQLITE_ROW)
3698 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3701 MY_SQLITE_FINALIZE_BOOL(query)
3705 am_Error_e CAmDatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3707 assert(sourceID!=0);
3708 sqlite3_stmt* query = NULL;
3709 sourceState = SS_UNKNNOWN;
3710 std::string command = "SELECT sourceState FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3712 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3713 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3715 sourceState = (am_SourceState_e) sqlite3_column_int(query, 0);
3717 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3719 logError("DatabaseHandler::getSoureState database error!:", eCode);
3721 MY_SQLITE_FINALIZE(query)
3725 am_Error_e CAmDatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3727 assert(sourceID!=0);
3728 assert(sourceState>=SS_UNKNNOWN && sourceState<=SS_MAX);
3729 sqlite3_stmt* query = NULL;
3730 std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID);
3732 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3733 MY_SQLITE_BIND_INT(query, 1, sourceState)
3734 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3736 logError("DatabaseHandler::changeSourceState SQLITE Step error code:", eCode);
3737 MY_SQLITE_FINALIZE(query)
3738 return (E_DATABASE_ERROR);
3741 MY_SQLITE_FINALIZE(query)
3745 am_Error_e CAmDatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3748 sqlite3_stmt* query = NULL;
3750 std::string command = "SELECT volume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3752 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3753 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3755 volume = sqlite3_column_int(query, 0);
3757 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3759 logError("DatabaseHandler::getSinkVolume database error!:", eCode);
3761 MY_SQLITE_FINALIZE(query)
3765 am_Error_e CAmDatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
3767 assert(sourceID!=0);
3768 sqlite3_stmt* query = NULL;
3770 std::string command = "SELECT volume FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3772 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3773 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3775 volume = sqlite3_column_int(query, 0);
3777 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3779 logError("DatabaseHandler::getSourceVolume database error!:", eCode);
3781 MY_SQLITE_FINALIZE(query)
3785 am_Error_e CAmDatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3788 if (!existSink(sinkID))
3789 return (E_DATABASE_ERROR); // todo: here we could change to non existent, but not shown in sequences
3791 sqlite3_stmt* query = NULL;
3793 std::string command = "SELECT value FROM SinkSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType);
3794 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3796 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3798 value = sqlite3_column_int(query, 0);
3801 if (eCode != SQLITE_DONE)
3803 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode);
3804 MY_SQLITE_FINALIZE(query)
3805 return (E_DATABASE_ERROR);
3808 MY_SQLITE_FINALIZE(query)
3813 am_Error_e CAmDatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3815 assert(sourceID!=0);
3816 if (!existSource(sourceID))
3817 return (E_DATABASE_ERROR); // todo: here we could change to non existent, but not shown in sequences
3819 sqlite3_stmt* query = NULL;
3821 std::string command = "SELECT value FROM SourceSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType);
3822 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3824 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3826 value = sqlite3_column_int(query, 0);
3829 if (eCode != SQLITE_DONE)
3831 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode);
3832 MY_SQLITE_FINALIZE(query)
3833 return (E_DATABASE_ERROR);
3836 MY_SQLITE_FINALIZE(query)
3841 am_Error_e CAmDatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
3843 assert(domainID!=0);
3844 sqlite3_stmt* query = NULL;
3846 std::string command = "SELECT domainState FROM " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
3848 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3849 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3851 state = (am_DomainState_e) sqlite3_column_int(query, 0);
3853 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3855 logError("DatabaseHandler::getDomainState database error!:", eCode);
3857 MY_SQLITE_FINALIZE(query)
3862 am_Error_e CAmDatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
3864 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3865 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
3866 int eCode = 0, eCode1 = 0;
3867 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3868 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
3869 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3871 domainID = sqlite3_column_int(query, 0);
3873 else if (eCode != SQLITE_DONE)
3875 logError("DatabaseHandler::peekDomain database error!:", eCode);
3876 MY_SQLITE_FINALIZE(query)
3877 return (E_DATABASE_ERROR);
3881 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
3882 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL)
3883 MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC)
3884 MY_SQLITE_BIND_INT(queryInsert, 2, 1)
3886 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3888 logError("DatabaseHandler::peekDomain SQLITE Step error code:", eCode1);
3889 MY_SQLITE_FINALIZE(queryInsert)
3890 MY_SQLITE_FINALIZE(query)
3891 return (E_DATABASE_ERROR);
3894 MY_SQLITE_FINALIZE(queryInsert)
3896 domainID = sqlite3_last_insert_rowid(mpDatabase);
3898 MY_SQLITE_FINALIZE(query)
3903 am_Error_e CAmDatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
3905 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3906 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
3907 int eCode = 0, eCode1 = 0;
3908 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3909 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
3910 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3912 sinkID = sqlite3_column_int(query, 0);
3914 else if (eCode != SQLITE_DONE)
3916 logError("DatabaseHandler::peekSink database error!:", eCode);
3917 MY_SQLITE_FINALIZE(query)
3918 return (E_DATABASE_ERROR);
3922 if (mFirstStaticSink)
3924 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3925 mFirstStaticSink = false;
3929 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
3931 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL)
3932 MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC)
3933 MY_SQLITE_BIND_INT(queryInsert, 2, 1)
3935 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3937 logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1);
3938 MY_SQLITE_FINALIZE(queryInsert)
3939 MY_SQLITE_FINALIZE(query)
3940 return (E_DATABASE_ERROR);
3943 MY_SQLITE_FINALIZE(queryInsert)
3945 sinkID = sqlite3_last_insert_rowid(mpDatabase);
3947 MY_SQLITE_FINALIZE(query)
3951 am_Error_e CAmDatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
3953 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3954 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
3955 int eCode = 0, eCode1 = 0;
3956 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3957 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
3958 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3960 sourceID = sqlite3_column_int(query, 0);
3962 else if (eCode != SQLITE_DONE)
3964 logError("DatabaseHandler::peekSink database error!:", eCode);
3965 MY_SQLITE_FINALIZE(query)
3966 return (E_DATABASE_ERROR);
3970 if (mFirstStaticSource)
3972 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3973 mFirstStaticSource = false;
3977 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
3979 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL)
3980 MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC)
3981 MY_SQLITE_BIND_INT(queryInsert, 2, 1)
3983 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3985 logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1);
3986 MY_SQLITE_FINALIZE(queryInsert)
3987 MY_SQLITE_FINALIZE(query)
3988 return (E_DATABASE_ERROR);
3991 MY_SQLITE_FINALIZE(queryInsert)
3992 sourceID = sqlite3_last_insert_rowid(mpDatabase);
3995 MY_SQLITE_FINALIZE(query)
3999 am_Error_e CAmDatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
4003 sqlite3_stmt* query = NULL;
4005 std::string command;
4007 if (!existSink(sinkID))
4009 return (E_NON_EXISTENT);
4011 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
4012 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4013 MY_SQLITE_BIND_INT(query, 1, volume)
4014 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4016 logError("DatabaseHandler::changeSinkVolume SQLITE Step error code:", eCode);
4017 MY_SQLITE_FINALIZE(query)
4018 return (E_DATABASE_ERROR);
4021 MY_SQLITE_FINALIZE(query)
4022 logInfo("DatabaseHandler::changeSinkVolume changed volume of sink:", sinkID, "to:", volume);
4026 am_Error_e CAmDatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
4028 assert(sourceID!=0);
4030 sqlite3_stmt* query = NULL;
4032 std::string command;
4034 if (!existSource(sourceID))
4036 return (E_NON_EXISTENT);
4038 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
4039 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4040 MY_SQLITE_BIND_INT(query, 1, volume)
4041 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4043 logError("DatabaseHandler::changeSourceVolume SQLITE Step error code:", eCode);
4044 MY_SQLITE_FINALIZE(query)
4045 return (E_DATABASE_ERROR);
4048 MY_SQLITE_FINALIZE(query)
4049 logInfo("DatabaseHandler::changeSourceVolume changed volume of source=:", sourceID, "to:", volume);
4054 am_Error_e CAmDatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
4056 assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX);
4057 assert(sourceID!=0);
4059 sqlite3_stmt* query = NULL;
4061 std::string command;
4063 if (!existSource(sourceID))
4065 return (E_NON_EXISTENT);
4067 command = "UPDATE SourceSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
4068 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4069 MY_SQLITE_BIND_INT(query, 1, soundProperty.value)
4070 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4072 logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:", eCode);
4073 MY_SQLITE_FINALIZE(query)
4074 return (E_DATABASE_ERROR);
4077 MY_SQLITE_FINALIZE(query)
4078 logInfo("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value);
4082 am_Error_e CAmDatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
4084 assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX);
4087 sqlite3_stmt* query = NULL;
4089 std::string command;
4091 if (!existSink(sinkID))
4093 return (E_NON_EXISTENT);
4095 command = "UPDATE SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
4096 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4097 MY_SQLITE_BIND_INT(query, 1, soundProperty.value)
4098 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4100 logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:", eCode);
4101 MY_SQLITE_FINALIZE(query)
4102 return (E_DATABASE_ERROR);
4106 MY_SQLITE_FINALIZE(query)
4107 logInfo("DatabaseHandler::changeSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value);
4111 am_Error_e CAmDatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
4113 assert(crossfaderID!=0);
4114 assert(hotsink>=HS_UNKNOWN && hotsink>=HS_MAX);
4116 sqlite3_stmt* query = NULL;
4118 std::string command;
4120 if (!existcrossFader(crossfaderID))
4122 return (E_NON_EXISTENT);
4124 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
4125 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4126 MY_SQLITE_BIND_INT(query, 1, hotsink)
4127 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4129 logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:", eCode);
4130 MY_SQLITE_FINALIZE(query)
4131 return (E_DATABASE_ERROR);
4133 MY_SQLITE_FINALIZE(query)
4134 logInfo("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader=", crossfaderID, "to:", hotsink);
4138 am_Error_e CAmDatabaseHandler::getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree)
4140 sqlite3_stmt* query = NULL;
4143 std::string command;
4144 am_domainID_t rootID = tree.returnRootDomainID();
4145 CAmRoutingTreeItem *parent = tree.returnRootItem();
4149 command = "SELECT g.domainSourceID,g.gatewayID FROM " + std::string(GATEWAY_TABLE) + " g WHERE domainSinkID=? AND NOT EXISTS (SELECT NULL FROM " + std::string(CONNECTION_TABLE) + " c WHERE c.sinkID = g.sinkID OR c.sourceID = g.sourceID )";
4153 command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=?";
4160 parent = flatTree.at(i - 1);
4161 rootID = parent->returnDomainID();
4163 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4164 MY_SQLITE_BIND_INT(query, 1, rootID)
4166 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4168 flatTree.push_back(tree.insertItem(sqlite3_column_int(query, 0), sqlite3_column_int(query, 1), parent));
4171 if (eCode != SQLITE_DONE)
4173 logError("DatabaseHandler::getRoutingTree SQLITE error code:", eCode);
4174 MY_SQLITE_FINALIZE(query)
4175 return (E_DATABASE_ERROR);
4178 MY_SQLITE_FINALIZE(query)
4180 } while (flatTree.size() > (i - 1));
4185 am_Error_e am::CAmDatabaseHandler::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID)
4188 return (E_NON_EXISTENT);
4190 am_Error_e returnVal = E_NON_EXISTENT;
4191 sqlite3_stmt* query = NULL;
4193 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE name=?";
4194 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4195 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
4197 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4199 sinkClassID = sqlite3_column_int(query, 0);
4202 else if (eCode != SQLITE_DONE)
4205 logError("DatabaseHandler::peekSinkClassID SQLITE error code:", eCode);
4206 MY_SQLITE_FINALIZE(query)
4207 returnVal = E_DATABASE_ERROR;
4210 MY_SQLITE_FINALIZE(query)
4214 am_Error_e am::CAmDatabaseHandler::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID)
4217 return (E_NON_EXISTENT);
4219 am_Error_e returnVal = E_NON_EXISTENT;
4220 sqlite3_stmt* query = NULL;
4222 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE name=?";
4223 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4224 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
4226 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4228 sourceClassID = sqlite3_column_int(query, 0);
4231 else if (eCode != SQLITE_DONE)
4234 logError("DatabaseHandler::peekSourceClassID SQLITE error code:", eCode);
4235 MY_SQLITE_FINALIZE(query)
4236 returnVal = E_DATABASE_ERROR;
4239 MY_SQLITE_FINALIZE(query)
4243 void CAmDatabaseHandler::createTables()
4245 for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++)
4247 if (!sqQuery("CREATE TABLE " + databaseTables[i]))
4248 throw std::runtime_error("CAmDatabaseHandler Could not create tables!");