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"
29 #include "CAmDatabaseObserver.h"
30 #include "CAmRouter.h"
31 #include "shared/CAmDltWrapper.h"
37 * Macro to handle SQLITE errors on prepare
39 #define MY_SQLITE_PREPARE_V2(db,zSql,nByte,ppStmt,pzTail) \
40 if ((eCode = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail))) \
42 logError("CAmDatabaseHandler::my_sqlite_prepare_v2 on Command",zSql,"failed with errorCode:", eCode); \
43 return (E_DATABASE_ERROR); \
46 #define MY_SQLITE_PREPARE_V2_BOOL(db,zSql,nByte,ppStmt,pzTail) \
47 if ((eCode = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail))) \
49 logError("CAmDatabaseHandler::my_sqlite_prepare_v2_bool on Command",zSql,"failed with errorCode:", eCode); \
54 * Macro to handle SQLITE errors bind text
56 #define MY_SQLITE_BIND_TEXT(query,index,text,size,static_) \
57 if ((eCode = sqlite3_bind_text(query, index, text, size, static_))) \
59 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode); \
60 return (E_DATABASE_ERROR); \
64 * Macro to handle SQLITE errors on bind int
66 #define MY_SQLITE_BIND_INT(query, index, data) \
67 if((eCode = sqlite3_bind_int(query, index, data))) \
69 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); \
70 return (E_DATABASE_ERROR); \
74 * Macro to handle SQLITE errors on reset
76 #define MY_SQLITE_RESET(query) \
77 if((eCode = sqlite3_reset(query))) \
79 logError("CAmDatabaseHandler::sqlite3_reset failed with errorCode:", eCode); \
80 return (E_DATABASE_ERROR); \
84 * Macro to handle SQLITE finalize
86 #define MY_SQLITE_FINALIZE(query) \
87 if((eCode = sqlite3_finalize(query))) \
89 logError("CAmDatabaseHandler::sqlite3_finalize failed with errorCode:", eCode); \
90 return (E_DATABASE_ERROR); \
93 #define MY_SQLITE_FINALIZE_BOOL(query) \
94 if((eCode = sqlite3_finalize(query))) \
96 logError("CAmDatabaseHandler::sqlite3_finalize failed with errorCode:", eCode); \
100 #define DOMAIN_TABLE "Domains" //!< domain table
101 #define SOURCE_CLASS_TABLE "SourceClasses" //!< source class table
102 #define SINK_CLASS_TABLE "SinkClasses" //!< sink class table
103 #define SOURCE_TABLE "Sources" //!< source table
104 #define SINK_TABLE "Sinks" //!< sink table
105 #define GATEWAY_TABLE "Gateways" //!< gateway table
106 #define CROSSFADER_TABLE "Crossfaders" //!< crossfader table
107 #define CONNECTION_TABLE "Connections" //!< connection table
108 #define MAINCONNECTION_TABLE "MainConnections" //!< main connection table
109 #define SYSTEM_TABLE "SystemProperties" //!< system properties table
111 * table that holds table informations
113 const std::string databaseTables[] =
114 { " 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);", //
115 " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", //
116 " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", //
117 " 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);", //
118 " 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);", //
119 " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER);", //
120 " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);", //
121 " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);", //
122 " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);", //
123 " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);" };
126 * template to converts T to std::string
131 inline std::string i2s(T const& x)
133 std::ostringstream o;
138 CAmDatabaseHandler::CAmDatabaseHandler(std::string databasePath) :
140 mPath(databasePath), //
141 mpDatabaseObserver(NULL), //
142 mFirstStaticSink(true), //
143 mFirstStaticSource(true), //
144 mFirstStaticGateway(true), //
145 mFirstStaticSinkClass(true), //
146 mFirstStaticSourceClass(true), //
147 mFirstStaticCrossfader(true), //
148 mListConnectionFormat()
151 std::ifstream infile(mPath.c_str());
155 if(remove(mPath.c_str())==0)
157 logError("DatabaseHandler::DatabaseHandler Knocked down database failed !");
159 logInfo("DatabaseHandler::DatabaseHandler Knocked down database");
162 bool dbOpen = openDatabase();
165 logInfo("DatabaseHandler::DatabaseHandler problems opening the database!");
171 CAmDatabaseHandler::~CAmDatabaseHandler()
173 logInfo("Closed Database");
174 sqlite3_close(mpDatabase);
177 am_Error_e CAmDatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
179 assert(domainData.domainID==0);
180 assert(!domainData.name.empty());
181 assert(!domainData.busname.empty());
182 assert(domainData.state>=DS_UNKNOWN && domainData.state<=DS_MAX);
184 //first check for a reserved domain
185 sqlite3_stmt* query = NULL;
188 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
189 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
190 MY_SQLITE_BIND_TEXT(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC)
191 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
193 domainID = sqlite3_column_int(query, 0);
194 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" + i2s(sqlite3_column_int(query, 0));
196 else if (eCode == SQLITE_DONE)
199 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)";
203 logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode);
204 return (E_DATABASE_ERROR);
207 MY_SQLITE_FINALIZE(query)
209 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
210 MY_SQLITE_BIND_TEXT(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC)
211 MY_SQLITE_BIND_TEXT(query, 2, domainData.busname.c_str(), domainData.busname.size(), SQLITE_STATIC)
212 MY_SQLITE_BIND_TEXT(query, 3, domainData.nodename.c_str(), domainData.nodename.size(), SQLITE_STATIC)
213 MY_SQLITE_BIND_INT(query, 4, domainData.early)
214 MY_SQLITE_BIND_INT(query, 5, domainData.complete)
215 MY_SQLITE_BIND_INT(query, 6, domainData.state)
216 MY_SQLITE_BIND_INT(query, 7, 0)
218 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
220 logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode);
221 MY_SQLITE_FINALIZE(query)
222 return (E_DATABASE_ERROR);
224 MY_SQLITE_FINALIZE(query)
227 domainID = sqlite3_last_insert_rowid(mpDatabase);
228 logInfo("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID);
230 am_Domain_s domain = domainData;
231 domain.domainID = domainID;
232 if (mpDatabaseObserver)
233 mpDatabaseObserver->newDomain(domain);
238 am_Error_e CAmDatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
240 assert(mainConnectionData.mainConnectionID==0);
241 assert(mainConnectionData.connectionState>=CS_UNKNOWN && mainConnectionData.connectionState<=CS_MAX);
242 assert(mainConnectionData.sinkID!=0);
243 assert(mainConnectionData.sourceID!=0);
245 sqlite3_stmt* query = NULL;
248 std::string command = "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)";
249 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
250 MY_SQLITE_BIND_INT(query, 1, mainConnectionData.sourceID)
251 MY_SQLITE_BIND_INT(query, 2, mainConnectionData.sinkID)
252 MY_SQLITE_BIND_INT(query, 3, mainConnectionData.connectionState)
254 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
256 logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode);
257 MY_SQLITE_FINALIZE(query)
258 return (E_DATABASE_ERROR);
261 MY_SQLITE_FINALIZE(query)
263 connectionID = sqlite3_last_insert_rowid(mpDatabase);
265 //now check the connectionTable for all connections in the route. IF connectionID exist
266 command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?");
267 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
268 std::vector<am_connectionID_t>::const_iterator elementIterator = mainConnectionData.listConnectionID.begin();
269 for (; elementIterator < mainConnectionData.listConnectionID.end(); ++elementIterator)
271 MY_SQLITE_BIND_INT(query, 1, *elementIterator)
273 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
275 int16_t temp_delay = sqlite3_column_int(query, 1);
276 if (temp_delay != -1 && delay != -1)
283 logError("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection: ", eCode);
284 MY_SQLITE_FINALIZE(query)
285 return (E_DATABASE_ERROR);
287 MY_SQLITE_RESET(query)
289 MY_SQLITE_FINALIZE(query)
291 //now we create a table with references to the connections;
292 command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
293 if (!this->sqQuery(command))
294 return (E_DATABASE_ERROR);
296 command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
297 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
298 std::vector<am_connectionID_t>::const_iterator listConnectionIterator(mainConnectionData.listConnectionID.begin());
299 for (; listConnectionIterator < mainConnectionData.listConnectionID.end(); ++listConnectionIterator)
301 MY_SQLITE_BIND_INT(query, 1, *listConnectionIterator)
302 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
304 logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode);
305 MY_SQLITE_FINALIZE(query)
306 return (E_DATABASE_ERROR);
308 MY_SQLITE_RESET(query)
311 MY_SQLITE_FINALIZE(query)
312 logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID);
314 if (mpDatabaseObserver)
316 am_MainConnectionType_s mainConnection;
317 mainConnection.mainConnectionID = connectionID;
318 mainConnection.connectionState = mainConnectionData.connectionState;
319 mainConnection.delay = delay;
320 mainConnection.sinkID = mainConnectionData.sinkID;
321 mainConnection.sourceID = mainConnectionData.sourceID;
322 mpDatabaseObserver->newMainConnection(mainConnection);
323 mpDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState);
326 //finally, we update the delay value for the maintable
329 return (changeDelayMainConnection(delay, connectionID));
332 am_Error_e CAmDatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
334 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
335 assert(sinkData.domainID!=0);
336 assert(!sinkData.name.empty());
337 assert(sinkData.sinkClassID!=0);
338 //todo: need to check if class exists?
339 assert(!sinkData.listConnectionFormats.empty());
340 assert(sinkData.muteState>=MS_UNKNOWN && sinkData.muteState<=MS_MAX);
342 sqlite3_stmt *query = NULL;
344 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
346 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
347 MY_SQLITE_BIND_TEXT(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC)
349 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
351 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));
353 else if (eCode == SQLITE_DONE)
355 //if sinkID is zero and the first Static Sink was already entered, the ID is created
356 if (sinkData.sinkID == 0 && !mFirstStaticSink && !existSinkName(sinkData.name))
358 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
362 //check if the ID already exists
363 if (existSinkNameOrID(sinkData.sinkID, sinkData.name))
365 MY_SQLITE_FINALIZE(query)
366 return (E_ALREADY_EXISTS);
368 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
373 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
374 MY_SQLITE_FINALIZE(query)
375 return (E_DATABASE_ERROR);
378 MY_SQLITE_FINALIZE(query)
380 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
381 MY_SQLITE_BIND_TEXT(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC)
382 MY_SQLITE_BIND_INT(query, 2, sinkData.domainID)
383 MY_SQLITE_BIND_INT(query, 3, sinkData.sinkClassID)
384 MY_SQLITE_BIND_INT(query, 4, sinkData.volume)
385 MY_SQLITE_BIND_INT(query, 5, sinkData.visible)
386 MY_SQLITE_BIND_INT(query, 6, sinkData.available.availability)
387 MY_SQLITE_BIND_INT(query, 7, sinkData.available.availabilityReason)
388 MY_SQLITE_BIND_INT(query, 8, sinkData.muteState)
389 MY_SQLITE_BIND_INT(query, 9, sinkData.mainVolume)
390 MY_SQLITE_BIND_INT(query, 10, 0)
392 //if the ID is not created, we add it to the query
393 if (sinkData.sinkID != 0)
395 MY_SQLITE_BIND_INT(query, 11, sinkData.sinkID)
398 //if the first static sink is entered, we need to set it onto the boundary
399 else if (mFirstStaticSink)
401 MY_SQLITE_BIND_INT(query, 11, DYNAMIC_ID_BOUNDARY)
402 mFirstStaticSink = false;
405 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
407 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
408 MY_SQLITE_FINALIZE(query)
409 return (E_DATABASE_ERROR);
412 MY_SQLITE_FINALIZE(query)
414 //now read back the sinkID
415 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
416 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
417 MY_SQLITE_BIND_TEXT(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC)
418 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
420 sinkID = sqlite3_column_int(query, 0);
425 logError("DatabaseHandler::existSink database error!:", eCode);
426 MY_SQLITE_FINALIZE(query)
427 return (E_DATABASE_ERROR);
429 MY_SQLITE_FINALIZE(query)
431 //now we need to create the additional tables:
432 command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
433 if (!this->sqQuery(command))
434 return (E_DATABASE_ERROR);
435 command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
436 if (!this->sqQuery(command))
437 return (E_DATABASE_ERROR);
438 command = "CREATE TABLE SinkNotificationConfiguration" + i2s(sinkID) + std::string("(type INTEGER, status INTEGER, parameter INTEGER)");
439 if (!this->sqQuery(command))
440 return (E_DATABASE_ERROR);
442 //fill ConnectionFormats
443 command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
444 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
445 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin();
446 for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator)
448 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
449 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
451 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
452 MY_SQLITE_FINALIZE(query)
453 return (E_DATABASE_ERROR);
455 MY_SQLITE_RESET(query)
458 //Fill SinkSoundProperties
459 command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
460 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
461 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin();
462 for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator)
464 MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type)
465 MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value)
466 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
468 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
469 MY_SQLITE_FINALIZE(query)
470 return (E_DATABASE_ERROR);
472 MY_SQLITE_RESET(query)
475 //Fill NotificationConfigurations
476 command = "INSERT INTO SinkNotificationConfiguration" + i2s(sinkID) + std::string("(type,status,parameter) VALUES (?,?,?)");
477 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
478 std::vector<am_NotificationConfiguration_s>::const_iterator NotificationConfigurationIterator(sinkData.listNotificationConfigurations.begin());
479 for (; NotificationConfigurationIterator < sinkData.listNotificationConfigurations.end(); ++NotificationConfigurationIterator)
481 MY_SQLITE_BIND_INT(query, 1, NotificationConfigurationIterator->type)
482 MY_SQLITE_BIND_INT(query, 2, NotificationConfigurationIterator->status)
483 MY_SQLITE_BIND_INT(query, 3, NotificationConfigurationIterator->parameter)
484 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
486 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
487 MY_SQLITE_FINALIZE(query)
488 return (E_DATABASE_ERROR);
490 MY_SQLITE_RESET(query)
493 if (sinkData.visible == true)
495 command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
496 if (!this->sqQuery(command))
497 return (E_DATABASE_ERROR);
499 //Fill MainSinkSoundProperties
500 command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
501 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
502 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin();
503 for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
505 MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type)
506 MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value)
507 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
509 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
510 MY_SQLITE_FINALIZE(query)
511 return (E_DATABASE_ERROR);
513 MY_SQLITE_RESET(query)
515 MY_SQLITE_FINALIZE(query)
517 //now we got MainNotificationConfigurations as well
518 command = "CREATE TABLE SinkMainNotificationConfiguration" + i2s(sinkID) + std::string("(type INTEGER, status INTEGER, parameter INTEGER)");
519 if (!this->sqQuery(command))
520 return (E_DATABASE_ERROR);
522 command = "INSERT INTO SinkMainNotificationConfiguration" + i2s(sinkID) + std::string("(type,status,parameter) VALUES (?,?,?)");
523 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
524 std::vector<am_NotificationConfiguration_s>::const_iterator mainNotificationConfigurationIterator(sinkData.listMainNotificationConfigurations.begin());
525 for (; mainNotificationConfigurationIterator < sinkData.listMainNotificationConfigurations.end(); ++mainNotificationConfigurationIterator)
527 MY_SQLITE_BIND_INT(query, 1, mainNotificationConfigurationIterator->type)
528 MY_SQLITE_BIND_INT(query, 2, mainNotificationConfigurationIterator->status)
529 MY_SQLITE_BIND_INT(query, 3, mainNotificationConfigurationIterator->parameter)
530 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
532 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
533 MY_SQLITE_FINALIZE(query)
534 return (E_DATABASE_ERROR);
536 MY_SQLITE_RESET(query)
538 MY_SQLITE_FINALIZE(query)
541 logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sinkData.name, "domainID:", sinkData.domainID, "classID:", sinkData.sinkClassID, "volume:", sinkData.volume, "assigned ID:", sinkID);
542 am_Sink_s sink = sinkData;
543 sink.sinkID = sinkID;
544 if (mpDatabaseObserver != NULL)
545 mpDatabaseObserver->newSink(sink);
549 am_Error_e CAmDatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
551 assert(crossfaderData.crossfaderID<DYNAMIC_ID_BOUNDARY);
552 assert(crossfaderData.hotSink>=HS_UNKNOWN && crossfaderData.hotSink<=HS_MAX);
553 assert(!crossfaderData.name.empty());
554 assert(existSink(crossfaderData.sinkID_A));
555 assert(existSink(crossfaderData.sinkID_B));
556 assert(existSource(crossfaderData.sourceID));
558 sqlite3_stmt* query = NULL;
562 //if gatewayData is zero and the first Static Sink was already entered, the ID is created
563 if (crossfaderData.crossfaderID == 0 && !mFirstStaticCrossfader)
565 command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink) VALUES (?,?,?,?,?)";
569 //check if the ID already exists
570 if (existcrossFader(crossfaderData.crossfaderID))
571 return (E_ALREADY_EXISTS);
572 command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink, crossfaderID) VALUES (?,?,?,?,?,?)";
575 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
577 MY_SQLITE_BIND_TEXT(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC)
578 MY_SQLITE_BIND_INT(query, 2, crossfaderData.sinkID_A)
579 MY_SQLITE_BIND_INT(query, 3, crossfaderData.sinkID_B)
580 MY_SQLITE_BIND_INT(query, 4, crossfaderData.sourceID)
581 MY_SQLITE_BIND_INT(query, 5, crossfaderData.hotSink)
583 //if the ID is not created, we add it to the query
584 if (crossfaderData.crossfaderID != 0)
586 MY_SQLITE_BIND_INT(query, 6, crossfaderData.crossfaderID)
589 //if the first static sink is entered, we need to set it onto the boundary
590 else if (mFirstStaticCrossfader)
592 MY_SQLITE_BIND_INT(query, 6, DYNAMIC_ID_BOUNDARY)
593 mFirstStaticCrossfader = false;
596 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
598 logError("DatabaseHandler::enterCrossfaderDB SQLITE Step error code:", eCode);
599 MY_SQLITE_FINALIZE(query)
600 return (E_DATABASE_ERROR);
603 MY_SQLITE_FINALIZE(query)
605 //now read back the crossfaderID
606 command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE name=?";
607 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
608 MY_SQLITE_BIND_TEXT(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC)
609 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
611 crossfaderID = sqlite3_column_int(query, 0);
616 logError("DatabaseHandler::enterCrossfaderDB database error!:", eCode);
617 MY_SQLITE_FINALIZE(query)
618 return (E_DATABASE_ERROR);
620 MY_SQLITE_FINALIZE(query)
622 logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID);
624 am_Crossfader_s crossfader(crossfaderData);
625 crossfader.crossfaderID = crossfaderID;
626 if (mpDatabaseObserver)
627 mpDatabaseObserver->newCrossfader(crossfader);
631 am_Error_e CAmDatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
633 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
634 assert(gatewayData.sinkID!=0);
635 assert(gatewayData.sourceID!=0);
636 assert(gatewayData.controlDomainID!=0);
637 assert(gatewayData.domainSinkID!=0);
638 assert(gatewayData.domainSourceID!=0);
639 assert(!gatewayData.name.empty());
640 assert(!gatewayData.convertionMatrix.empty());
641 assert(!gatewayData.listSinkFormats.empty());
642 assert(!gatewayData.listSourceFormats.empty());
644 //might be that the sinks and sources are not there during registration time
645 //assert(existSink(gatewayData.sinkID));
646 //assert(existSource(gatewayData.sourceID));
648 sqlite3_stmt* query = NULL;
652 //if gatewayData is zero and the first Static Sink was already entered, the ID is created
653 if (gatewayData.gatewayID == 0 && !mFirstStaticGateway)
655 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID) VALUES (?,?,?,?,?,?)";
659 //check if the ID already exists
660 if (existGateway(gatewayData.gatewayID))
661 return (E_ALREADY_EXISTS);
662 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID) VALUES (?,?,?,?,?,?,?)";
665 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
666 MY_SQLITE_BIND_TEXT(query, 1, gatewayData.name.c_str(), gatewayData.name.size(), SQLITE_STATIC)
667 MY_SQLITE_BIND_INT(query, 2, gatewayData.sinkID)
668 MY_SQLITE_BIND_INT(query, 3, gatewayData.sourceID)
669 MY_SQLITE_BIND_INT(query, 4, gatewayData.domainSinkID)
670 MY_SQLITE_BIND_INT(query, 5, gatewayData.domainSourceID)
671 MY_SQLITE_BIND_INT(query, 6, gatewayData.controlDomainID)
673 //if the ID is not created, we add it to the query
674 if (gatewayData.gatewayID != 0)
676 MY_SQLITE_BIND_INT(query, 7, gatewayData.gatewayID)
679 //if the first static sink is entered, we need to set it onto the boundary
680 else if (mFirstStaticGateway)
682 MY_SQLITE_BIND_INT(query, 7, DYNAMIC_ID_BOUNDARY)
683 mFirstStaticGateway = false;
686 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
688 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
689 MY_SQLITE_FINALIZE(query)
690 return (E_DATABASE_ERROR);
693 MY_SQLITE_FINALIZE(query)
695 gatewayID = sqlite3_last_insert_rowid(mpDatabase);
697 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
698 mListConnectionFormat.insert(std::make_pair(gatewayID, gatewayData.convertionMatrix));
700 command = "CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
701 if (!this->sqQuery(command))
702 return (E_DATABASE_ERROR);
703 command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
704 if (!this->sqQuery(command))
705 return (E_DATABASE_ERROR);
707 //fill ConnectionFormats
708 command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
709 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
710 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin();
711 for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator)
713 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
714 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
716 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
717 MY_SQLITE_FINALIZE(query)
718 return (E_DATABASE_ERROR);
720 MY_SQLITE_RESET(query)
722 MY_SQLITE_FINALIZE(query)
724 command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
725 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
726 connectionFormatIterator = gatewayData.listSinkFormats.begin();
727 for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator)
729 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
730 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
732 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
733 MY_SQLITE_FINALIZE(query)
734 return (E_DATABASE_ERROR);
736 MY_SQLITE_RESET(query)
738 MY_SQLITE_FINALIZE(query)
740 logInfo("DatabaseHandler::enterGatewayDB entered new gateway with name", gatewayData.name, "sourceID:", gatewayData.sourceID, "sinkID:", gatewayData.sinkID, "assigned ID:", gatewayID);
741 am_Gateway_s gateway = gatewayData;
742 gateway.gatewayID = gatewayID;
743 if (mpDatabaseObserver)
744 mpDatabaseObserver->newGateway(gateway);
748 am_Error_e CAmDatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
750 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
751 assert(sourceData.domainID!=0);
752 assert(!sourceData.name.empty());
753 assert(sourceData.sourceClassID!=0);
754 // \todo: need to check if class exists?
755 assert(!sourceData.listConnectionFormats.empty());
756 assert(sourceData.sourceState>=SS_UNKNNOWN && sourceData.sourceState<=SS_MAX);
758 sqlite3_stmt* query = NULL;
761 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
763 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
764 MY_SQLITE_BIND_TEXT(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC)
766 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
768 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));
770 else if (eCode == SQLITE_DONE)
772 //if sinkID is zero and the first Static Sink was already entered, the ID is created
773 if (sourceData.sourceID == 0 && !mFirstStaticSource && !existSourceName(sourceData.name))
775 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
779 //check if the ID already exists
780 if (existSourceNameOrID(sourceData.sourceID, sourceData.name))
782 MY_SQLITE_FINALIZE(query)
783 return (E_ALREADY_EXISTS);
785 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
790 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
791 MY_SQLITE_FINALIZE(query)
792 return (E_DATABASE_ERROR);
795 MY_SQLITE_FINALIZE(query)
797 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
798 MY_SQLITE_BIND_TEXT(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC)
799 MY_SQLITE_BIND_INT(query, 2, sourceData.domainID)
800 MY_SQLITE_BIND_INT(query, 3, sourceData.sourceClassID)
801 MY_SQLITE_BIND_INT(query, 4, sourceData.sourceState)
802 MY_SQLITE_BIND_INT(query, 5, sourceData.volume)
803 MY_SQLITE_BIND_INT(query, 6, sourceData.visible)
804 MY_SQLITE_BIND_INT(query, 7, sourceData.available.availability)
805 MY_SQLITE_BIND_INT(query, 8, sourceData.available.availabilityReason)
806 MY_SQLITE_BIND_INT(query, 9, sourceData.interruptState)
807 MY_SQLITE_BIND_INT(query, 10, 0)
809 //if the ID is not created, we add it to the query
810 if (sourceData.sourceID != 0)
812 MY_SQLITE_BIND_INT(query, 11, sourceData.sourceID)
815 //if the first static sink is entered, we need to set it onto the boundary
816 else if (mFirstStaticSource)
818 MY_SQLITE_BIND_INT(query, 11, DYNAMIC_ID_BOUNDARY)
819 mFirstStaticSource = false;
822 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
824 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
825 MY_SQLITE_FINALIZE(query)
826 return (E_DATABASE_ERROR);
829 MY_SQLITE_FINALIZE(query)
831 //now read back the sinkID
832 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
833 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
834 MY_SQLITE_BIND_TEXT(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC)
835 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
837 sourceID = sqlite3_column_int(query, 0);
842 logError("DatabaseHandler::existSink database error!:", eCode);
843 MY_SQLITE_FINALIZE(query)
844 return (E_DATABASE_ERROR);
846 MY_SQLITE_FINALIZE(query)
848 //now we need to create the additional tables:
849 command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
850 if (!this->sqQuery(command))
851 return (E_DATABASE_ERROR);
852 command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
853 if (!this->sqQuery(command))
854 return (E_DATABASE_ERROR);
855 command = "CREATE TABLE SourceNotificationConfiguration" + i2s(sourceID) + std::string("(type INTEGER, status INTEGER, parameter INTEGER)");
856 if (!this->sqQuery(command))
857 return (E_DATABASE_ERROR);
859 //fill ConnectionFormats
860 command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
861 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
862 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin();
863 for (; connectionFormatIterator != sourceData.listConnectionFormats.end(); ++connectionFormatIterator)
865 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
866 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
868 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
869 MY_SQLITE_FINALIZE(query)
870 return (E_DATABASE_ERROR);
872 MY_SQLITE_RESET(query)
874 MY_SQLITE_FINALIZE(query)
876 //Fill SinkSoundProperties
877 command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
878 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
879 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin();
880 for (; SoundPropertyIterator != sourceData.listSoundProperties.end(); ++SoundPropertyIterator)
882 MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type)
883 MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value)
884 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
886 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
887 MY_SQLITE_FINALIZE(query)
888 return (E_DATABASE_ERROR);
890 MY_SQLITE_RESET(query)
893 //Fill NotificationConfigurations
894 command = "INSERT INTO SourceNotificationConfiguration" + i2s(sourceID) + std::string("(type,status,parameter) VALUES (?,?,?)");
895 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
896 std::vector<am_NotificationConfiguration_s>::const_iterator NotificationConfigurationIterator(sourceData.listNotificationConfigurations.begin());
897 for (; NotificationConfigurationIterator < sourceData.listNotificationConfigurations.end(); ++NotificationConfigurationIterator)
899 MY_SQLITE_BIND_INT(query, 1, NotificationConfigurationIterator->type)
900 MY_SQLITE_BIND_INT(query, 2, NotificationConfigurationIterator->status)
901 MY_SQLITE_BIND_INT(query, 3, NotificationConfigurationIterator->parameter)
902 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
904 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
905 MY_SQLITE_FINALIZE(query)
906 return (E_DATABASE_ERROR);
908 MY_SQLITE_RESET(query)
911 if (sourceData.visible == true)
913 command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
914 if (!this->sqQuery(command))
915 return (E_DATABASE_ERROR);
917 //Fill MainSinkSoundProperties
918 command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
919 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
920 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin();
921 for (; mainSoundPropertyIterator != sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
923 MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type)
924 MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value)
925 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
927 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
928 MY_SQLITE_FINALIZE(query)
929 return (E_DATABASE_ERROR);
931 MY_SQLITE_RESET(query)
933 MY_SQLITE_FINALIZE(query)
935 //now we got MainNotificationConfigurations as well
936 command = "CREATE TABLE SourceMainNotificationConfiguration" + i2s(sourceID) + std::string("(type INTEGER, status INTEGER, parameter INTEGER)");
937 if (!this->sqQuery(command))
938 return (E_DATABASE_ERROR);
940 command = "INSERT INTO SourceMainNotificationConfiguration" + i2s(sourceID) + std::string("(type,status,parameter) VALUES (?,?,?)");
941 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
942 std::vector<am_NotificationConfiguration_s>::const_iterator mainNotificationConfigurationIterator(sourceData.listMainNotificationConfigurations.begin());
943 for (; mainNotificationConfigurationIterator != sourceData.listMainNotificationConfigurations.end(); ++mainNotificationConfigurationIterator)
945 MY_SQLITE_BIND_INT(query, 1, mainNotificationConfigurationIterator->type)
946 MY_SQLITE_BIND_INT(query, 2, mainNotificationConfigurationIterator->status)
947 MY_SQLITE_BIND_INT(query, 3, mainNotificationConfigurationIterator->parameter)
948 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
950 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
951 MY_SQLITE_FINALIZE(query)
952 return (E_DATABASE_ERROR);
954 MY_SQLITE_RESET(query)
956 MY_SQLITE_FINALIZE(query)
959 logInfo("DatabaseHandler::enterSourceDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID);
961 am_Source_s source = sourceData;
962 source.sourceID = sourceID;
963 if (mpDatabaseObserver)
964 mpDatabaseObserver->newSource(source);
968 am_Error_e CAmDatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector<am_connectionID_t>& listConnectionID)
970 assert(mainconnectionID!=0);
971 if (!existMainConnection(mainconnectionID))
973 return (E_NON_EXISTENT);
975 sqlite3_stmt* query = NULL;
980 command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?");
981 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
982 std::vector<am_connectionID_t>::const_iterator elementIterator = listConnectionID.begin();
983 for (; elementIterator < listConnectionID.end(); ++elementIterator)
985 MY_SQLITE_BIND_INT(query, 1, *elementIterator)
987 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
989 int16_t temp_delay = sqlite3_column_int(query, 1);
990 if (temp_delay != -1 && delay != -1)
997 logError("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection: ", eCode);
998 MY_SQLITE_FINALIZE(query)
999 return (E_DATABASE_ERROR);
1001 MY_SQLITE_RESET(query)
1004 MY_SQLITE_FINALIZE(query)
1006 //now we delete the data in the table
1007 command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID);
1008 if (!this->sqQuery(command))
1009 return (E_DATABASE_ERROR);
1011 command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
1012 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1013 std::vector<am_connectionID_t>::const_iterator listConnectionIterator(listConnectionID.begin());
1014 for (; listConnectionIterator != listConnectionID.end(); ++listConnectionIterator)
1016 MY_SQLITE_BIND_INT(query, 1, *listConnectionIterator)
1017 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1019 logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:", eCode);
1020 MY_SQLITE_FINALIZE(query)
1021 return (E_DATABASE_ERROR);
1023 MY_SQLITE_RESET(query)
1026 if (changeDelayMainConnection(delay,mainconnectionID)!=E_OK)
1027 logError("DatabaseHandler::changeMainConnectionRouteDB error while changing mainConnectionDelay to ", delay);
1029 MY_SQLITE_FINALIZE(query)
1030 logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID);
1034 am_Error_e CAmDatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
1036 assert(mainconnectionID!=0);
1037 assert(connectionState>=CS_UNKNOWN && connectionState<=CS_MAX);
1039 sqlite3_stmt* query = NULL;
1041 std::string command;
1043 if (!existMainConnection(mainconnectionID))
1045 return (E_NON_EXISTENT);
1047 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
1048 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1049 MY_SQLITE_BIND_INT(query, 1, connectionState)
1050 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1052 logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:", eCode);
1053 MY_SQLITE_FINALIZE(query)
1054 return (E_DATABASE_ERROR);
1056 MY_SQLITE_FINALIZE(query)
1057 logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState);
1059 if (mpDatabaseObserver)
1060 mpDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState);
1064 am_Error_e CAmDatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
1068 sqlite3_stmt* query = NULL;
1070 std::string command;
1072 if (!existSink(sinkID))
1074 return (E_NON_EXISTENT);
1076 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
1077 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1078 MY_SQLITE_BIND_INT(query, 1, mainVolume)
1079 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1081 logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:", eCode);
1082 MY_SQLITE_FINALIZE(query)
1083 return (E_DATABASE_ERROR);
1086 MY_SQLITE_FINALIZE(query)
1087 logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume);
1089 if (mpDatabaseObserver)
1090 mpDatabaseObserver->volumeChanged(sinkID, mainVolume);
1095 am_Error_e CAmDatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
1098 assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX);
1099 assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX);
1101 sqlite3_stmt* query = NULL;
1103 std::string command;
1105 if (!existSink(sinkID))
1107 return (E_NON_EXISTENT);
1109 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
1110 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1111 MY_SQLITE_BIND_INT(query, 1, availability.availability)
1112 MY_SQLITE_BIND_INT(query, 2, availability.availabilityReason)
1113 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1115 logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:", eCode);
1116 MY_SQLITE_FINALIZE(query)
1117 return (E_DATABASE_ERROR);
1120 MY_SQLITE_FINALIZE(query)
1121 logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason);
1123 if (mpDatabaseObserver && sourceVisible(sinkID))
1124 mpDatabaseObserver->sinkAvailabilityChanged(sinkID, availability);
1128 am_Error_e CAmDatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
1130 assert(domainID!=0);
1131 assert(domainState>=DS_UNKNOWN && domainState<=DS_MAX);
1133 sqlite3_stmt* query = NULL;
1135 std::string command;
1137 if (!existDomain(domainID))
1139 return (E_NON_EXISTENT);
1141 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
1142 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1143 MY_SQLITE_BIND_INT(query, 1, domainState)
1144 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1146 logError("DatabaseHandler::changDomainStateDB SQLITE Step error code:", eCode);
1147 MY_SQLITE_FINALIZE(query)
1148 return (E_DATABASE_ERROR);
1151 MY_SQLITE_FINALIZE(query)
1153 logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState);
1157 am_Error_e CAmDatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
1160 assert(muteState>=MS_UNKNOWN && muteState<=MS_MAX);
1162 sqlite3_stmt* query = NULL;
1164 std::string command;
1166 if (!existSink(sinkID))
1168 return (E_NON_EXISTENT);
1170 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
1171 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1172 MY_SQLITE_BIND_INT(query, 1, muteState)
1173 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1175 logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:", eCode);
1176 MY_SQLITE_FINALIZE(query)
1177 return (E_DATABASE_ERROR);
1180 MY_SQLITE_FINALIZE(query)
1181 logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState);
1183 if (mpDatabaseObserver)
1184 mpDatabaseObserver->sinkMuteStateChanged(sinkID, muteState);
1189 am_Error_e CAmDatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
1191 assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX);
1194 sqlite3_stmt* query = NULL;
1196 std::string command;
1198 if (!existSink(sinkID))
1200 return (E_NON_EXISTENT);
1202 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1203 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1204 MY_SQLITE_BIND_INT(query, 1, soundProperty.value)
1205 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1207 logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:", eCode);
1208 MY_SQLITE_FINALIZE(query)
1209 return (E_DATABASE_ERROR);
1212 MY_SQLITE_FINALIZE(query)
1213 logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value);
1214 if (mpDatabaseObserver)
1215 mpDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty);
1219 am_Error_e CAmDatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1221 assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX);
1222 assert(sourceID!=0);
1224 sqlite3_stmt* query = NULL;
1226 std::string command;
1228 if (!existSource(sourceID))
1230 return (E_NON_EXISTENT);
1232 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1233 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1234 MY_SQLITE_BIND_INT(query, 1, soundProperty.value)
1235 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1237 logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:", eCode);
1238 MY_SQLITE_FINALIZE(query)
1239 return (E_DATABASE_ERROR);
1241 MY_SQLITE_FINALIZE(query)
1243 logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value);
1245 if (mpDatabaseObserver)
1246 mpDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty);
1250 am_Error_e CAmDatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1252 assert(sourceID!=0);
1253 assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX);
1254 assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX);
1256 sqlite3_stmt* query = NULL;
1258 std::string command;
1260 if (!existSource(sourceID))
1262 return (E_NON_EXISTENT);
1264 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1265 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1266 MY_SQLITE_BIND_INT(query, 1, availability.availability)
1267 MY_SQLITE_BIND_INT(query, 2, availability.availabilityReason)
1268 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1270 logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:", eCode);
1271 MY_SQLITE_FINALIZE(query)
1272 return (E_DATABASE_ERROR);
1275 MY_SQLITE_FINALIZE(query)
1277 logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason);
1279 if (mpDatabaseObserver && sourceVisible(sourceID))
1280 mpDatabaseObserver->sourceAvailabilityChanged(sourceID, availability);
1284 am_Error_e CAmDatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1286 assert(property.type>=SYP_UNKNOWN && property.type<=SYP_MAX);
1287 sqlite3_stmt* query = NULL;
1289 std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1291 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1292 MY_SQLITE_BIND_INT(query, 1, property.value)
1293 MY_SQLITE_BIND_INT(query, 2, property.type)
1295 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1297 logError("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:", eCode);
1298 MY_SQLITE_FINALIZE(query)
1299 return (E_DATABASE_ERROR);
1302 MY_SQLITE_FINALIZE(query)
1304 logInfo("DatabaseHandler::changeSystemPropertyDB changed system property");
1306 if (mpDatabaseObserver)
1307 mpDatabaseObserver->systemPropertyChanged(property);
1312 am_Error_e CAmDatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1314 assert(mainConnectionID!=0);
1316 if (!existMainConnection(mainConnectionID))
1318 return (E_NON_EXISTENT);
1320 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1321 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1322 if (!sqQuery(command))
1323 return (E_DATABASE_ERROR);
1324 if (!sqQuery(command1))
1325 return (E_DATABASE_ERROR);
1326 logInfo("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID);
1327 if (mpDatabaseObserver)
1329 mpDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED);
1330 mpDatabaseObserver->removedMainConnection(mainConnectionID);
1335 am_Error_e CAmDatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1339 if (!existSink(sinkID))
1341 return (E_NON_EXISTENT);
1344 bool visible = sinkVisible(sinkID);
1346 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1347 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1348 std::string command2 = "DROP table SinkSoundProperty" + i2s(sinkID);
1349 std::string command3 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1350 std::string command4 = "DROP table SinkNotificationConfiguration" + i2s(sinkID);
1351 std::string command5 = "DROP table SinkMainNotificationConfiguration" + i2s(sinkID);
1352 if (!sqQuery(command))
1353 return (E_DATABASE_ERROR);
1354 if (!sqQuery(command1))
1355 return (E_DATABASE_ERROR);
1356 if (!sqQuery(command2))
1357 return (E_DATABASE_ERROR);
1358 if (!sqQuery(command4))
1359 return (E_DATABASE_ERROR);
1360 if (visible) //only drop table if it ever existed
1362 if (!sqQuery(command3))
1363 return (E_DATABASE_ERROR);
1364 if (!sqQuery(command5))
1365 return (E_DATABASE_ERROR);
1367 logInfo("DatabaseHandler::removeSinkDB removed:", sinkID);
1369 if (mpDatabaseObserver != NULL)
1370 mpDatabaseObserver->removedSink(sinkID, visible);
1375 am_Error_e CAmDatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1377 assert(sourceID!=0);
1379 if (!existSource(sourceID))
1381 return (E_NON_EXISTENT);
1384 bool visible = sourceVisible(sourceID);
1386 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1387 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1388 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1389 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1390 std::string command4 = "DROP table SourceNotificationConfiguration" + i2s(sourceID);
1391 std::string command5 = "DROP table SourceMainNotificationConfiguration" + i2s(sourceID);
1392 if (!sqQuery(command))
1393 return (E_DATABASE_ERROR);
1394 if (!sqQuery(command1))
1395 return (E_DATABASE_ERROR);
1396 if (!sqQuery(command3))
1397 return (E_DATABASE_ERROR);
1398 if (!sqQuery(command4))
1399 return (E_DATABASE_ERROR);
1403 if (!sqQuery(command2))
1404 return (E_DATABASE_ERROR);
1405 if (!sqQuery(command5))
1406 return (E_DATABASE_ERROR);
1408 logInfo("DatabaseHandler::removeSourceDB removed:", sourceID);
1409 if (mpDatabaseObserver)
1410 mpDatabaseObserver->removedSource(sourceID, visible);
1414 am_Error_e CAmDatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1416 assert(gatewayID!=0);
1418 if (!existGateway(gatewayID))
1420 return (E_NON_EXISTENT);
1422 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1423 if (!sqQuery(command))
1424 return (E_DATABASE_ERROR);
1425 logInfo("DatabaseHandler::removeGatewayDB removed:", gatewayID);
1426 if (mpDatabaseObserver)
1427 mpDatabaseObserver->removeGateway(gatewayID);
1431 am_Error_e CAmDatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1433 assert(crossfaderID!=0);
1435 if (!existcrossFader(crossfaderID))
1437 return (E_NON_EXISTENT);
1439 std::string command = "DELETE from " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID);
1440 if (!sqQuery(command))
1441 return (E_DATABASE_ERROR);
1442 logInfo("DatabaseHandler::removeCrossfaderDB removed:", crossfaderID);
1443 if (mpDatabaseObserver)
1444 mpDatabaseObserver->removeCrossfader(crossfaderID);
1448 am_Error_e CAmDatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1450 assert(domainID!=0);
1452 if (!existDomain(domainID))
1454 return (E_NON_EXISTENT);
1456 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1457 if (!sqQuery(command))
1458 return (E_DATABASE_ERROR);
1459 logInfo("DatabaseHandler::removeDomainDB removed:", domainID);
1460 if (mpDatabaseObserver)
1461 mpDatabaseObserver->removeDomain(domainID);
1465 am_Error_e CAmDatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1467 assert(sinkClassID!=0);
1469 if (!existSinkClass(sinkClassID))
1471 return (E_NON_EXISTENT);
1473 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1474 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1475 if (!sqQuery(command))
1476 return (E_DATABASE_ERROR);
1477 if (!sqQuery(command1))
1478 return (E_DATABASE_ERROR);
1480 logInfo("DatabaseHandler::removeSinkClassDB removed:", sinkClassID);
1481 if (mpDatabaseObserver)
1482 mpDatabaseObserver->numberOfSinkClassesChanged();
1487 am_Error_e CAmDatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1489 assert(sourceClassID!=0);
1491 if (!existSourceClass(sourceClassID))
1493 return (E_NON_EXISTENT);
1495 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1496 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1497 if (!sqQuery(command))
1498 return (E_DATABASE_ERROR);
1499 if (!sqQuery(command1))
1500 return (E_DATABASE_ERROR);
1501 logInfo("DatabaseHandler::removeSourceClassDB removed:", sourceClassID);
1502 if (mpDatabaseObserver)
1503 mpDatabaseObserver->numberOfSourceClassesChanged();
1507 am_Error_e CAmDatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1509 assert(connectionID!=0);
1511 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1512 if (!sqQuery(command))
1513 return (E_DATABASE_ERROR);
1514 logInfo("DatabaseHandler::removeConnection removed:", connectionID);
1518 am_Error_e CAmDatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1520 assert(sourceID!=0);
1522 if (!existSource(sourceID))
1524 return (E_NON_EXISTENT);
1526 sqlite3_stmt* query = NULL;
1528 am_ClassProperty_s propertyTemp;
1529 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + (i2s(sourceID));
1530 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1532 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1534 classInfo.sourceClassID = sqlite3_column_int(query, 0);
1537 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1539 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1540 MY_SQLITE_FINALIZE(query)
1541 return (E_DATABASE_ERROR);
1544 MY_SQLITE_FINALIZE(query)
1546 command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1547 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1549 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1551 classInfo.name = std::string((const char*) sqlite3_column_text(query, 0));
1554 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1556 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1557 MY_SQLITE_FINALIZE(query)
1558 return (E_DATABASE_ERROR);
1561 MY_SQLITE_FINALIZE(query)
1563 //read out Properties
1564 command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID);
1565 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1566 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1568 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1569 propertyTemp.value = sqlite3_column_int(query, 1);
1570 classInfo.listClassProperties.push_back(propertyTemp);
1573 if (eCode != SQLITE_DONE)
1575 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1576 MY_SQLITE_FINALIZE(query)
1577 return (E_DATABASE_ERROR);
1580 MY_SQLITE_FINALIZE(query)
1584 am_Error_e CAmDatabaseHandler::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const
1589 if (!existSink(sinkID))
1591 return (E_NON_EXISTENT);
1594 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL, *qMainNotification = NULL, *qNotification = NULL;
1596 am_ConnectionFormat_e tempConnectionFormat;
1597 am_SoundProperty_s tempSoundProperty;
1598 am_MainSoundProperty_s tempMainSoundProperty;
1599 am_NotificationConfiguration_s tempNotificationConfiguration,tempMainNotification;
1600 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);
1601 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1603 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1605 sinkData.name = std::string((const char*) sqlite3_column_text(query, 0));
1606 sinkData.domainID = sqlite3_column_int(query, 1);
1607 sinkData.sinkClassID = sqlite3_column_int(query, 2);
1608 sinkData.volume = sqlite3_column_int(query, 3);
1609 sinkData.visible = sqlite3_column_int(query, 4);
1610 sinkData.available.availability = (am_Availability_e) sqlite3_column_int(query, 5);
1611 sinkData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
1612 sinkData.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
1613 sinkData.mainVolume = sqlite3_column_int(query, 8);
1614 sinkData.sinkID = sqlite3_column_int(query, 9);
1616 //read out the connectionFormats
1617 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
1618 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
1619 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1621 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1622 sinkData.listConnectionFormats.push_back(tempConnectionFormat);
1625 MY_SQLITE_FINALIZE(qConnectionFormat)
1627 //read out sound properties
1628 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(sinkID);
1629 MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
1630 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1632 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1633 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1634 sinkData.listSoundProperties.push_back(tempSoundProperty);
1637 MY_SQLITE_FINALIZE(qSoundProperty)
1639 std::string notificationCommand = "SELECT type, status, parameter FROM SinkNotificationConfiguration" + i2s(sinkID);
1640 MY_SQLITE_PREPARE_V2(mpDatabase, notificationCommand.c_str(), -1, &qNotification, NULL)
1642 while ((eCode = sqlite3_step(qNotification)) == SQLITE_ROW)
1644 tempNotificationConfiguration.type = static_cast<am_NotificationType_e>(sqlite3_column_int(qNotification, 0));
1645 tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qNotification, 1));
1646 tempNotificationConfiguration.parameter= static_cast<int16_t>(sqlite3_column_int(qNotification, 2));
1647 sinkData.listNotificationConfigurations.push_back(tempNotificationConfiguration);
1649 MY_SQLITE_FINALIZE(qNotification)
1651 if (sinkData.visible)
1654 //read out MainSoundProperties
1655 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
1656 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
1657 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1659 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1660 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1661 sinkData.listMainSoundProperties.push_back(tempMainSoundProperty);
1664 MY_SQLITE_FINALIZE(qMAinSoundProperty)
1666 std::string mainNotificationCommand = "SELECT type, status, parameter FROM SinkMainNotificationConfiguration" + i2s(sinkID);
1667 MY_SQLITE_PREPARE_V2(mpDatabase, mainNotificationCommand.c_str(), -1, &qMainNotification, NULL)
1669 while ((eCode = sqlite3_step(qMainNotification)) == SQLITE_ROW)
1671 tempMainNotification.type = static_cast<am_NotificationType_e>(sqlite3_column_int(qMainNotification, 0));
1672 tempMainNotification.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qMainNotification, 1));
1673 tempMainNotification.parameter= static_cast<int16_t>(sqlite3_column_int(qMainNotification, 2));
1674 sinkData.listMainNotificationConfigurations.push_back(tempMainNotification);
1676 MY_SQLITE_FINALIZE(qMainNotification)
1680 else if (eCode != SQLITE_DONE)
1682 logError("DatabaseHandler::getSinkInfoDB SQLITE error code:", eCode);
1683 MY_SQLITE_FINALIZE(query)
1684 return (E_DATABASE_ERROR);
1687 MY_SQLITE_FINALIZE(query)
1692 am_Error_e CAmDatabaseHandler::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const
1694 assert(sourceID!=0);
1696 if (!existSource(sourceID))
1698 return (E_NON_EXISTENT);
1701 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL, *qMainNotification = NULL, *qNotification = NULL;
1703 am_ConnectionFormat_e tempConnectionFormat;
1704 am_SoundProperty_s tempSoundProperty;
1705 am_MainSoundProperty_s tempMainSoundProperty;
1706 am_NotificationConfiguration_s tempNotificationConfiguration,tempMainNotification;
1707 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);
1708 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1710 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1712 sourceData.name = std::string((const char*) sqlite3_column_text(query, 0));
1713 sourceData.domainID = sqlite3_column_int(query, 1);
1714 sourceData.sourceClassID = sqlite3_column_int(query, 2);
1715 sourceData.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
1716 sourceData.volume = sqlite3_column_int(query, 4);
1717 sourceData.visible = sqlite3_column_int(query, 5);
1718 sourceData.available.availability = (am_Availability_e) sqlite3_column_int(query, 6);
1719 sourceData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
1720 sourceData.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
1721 sourceData.sourceID = sqlite3_column_int(query, 9);
1723 //read out the connectionFormats
1724 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
1725 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
1726 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1728 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1729 sourceData.listConnectionFormats.push_back(tempConnectionFormat);
1732 MY_SQLITE_FINALIZE(qConnectionFormat)
1734 //read out sound properties
1735 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(sourceID);
1736 MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
1737 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1739 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1740 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1741 sourceData.listSoundProperties.push_back(tempSoundProperty);
1744 MY_SQLITE_FINALIZE(qSoundProperty)
1746 std::string notificationCommand = "SELECT type, status, parameter FROM SourceNotificationConfiguration" + i2s(sourceID);
1747 MY_SQLITE_PREPARE_V2(mpDatabase, notificationCommand.c_str(), -1, &qNotification, NULL)
1749 while ((eCode = sqlite3_step(qNotification)) == SQLITE_ROW)
1751 tempNotificationConfiguration.type = static_cast<am_NotificationType_e>(sqlite3_column_int(qNotification, 0));
1752 tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qNotification, 1));
1753 tempNotificationConfiguration.parameter= static_cast<int16_t>(sqlite3_column_int(qNotification, 2));
1754 sourceData.listNotificationConfigurations.push_back(tempNotificationConfiguration);
1756 MY_SQLITE_FINALIZE(qNotification)
1758 if (sourceData.visible)
1761 //read out MainSoundProperties
1762 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
1763 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
1764 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1766 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1767 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1768 sourceData.listMainSoundProperties.push_back(tempMainSoundProperty);
1771 MY_SQLITE_FINALIZE(qMAinSoundProperty)
1773 std::string mainNotificationCommand = "SELECT type, status, parameter FROM SourceMainNotificationConfiguration" + i2s(sourceID);
1774 MY_SQLITE_PREPARE_V2(mpDatabase, mainNotificationCommand.c_str(), -1, &qMainNotification, NULL)
1776 while ((eCode = sqlite3_step(qMainNotification)) == SQLITE_ROW)
1778 tempMainNotification.type = static_cast<am_NotificationType_e>(sqlite3_column_int(qMainNotification, 0));
1779 tempMainNotification.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qMainNotification, 1));
1780 tempMainNotification.parameter= static_cast<int16_t>(sqlite3_column_int(qMainNotification, 2));
1781 sourceData.listMainNotificationConfigurations.push_back(tempMainNotification);
1783 MY_SQLITE_FINALIZE(qMainNotification)
1787 else if (eCode != SQLITE_DONE)
1789 logError("DatabaseHandler::getSourceInfoDB SQLITE error code:", eCode);
1790 MY_SQLITE_FINALIZE(query)
1791 return (E_DATABASE_ERROR);
1794 MY_SQLITE_FINALIZE(query)
1799 am_Error_e am::CAmDatabaseHandler::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const
1801 assert(mainConnectionID!=0);
1802 if (!existMainConnection(mainConnectionID))
1804 return (E_NON_EXISTENT);
1806 sqlite3_stmt *query = NULL, *query1 = NULL;
1808 am_MainConnection_s temp;
1809 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1810 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
1811 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1813 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1815 mainConnectionData.mainConnectionID = sqlite3_column_int(query, 0);
1816 mainConnectionData.sourceID = sqlite3_column_int(query, 1);
1817 mainConnectionData.sinkID = sqlite3_column_int(query, 2);
1818 mainConnectionData.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
1819 mainConnectionData.delay = sqlite3_column_int(query, 4);
1820 std::string statement = command1 + i2s(mainConnectionID);
1821 MY_SQLITE_PREPARE_V2(mpDatabase, statement.c_str(), -1, &query1, NULL)
1822 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW)
1824 mainConnectionData.listConnectionID.push_back(sqlite3_column_int(query1, 0));
1826 MY_SQLITE_FINALIZE(query1)
1829 if (eCode != SQLITE_DONE)
1831 logError("DatabaseHandler::getMainConnectionInfoDB SQLITE error code:", eCode);
1832 MY_SQLITE_FINALIZE(query)
1833 return (E_DATABASE_ERROR);
1836 MY_SQLITE_FINALIZE(query)
1841 am_Error_e CAmDatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1843 assert(sinkClass.sinkClassID!=0);
1844 assert(!sinkClass.listClassProperties.empty());
1846 sqlite3_stmt* query = NULL;
1849 //check if the ID already exists
1850 if (!existSinkClass(sinkClass.sinkClassID))
1851 return (E_NON_EXISTENT);
1853 //fill ConnectionFormats
1854 std::string command = "UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1855 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1856 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
1857 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
1859 MY_SQLITE_BIND_INT(query, 1, Iterator->value)
1860 MY_SQLITE_BIND_INT(query, 2, Iterator->classProperty)
1861 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1863 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode);
1864 MY_SQLITE_FINALIZE(query)
1865 return (E_DATABASE_ERROR); if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1867 logError("DatabaseHandler::changeMainSourceNotificationConfigurationDB SQLITE Step error code:", eCode);
1868 MY_SQLITE_FINALIZE(query)
1869 return (E_DATABASE_ERROR);
1871 MY_SQLITE_FINALIZE(query)
1873 MY_SQLITE_RESET(query)
1876 MY_SQLITE_FINALIZE(query)
1878 logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo");
1882 am_Error_e CAmDatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1884 assert(sourceClass.sourceClassID!=0);
1885 assert(!sourceClass.listClassProperties.empty());
1887 sqlite3_stmt* query = NULL;
1890 //check if the ID already exists
1891 if (!existSourceClass(sourceClass.sourceClassID))
1892 return (E_NON_EXISTENT);
1894 //fill ConnectionFormats
1895 std::string command = "UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1896 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1897 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
1898 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
1900 MY_SQLITE_BIND_INT(query, 1, Iterator->value)
1901 MY_SQLITE_BIND_INT(query, 2, Iterator->classProperty)
1902 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1904 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode);
1905 MY_SQLITE_FINALIZE(query)
1906 return (E_DATABASE_ERROR);
1908 MY_SQLITE_RESET(query)
1911 MY_SQLITE_FINALIZE(query)
1913 logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo");
1917 am_Error_e CAmDatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1921 if (!existSink(sinkID))
1923 return (E_NON_EXISTENT);
1925 sqlite3_stmt* query = NULL;
1927 am_ClassProperty_s propertyTemp;
1928 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + (i2s(sinkID));
1929 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1931 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1933 sinkClass.sinkClassID = sqlite3_column_int(query, 0);
1936 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1938 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1939 MY_SQLITE_FINALIZE(query)
1940 return (E_DATABASE_ERROR);
1943 MY_SQLITE_FINALIZE(query)
1945 command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1946 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1948 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1950 sinkClass.name = std::string((const char*) sqlite3_column_text(query, 0));
1953 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1955 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1956 MY_SQLITE_FINALIZE(query)
1957 return (E_DATABASE_ERROR);
1960 MY_SQLITE_FINALIZE(query)
1962 //read out Properties
1963 command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID);
1964 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1965 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1967 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1968 propertyTemp.value = sqlite3_column_int(query, 1);
1969 sinkClass.listClassProperties.push_back(propertyTemp);
1972 if (eCode != SQLITE_DONE)
1974 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1975 MY_SQLITE_FINALIZE(query)
1976 return (E_DATABASE_ERROR);
1979 MY_SQLITE_FINALIZE(query)
1983 am_Error_e CAmDatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1985 assert(gatewayID!=0);
1986 if (!existGateway(gatewayID))
1988 return (E_NON_EXISTENT);
1990 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
1992 am_ConnectionFormat_e tempConnectionFormat;
1993 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1994 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
1996 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1998 gatewayData.name = std::string((const char*) sqlite3_column_text(query, 0));
1999 gatewayData.sinkID = sqlite3_column_int(query, 1);
2000 gatewayData.sourceID = sqlite3_column_int(query, 2);
2001 gatewayData.domainSinkID = sqlite3_column_int(query, 3);
2002 gatewayData.domainSourceID = sqlite3_column_int(query, 4);
2003 gatewayData.controlDomainID = sqlite3_column_int(query, 5);
2004 gatewayData.gatewayID = sqlite3_column_int(query, 6);
2007 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2008 iter = mListConnectionFormat.find(gatewayData.gatewayID);
2009 if (iter == mListConnectionFormat.end())
2011 logError("DatabaseHandler::getGatewayInfoDB database error with convertionFormat");
2012 MY_SQLITE_FINALIZE(query)
2013 return (E_DATABASE_ERROR);
2015 gatewayData.convertionMatrix = iter->second;
2017 //read out the connectionFormats
2018 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
2019 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL)
2020 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
2022 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
2023 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
2026 MY_SQLITE_FINALIZE(qSourceConnectionFormat)
2028 //read out sound properties
2029 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
2030 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL)
2031 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
2033 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
2034 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
2037 MY_SQLITE_FINALIZE(qSinkConnectionFormat)
2041 if (eCode != SQLITE_DONE)
2043 logError("DatabaseHandler::getGatewayInfoDB SQLITE error code:", eCode);
2044 MY_SQLITE_FINALIZE(query)
2045 return (E_DATABASE_ERROR);
2048 MY_SQLITE_FINALIZE(query)
2054 am_Error_e CAmDatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
2056 assert(crossfaderID!=0);
2057 if (!existcrossFader(crossfaderID))
2059 return (E_NON_EXISTENT);
2061 sqlite3_stmt* query = NULL;
2063 std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID);
2064 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2066 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2068 crossfaderData.name = std::string((const char*) sqlite3_column_text(query, 0));
2069 crossfaderData.sinkID_A = sqlite3_column_int(query, 1);
2070 crossfaderData.sinkID_B = sqlite3_column_int(query, 2);
2071 crossfaderData.sourceID = sqlite3_column_int(query, 3);
2072 crossfaderData.hotSink = static_cast<am_HotSink_e>(sqlite3_column_int(query, 4));
2073 crossfaderData.crossfaderID = sqlite3_column_int(query, 5);
2076 if (eCode != SQLITE_DONE)
2078 logError("DatabaseHandler::getCrossfaderInfoDB SQLITE error code:", eCode);
2079 MY_SQLITE_FINALIZE(query)
2080 return (E_DATABASE_ERROR);
2083 MY_SQLITE_FINALIZE(query)
2088 am_Error_e CAmDatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
2090 assert(domainID!=0);
2092 if (!existDomain(domainID))
2094 return (E_NON_EXISTENT);
2096 sqlite3_stmt* query = NULL;
2099 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND domainID=" + (i2s(domainID));
2100 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2102 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2104 temp = sqlite3_column_int(query, 0);
2105 listSinkID.push_back(temp);
2108 if (eCode != SQLITE_DONE)
2110 logError("DatabaseHandler::getListSinksOfDomain SQLITE error code:", eCode);
2111 MY_SQLITE_FINALIZE(query)
2112 return (E_DATABASE_ERROR);
2115 MY_SQLITE_FINALIZE(query)
2119 am_Error_e CAmDatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
2121 assert(domainID!=0);
2122 listSourceID.clear();
2123 if (!existDomain(domainID))
2125 return (E_NON_EXISTENT);
2127 sqlite3_stmt* query = NULL;
2130 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
2132 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2134 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2136 temp = sqlite3_column_int(query, 0);
2137 listSourceID.push_back(temp);
2140 if (eCode != SQLITE_DONE)
2142 logError("DatabaseHandler::getListSourcesOfDomain SQLITE error code:", eCode);
2143 MY_SQLITE_FINALIZE(query)
2144 return (E_DATABASE_ERROR);
2147 MY_SQLITE_FINALIZE(query)
2152 am_Error_e CAmDatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listCrossfader) const
2154 assert(domainID!=0);
2155 listCrossfader.clear();
2156 if (!existDomain(domainID))
2158 return (E_NON_EXISTENT);
2160 sqlite3_stmt* query = NULL;
2162 am_crossfaderID_t temp;
2164 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);
2165 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2167 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2169 temp = sqlite3_column_int(query, 0);
2170 listCrossfader.push_back(temp);
2173 if (eCode != SQLITE_DONE)
2175 logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE error code:", eCode);
2176 MY_SQLITE_FINALIZE(query)
2177 return (E_DATABASE_ERROR);
2180 MY_SQLITE_FINALIZE(query)
2186 am_Error_e CAmDatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
2188 assert(domainID!=0);
2189 listGatewaysID.clear();
2190 if (!existDomain(domainID))
2192 return (E_NON_EXISTENT);
2194 sqlite3_stmt* query = NULL;
2196 am_gatewayID_t temp;
2198 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" + i2s(domainID);
2199 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2201 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2203 temp = sqlite3_column_int(query, 0);
2204 listGatewaysID.push_back(temp);
2207 if (eCode != SQLITE_DONE)
2209 logError("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:", eCode);
2210 MY_SQLITE_FINALIZE(query)
2211 return (E_DATABASE_ERROR);
2214 MY_SQLITE_FINALIZE(query)
2219 am_Error_e CAmDatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
2221 listMainConnections.clear();
2222 sqlite3_stmt *query = NULL, *query1 = NULL;
2224 am_MainConnection_s temp;
2225 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2226 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
2227 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2229 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2231 temp.mainConnectionID = sqlite3_column_int(query, 0);
2232 temp.sourceID = sqlite3_column_int(query, 1);
2233 temp.sinkID = sqlite3_column_int(query, 2);
2234 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2235 temp.delay = sqlite3_column_int(query, 4);
2236 std::string statement = command1 + i2s(temp.mainConnectionID);
2237 MY_SQLITE_PREPARE_V2(mpDatabase, statement.c_str(), -1, &query1, NULL)
2238 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW)
2240 temp.listConnectionID.push_back(sqlite3_column_int(query1, 0));
2242 listMainConnections.push_back(temp);
2243 MY_SQLITE_FINALIZE(query1)
2246 if (eCode != SQLITE_DONE)
2248 logError("DatabaseHandler::getListMainConnections SQLITE error code:", eCode);
2249 MY_SQLITE_FINALIZE(query)
2250 return (E_DATABASE_ERROR);
2253 MY_SQLITE_FINALIZE(query)
2258 am_Error_e CAmDatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
2260 listDomains.clear();
2261 sqlite3_stmt* query = NULL;
2264 std::string command = "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
2265 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2267 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2269 temp.domainID = sqlite3_column_int(query, 0);
2270 temp.name = std::string((const char*) sqlite3_column_text(query, 1));
2271 temp.busname = std::string((const char*) sqlite3_column_text(query, 2));
2272 temp.nodename = std::string((const char*) sqlite3_column_text(query, 3));
2273 temp.early = sqlite3_column_int(query, 4);
2274 temp.complete = sqlite3_column_int(query, 5);
2275 temp.state = (am_DomainState_e) sqlite3_column_int(query, 6);
2276 listDomains.push_back(temp);
2279 if (eCode != SQLITE_DONE)
2281 logError("DatabaseHandler::getListDomains SQLITE error code:", eCode);
2282 MY_SQLITE_FINALIZE(query)
2283 return (E_DATABASE_ERROR);
2286 MY_SQLITE_FINALIZE(query)
2291 am_Error_e CAmDatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
2293 listConnections.clear();
2294 sqlite3_stmt* query = NULL;
2296 am_Connection_s temp;
2297 std::string command = "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE reserved=0";
2298 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2300 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2302 temp.connectionID = sqlite3_column_int(query, 0);
2303 temp.sourceID = sqlite3_column_int(query, 1);
2304 temp.sinkID = sqlite3_column_int(query, 2);
2305 temp.delay = sqlite3_column_int(query, 3);
2306 temp.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query, 4);
2307 listConnections.push_back(temp);
2310 if (eCode != SQLITE_DONE)
2312 logError("DatabaseHandler::getListConnections SQLITE error code:", eCode);
2313 MY_SQLITE_FINALIZE(query)
2314 return (E_DATABASE_ERROR);
2317 MY_SQLITE_FINALIZE(query)
2322 am_Error_e CAmDatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
2325 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qNotificationConfiguration= NULL, *qMAinSoundProperty = NULL, *qMainNotificationConfiguration= NULL;
2328 am_ConnectionFormat_e tempConnectionFormat;
2329 am_SoundProperty_s tempSoundProperty;
2330 am_MainSoundProperty_s tempMainSoundProperty;
2331 am_NotificationConfiguration_s tempNotificationConfiguration;
2332 am_NotificationConfiguration_s tempMainNotificationConfiguration;
2333 std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0";
2334 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2336 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2338 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2339 temp.domainID = sqlite3_column_int(query, 1);
2340 temp.sinkClassID = sqlite3_column_int(query, 2);
2341 temp.volume = sqlite3_column_int(query, 3);
2342 temp.visible = sqlite3_column_int(query, 4);
2343 temp.available.availability = (am_Availability_e) sqlite3_column_int(query, 5);
2344 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
2345 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
2346 temp.mainVolume = sqlite3_column_int(query, 8);
2347 temp.sinkID = sqlite3_column_int(query, 9);
2349 //read out the connectionFormats
2350 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID);
2351 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
2352 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2354 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2355 temp.listConnectionFormats.push_back(tempConnectionFormat);
2358 MY_SQLITE_FINALIZE(qConnectionFormat)
2360 //read out sound properties
2361 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
2362 MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
2363 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
2365 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
2366 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
2367 temp.listSoundProperties.push_back(tempSoundProperty);
2370 MY_SQLITE_FINALIZE(qSoundProperty)
2372 //read out notifications
2373 std::string commandNotificationConfiguration = "SELECT type, status, parameter FROM SinkNotificationConfiguration" + i2s(temp.sinkID);
2374 MY_SQLITE_PREPARE_V2(mpDatabase, commandNotificationConfiguration.c_str(), -1, &qNotificationConfiguration, NULL)
2375 while ((eCode = sqlite3_step(qNotificationConfiguration)) == SQLITE_ROW)
2377 tempNotificationConfiguration.type = static_cast<am_NotificationType_e> (sqlite3_column_int(qNotificationConfiguration, 0));
2378 tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e> (sqlite3_column_int(qNotificationConfiguration, 1));
2379 tempNotificationConfiguration.parameter = static_cast<int16_t> (sqlite3_column_int(qNotificationConfiguration, 2));
2380 temp.listNotificationConfigurations.push_back(tempNotificationConfiguration);
2383 MY_SQLITE_FINALIZE(qNotificationConfiguration)
2385 //read out MainSoundProperties if sink is visible
2388 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID);
2389 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
2390 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
2392 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
2393 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2394 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2397 MY_SQLITE_FINALIZE(qMAinSoundProperty)
2399 //and mainNotificationConfigurations
2400 std::string commandMainNotificationConfiguration = "SELECT type, status, parameter FROM SinkMainNotificationConfiguration" + i2s(temp.sinkID);
2401 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainNotificationConfiguration.c_str(), -1, &qMainNotificationConfiguration, NULL)
2402 while ((eCode = sqlite3_step(qMainNotificationConfiguration)) == SQLITE_ROW)
2404 tempMainNotificationConfiguration.type = static_cast <am_NotificationType_e> (sqlite3_column_int(qMainNotificationConfiguration, 0));
2405 tempMainNotificationConfiguration.status = static_cast <am_NotificationStatus_e> (sqlite3_column_int(qMainNotificationConfiguration, 1));
2406 tempMainNotificationConfiguration.parameter = static_cast <uint16_t>(sqlite3_column_int(qMainNotificationConfiguration, 2));
2407 temp.listMainNotificationConfigurations.push_back(tempMainNotificationConfiguration);
2410 MY_SQLITE_FINALIZE(qMainNotificationConfiguration)
2413 listSinks.push_back(temp);
2414 temp.listConnectionFormats.clear();
2415 temp.listMainSoundProperties.clear();
2416 temp.listSoundProperties.clear();
2419 if (eCode != SQLITE_DONE)
2421 logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
2422 MY_SQLITE_FINALIZE(query)
2423 return (E_DATABASE_ERROR);
2426 MY_SQLITE_FINALIZE(query)
2431 am_Error_e CAmDatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
2433 listSources.clear();
2434 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL, *qNotification(NULL), *qMainNotification(NULL);
2437 am_ConnectionFormat_e tempConnectionFormat;
2438 am_SoundProperty_s tempSoundProperty;
2439 am_MainSoundProperty_s tempMainSoundProperty;
2440 am_NotificationConfiguration_s tempNotificationConfiguration;
2441 std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0";
2442 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2444 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2446 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2447 temp.domainID = sqlite3_column_int(query, 1);
2448 temp.sourceClassID = sqlite3_column_int(query, 2);
2449 temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
2450 temp.volume = sqlite3_column_int(query, 4);
2451 temp.visible = sqlite3_column_int(query, 5);
2452 temp.available.availability = (am_Availability_e) sqlite3_column_int(query, 6);
2453 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
2454 temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
2455 temp.sourceID = sqlite3_column_int(query, 9);
2457 //read out the connectionFormats
2458 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID);
2459 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
2460 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2462 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2463 temp.listConnectionFormats.push_back(tempConnectionFormat);
2466 MY_SQLITE_FINALIZE(qConnectionFormat)
2468 //read out sound properties
2469 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
2470 MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
2471 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
2473 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
2474 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
2475 temp.listSoundProperties.push_back(tempSoundProperty);
2478 MY_SQLITE_FINALIZE(qSoundProperty)
2480 std::string notificationCommand = "SELECT type, status, parameter FROM SourceNotificationConfiguration" + i2s(temp.sourceID);
2481 MY_SQLITE_PREPARE_V2(mpDatabase, notificationCommand.c_str(), -1, &qNotification, NULL)
2483 while ((eCode = sqlite3_step(qNotification)) == SQLITE_ROW)
2485 tempNotificationConfiguration.type = static_cast<am_NotificationType_e>(sqlite3_column_int(qNotification, 0));
2486 tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qNotification, 1));
2487 tempNotificationConfiguration.parameter= static_cast<int16_t>(sqlite3_column_int(qNotification, 2));
2488 temp.listNotificationConfigurations.push_back(tempNotificationConfiguration);
2490 MY_SQLITE_FINALIZE(qNotification)
2492 //read out MainSoundProperties if source is visible
2495 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID);
2496 MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
2497 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
2499 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
2500 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2501 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2504 MY_SQLITE_FINALIZE(qMAinSoundProperty)
2506 std::string mainNotificationCommand = "SELECT type, status, parameter FROM SourceMainNotificationConfiguration" + i2s(temp.sourceID);
2507 MY_SQLITE_PREPARE_V2(mpDatabase, mainNotificationCommand.c_str(), -1, &qMainNotification, NULL)
2509 while ((eCode = sqlite3_step(qMainNotification)) == SQLITE_ROW)
2511 tempNotificationConfiguration.type = static_cast<am_NotificationType_e>(sqlite3_column_int(qMainNotification, 0));
2512 tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qMainNotification, 1));
2513 tempNotificationConfiguration.parameter= static_cast<int16_t>(sqlite3_column_int(qMainNotification, 2));
2514 temp.listMainNotificationConfigurations.push_back(tempNotificationConfiguration);
2516 MY_SQLITE_FINALIZE(qMainNotification)
2520 listSources.push_back(temp);
2521 temp.listConnectionFormats.clear();
2522 temp.listMainSoundProperties.clear();
2523 temp.listSoundProperties.clear();
2526 if (eCode != SQLITE_DONE)
2528 logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
2529 MY_SQLITE_FINALIZE(query)
2530 return (E_DATABASE_ERROR);
2533 MY_SQLITE_FINALIZE(query)
2538 am_Error_e CAmDatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
2540 listSourceClasses.clear();
2542 sqlite3_stmt* query = NULL, *subQuery = NULL;
2543 int eCode = 0, eCode1;
2544 am_SourceClass_s classTemp;
2545 am_ClassProperty_s propertyTemp;
2547 std::string command = "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
2548 std::string command2;
2549 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2551 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2553 classTemp.sourceClassID = sqlite3_column_int(query, 0);
2554 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2556 //read out Properties
2557 command2 = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classTemp.sourceClassID);
2558 MY_SQLITE_PREPARE_V2(mpDatabase, command2.c_str(), -1, &subQuery, NULL)
2560 while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW)
2562 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2563 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2564 classTemp.listClassProperties.push_back(propertyTemp);
2567 if (eCode1 != SQLITE_DONE)
2569 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode1);
2570 MY_SQLITE_FINALIZE(query)
2571 MY_SQLITE_FINALIZE(subQuery)
2572 return (E_DATABASE_ERROR);
2575 MY_SQLITE_FINALIZE(subQuery)
2577 listSourceClasses.push_back(classTemp);
2580 if (eCode != SQLITE_DONE)
2582 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2583 MY_SQLITE_FINALIZE(subQuery)
2584 return (E_DATABASE_ERROR);
2587 MY_SQLITE_FINALIZE(query)
2592 am_Error_e CAmDatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2594 listCrossfaders.clear();
2595 sqlite3_stmt* query = NULL;
2597 am_Crossfader_s tempData;
2598 std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE);
2599 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2601 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2603 tempData.name = std::string((const char*) sqlite3_column_text(query, 0));
2604 tempData.sinkID_A = sqlite3_column_int(query, 1);
2605 tempData.sinkID_B = sqlite3_column_int(query, 2);
2606 tempData.sourceID = sqlite3_column_int(query, 3);
2607 tempData.hotSink = static_cast<am_HotSink_e>(sqlite3_column_int(query, 4));
2608 tempData.crossfaderID = sqlite3_column_int(query, 5);
2609 listCrossfaders.push_back(tempData);
2612 if (eCode != SQLITE_DONE)
2614 logError("DatabaseHandler::getListCrossfaders SQLITE error code:", eCode);
2615 MY_SQLITE_FINALIZE(query)
2616 return (E_DATABASE_ERROR);
2619 MY_SQLITE_FINALIZE(query)
2624 am_Error_e CAmDatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2626 listGateways.clear();
2627 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
2630 am_ConnectionFormat_e tempConnectionFormat;
2632 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2633 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2635 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2637 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2638 temp.sinkID = sqlite3_column_int(query, 1);
2639 temp.sourceID = sqlite3_column_int(query, 2);
2640 temp.domainSinkID = sqlite3_column_int(query, 3);
2641 temp.domainSourceID = sqlite3_column_int(query, 4);
2642 temp.controlDomainID = sqlite3_column_int(query, 5);
2643 temp.gatewayID = sqlite3_column_int(query, 6);
2646 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2647 iter = mListConnectionFormat.find(temp.gatewayID);
2648 if (iter == mListConnectionFormat.end())
2650 logError("DatabaseHandler::getListGateways database error with convertionFormat");
2652 return (E_DATABASE_ERROR);
2654 temp.convertionMatrix = iter->second;
2656 //read out the connectionFormats
2657 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2658 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL)
2659 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
2661 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
2662 temp.listSourceFormats.push_back(tempConnectionFormat);
2665 MY_SQLITE_FINALIZE(qSourceConnectionFormat)
2667 //read out sound properties
2668 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2669 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL)
2670 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
2672 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
2673 temp.listSinkFormats.push_back(tempConnectionFormat);
2676 MY_SQLITE_FINALIZE(qSinkConnectionFormat)
2678 listGateways.push_back(temp);
2679 temp.listSinkFormats.clear();
2680 temp.listSourceFormats.clear();
2683 if (eCode != SQLITE_DONE)
2685 logError("DatabaseHandler::getListGateways SQLITE error code:", eCode);
2686 MY_SQLITE_FINALIZE(query)
2687 return (E_DATABASE_ERROR);
2690 MY_SQLITE_FINALIZE(query)
2695 am_Error_e CAmDatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2697 listSinkClasses.clear();
2699 sqlite3_stmt* query = NULL, *subQuery = NULL;
2701 am_SinkClass_s classTemp;
2702 am_ClassProperty_s propertyTemp;
2704 std::string command = "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2705 std::string command2;
2706 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2708 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2710 classTemp.sinkClassID = sqlite3_column_int(query, 0);
2711 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2713 //read out Properties
2714 command2 = "SELECT classProperty, value FROM SinkClassProperties" + i2s(classTemp.sinkClassID);
2715 MY_SQLITE_PREPARE_V2(mpDatabase, command2.c_str(), -1, &subQuery, NULL)
2717 while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW)
2719 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2720 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2721 classTemp.listClassProperties.push_back(propertyTemp);
2724 if (eCode != SQLITE_DONE)
2726 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2728 return (E_DATABASE_ERROR);
2731 MY_SQLITE_FINALIZE(subQuery)
2733 listSinkClasses.push_back(classTemp);
2736 if (eCode != SQLITE_DONE)
2738 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2739 MY_SQLITE_FINALIZE(query)
2740 return (E_DATABASE_ERROR);
2743 MY_SQLITE_FINALIZE(query)
2748 am_Error_e CAmDatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2750 listConnections.clear();
2751 sqlite3_stmt *query = NULL;
2753 am_MainConnectionType_s temp;
2755 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2756 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2758 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2760 temp.mainConnectionID = sqlite3_column_int(query, 0);
2761 temp.sourceID = sqlite3_column_int(query, 1);
2762 temp.sinkID = sqlite3_column_int(query, 2);
2763 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2764 temp.delay = sqlite3_column_int(query, 4);
2765 listConnections.push_back(temp);
2768 if (eCode != SQLITE_DONE)
2770 logError("DatabaseHandler::getListVisibleMainConnections SQLITE error code:", eCode);
2771 MY_SQLITE_FINALIZE(query)
2772 return (E_DATABASE_ERROR);
2775 MY_SQLITE_FINALIZE(query)
2780 am_Error_e CAmDatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2782 listMainSinks.clear();
2783 sqlite3_stmt* query = NULL;
2787 std::string command = "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2788 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2790 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2792 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2793 temp.sinkID = sqlite3_column_int(query, 1);
2794 temp.availability.availability = (am_Availability_e) sqlite3_column_int(query, 2);
2795 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2796 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 4);
2797 temp.volume = sqlite3_column_int(query, 5);
2798 temp.sinkClassID = sqlite3_column_int(query, 6);
2799 listMainSinks.push_back(temp);
2802 if (eCode != SQLITE_DONE)
2804 logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
2805 MY_SQLITE_FINALIZE(query)
2806 return (E_DATABASE_ERROR);
2809 MY_SQLITE_FINALIZE(query)
2814 am_Error_e CAmDatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2816 listMainSources.clear();
2817 sqlite3_stmt* query = NULL;
2819 am_SourceType_s temp;
2820 std::string command = "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2821 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2823 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2825 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2826 temp.sourceClassID = sqlite3_column_int(query, 1);
2827 temp.availability.availability = (am_Availability_e) sqlite3_column_int(query, 2);
2828 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2829 temp.sourceID = sqlite3_column_int(query, 4);
2831 listMainSources.push_back(temp);
2834 if (eCode != SQLITE_DONE)
2836 logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
2837 MY_SQLITE_FINALIZE(query)
2838 return (E_DATABASE_ERROR);
2841 MY_SQLITE_FINALIZE(query)
2846 am_Error_e CAmDatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2849 if (!existSink(sinkID))
2850 return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences
2851 listSoundProperties.clear();
2853 sqlite3_stmt* query = NULL;
2855 am_MainSoundProperty_s temp;
2856 std::string command = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2857 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2859 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2861 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2862 temp.value = sqlite3_column_int(query, 1);
2863 listSoundProperties.push_back(temp);
2866 if (eCode != SQLITE_DONE)
2868 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode);
2869 MY_SQLITE_FINALIZE(query)
2870 return (E_DATABASE_ERROR);
2873 MY_SQLITE_FINALIZE(query)
2878 am_Error_e CAmDatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2880 assert(sourceID!=0);
2881 if (!existSource(sourceID))
2882 return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences
2883 listSourceProperties.clear();
2885 sqlite3_stmt* query = NULL;
2887 am_MainSoundProperty_s temp;
2888 std::string command = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2889 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2891 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2893 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2894 temp.value = sqlite3_column_int(query, 1);
2895 listSourceProperties.push_back(temp);
2898 if (eCode != SQLITE_DONE)
2900 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode);
2901 MY_SQLITE_FINALIZE(query)
2902 return (E_DATABASE_ERROR);
2905 MY_SQLITE_FINALIZE(query)
2910 am_Error_e CAmDatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2912 listSystemProperties.clear();
2914 sqlite3_stmt* query = NULL;
2916 am_SystemProperty_s temp;
2917 std::string command = "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2918 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
2920 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2922 temp.type = (am_SystemPropertyType_e) sqlite3_column_int(query, 0);
2923 temp.value = sqlite3_column_int(query, 1);
2924 listSystemProperties.push_back(temp);
2927 if (eCode != SQLITE_DONE)
2929 logError("DatabaseHandler::getListSystemProperties SQLITE error code:", eCode);
2930 MY_SQLITE_FINALIZE(query)
2931 return (E_DATABASE_ERROR);
2934 MY_SQLITE_FINALIZE(query)
2939 am_Error_e am::CAmDatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2941 listConnectionFormats.clear();
2942 sqlite3_stmt *qConnectionFormat = NULL;
2944 am_ConnectionFormat_e tempConnectionFormat;
2945 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
2946 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
2947 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2949 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2950 listConnectionFormats.push_back(tempConnectionFormat);
2953 MY_SQLITE_FINALIZE(qConnectionFormat)
2958 am_Error_e am::CAmDatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2960 listConnectionFormats.clear();
2961 sqlite3_stmt* qConnectionFormat = NULL;
2963 am_ConnectionFormat_e tempConnectionFormat;
2965 //read out the connectionFormats
2966 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
2967 MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
2968 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2970 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2971 listConnectionFormats.push_back(tempConnectionFormat);
2974 MY_SQLITE_FINALIZE(qConnectionFormat)
2979 am_Error_e am::CAmDatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const
2981 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2982 iter = mListConnectionFormat.find(gatewayID);
2983 if (iter == mListConnectionFormat.end())
2985 logError("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat");
2987 return (E_DATABASE_ERROR);
2989 listConnectionFormat = iter->second;
2994 am_Error_e CAmDatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2996 assert(mainConnectionID!=0);
2998 sqlite3_stmt *query = NULL;
3001 std::string command = "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
3002 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3004 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3006 delay = sqlite3_column_int(query, 0);
3009 if (eCode != SQLITE_DONE)
3011 logError("DatabaseHandler::getTimingInformation SQLITE error code:", eCode);
3012 MY_SQLITE_FINALIZE(query)
3013 return (E_DATABASE_ERROR);
3016 MY_SQLITE_FINALIZE(query)
3019 return (E_NOT_POSSIBLE);
3024 bool CAmDatabaseHandler::sqQuery(const std::string& query)
3026 sqlite3_stmt* statement;
3028 if ((eCode = sqlite3_exec(mpDatabase, query.c_str(), NULL, &statement, NULL)) != SQLITE_OK)
3030 logError("DatabaseHandler::sqQuery SQL Query failed:", query.c_str(), "error code:", eCode);
3036 bool CAmDatabaseHandler::openDatabase()
3038 if (sqlite3_open_v2(mPath.c_str(), &mpDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
3040 logInfo("DatabaseHandler::openDatabase opened database");
3043 logError("DatabaseHandler::openDatabase failed to open database");
3047 am_Error_e CAmDatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
3049 assert(connectionID!=0);
3051 sqlite3_stmt* query = NULL;
3053 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE delay=? AND mainConnectionID=?";
3054 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3055 MY_SQLITE_BIND_INT(query, 1, delay)
3056 MY_SQLITE_BIND_INT(query, 2, connectionID)
3057 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3059 MY_SQLITE_FINALIZE(query)
3062 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
3063 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3064 MY_SQLITE_BIND_INT(query, 1, delay)
3065 MY_SQLITE_BIND_INT(query, 2, connectionID)
3067 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3069 logError("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:", eCode);
3071 MY_SQLITE_FINALIZE(query)
3072 return (E_DATABASE_ERROR);
3075 if (mpDatabaseObserver)
3076 mpDatabaseObserver->timingInformationChanged(connectionID, delay);
3078 MY_SQLITE_FINALIZE(query)
3082 am_Error_e CAmDatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
3084 assert(connection.connectionID==0);
3085 assert(connection.sinkID!=0);
3086 assert(connection.sourceID!=0);
3087 //connection format is not checked, because it's project specific
3089 sqlite3_stmt* query = NULL;
3091 std::string command = "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
3093 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3094 MY_SQLITE_BIND_INT(query, 1, connection.sinkID)
3095 MY_SQLITE_BIND_INT(query, 2, connection.sourceID)
3096 MY_SQLITE_BIND_INT(query, 3, connection.delay)
3097 MY_SQLITE_BIND_INT(query, 4, connection.connectionFormat)
3098 MY_SQLITE_BIND_INT(query, 5, true)
3100 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3102 logError("DatabaseHandler::enterConnectionDB SQLITE Step error code:", eCode);
3103 MY_SQLITE_FINALIZE(query)
3104 return (E_DATABASE_ERROR);
3107 MY_SQLITE_FINALIZE(query)
3109 connectionID = sqlite3_last_insert_rowid(mpDatabase);
3111 logInfo("DatabaseHandler::enterConnectionDB entered new connection sourceID=", connection.sourceID, "sinkID=", connection.sinkID, "sourceID=", connection.sourceID, "connectionFormat=", connection.connectionFormat, "assigned ID=", connectionID);
3115 am_Error_e CAmDatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
3117 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
3118 assert(!sinkClass.name.empty());
3120 sqlite3_stmt* query = NULL;
3122 std::string command;
3124 //if sinkID is zero and the first Static Sink was already entered, the ID is created
3125 if (sinkClass.sinkClassID == 0 && !mFirstStaticSinkClass)
3127 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
3131 //check if the ID already exists
3132 if (existSinkClass(sinkClass.sinkClassID))
3133 return (E_ALREADY_EXISTS);
3134 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
3137 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3138 MY_SQLITE_BIND_TEXT(query, 1, sinkClass.name.c_str(), sinkClass.name.size(), SQLITE_STATIC)
3140 //if the ID is not created, we add it to the query
3141 if (sinkClass.sinkClassID != 0)
3143 MY_SQLITE_BIND_INT(query, 2, sinkClass.sinkClassID)
3146 //if the first static sink is entered, we need to set it onto the boundary
3147 else if (mFirstStaticSinkClass)
3149 MY_SQLITE_BIND_INT(query, 2, DYNAMIC_ID_BOUNDARY)
3150 mFirstStaticSinkClass = false;
3153 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3155 logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode);
3156 MY_SQLITE_FINALIZE(query)
3157 return (E_DATABASE_ERROR);
3160 MY_SQLITE_FINALIZE(query)
3162 sinkClassID = sqlite3_last_insert_rowid(mpDatabase); //todo:change last_insert implementations for mulithread usage...
3164 //now we need to create the additional tables:
3165 command = "CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
3166 if (!this->sqQuery(command))
3167 return (E_DATABASE_ERROR);
3169 //fill ConnectionFormats
3170 command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
3171 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3172 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
3173 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
3175 MY_SQLITE_BIND_INT(query, 1, Iterator->classProperty)
3176 MY_SQLITE_BIND_INT(query, 2, Iterator->value)
3177 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3179 logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode);
3180 MY_SQLITE_FINALIZE(query)
3181 return (E_DATABASE_ERROR);
3183 MY_SQLITE_RESET(query)
3186 MY_SQLITE_FINALIZE(query)
3188 logInfo("DatabaseHandler::enterSinkClassDB entered new sinkClass");
3189 if (mpDatabaseObserver)
3190 mpDatabaseObserver->numberOfSinkClassesChanged();
3194 am_Error_e CAmDatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
3196 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
3197 assert(!sourceClass.name.empty());
3199 sqlite3_stmt* query = NULL;
3201 std::string command;
3203 //if sinkID is zero and the first Static Sink was already entered, the ID is created
3204 if (sourceClass.sourceClassID == 0 && !mFirstStaticSourceClass)
3206 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
3210 //check if the ID already exists
3211 if (existSourceClass(sourceClass.sourceClassID))
3212 return (E_ALREADY_EXISTS);
3213 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
3216 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3217 MY_SQLITE_BIND_TEXT(query, 1, sourceClass.name.c_str(), sourceClass.name.size(), SQLITE_STATIC)
3219 //if the ID is not created, we add it to the query
3220 if (sourceClass.sourceClassID != 0)
3222 MY_SQLITE_BIND_INT(query, 2, sourceClass.sourceClassID)
3225 //if the first static sink is entered, we need to set it onto the boundary
3226 else if (mFirstStaticSourceClass)
3228 MY_SQLITE_BIND_INT(query, 2, DYNAMIC_ID_BOUNDARY)
3229 mFirstStaticSourceClass = false;
3232 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3234 logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode);
3235 MY_SQLITE_FINALIZE(query)
3236 return (E_DATABASE_ERROR);
3239 MY_SQLITE_FINALIZE(query)
3241 sourceClassID = sqlite3_last_insert_rowid(mpDatabase); //todo:change last_insert implementations for mulithread usage...
3243 //now we need to create the additional tables:
3244 command = "CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
3245 if (!this->sqQuery(command))
3246 return (E_DATABASE_ERROR);
3248 //fill ConnectionFormats
3249 command = "INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
3250 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3251 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
3252 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
3254 MY_SQLITE_BIND_INT(query, 1, Iterator->classProperty)
3255 MY_SQLITE_BIND_INT(query, 2, Iterator->value)
3256 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3258 logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode);
3259 MY_SQLITE_FINALIZE(query)
3260 return (E_DATABASE_ERROR);
3262 MY_SQLITE_RESET(query)
3265 MY_SQLITE_FINALIZE(query)
3267 logInfo("DatabaseHandler::enterSourceClassDB entered new sourceClass");
3269 if (mpDatabaseObserver)
3270 mpDatabaseObserver->numberOfSourceClassesChanged();
3274 am_Error_e CAmDatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
3276 assert(!listSystemProperties.empty());
3277 sqlite3_stmt* query = NULL;
3279 std::vector<am_SystemProperty_s>::const_iterator listIterator = listSystemProperties.begin();
3280 std::string command = "DELETE FROM " + std::string(SYSTEM_TABLE);
3281 if (!this->sqQuery(command))
3282 return (E_DATABASE_ERROR);
3284 command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
3286 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3287 for (; listIterator < listSystemProperties.end(); ++listIterator)
3289 MY_SQLITE_BIND_INT(query, 1, listIterator->type)
3290 MY_SQLITE_BIND_INT(query, 2, listIterator->value)
3292 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3294 logError("DatabaseHandler::enterSystemProperties SQLITE Step error code:", eCode);
3295 MY_SQLITE_FINALIZE(query)
3296 return (E_DATABASE_ERROR);
3299 MY_SQLITE_RESET(query)
3302 MY_SQLITE_FINALIZE(query)
3304 logInfo("DatabaseHandler::enterSystemProperties entered system properties");
3309 * checks for a certain mainConnection
3310 * @param mainConnectionID to be checked for
3311 * @return true if it exists
3313 bool CAmDatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
3315 sqlite3_stmt* query = NULL;
3316 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
3318 bool returnVal = true;
3319 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3320 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3322 else if (eCode != SQLITE_ROW)
3325 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3328 MY_SQLITE_FINALIZE_BOOL(query)
3333 * checks for a certain Source
3334 * @param sourceID to be checked for
3335 * @return true if it exists
3337 bool CAmDatabaseHandler::existSource(const am_sourceID_t sourceID) const
3339 sqlite3_stmt* query = NULL;
3340 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
3342 bool returnVal = true;
3343 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3344 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3346 else if (eCode != SQLITE_ROW)
3349 logError("DatabaseHandler::existSource database error!:", eCode);
3351 MY_SQLITE_FINALIZE_BOOL(query)
3356 * checks if a source name or ID exists
3357 * @param sourceID the sourceID
3358 * @param name the name
3359 * @return true if it exits
3361 bool CAmDatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
3363 sqlite3_stmt* query = NULL;
3364 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
3366 bool returnVal = true;
3367 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3369 if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC)))
3371 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode);
3375 if ((eCode = sqlite3_bind_int(query, 2, sourceID)))
3377 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3381 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3383 else if (eCode != SQLITE_ROW)
3386 logError("DatabaseHandler::existSource database error!:", eCode);
3388 MY_SQLITE_FINALIZE_BOOL(query)
3393 * checks if a name exits
3394 * @param name the name
3395 * @return true if it exits
3397 bool CAmDatabaseHandler::existSourceName(const std::string & name) const
3399 sqlite3_stmt* query = NULL;
3400 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
3402 bool returnVal = true;
3403 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3405 if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC)))
3407 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode);
3411 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3413 else if (eCode != SQLITE_ROW)
3416 logError("DatabaseHandler::existSource database error!:", eCode);
3419 MY_SQLITE_FINALIZE_BOOL(query)
3424 * checks for a certain Sink
3425 * @param sinkID to be checked for
3426 * @return true if it exists
3428 bool CAmDatabaseHandler::existSink(const am_sinkID_t sinkID) const
3430 sqlite3_stmt* query = NULL;
3431 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3433 bool returnVal = true;
3434 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3436 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3438 else if (eCode != SQLITE_ROW)
3441 logError("DatabaseHandler::existSink database error!:", eCode);
3443 MY_SQLITE_FINALIZE_BOOL(query)
3448 * checks if a sink with the ID or the name exists
3449 * @param sinkID the ID
3450 * @param name the name
3451 * @return true if it exists.
3453 bool CAmDatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
3455 sqlite3_stmt* query = NULL;
3456 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
3458 bool returnVal = true;
3459 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3461 if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC)))
3463 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode);
3467 if ((eCode = sqlite3_bind_int(query, 2, sinkID)))
3469 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3473 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3475 else if (eCode != SQLITE_ROW)
3478 logError("DatabaseHandler::existSink database error!:", eCode);
3481 MY_SQLITE_FINALIZE_BOOL(query)
3486 * checks if a sink with the name exists
3487 * @param name the name
3488 * @return true if it exists
3490 bool CAmDatabaseHandler::existSinkName(const std::string & name) const
3492 sqlite3_stmt* query = NULL;
3493 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
3495 bool returnVal = true;
3496 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3498 if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC)))
3500 logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode);
3504 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3506 else if (eCode != SQLITE_ROW)
3509 logError("DatabaseHandler::existSink database error!:", eCode);
3512 MY_SQLITE_FINALIZE_BOOL(query)
3517 * checks for a certain domain
3518 * @param domainID to be checked for
3519 * @return true if it exists
3521 bool CAmDatabaseHandler::existDomain(const am_domainID_t domainID) const
3523 sqlite3_stmt* query = NULL;
3524 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
3526 bool returnVal = true;
3527 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3529 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3531 else if (eCode != SQLITE_ROW)
3534 logError("DatabaseHandler::existDomain database error!:", eCode);
3537 MY_SQLITE_FINALIZE_BOOL(query)
3542 * checks for certain gateway
3543 * @param gatewayID to be checked for
3544 * @return true if it exists
3546 bool CAmDatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
3548 sqlite3_stmt* query = NULL;
3549 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
3551 bool returnVal = true;
3552 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3554 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3556 else if (eCode != SQLITE_ROW)
3559 logError("DatabaseHandler::existGateway database error!:", eCode);
3562 MY_SQLITE_FINALIZE_BOOL(query)
3566 am_Error_e CAmDatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
3568 assert(sourceID!=0);
3570 sqlite3_stmt* query = NULL;
3571 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3573 am_Error_e returnVal = E_DATABASE_ERROR;
3574 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3575 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3577 domainID = sqlite3_column_int(query, 0);
3582 logError("DatabaseHandler::getDomainOfSource database error!:", eCode);
3585 MY_SQLITE_FINALIZE(query)
3589 am_Error_e am::CAmDatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const
3593 sqlite3_stmt* query = NULL;
3594 std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3596 am_Error_e returnVal = E_DATABASE_ERROR;
3597 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3599 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3601 domainID = sqlite3_column_int(query, 0);
3606 logError("DatabaseHandler::getDomainOfSink database error!:", eCode);
3609 MY_SQLITE_FINALIZE(query)
3614 * checks for certain SinkClass
3615 * @param sinkClassID
3616 * @return true if it exists
3618 bool CAmDatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3620 sqlite3_stmt* query = NULL;
3621 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
3623 bool returnVal = true;
3624 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3625 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3627 else if (eCode != SQLITE_ROW)
3630 logError("DatabaseHandler::existSinkClass database error!:", eCode);
3633 MY_SQLITE_FINALIZE_BOOL(query)
3638 * checks for certain sourceClass
3639 * @param sourceClassID
3640 * @return true if it exists
3642 bool CAmDatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3644 sqlite3_stmt* query = NULL;
3645 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
3647 bool returnVal = true;
3648 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3650 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3652 else if (eCode != SQLITE_ROW)
3655 logError("DatabaseHandler::existSinkClass database error!:", eCode);
3658 MY_SQLITE_FINALIZE_BOOL(query)
3662 am_Error_e CAmDatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3664 assert(connectionID!=0);
3666 sqlite3_stmt *query = NULL, *queryMainConnectionSubIDs = NULL;
3667 int eCode = 0, eCode1 = 0;
3668 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3670 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3671 MY_SQLITE_BIND_INT(query, 1, delay)
3672 MY_SQLITE_BIND_INT(query, 2, connectionID)
3674 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3676 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:", eCode);
3677 MY_SQLITE_FINALIZE(query)
3678 return (E_DATABASE_ERROR);
3681 MY_SQLITE_FINALIZE(query)
3683 //now we need to find all mainConnections that use the changed connection and update their timing
3685 int tempMainConnectionID;
3686 //first get all route tables for all mainconnections
3687 command = "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'";
3688 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3690 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3692 //now check if the connection ID is in this table
3693 std::string tablename = std::string((const char*) sqlite3_column_text(query, 0));
3694 std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID);
3695 MY_SQLITE_PREPARE_V2(mpDatabase, command2.c_str(), -1, &queryMainConnectionSubIDs, NULL)
3696 if ((eCode1 = sqlite3_step(queryMainConnectionSubIDs)) == SQLITE_ROW)
3698 //if the connection ID is in, recalculate the mainconnection delay
3699 std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID;
3700 changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID), tempMainConnectionID);
3702 else if (eCode1 != SQLITE_DONE)
3704 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode1);
3706 return (E_DATABASE_ERROR);
3708 MY_SQLITE_FINALIZE(queryMainConnectionSubIDs)
3711 if (eCode != SQLITE_DONE)
3713 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode);
3714 MY_SQLITE_FINALIZE(query)
3715 return (E_DATABASE_ERROR);
3718 MY_SQLITE_FINALIZE(query)
3723 am_Error_e CAmDatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3725 assert(connectionID!=0);
3727 sqlite3_stmt *query = NULL;
3729 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3731 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3732 MY_SQLITE_BIND_INT(query, 1, connectionID)
3734 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3736 logError("DatabaseHandler::changeConnectionFinal SQLITE Step error code:", eCode);
3737 MY_SQLITE_FINALIZE(query)
3738 return (E_DATABASE_ERROR);
3741 MY_SQLITE_FINALIZE(query)
3745 am_timeSync_t CAmDatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3747 assert(mainConnectionID!=0);
3748 sqlite3_stmt* query = NULL;
3749 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";
3751 am_timeSync_t delay = 0;
3752 am_timeSync_t min = 0;
3753 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3754 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3756 delay = sqlite3_column_int(query, 0);
3757 min = sqlite3_column_int(query, 1);
3759 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3761 logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:", eCode);
3762 MY_SQLITE_FINALIZE(query)
3763 return (E_DATABASE_ERROR);
3766 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3768 logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:", eCode);
3769 return (E_DATABASE_ERROR);
3778 * registers the Observer at the Database
3779 * @param iObserver pointer to the observer
3781 void CAmDatabaseHandler::registerObserver(CAmDatabaseObserver *iObserver)
3783 assert(iObserver!=NULL);
3784 mpDatabaseObserver = iObserver;
3788 * gives information about the visibility of a source
3789 * @param sourceID the sourceID
3790 * @return true if source is visible
3792 bool CAmDatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3794 assert(sourceID!=0);
3795 sqlite3_stmt* query = NULL;
3796 std::string command = "SELECT visible FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3798 bool returnVal = false;
3799 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3801 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3803 returnVal = (bool) sqlite3_column_int(query, 0);
3805 else if (eCode != SQLITE_DONE)
3808 logError("DatabaseHandler::sourceVisible database error!:", eCode);
3811 MY_SQLITE_FINALIZE_BOOL(query)
3816 * gives information about the visibility of a sink
3817 * @param sinkID the sinkID
3818 * @return true if source is visible
3820 bool CAmDatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3822 sqlite3_stmt* query = NULL;
3823 std::string command = "SELECT visible FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3825 bool returnVal = false;
3826 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3827 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3829 returnVal = sqlite3_column_int(query, 0);
3831 else if (eCode != SQLITE_DONE)
3834 logError("DatabaseHandler::sinkVisible database error!:", eCode);
3837 MY_SQLITE_FINALIZE_BOOL(query)
3842 * checks if a connection already exists.
3843 * Only takes sink, source and format information for search!
3844 * @param connection the connection to be checked
3845 * @return true if connections exists
3847 bool CAmDatabaseHandler::existConnection(const am_Connection_s connection)
3849 sqlite3_stmt* query = NULL;
3850 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3852 bool returnVal = true;
3853 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3855 if ((eCode = sqlite3_bind_int(query, 1, connection.sinkID)))
3857 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3861 if ((eCode = sqlite3_bind_int(query, 2, connection.sourceID)))
3863 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3867 if ((eCode = sqlite3_bind_int(query, 3, connection.connectionFormat)))
3869 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3873 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3875 else if (eCode != SQLITE_ROW)
3878 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3881 MY_SQLITE_FINALIZE_BOOL(query)
3886 * checks if a connection with the given ID exists
3887 * @param connectionID
3888 * @return true if connection exits
3890 bool CAmDatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3892 sqlite3_stmt* query = NULL;
3893 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3895 bool returnVal = true;
3896 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3898 if ((eCode = sqlite3_bind_int(query, 1, connectionID)))
3900 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3904 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3906 else if (eCode != SQLITE_ROW)
3909 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3912 MY_SQLITE_FINALIZE_BOOL(query)
3917 * checks if a CrossFader exists
3918 * @param crossfaderID the ID of the crossfader to be checked
3919 * @return true if exists
3921 bool CAmDatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3923 sqlite3_stmt* query = NULL;
3924 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3926 bool returnVal = true;
3927 MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
3929 if ((eCode = sqlite3_bind_int(query, 1, crossfaderID)))
3931 logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode);
3935 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3937 else if (eCode != SQLITE_ROW)
3940 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3943 MY_SQLITE_FINALIZE_BOOL(query)
3947 am_Error_e CAmDatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3949 assert(sourceID!=0);
3950 sqlite3_stmt* query = NULL;
3951 sourceState = SS_UNKNNOWN;
3952 std::string command = "SELECT sourceState FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3954 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3955 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3957 sourceState = (am_SourceState_e) sqlite3_column_int(query, 0);
3959 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3961 logError("DatabaseHandler::getSoureState database error!:", eCode);
3963 MY_SQLITE_FINALIZE(query)
3967 am_Error_e CAmDatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3969 assert(sourceID!=0);
3970 assert(sourceState>=SS_UNKNNOWN && sourceState<=SS_MAX);
3971 sqlite3_stmt* query = NULL;
3972 std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID);
3974 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3975 MY_SQLITE_BIND_INT(query, 1, sourceState)
3976 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3978 logError("DatabaseHandler::changeSourceState SQLITE Step error code:", eCode);
3979 MY_SQLITE_FINALIZE(query)
3980 return (E_DATABASE_ERROR);
3983 MY_SQLITE_FINALIZE(query)
3987 am_Error_e CAmDatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3990 sqlite3_stmt* query = NULL;
3992 std::string command = "SELECT volume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3994 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
3995 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3997 volume = sqlite3_column_int(query, 0);
3999 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
4001 logError("DatabaseHandler::getSinkVolume database error!:", eCode);
4003 MY_SQLITE_FINALIZE(query)
4007 am_Error_e CAmDatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
4009 assert(sourceID!=0);
4010 sqlite3_stmt* query = NULL;
4012 std::string command = "SELECT volume FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
4014 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4015 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4017 volume = sqlite3_column_int(query, 0);
4019 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
4021 logError("DatabaseHandler::getSourceVolume database error!:", eCode);
4023 MY_SQLITE_FINALIZE(query)
4027 am_Error_e CAmDatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, int16_t & value) const
4030 if (!existSink(sinkID))
4031 return (E_DATABASE_ERROR); // todo: here we could change to non existent, but not shown in sequences
4033 sqlite3_stmt* query = NULL;
4035 std::string command = "SELECT value FROM SinkSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType);
4036 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4038 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4040 value = sqlite3_column_int(query, 0);
4044 logError("DatabaseHandler::getDomainState database error!:", eCode);
4045 MY_SQLITE_FINALIZE(query)
4046 return (E_DATABASE_ERROR);
4049 MY_SQLITE_FINALIZE(query)
4054 am_Error_e CAmDatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, int16_t & value) const
4056 assert(sourceID!=0);
4057 if (!existSource(sourceID))
4058 return (E_DATABASE_ERROR); // todo: here we could change to non existent, but not shown in sequences
4060 sqlite3_stmt* query = NULL;
4062 std::string command = "SELECT value FROM SourceSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType);
4063 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4065 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4067 value = sqlite3_column_int(query, 0);
4070 if (eCode != SQLITE_DONE)
4072 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode);
4073 MY_SQLITE_FINALIZE(query)
4074 return (E_DATABASE_ERROR);
4077 MY_SQLITE_FINALIZE(query)
4082 am_Error_e CAmDatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const
4084 assert(domainID!=0);
4085 sqlite3_stmt* query = NULL;
4087 std::string command = "SELECT domainState FROM " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
4089 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4090 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4092 state = (am_DomainState_e) sqlite3_column_int(query, 0);
4094 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
4096 logError("DatabaseHandler::getDomainState database error!:", eCode);
4098 MY_SQLITE_FINALIZE(query)
4103 am_Error_e CAmDatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
4106 sqlite3_stmt* query = NULL, *queryInsert = NULL;
4107 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
4108 int eCode = 0, eCode1 = 0;
4109 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4110 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
4111 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4113 domainID = sqlite3_column_int(query, 0);
4115 else if (eCode != SQLITE_DONE)
4117 logError("DatabaseHandler::peekDomain database error!:", eCode);
4118 MY_SQLITE_FINALIZE(query)
4119 return (E_DATABASE_ERROR);
4123 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
4124 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL)
4125 MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC)
4126 MY_SQLITE_BIND_INT(queryInsert, 2, 1)
4128 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
4130 logError("DatabaseHandler::peekDomain SQLITE Step error code:", eCode1);
4131 MY_SQLITE_FINALIZE(queryInsert)
4132 MY_SQLITE_FINALIZE(query)
4133 return (E_DATABASE_ERROR);
4136 MY_SQLITE_FINALIZE(queryInsert)
4138 domainID = sqlite3_last_insert_rowid(mpDatabase);
4140 MY_SQLITE_FINALIZE(query)
4145 am_Error_e CAmDatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
4147 sqlite3_stmt* query = NULL, *queryInsert = NULL;
4148 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
4149 int eCode = 0, eCode1 = 0;
4150 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4151 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
4152 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4154 sinkID = sqlite3_column_int(query, 0);
4156 else if (eCode != SQLITE_DONE)
4158 logError("DatabaseHandler::peekSink database error!:", eCode);
4159 MY_SQLITE_FINALIZE(query)
4160 return (E_DATABASE_ERROR);
4164 if (mFirstStaticSink)
4166 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
4167 mFirstStaticSink = false;
4171 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
4173 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL)
4174 MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC)
4175 MY_SQLITE_BIND_INT(queryInsert, 2, 1)
4177 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
4179 logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1);
4180 MY_SQLITE_FINALIZE(queryInsert)
4181 MY_SQLITE_FINALIZE(query)
4182 return (E_DATABASE_ERROR);
4185 MY_SQLITE_FINALIZE(queryInsert)
4187 sinkID = sqlite3_last_insert_rowid(mpDatabase);
4189 MY_SQLITE_FINALIZE(query)
4193 am_Error_e CAmDatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
4195 sqlite3_stmt* query = NULL, *queryInsert = NULL;
4196 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
4197 int eCode = 0, eCode1 = 0;
4198 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4199 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
4200 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4202 sourceID = sqlite3_column_int(query, 0);
4204 else if (eCode != SQLITE_DONE)
4206 logError("DatabaseHandler::peekSink database error!:", eCode);
4207 MY_SQLITE_FINALIZE(query)
4208 return (E_DATABASE_ERROR);
4212 if (mFirstStaticSource)
4214 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
4215 mFirstStaticSource = false;
4219 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
4221 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL)
4222 MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC)
4223 MY_SQLITE_BIND_INT(queryInsert, 2, 1)
4225 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
4227 logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1);
4228 MY_SQLITE_FINALIZE(queryInsert)
4229 MY_SQLITE_FINALIZE(query)
4230 return (E_DATABASE_ERROR);
4233 MY_SQLITE_FINALIZE(queryInsert)
4234 sourceID = sqlite3_last_insert_rowid(mpDatabase);
4237 MY_SQLITE_FINALIZE(query)
4241 am_Error_e CAmDatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
4245 sqlite3_stmt* query = NULL;
4247 std::string command;
4249 if (!existSink(sinkID))
4251 return (E_NON_EXISTENT);
4253 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
4254 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4255 MY_SQLITE_BIND_INT(query, 1, volume)
4256 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4258 logError("DatabaseHandler::changeSinkVolume SQLITE Step error code:", eCode);
4259 MY_SQLITE_FINALIZE(query)
4260 return (E_DATABASE_ERROR);
4263 MY_SQLITE_FINALIZE(query)
4264 logInfo("DatabaseHandler::changeSinkVolume changed volume of sink:", sinkID, "to:", volume);
4268 am_Error_e CAmDatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
4270 assert(sourceID!=0);
4272 sqlite3_stmt* query = NULL;
4274 std::string command;
4276 if (!existSource(sourceID))
4278 return (E_NON_EXISTENT);
4280 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
4281 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4282 MY_SQLITE_BIND_INT(query, 1, volume)
4283 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4285 logError("DatabaseHandler::changeSourceVolume SQLITE Step error code:", eCode);
4286 MY_SQLITE_FINALIZE(query)
4287 return (E_DATABASE_ERROR);
4290 MY_SQLITE_FINALIZE(query)
4291 logInfo("DatabaseHandler::changeSourceVolume changed volume of source=:", sourceID, "to:", volume);
4296 am_Error_e CAmDatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
4298 assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX);
4299 assert(sourceID!=0);
4301 sqlite3_stmt* query = NULL;
4303 std::string command;
4305 if (!existSource(sourceID))
4307 return (E_NON_EXISTENT);
4309 command = "UPDATE SourceSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
4310 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4311 MY_SQLITE_BIND_INT(query, 1, soundProperty.value)
4312 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4314 logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:", eCode);
4315 MY_SQLITE_FINALIZE(query)
4316 return (E_DATABASE_ERROR);
4319 MY_SQLITE_FINALIZE(query)
4320 logInfo("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value);
4324 am_Error_e CAmDatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
4326 assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX);
4329 sqlite3_stmt* query = NULL;
4331 std::string command;
4333 if (!existSink(sinkID))
4335 return (E_NON_EXISTENT);
4337 command = "UPDATE SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
4338 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4339 MY_SQLITE_BIND_INT(query, 1, soundProperty.value)
4340 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4342 logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:", eCode);
4343 MY_SQLITE_FINALIZE(query)
4344 return (E_DATABASE_ERROR);
4348 MY_SQLITE_FINALIZE(query)
4349 logInfo("DatabaseHandler::changeSinkSoundPropertyDB changed SinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value);
4353 am_Error_e CAmDatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
4355 assert(crossfaderID!=0);
4356 assert(hotsink>=HS_UNKNOWN && hotsink>=HS_MAX);
4358 sqlite3_stmt* query = NULL;
4360 std::string command;
4362 if (!existcrossFader(crossfaderID))
4364 return (E_NON_EXISTENT);
4366 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
4367 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4368 MY_SQLITE_BIND_INT(query, 1, hotsink)
4369 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4371 logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:", eCode);
4372 MY_SQLITE_FINALIZE(query)
4373 return (E_DATABASE_ERROR);
4375 MY_SQLITE_FINALIZE(query)
4376 logInfo("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader=", crossfaderID, "to:", hotsink);
4380 am_Error_e CAmDatabaseHandler::getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree)
4382 sqlite3_stmt* query = NULL;
4385 std::string command;
4386 am_domainID_t rootID = tree.returnRootDomainID();
4387 CAmRoutingTreeItem *parent = tree.returnRootItem();
4391 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 )";
4395 command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=?";
4402 parent = flatTree.at(i - 1);
4403 rootID = parent->returnDomainID();
4405 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4406 MY_SQLITE_BIND_INT(query, 1, rootID)
4408 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4410 // additional check to avoid cyclic routes
4411 const am_domainID_t domainSourceID = sqlite3_column_int(query, 0);
4412 bool sourceDomainAlreadyHandledAsSink = false;
4413 for (std::vector<CAmRoutingTreeItem*>::const_iterator iFT = flatTree.begin(); iFT != flatTree.end(); ++iFT)
4415 if (domainSourceID == (*iFT)->returnParent()->returnDomainID()) sourceDomainAlreadyHandledAsSink = true;
4418 if (!sourceDomainAlreadyHandledAsSink)
4420 // logInfo("DatabaseHandler::getRoutingTree ", rootID, ", ", domainSourceID, ", ", sqlite3_column_int(query, 1));
4421 flatTree.push_back(tree.insertItem(domainSourceID, sqlite3_column_int(query, 1), parent));
4425 if (eCode != SQLITE_DONE)
4427 logError("DatabaseHandler::getRoutingTree SQLITE error code:", eCode);
4428 MY_SQLITE_FINALIZE(query)
4429 return (E_DATABASE_ERROR);
4432 MY_SQLITE_FINALIZE(query)
4434 } while (flatTree.size() > (i - 1));
4439 am_Error_e am::CAmDatabaseHandler::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID)
4442 return (E_NON_EXISTENT);
4444 am_Error_e returnVal = E_NON_EXISTENT;
4445 sqlite3_stmt* query = NULL;
4447 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE name=?";
4448 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4449 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
4451 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4453 sinkClassID = sqlite3_column_int(query, 0);
4456 else if (eCode != SQLITE_DONE)
4459 logError("DatabaseHandler::peekSinkClassID SQLITE error code:", eCode);
4460 MY_SQLITE_FINALIZE(query)
4461 returnVal = E_DATABASE_ERROR;
4464 MY_SQLITE_FINALIZE(query)
4468 am_Error_e am::CAmDatabaseHandler::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID)
4471 return (E_NON_EXISTENT);
4473 am_Error_e returnVal = E_NON_EXISTENT;
4474 sqlite3_stmt* query = NULL;
4476 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE name=?";
4477 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4478 MY_SQLITE_BIND_TEXT(query, 1, name.c_str(), name.size(), SQLITE_STATIC)
4480 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4482 sourceClassID = sqlite3_column_int(query, 0);
4485 else if (eCode != SQLITE_DONE)
4488 logError("DatabaseHandler::peekSourceClassID SQLITE error code:", eCode);
4489 MY_SQLITE_FINALIZE(query)
4490 returnVal = E_DATABASE_ERROR;
4493 MY_SQLITE_FINALIZE(query)
4498 am_Error_e CAmDatabaseHandler::changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_ConnectionFormat_e>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties)
4500 assert(sourceID!=0);
4502 sqlite3_stmt* query = NULL;
4504 std::string command;
4505 am_sourceClass_t sourceClassOut(sourceClassID);
4506 std::vector<am_MainSoundProperty_s> listMainSoundPropertiesOut(listMainSoundProperties);
4508 if (!existSource(sourceID))
4510 return (E_NON_EXISTENT);
4513 //check if sinkClass needs to be changed
4514 if (sourceClassID!=0)
4516 command = "UPDATE"+ std::string(SOURCE_TABLE)+ " SET sourceClassID=? WHERE sourceID=" + i2s(sourceID);
4517 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4518 MY_SQLITE_BIND_INT(query, 1, sourceClassID)
4519 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4521 logError("DatabaseHandler::changeSource SQLITE Step error code:", eCode);
4522 MY_SQLITE_FINALIZE(query)
4523 return (E_DATABASE_ERROR);
4525 MY_SQLITE_FINALIZE(query);
4528 else //we need to read out the active one
4530 command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 and sourceID=" + i2s(sourceID);
4531 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4533 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4535 sourceClassOut = sqlite3_column_int(query, 0);
4537 MY_SQLITE_FINALIZE(query)
4540 //check if soundProperties need to be updated
4541 if (!listSoundProperties.empty())
4543 //first we drop the table
4544 command = "DELETE from SourceSoundProperty" + i2s(sourceID);
4545 if (!sqQuery(command))
4546 return (E_DATABASE_ERROR);
4548 //then we'll have a new one
4549 //Fill SinkSoundProperties
4550 command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
4551 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4552 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = listSoundProperties.begin();
4553 for (; SoundPropertyIterator < listSoundProperties.end(); ++SoundPropertyIterator)
4555 MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type)
4556 MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value)
4557 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4559 logError("DatabaseHandler::changeSource SQLITE Step error code:", eCode);
4560 MY_SQLITE_FINALIZE(query)
4561 return (E_DATABASE_ERROR);
4563 MY_SQLITE_RESET(query)
4565 MY_SQLITE_FINALIZE(query)
4568 //check if we have to update the list of connectionformats
4569 if (!listConnectionFormats.empty())
4571 //first clear the table
4572 command = "DELETE from SourceConnectionFormat" + i2s(sourceID);
4573 if (!sqQuery(command))
4574 return (E_DATABASE_ERROR);
4576 //fill ConnectionFormats
4577 command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
4578 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4579 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = listConnectionFormats.begin();
4580 for (; connectionFormatIterator < listConnectionFormats.end(); ++connectionFormatIterator)
4582 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
4583 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4585 logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode);
4586 MY_SQLITE_FINALIZE(query)
4587 return (E_DATABASE_ERROR);
4589 MY_SQLITE_RESET(query)
4591 MY_SQLITE_FINALIZE(query)
4594 //then we need to check if we need to update the listMainSoundProperties
4595 if (!listMainSoundProperties.empty() && sourceVisible(sourceID))
4597 command = "DELETE from SourceMainSoundProperty" + i2s(sourceID);
4598 if (!sqQuery(command))
4599 return (E_DATABASE_ERROR);
4601 //Fill MainSinkSoundProperties
4602 command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
4603 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4604 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = listMainSoundProperties.begin();
4605 for (; mainSoundPropertyIterator < listMainSoundProperties.end(); ++mainSoundPropertyIterator)
4607 MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type)
4608 MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value)
4609 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4611 logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode);
4612 MY_SQLITE_FINALIZE(query)
4613 return (E_DATABASE_ERROR);
4615 MY_SQLITE_RESET(query)
4617 MY_SQLITE_FINALIZE(query)
4619 else //read out the properties
4621 getListMainSourceSoundProperties(sourceID,listMainSoundPropertiesOut);
4624 logInfo("DatabaseHandler::changeSource changed changeSink of source:", sourceID);
4626 if (mpDatabaseObserver != NULL)
4628 mpDatabaseObserver->sourceUpdated(sourceID,sourceClassOut,listMainSoundPropertiesOut,sourceVisible(sourceID));
4635 am_Error_e CAmDatabaseHandler::changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_ConnectionFormat_e>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties)
4639 sqlite3_stmt* query = NULL;
4641 std::string command;
4642 am_sinkClass_t sinkClassOut(sinkClassID);
4643 std::vector<am_MainSoundProperty_s> listMainSoundPropertiesOut(listMainSoundProperties);
4645 if (!existSink(sinkID))
4647 return (E_NON_EXISTENT);
4650 //check if sinkClass needs to be changed
4653 command = "UPDATE"+ std::string(SINK_TABLE)+ " SET sinkClassID=? WHERE sinkID=" + i2s(sinkID);
4654 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4655 MY_SQLITE_BIND_INT(query, 1, sinkClassID)
4656 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4658 logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode);
4659 MY_SQLITE_FINALIZE(query)
4660 return (E_DATABASE_ERROR);
4662 MY_SQLITE_FINALIZE(query);
4665 else //we need to read out the active one
4667 command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 and sinkID=" + i2s(sinkID);
4668 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4670 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4672 sinkClassOut = sqlite3_column_int(query, 0);
4674 MY_SQLITE_FINALIZE(query)
4677 //check if soundProperties need to be updated
4678 if (!listSoundProperties.empty())
4680 //first we drop the table
4681 command = "DELETE from SinkSoundProperty" + i2s(sinkID);
4682 if (!sqQuery(command))
4683 return (E_DATABASE_ERROR);
4685 //then we'll have a new one
4686 //Fill SinkSoundProperties
4687 command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
4688 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4689 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = listSoundProperties.begin();
4690 for (; SoundPropertyIterator < listSoundProperties.end(); ++SoundPropertyIterator)
4692 MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type)
4693 MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value)
4694 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4696 logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode);
4697 MY_SQLITE_FINALIZE(query)
4698 return (E_DATABASE_ERROR);
4700 MY_SQLITE_RESET(query)
4702 MY_SQLITE_FINALIZE(query)
4705 //check if we have to update the list of connectionformats
4706 if (!listConnectionFormats.empty())
4708 //first clear the table
4709 command = "DELETE from SinkConnectionFormat" + i2s(sinkID);
4710 if (!sqQuery(command))
4711 return (E_DATABASE_ERROR);
4713 //fill ConnectionFormats
4714 command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
4715 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4716 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = listConnectionFormats.begin();
4717 for (; connectionFormatIterator < listConnectionFormats.end(); ++connectionFormatIterator)
4719 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
4720 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4722 logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode);
4723 MY_SQLITE_FINALIZE(query)
4724 return (E_DATABASE_ERROR);
4726 MY_SQLITE_RESET(query)
4728 MY_SQLITE_FINALIZE(query)
4731 //then we need to check if we need to update the listMainSoundProperties
4732 if (!listMainSoundProperties.empty() && sinkVisible(sinkID))
4734 command = "DELETE from SinkMainSoundProperty" + i2s(sinkID);
4735 if (!sqQuery(command))
4736 return (E_DATABASE_ERROR);
4738 //Fill MainSinkSoundProperties
4739 command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
4740 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4741 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = listMainSoundProperties.begin();
4742 for (; mainSoundPropertyIterator < listMainSoundProperties.end(); ++mainSoundPropertyIterator)
4744 MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type)
4745 MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value)
4746 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4748 logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode);
4749 MY_SQLITE_FINALIZE(query)
4750 return (E_DATABASE_ERROR);
4752 MY_SQLITE_RESET(query)
4754 MY_SQLITE_FINALIZE(query)
4756 else //read out the properties
4758 getListMainSinkSoundProperties(sinkID,listMainSoundPropertiesOut);
4761 logInfo("DatabaseHandler::changeSink changed changeSink of sink:", sinkID);
4763 if (mpDatabaseObserver != NULL)
4765 mpDatabaseObserver->sinkUpdated(sinkID,sinkClassOut,listMainSoundPropertiesOut,sinkVisible(sinkID));
4771 am_Error_e CAmDatabaseHandler::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations)
4774 if (!existSink(sinkID))
4775 return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences
4776 listMainNotificationConfigurations.clear();
4778 sqlite3_stmt* query = NULL;
4780 am_NotificationConfiguration_s temp;
4781 std::string command = "SELECT type, status, parameter FROM SinkMainNotificationConfiguration" + i2s(sinkID);
4782 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4784 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4786 temp.type = static_cast<am_NotificationType_e>(sqlite3_column_int(query, 0));
4787 temp.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(query, 1));
4788 temp.parameter= static_cast<int16_t>(sqlite3_column_int(query, 2));
4789 listMainNotificationConfigurations.push_back(temp);
4792 if (eCode != SQLITE_DONE)
4794 logError("DatabaseHandler::getListSinkMainNotificationConfigurations SQLITE error code:", eCode);
4795 MY_SQLITE_FINALIZE(query)
4796 return (E_DATABASE_ERROR);
4799 MY_SQLITE_FINALIZE(query)
4805 am_Error_e CAmDatabaseHandler::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations)
4807 assert(sourceID!=0);
4808 if (!existSource(sourceID))
4809 return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences
4810 listMainNotificationConfigurations.clear();
4812 sqlite3_stmt* query = NULL;
4814 am_NotificationConfiguration_s temp;
4815 std::string command = "SELECT type, status, parameter FROM SourceMainNotificationConfiguration" + i2s(sourceID);
4816 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4818 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4820 temp.type = static_cast<am_NotificationType_e>(sqlite3_column_int(query, 0));
4821 temp.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(query, 1));
4822 temp.parameter= static_cast<int16_t>(sqlite3_column_int(query, 2));
4823 listMainNotificationConfigurations.push_back(temp);
4826 if (eCode != SQLITE_DONE)
4828 logError("DatabaseHandler::getListSourceMainNotificationConfigurations SQLITE error code:", eCode);
4829 MY_SQLITE_FINALIZE(query)
4830 return (E_DATABASE_ERROR);
4833 MY_SQLITE_FINALIZE(query)
4838 am_Error_e CAmDatabaseHandler::changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration)
4842 sqlite3_stmt* query = NULL;
4844 std::string command;
4846 if (!existSink(sinkID))
4848 return (E_NON_EXISTENT);
4850 command = "UPDATE SinkMainNotificationConfiguration" + i2s(sinkID) + " SET status=?, parameter=? WHERE type=" + i2s(mainNotificationConfiguration.type);
4851 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4852 MY_SQLITE_BIND_INT(query, 1, mainNotificationConfiguration.status)
4853 MY_SQLITE_BIND_INT(query, 2, mainNotificationConfiguration.parameter)
4854 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4856 logError("DatabaseHandler::changeMainSinkNotificationConfigurationDB SQLITE Step error code:", eCode);
4857 MY_SQLITE_FINALIZE(query)
4858 return (E_DATABASE_ERROR);
4860 MY_SQLITE_FINALIZE(query)
4862 logInfo("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter);
4864 if (mpDatabaseObserver)
4865 mpDatabaseObserver->sinkMainNotificationConfigurationChanged(sinkID, mainNotificationConfiguration);
4869 am_Error_e CAmDatabaseHandler::changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration)
4871 assert(sourceID!=0);
4873 sqlite3_stmt* query = NULL;
4875 std::string command;
4877 if (!existSource(sourceID))
4879 return (E_NON_EXISTENT);
4881 command = "UPDATE SourceMainNotificationConfiguration" + i2s(sourceID) + " SET status=?, parameter=? WHERE type=" + i2s(mainNotificationConfiguration.type);
4882 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4883 MY_SQLITE_BIND_INT(query, 1, mainNotificationConfiguration.status)
4884 MY_SQLITE_BIND_INT(query, 2, mainNotificationConfiguration.parameter)
4885 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4887 logError("DatabaseHandler::changeMainSourceNotificationConfigurationDB SQLITE Step error code:", eCode);
4888 MY_SQLITE_FINALIZE(query)
4889 return (E_DATABASE_ERROR);
4891 MY_SQLITE_FINALIZE(query)
4893 logInfo("DatabaseHandler::changeMainSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter);
4895 if (mpDatabaseObserver)
4896 mpDatabaseObserver->sourceMainNotificationConfigurationChanged(sourceID, mainNotificationConfiguration);
4900 am_Error_e CAmDatabaseHandler::changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_ConnectionFormat_e>& listSourceConnectionFormats, const std::vector<am_ConnectionFormat_e>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix)
4902 assert(gatewayID!=0);
4904 sqlite3_stmt* query = NULL;
4906 std::string command;
4908 if (!existGateway(gatewayID))
4910 return (E_NON_EXISTENT);
4913 if (!listSourceConnectionFormats.empty())
4916 command = "DELETE from GatewaySourceFormat" + i2s(gatewayID);
4917 if (!sqQuery(command))
4918 return (E_DATABASE_ERROR);
4920 //fill ConnectionFormats
4921 command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
4922 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4923 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = listSourceConnectionFormats.begin();
4924 for (; connectionFormatIterator < listSourceConnectionFormats.end(); ++connectionFormatIterator)
4926 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
4927 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4929 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
4930 MY_SQLITE_FINALIZE(query)
4931 return (E_DATABASE_ERROR);
4933 MY_SQLITE_RESET(query)
4935 MY_SQLITE_FINALIZE(query)
4938 if (!listSinkConnectionFormats.empty())
4941 command = "DELETE from GatewaySinkFormat" + i2s(gatewayID);
4942 if (!sqQuery(command))
4943 return (E_DATABASE_ERROR);
4945 command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
4946 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4947 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = listSinkConnectionFormats.begin();
4948 for (; connectionFormatIterator < listSinkConnectionFormats.end(); ++connectionFormatIterator)
4950 MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
4951 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4953 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
4954 MY_SQLITE_FINALIZE(query)
4955 return (E_DATABASE_ERROR);
4957 MY_SQLITE_RESET(query)
4959 MY_SQLITE_FINALIZE(query)
4962 if (!convertionMatrix.empty())
4964 mListConnectionFormat.clear();
4965 mListConnectionFormat.insert(std::make_pair(gatewayID, convertionMatrix));
4968 logInfo("DatabaseHandler::changeGatewayDB changed Gateway with ID", gatewayID);
4970 //todo: check if observer needs to be adopted.
4974 am_Error_e CAmDatabaseHandler::changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s notificationConfiguration)
4978 sqlite3_stmt* query = NULL;
4980 std::string command;
4982 if (!existSink(sinkID))
4984 return (E_NON_EXISTENT);
4986 command = "UPDATE SinkNotificationConfiguration" + i2s(sinkID) + " SET status=?, parameter=? WHERE type=" + i2s(notificationConfiguration.type);
4987 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
4988 MY_SQLITE_BIND_INT(query, 1, notificationConfiguration.status)
4989 MY_SQLITE_BIND_INT(query, 2, notificationConfiguration.parameter)
4990 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4992 logError("DatabaseHandler::changeMainSinkNotificationConfigurationDB SQLITE Step error code:", eCode);
4993 MY_SQLITE_FINALIZE(query)
4994 return (E_DATABASE_ERROR);
4996 MY_SQLITE_FINALIZE(query)
4998 logInfo("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", notificationConfiguration.type, "to status=", notificationConfiguration.status, "and parameter=",notificationConfiguration.parameter);
5000 //todo:: inform obsever here...
5004 am_Error_e CAmDatabaseHandler::changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s notificationConfiguration)
5006 assert(sourceID!=0);
5008 sqlite3_stmt* query = NULL;
5010 std::string command;
5012 if (!existSource(sourceID))
5014 return (E_NON_EXISTENT);
5016 command = "UPDATE SourceNotificationConfiguration" + i2s(sourceID) + " SET status=?, parameter=? WHERE type=" + i2s(notificationConfiguration.type);
5017 MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
5018 MY_SQLITE_BIND_INT(query, 1, notificationConfiguration.status)
5019 MY_SQLITE_BIND_INT(query, 2, notificationConfiguration.parameter)
5020 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
5022 logError("DatabaseHandler::changeMainSourceNotificationConfigurationDB SQLITE Step error code:", eCode);
5023 MY_SQLITE_FINALIZE(query)
5024 return (E_DATABASE_ERROR);
5026 MY_SQLITE_FINALIZE(query)
5028 logInfo("DatabaseHandler::changeSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", notificationConfiguration.type, "to status=", notificationConfiguration.status, "and parameter=",notificationConfiguration.parameter);
5030 //todo:: implement observer function
5034 void CAmDatabaseHandler::createTables()
5036 for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++)
5038 if (!sqQuery("CREATE TABLE " + databaseTables[i]))
5039 throw std::runtime_error("CAmDatabaseHandler Could not create tables!");