2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file Databasehandler.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG Christian Mueller Christian.ei.mueller@bmw.de
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
25 #include "DatabaseHandler.h"
26 #include "DatabaseObserver.h"
32 #include "DLTWrapper.h"
35 #define DOMAIN_TABLE "Domains"
36 #define SOURCE_CLASS_TABLE "SourceClasses"
37 #define SINK_CLASS_TABLE "SinkClasses"
38 #define SOURCE_TABLE "Sources"
39 #define SINK_TABLE "Sinks"
40 #define GATEWAY_TABLE "Gateways"
41 #define CROSSFADER_TABLE "Crossfaders"
42 #define CONNECTION_TABLE "Connections"
43 #define MAINCONNECTION_TABLE "MainConnections"
44 #define INTERRUPT_TABLE "Interrupts"
45 #define MAIN_TABLE "MainTable"
46 #define SYSTEM_TABLE "SystemProperties"
50 const std::string databaseTables[] =
51 { " 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);", //
52 " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", //
53 " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", //
54 " 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);", //
55 " 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);", //
56 " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER);", //
57 " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);", //
58 " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);", //
59 " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);", //
60 " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);" };
63 * template to converts T to std::string
64 * @param i the value to be converted
68 inline std::string i2s(T const& x)
75 DatabaseHandler::DatabaseHandler(std::string databasePath) :
77 mPath(databasePath), //
78 mDatabaseObserver(NULL), //
79 mFirstStaticSink(true), //
80 mFirstStaticSource(true), //
81 mFirstStaticGateway(true), //
82 mFirstStaticSinkClass(true), //
83 mFirstStaticSourceClass(true), //
84 mFirstStaticCrossfader(true), //
85 mListConnectionFormat()
88 std::ifstream infile(mPath.c_str());
92 remove(mPath.c_str());
93 logInfo("DatabaseHandler::DatabaseHandler Knocked down database");
96 bool dbOpen = openDatabase();
99 logInfo("DatabaseHandler::DatabaseHandler problems opening the database!");
105 DatabaseHandler::~DatabaseHandler()
107 logInfo("Closed Database");
108 sqlite3_close(mDatabase);
111 am_Error_e DatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
113 assert(domainData.domainID==0);
114 assert(!domainData.name.empty());
115 assert(!domainData.busname.empty());
116 assert(domainData.state>=DS_UNKNOWN && domainData.state<=DS_MAX);
118 //first check for a reserved domain
119 sqlite3_stmt* query = NULL, *queryFinal;
121 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
122 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
123 sqlite3_bind_text(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC);
124 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
126 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" + i2s(sqlite3_column_int(query, 0));
128 else if (eCode == SQLITE_DONE)
131 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)";
135 logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode);
136 return E_DATABASE_ERROR;
139 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
141 logError("DatabaseHandler::enterDomainDB SQLITE Finalize error code:", eCode);
142 return E_DATABASE_ERROR;
145 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
146 sqlite3_bind_text(queryFinal, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC);
147 sqlite3_bind_text(queryFinal, 2, domainData.busname.c_str(), domainData.busname.size(), SQLITE_STATIC);
148 sqlite3_bind_text(queryFinal, 3, domainData.nodename.c_str(), domainData.nodename.size(), SQLITE_STATIC);
149 sqlite3_bind_int(queryFinal, 4, domainData.early);
150 sqlite3_bind_int(queryFinal, 5, domainData.complete);
151 sqlite3_bind_int(queryFinal, 6, domainData.state);
152 sqlite3_bind_int(queryFinal, 7, 0);
154 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
156 logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode);
157 return E_DATABASE_ERROR;
160 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
162 logError("DatabaseHandler::enterDomainDB SQLITE Finalize error code:", eCode);
163 return E_DATABASE_ERROR;
166 domainID = sqlite3_last_insert_rowid(mDatabase);
167 logInfo("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID);
169 am_Domain_s domain = domainData;
170 domain.domainID = domainID;
171 if (mDatabaseObserver)
172 mDatabaseObserver->newDomain(domain);
177 am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
179 assert(mainConnectionData.mainConnectionID==0);
180 assert(mainConnectionData.connectionState>=CS_UNKNOWN && mainConnectionData.connectionState<=CS_MAX);
181 assert(mainConnectionData.sinkID!=0);
182 assert(mainConnectionData.sourceID!=0);
184 sqlite3_stmt* query = NULL;
187 std::string command = "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)";
188 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
189 sqlite3_bind_int(query, 1, mainConnectionData.sourceID);
190 sqlite3_bind_int(query, 2, mainConnectionData.sinkID);
191 sqlite3_bind_int(query, 3, mainConnectionData.connectionState);
193 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
195 logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode);
196 return E_DATABASE_ERROR;
199 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
201 logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode);
202 return E_DATABASE_ERROR;
205 connectionID = sqlite3_last_insert_rowid(mDatabase);
207 //now check the connectionTable for all connections in the route. IF connectionID exist
208 command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?");
209 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
210 std::vector<am_connectionID_t>::const_iterator elementIterator = mainConnectionData.listConnectionID.begin();
211 for (; elementIterator < mainConnectionData.listConnectionID.end(); ++elementIterator)
213 sqlite3_bind_int(query, 1, *elementIterator);
215 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
217 int16_t temp_delay = sqlite3_column_int(query, 1);
218 if (temp_delay != -1 && delay != -1)
225 logError("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:", eCode);
226 return E_DATABASE_ERROR;
228 sqlite3_reset(query);
231 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
233 logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode);
234 return E_DATABASE_ERROR;
237 //now we create a table with references to the connections;
238 command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
239 assert(this->sqQuery(command));
241 command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
242 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
243 std::vector<am_connectionID_t>::const_iterator listConnectionIterator(mainConnectionData.listConnectionID.begin());
244 for (; listConnectionIterator < mainConnectionData.listConnectionID.end(); ++listConnectionIterator)
246 sqlite3_bind_int(query, 1, *listConnectionIterator);
247 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
249 logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode);
250 return E_DATABASE_ERROR;
252 sqlite3_reset(query);
255 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
257 logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode);
258 return E_DATABASE_ERROR;
261 logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID);
263 if (mDatabaseObserver)
265 mDatabaseObserver->numberOfMainConnectionsChanged();
266 mDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState);
269 //finally, we update the delay value for the maintable
272 return changeDelayMainConnection(delay, connectionID);
275 am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
277 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
278 assert(sinkData.domainID!=0);
279 assert(!sinkData.name.empty());
280 assert(sinkData.sinkClassID!=0);
281 // \todo: need to check if class exists?
282 assert(!sinkData.listConnectionFormats.empty());
283 assert(sinkData.muteState>=MS_UNKNOWN && sinkData.muteState<=MS_MAX);
285 sqlite3_stmt *query = NULL, *queryFinal = NULL;
287 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
289 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
290 sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
292 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
294 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));
296 else if (eCode == SQLITE_DONE)
298 //if sinkID is zero and the first Static Sink was already entered, the ID is created
299 if (sinkData.sinkID == 0 && !mFirstStaticSink && !existSinkName(sinkData.name))
301 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
305 //check if the ID already exists
306 if (existSinkNameOrID(sinkData.sinkID, sinkData.name))
308 sqlite3_finalize(query);
309 return E_ALREADY_EXISTS;
311 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
316 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
317 sqlite3_finalize(query);
318 return E_DATABASE_ERROR;
321 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
323 logError("DatabaseHandler::enterSinkDB SQLITE Finalize error code:", eCode);
324 return E_DATABASE_ERROR;
327 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
328 sqlite3_bind_text(queryFinal, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
329 sqlite3_bind_int(queryFinal, 2, sinkData.domainID);
330 sqlite3_bind_int(queryFinal, 3, sinkData.sinkClassID);
331 sqlite3_bind_int(queryFinal, 4, sinkData.volume);
332 sqlite3_bind_int(queryFinal, 5, sinkData.visible);
333 sqlite3_bind_int(queryFinal, 6, sinkData.available.availability);
334 sqlite3_bind_int(queryFinal, 7, sinkData.available.availabilityReason);
335 sqlite3_bind_int(queryFinal, 8, sinkData.muteState);
336 sqlite3_bind_int(queryFinal, 9, sinkData.mainVolume);
337 sqlite3_bind_int(queryFinal, 10, 0);
339 //if the ID is not created, we add it to the query
340 if (sinkData.sinkID != 0)
342 sqlite3_bind_int(queryFinal, 11, sinkData.sinkID);
345 //if the first static sink is entered, we need to set it onto the boundary
346 else if (mFirstStaticSink)
348 sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY);
349 mFirstStaticSink = false;
352 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
354 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
355 sqlite3_finalize(queryFinal);
356 return E_DATABASE_ERROR;
359 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
361 logError("DatabaseHandler::enterSinkDB SQLITE Finalize error code:", eCode);
362 return E_DATABASE_ERROR;
365 //now read back the sinkID
366 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
367 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
368 sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
369 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
371 sinkID = sqlite3_column_int(query, 0);
376 logError("DatabaseHandler::existSink database error!:", eCode);
377 sqlite3_finalize(query);
378 return E_DATABASE_ERROR;
380 sqlite3_finalize(query);
382 //now we need to create the additional tables:
383 command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
384 assert(this->sqQuery(command));
385 command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
386 assert(this->sqQuery(command));
388 //fill ConnectionFormats
389 command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
390 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
391 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin();
392 for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator)
394 sqlite3_bind_int(query, 1, *connectionFormatIterator);
395 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
397 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
398 sqlite3_finalize(query);
399 return E_DATABASE_ERROR;
401 sqlite3_reset(query);
404 //Fill SinkSoundProperties
405 command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
406 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
407 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin();
408 for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator)
410 sqlite3_bind_int(query, 1, SoundPropertyIterator->type);
411 sqlite3_bind_int(query, 2, SoundPropertyIterator->value);
412 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
414 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
415 sqlite3_finalize(query);
416 return E_DATABASE_ERROR;
418 sqlite3_reset(query);
421 if (sinkData.visible == true)
423 command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
424 assert(this->sqQuery(command));
426 //Fill MainSinkSoundProperties
427 command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
428 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
429 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin();
430 for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
432 sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type);
433 sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value);
434 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
436 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
437 sqlite3_finalize(query);
438 return E_DATABASE_ERROR;
440 sqlite3_reset(query);
444 logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sinkData.name, "domainID:", sinkData.domainID, "classID:", sinkData.sinkClassID, "volume:", sinkData.volume, "assigned ID:", sinkID);
445 am_Sink_s sink = sinkData;
446 sink.sinkID = sinkID;
447 if (mDatabaseObserver != NULL)
448 mDatabaseObserver->newSink(sink);
452 am_Error_e DatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
454 assert(crossfaderData.crossfaderID<DYNAMIC_ID_BOUNDARY);
455 assert(crossfaderData.hotSink>=HS_UNKNOWN && crossfaderData.hotSink<=HS_MAX);
456 assert(!crossfaderData.name.empty());
457 assert(existSink(crossfaderData.sinkID_A));
458 assert(existSink(crossfaderData.sinkID_B));
459 assert(existSource(crossfaderData.sourceID));
461 sqlite3_stmt* query = NULL;
465 //if gatewayData is zero and the first Static Sink was already entered, the ID is created
466 if (crossfaderData.crossfaderID == 0 && !mFirstStaticCrossfader)
468 command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink) VALUES (?,?,?,?,?)";
472 //check if the ID already exists
473 if (existcrossFader(crossfaderData.crossfaderID))
474 return E_ALREADY_EXISTS;
475 command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink, crossfaderID) VALUES (?,?,?,?,?,?)";
478 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
480 sqlite3_bind_text(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC);
481 sqlite3_bind_int(query, 2, crossfaderData.sinkID_A);
482 sqlite3_bind_int(query, 3, crossfaderData.sinkID_B);
483 sqlite3_bind_int(query, 4, crossfaderData.sourceID);
484 sqlite3_bind_int(query, 5, crossfaderData.hotSink);
486 //if the ID is not created, we add it to the query
487 if (crossfaderData.crossfaderID != 0)
489 sqlite3_bind_int(query, 6, crossfaderData.crossfaderID);
492 //if the first static sink is entered, we need to set it onto the boundary
493 else if (mFirstStaticCrossfader)
495 sqlite3_bind_int(query, 6, DYNAMIC_ID_BOUNDARY);
496 mFirstStaticCrossfader = false;
499 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
501 logError("DatabaseHandler::enterCrossfaderDB SQLITE Step error code:", eCode);
502 sqlite3_finalize(query);
503 return E_DATABASE_ERROR;
506 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
508 logError("DatabaseHandler::enterCrossfaderDB SQLITE Finalize error code:", eCode);
509 sqlite3_finalize(query);
510 return E_DATABASE_ERROR;
513 //now read back the crossfaderID
514 command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE name=?";
515 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
516 sqlite3_bind_text(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC);
517 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
519 crossfaderID = sqlite3_column_int(query, 0);
524 logError("DatabaseHandler::enterCrossfaderDB database error!:", eCode);
525 sqlite3_finalize(query);
526 return E_DATABASE_ERROR;
528 sqlite3_finalize(query);
530 logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID);
532 am_Crossfader_s crossfader(crossfaderData);
533 crossfader.crossfaderID = crossfaderID;
534 if (mDatabaseObserver)
535 mDatabaseObserver->newCrossfader(crossfader);
539 am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
541 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
542 assert(gatewayData.sinkID!=0);
543 assert(gatewayData.sourceID!=0);
544 assert(gatewayData.controlDomainID!=0);
545 assert(gatewayData.domainSinkID!=0);
546 assert(gatewayData.domainSourceID!=0);
547 assert(!gatewayData.name.empty());
548 assert(!gatewayData.convertionMatrix.empty());
549 assert(!gatewayData.listSinkFormats.empty());
550 assert(!gatewayData.listSourceFormats.empty());
551 assert(existSink(gatewayData.sinkID));
552 assert(existSource(gatewayData.sourceID));
554 sqlite3_stmt* query = NULL;
558 //if gatewayData is zero and the first Static Sink was already entered, the ID is created
559 if (gatewayData.gatewayID == 0 && !mFirstStaticGateway)
561 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID) VALUES (?,?,?,?,?,?)";
565 //check if the ID already exists
566 if (existGateway(gatewayData.gatewayID))
567 return E_ALREADY_EXISTS;
568 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID) VALUES (?,?,?,?,?,?,?)";
571 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
572 sqlite3_bind_text(query, 1, gatewayData.name.c_str(), gatewayData.name.size(), SQLITE_STATIC);
573 sqlite3_bind_int(query, 2, gatewayData.sinkID);
574 sqlite3_bind_int(query, 3, gatewayData.sourceID);
575 sqlite3_bind_int(query, 4, gatewayData.domainSinkID);
576 sqlite3_bind_int(query, 5, gatewayData.domainSourceID);
577 sqlite3_bind_int(query, 6, gatewayData.controlDomainID);
579 //if the ID is not created, we add it to the query
580 if (gatewayData.gatewayID != 0)
582 sqlite3_bind_int(query, 7, gatewayData.gatewayID);
585 //if the first static sink is entered, we need to set it onto the boundary
586 else if (mFirstStaticGateway)
588 sqlite3_bind_int(query, 7, DYNAMIC_ID_BOUNDARY);
589 mFirstStaticGateway = false;
592 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
594 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
595 return E_DATABASE_ERROR;
598 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
600 logError("DatabaseHandler::enterGatewayDB SQLITE Finalize error code:", eCode);
601 return E_DATABASE_ERROR;
604 gatewayID = sqlite3_last_insert_rowid(mDatabase);
606 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
607 mListConnectionFormat.insert(std::make_pair(gatewayID, gatewayData.convertionMatrix));
609 command = "CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
610 assert(this->sqQuery(command));
611 command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
612 assert(this->sqQuery(command));
614 //fill ConnectionFormats
615 command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
616 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
617 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin();
618 for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator)
620 sqlite3_bind_int(query, 1, *connectionFormatIterator);
621 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
623 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
624 return E_DATABASE_ERROR;
626 sqlite3_reset(query);
629 command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
630 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
631 connectionFormatIterator = gatewayData.listSinkFormats.begin();
632 for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator)
634 sqlite3_bind_int(query, 1, *connectionFormatIterator);
635 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
637 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
638 return E_DATABASE_ERROR;
640 sqlite3_reset(query);
643 logInfo("DatabaseHandler::enterGatewayDB entered new gateway with name", gatewayData.name, "sourceID:", gatewayData.sourceID, "sinkID:", gatewayData.sinkID, "assigned ID:", gatewayID);
644 am_Gateway_s gateway = gatewayData;
645 gateway.gatewayID = gatewayID;
646 if (mDatabaseObserver)
647 mDatabaseObserver->newGateway(gateway);
651 am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
653 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
654 assert(sourceData.domainID!=0);
655 assert(!sourceData.name.empty());
656 assert(sourceData.sourceClassID!=0);
657 // \todo: need to check if class exists?
658 assert(!sourceData.listConnectionFormats.empty());
659 assert(sourceData.sourceState>=SS_UNKNNOWN && sourceData.sourceState<=SS_MAX);
661 sqlite3_stmt* query = NULL, *queryFinal = NULL;
664 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
666 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
667 sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
669 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
671 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));
673 else if (eCode == SQLITE_DONE)
675 //if sinkID is zero and the first Static Sink was already entered, the ID is created
676 if (sourceData.sourceID == 0 && !mFirstStaticSource && !existSourceName(sourceData.name))
678 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
682 //check if the ID already exists
683 if (existSourceNameOrID(sourceData.sourceID, sourceData.name))
685 sqlite3_finalize(query);
686 return E_ALREADY_EXISTS;
688 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
693 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
694 sqlite3_finalize(query);
695 return E_DATABASE_ERROR;
698 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
700 logError("DatabaseHandler::enterSourceDB SQLITE Finalize error code:", eCode);
701 return E_DATABASE_ERROR;
703 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
704 sqlite3_bind_text(queryFinal, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
705 sqlite3_bind_int(queryFinal, 2, sourceData.domainID);
706 sqlite3_bind_int(queryFinal, 3, sourceData.sourceClassID);
707 sqlite3_bind_int(queryFinal, 4, sourceData.sourceState);
708 sqlite3_bind_int(queryFinal, 5, sourceData.volume);
709 sqlite3_bind_int(queryFinal, 6, sourceData.visible);
710 sqlite3_bind_int(queryFinal, 7, sourceData.available.availability);
711 sqlite3_bind_int(queryFinal, 8, sourceData.available.availabilityReason);
712 sqlite3_bind_int(queryFinal, 9, sourceData.interruptState);
713 sqlite3_bind_int(queryFinal, 10, 0);
715 //if the ID is not created, we add it to the query
716 if (sourceData.sourceID != 0)
718 sqlite3_bind_int(queryFinal, 11, sourceData.sourceID);
721 //if the first static sink is entered, we need to set it onto the boundary
722 else if (mFirstStaticSource)
724 sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY);
725 mFirstStaticSource = false;
728 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
730 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
731 sqlite3_finalize(queryFinal);
732 return E_DATABASE_ERROR;
735 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
737 logError("DatabaseHandler::enterSourceDB SQLITE Finalize error code:", eCode);
738 sqlite3_finalize(queryFinal);
739 return E_DATABASE_ERROR;
742 //now read back the sinkID
743 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
744 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
745 sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
746 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
748 sourceID = sqlite3_column_int(query, 0);
753 logError("DatabaseHandler::existSink database error!:", eCode);
754 sqlite3_finalize(query);
755 return E_DATABASE_ERROR;
757 sqlite3_finalize(query);
759 //now we need to create the additional tables:
760 command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
761 assert(this->sqQuery(command));
762 command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
763 assert(this->sqQuery(command));
765 //fill ConnectionFormats
766 command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
767 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
768 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin();
769 for (; connectionFormatIterator < sourceData.listConnectionFormats.end(); ++connectionFormatIterator)
771 sqlite3_bind_int(query, 1, *connectionFormatIterator);
772 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
774 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
775 sqlite3_finalize(query);
776 return E_DATABASE_ERROR;
778 sqlite3_reset(query);
781 //Fill SinkSoundProperties
782 command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
783 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
784 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin();
785 for (; SoundPropertyIterator < sourceData.listSoundProperties.end(); ++SoundPropertyIterator)
787 sqlite3_bind_int(query, 1, SoundPropertyIterator->type);
788 sqlite3_bind_int(query, 2, SoundPropertyIterator->value);
789 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
791 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
792 sqlite3_finalize(query);
793 return E_DATABASE_ERROR;
795 sqlite3_reset(query);
798 if (sourceData.visible == true)
800 command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
801 assert(this->sqQuery(command));
803 //Fill MainSinkSoundProperties
804 command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
805 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
806 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin();
807 for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
809 sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type);
810 sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value);
811 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
813 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
814 sqlite3_finalize(query);
815 return E_DATABASE_ERROR;
817 sqlite3_reset(query);
821 logInfo("DatabaseHandler::enterSinkDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID);
823 am_Source_s source = sourceData;
824 source.sourceID = sourceID;
825 if (mDatabaseObserver)
826 mDatabaseObserver->newSource(source);
830 am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector<am_connectionID_t>& listConnectionID)
832 assert(mainconnectionID!=0);
833 if (!existMainConnection(mainconnectionID))
835 return E_NON_EXISTENT;
837 sqlite3_stmt* query = NULL;
842 command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?");
843 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
844 std::vector<am_connectionID_t>::const_iterator elementIterator = listConnectionID.begin();
845 for (; elementIterator < listConnectionID.end(); ++elementIterator)
847 sqlite3_bind_int(query, 1, *elementIterator);
849 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
851 int16_t temp_delay = sqlite3_column_int(query, 1);
852 if (temp_delay != -1 && delay != -1)
859 logError("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:", eCode);
861 return E_DATABASE_ERROR;
863 sqlite3_reset(query);
866 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
868 logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:", eCode);
870 return E_DATABASE_ERROR;
873 //now we delete the data in the table
874 command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID);
875 assert(this->sqQuery(command));
877 command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
878 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
879 std::vector<am_connectionID_t>::const_iterator listConnectionIterator(listConnectionID.begin());
880 for (; listConnectionIterator != listConnectionID.end(); ++listConnectionIterator)
882 sqlite3_bind_int(query, 1, *listConnectionIterator);
883 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
885 logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:", eCode);
887 return E_DATABASE_ERROR;
889 sqlite3_reset(query);
892 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
894 logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:", eCode);
896 return E_DATABASE_ERROR;
898 logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID);
902 am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
904 assert(mainconnectionID!=0);
905 assert(connectionState>=CS_UNKNOWN && connectionState<=CS_MAX);
907 sqlite3_stmt* query = NULL;
911 if (!existMainConnection(mainconnectionID))
913 return E_NON_EXISTENT;
915 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
916 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
917 sqlite3_bind_int(query, 1, connectionState);
918 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
920 logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:", eCode);
921 return E_DATABASE_ERROR;
923 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
925 logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:", eCode);
926 return E_DATABASE_ERROR;
928 logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState);
930 if (mDatabaseObserver)
931 mDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState);
935 am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
939 sqlite3_stmt* query = NULL;
943 if (!existSink(sinkID))
945 return E_NON_EXISTENT;
947 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
948 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
949 sqlite3_bind_int(query, 1, mainVolume);
950 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
952 logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:", eCode);
953 return E_DATABASE_ERROR;
955 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
957 logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:", eCode);
958 return E_DATABASE_ERROR;
961 logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume);
963 if (mDatabaseObserver)
964 mDatabaseObserver->volumeChanged(sinkID, mainVolume);
969 am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
972 assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX);
973 assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX);
975 sqlite3_stmt* query = NULL;
979 if (!existSink(sinkID))
981 return E_NON_EXISTENT;
983 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
984 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
985 sqlite3_bind_int(query, 1, availability.availability);
986 sqlite3_bind_int(query, 2, availability.availabilityReason);
987 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
989 logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:", eCode);
990 return E_DATABASE_ERROR;
993 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
995 logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:", eCode);
996 return E_DATABASE_ERROR;
999 logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason);
1001 if (mDatabaseObserver && sourceVisible(sinkID))
1002 mDatabaseObserver->sinkAvailabilityChanged(sinkID, availability);
1006 am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
1008 assert(domainID!=0);
1009 assert(domainState>=DS_UNKNOWN && domainState<=DS_MAX);
1011 sqlite3_stmt* query = NULL;
1013 std::string command;
1015 if (!existDomain(domainID))
1017 return E_NON_EXISTENT;
1019 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
1020 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1021 sqlite3_bind_int(query, 1, domainState);
1022 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1024 logError("DatabaseHandler::changDomainStateDB SQLITE Step error code:", eCode);
1026 return E_DATABASE_ERROR;
1029 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1031 logError("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:", eCode);
1032 return E_DATABASE_ERROR;
1035 logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState);
1039 am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
1042 assert(muteState>=MS_UNKNOWN && muteState<=MS_MAX);
1044 sqlite3_stmt* query = NULL;
1046 std::string command;
1048 if (!existSink(sinkID))
1050 return E_NON_EXISTENT;
1052 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
1053 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1054 sqlite3_bind_int(query, 1, muteState);
1055 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1057 logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:", eCode);
1058 return E_DATABASE_ERROR;
1061 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1063 logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:", eCode);
1064 return E_DATABASE_ERROR;
1067 logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState);
1069 if (mDatabaseObserver)
1070 mDatabaseObserver->sinkMuteStateChanged(sinkID, muteState);
1075 am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
1077 assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX);
1080 sqlite3_stmt* query = NULL;
1082 std::string command;
1084 if (!existSink(sinkID))
1086 return E_NON_EXISTENT;
1088 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1089 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1090 sqlite3_bind_int(query, 1, soundProperty.value);
1091 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1093 logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:", eCode);
1094 return E_DATABASE_ERROR;
1097 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1099 logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:", eCode);
1100 return E_DATABASE_ERROR;
1103 logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value);
1104 if (mDatabaseObserver)
1105 mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty);
1109 am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1111 assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX);
1112 assert(sourceID!=0);
1114 sqlite3_stmt* query = NULL;
1116 std::string command;
1118 if (!existSource(sourceID))
1120 return E_NON_EXISTENT;
1122 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1123 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1124 sqlite3_bind_int(query, 1, soundProperty.value);
1125 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1127 logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:", eCode);
1128 return E_DATABASE_ERROR;
1131 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1133 logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:", eCode);
1134 return E_DATABASE_ERROR;
1137 logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value);
1139 if (mDatabaseObserver)
1140 mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty);
1144 am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1146 assert(sourceID!=0);
1147 assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX);
1148 assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX);
1150 sqlite3_stmt* query = NULL;
1152 std::string command;
1154 if (!existSource(sourceID))
1156 return E_NON_EXISTENT;
1158 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1159 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1160 sqlite3_bind_int(query, 1, availability.availability);
1161 sqlite3_bind_int(query, 2, availability.availabilityReason);
1162 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1164 logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:", eCode);
1165 return E_DATABASE_ERROR;
1168 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1170 logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:", eCode);
1171 return E_DATABASE_ERROR;
1174 logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason);
1176 if (mDatabaseObserver && sourceVisible(sourceID))
1177 mDatabaseObserver->sourceAvailabilityChanged(sourceID, availability);
1181 am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1183 assert(property.type>=SYP_UNKNOWN && property.type<=SYP_MAX);
1184 sqlite3_stmt* query = NULL;
1186 std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1188 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1189 sqlite3_bind_int(query, 1, property.value);
1190 sqlite3_bind_int(query, 2, property.type);
1192 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1194 logError("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:", eCode);
1195 return E_DATABASE_ERROR;
1198 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1200 logError("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:", eCode);
1201 return E_DATABASE_ERROR;
1204 logInfo("DatabaseHandler::changeSystemPropertyDB changed system property");
1206 if (mDatabaseObserver)
1207 mDatabaseObserver->systemPropertyChanged(property);
1212 am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1214 assert(mainConnectionID!=0);
1216 if (!existMainConnection(mainConnectionID))
1218 return E_NON_EXISTENT;
1220 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1221 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1222 if (!sqQuery(command))
1223 return E_DATABASE_ERROR;
1224 if (!sqQuery(command1))
1225 return E_DATABASE_ERROR;
1226 logInfo("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID);
1227 if (mDatabaseObserver)
1229 mDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED);
1230 mDatabaseObserver->numberOfMainConnectionsChanged();
1235 am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1239 if (!existSink(sinkID))
1241 return E_NON_EXISTENT;
1243 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1244 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1245 std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1246 std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID);
1247 if (!sqQuery(command))
1248 return E_DATABASE_ERROR;
1249 if (!sqQuery(command1))
1250 return E_DATABASE_ERROR;
1251 if (!sqQuery(command2))
1252 return E_DATABASE_ERROR;
1253 if (!sqQuery(command3))
1254 return E_DATABASE_ERROR;
1255 logInfo("DatabaseHandler::removeSinkDB removed:", sinkID);
1257 if (mDatabaseObserver != NULL)
1258 mDatabaseObserver->removedSink(sinkID);
1263 am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1265 assert(sourceID!=0);
1267 if (!existSource(sourceID))
1269 return E_NON_EXISTENT;
1271 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1272 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1273 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1274 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1275 if (!sqQuery(command))
1276 return E_DATABASE_ERROR;
1277 if (!sqQuery(command1))
1278 return E_DATABASE_ERROR;
1279 if (!sqQuery(command2))
1280 return E_DATABASE_ERROR;
1281 if (!sqQuery(command3))
1282 return E_DATABASE_ERROR;
1283 logInfo("DatabaseHandler::removeSourceDB removed:", sourceID);
1284 if (mDatabaseObserver)
1285 mDatabaseObserver->removedSource(sourceID);
1289 am_Error_e DatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1291 assert(gatewayID!=0);
1293 if (!existGateway(gatewayID))
1295 return E_NON_EXISTENT;
1297 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1298 if (!sqQuery(command))
1299 return E_DATABASE_ERROR;
1300 logInfo("DatabaseHandler::removeGatewayDB removed:", gatewayID);
1301 if (mDatabaseObserver)
1302 mDatabaseObserver->removeGateway(gatewayID);
1306 am_Error_e DatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1308 assert(crossfaderID!=0);
1310 if (!existcrossFader(crossfaderID))
1312 return E_NON_EXISTENT;
1314 std::string command = "DELETE from " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID);
1315 if (!sqQuery(command))
1316 return E_DATABASE_ERROR;
1317 logInfo("DatabaseHandler::removeDomainDB removed:", crossfaderID);
1318 if (mDatabaseObserver)
1319 mDatabaseObserver->removeCrossfader(crossfaderID);
1323 am_Error_e DatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1325 assert(domainID!=0);
1327 if (!existDomain(domainID))
1329 return E_NON_EXISTENT;
1331 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1332 if (!sqQuery(command))
1333 return E_DATABASE_ERROR;
1334 logInfo("DatabaseHandler::removeDomainDB removed:", domainID);
1335 if (mDatabaseObserver)
1336 mDatabaseObserver->removeDomain(domainID);
1340 am_Error_e DatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1342 assert(sinkClassID!=0);
1344 if (!existSinkClass(sinkClassID))
1346 return E_NON_EXISTENT;
1348 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1349 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1350 if (!sqQuery(command))
1351 return E_DATABASE_ERROR;
1352 if (!sqQuery(command1))
1353 return E_DATABASE_ERROR;
1355 logInfo("DatabaseHandler::removeSinkClassDB removed:", sinkClassID);
1356 if (mDatabaseObserver)
1357 mDatabaseObserver->numberOfSinkClassesChanged();
1362 am_Error_e DatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1364 assert(sourceClassID!=0);
1366 if (!existSourceClass(sourceClassID))
1368 return E_NON_EXISTENT;
1370 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1371 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1372 if (!sqQuery(command))
1373 return E_DATABASE_ERROR;
1374 if (!sqQuery(command1))
1375 return E_DATABASE_ERROR;
1376 logInfo("DatabaseHandler::removeSourceClassDB removed:", sourceClassID);
1377 if (mDatabaseObserver)
1378 mDatabaseObserver->numberOfSourceClassesChanged();
1382 am_Error_e DatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1384 assert(connectionID!=0);
1386 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1387 if (!sqQuery(command))
1388 return E_DATABASE_ERROR;
1389 logInfo("DatabaseHandler::removeConnection removed:", connectionID);
1393 am_Error_e DatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1395 assert(sourceID!=0);
1397 if (!existSource(sourceID))
1399 return E_NON_EXISTENT;
1401 sqlite3_stmt* query = NULL;
1403 am_ClassProperty_s propertyTemp;
1404 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + (i2s(sourceID));
1405 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1407 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1409 classInfo.sourceClassID = sqlite3_column_int(query, 0);
1412 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1414 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1415 return E_DATABASE_ERROR;
1418 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1420 logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode);
1421 return E_DATABASE_ERROR;
1424 command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1425 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1427 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1429 classInfo.name = std::string((const char*) sqlite3_column_text(query, 0));
1432 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1434 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1435 return E_DATABASE_ERROR;
1438 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1440 logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode);
1441 return E_DATABASE_ERROR;
1444 //read out Properties
1445 command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID);
1446 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1447 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1449 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1450 propertyTemp.value = sqlite3_column_int(query, 1);
1451 classInfo.listClassProperties.push_back(propertyTemp);
1454 if (eCode != SQLITE_DONE)
1456 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1457 return E_DATABASE_ERROR;
1460 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1462 logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode);
1463 return E_DATABASE_ERROR;
1468 am_Error_e DatabaseHandler::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const
1473 if (!existSink(sinkID))
1475 return E_NON_EXISTENT;
1478 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
1480 am_ConnectionFormat_e tempConnectionFormat;
1481 am_SoundProperty_s tempSoundProperty;
1482 am_MainSoundProperty_s tempMainSoundProperty;
1483 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);
1484 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1486 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1488 sinkData.name = std::string((const char*) sqlite3_column_text(query, 0));
1489 sinkData.domainID = sqlite3_column_int(query, 1);
1490 sinkData.sinkClassID = sqlite3_column_int(query, 2);
1491 sinkData.volume = sqlite3_column_int(query, 3);
1492 sinkData.visible = sqlite3_column_int(query, 4);
1493 sinkData.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5);
1494 sinkData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
1495 sinkData.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
1496 sinkData.mainVolume = sqlite3_column_int(query, 8);
1497 sinkData.sinkID = sqlite3_column_int(query, 9);
1499 //read out the connectionFormats
1500 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
1501 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
1502 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1504 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1505 sinkData.listConnectionFormats.push_back(tempConnectionFormat);
1508 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
1510 logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode);
1512 return E_DATABASE_ERROR;
1515 //read out sound properties
1516 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(sinkID);
1517 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
1518 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1520 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1521 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1522 sinkData.listSoundProperties.push_back(tempSoundProperty);
1525 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
1527 logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode);
1529 return E_DATABASE_ERROR;
1532 //read out MainSoundProperties
1533 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
1534 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
1535 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1537 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1538 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1539 sinkData.listMainSoundProperties.push_back(tempMainSoundProperty);
1542 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
1544 logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode);
1546 return E_DATABASE_ERROR;
1550 else if (eCode != SQLITE_DONE)
1552 logError("DatabaseHandler::getSinkInfoDB SQLITE error code:", eCode);
1554 return E_DATABASE_ERROR;
1557 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1559 logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode);
1561 return E_DATABASE_ERROR;
1567 am_Error_e DatabaseHandler::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const
1569 assert(sourceID!=0);
1571 if (!existSource(sourceID))
1573 return E_NON_EXISTENT;
1576 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
1578 am_ConnectionFormat_e tempConnectionFormat;
1579 am_SoundProperty_s tempSoundProperty;
1580 am_MainSoundProperty_s tempMainSoundProperty;
1581 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);
1582 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1584 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1586 sourceData.name = std::string((const char*) sqlite3_column_text(query, 0));
1587 sourceData.domainID = sqlite3_column_int(query, 1);
1588 sourceData.sourceClassID = sqlite3_column_int(query, 2);
1589 sourceData.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
1590 sourceData.volume = sqlite3_column_int(query, 4);
1591 sourceData.visible = sqlite3_column_int(query, 5);
1592 sourceData.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6);
1593 sourceData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
1594 sourceData.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
1595 sourceData.sourceID = sqlite3_column_int(query, 9);
1597 //read out the connectionFormats
1598 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
1599 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
1600 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
1602 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
1603 sourceData.listConnectionFormats.push_back(tempConnectionFormat);
1606 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
1608 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
1610 return E_DATABASE_ERROR;
1613 //read out sound properties
1614 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(sourceID);
1615 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
1616 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
1618 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
1619 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
1620 sourceData.listSoundProperties.push_back(tempSoundProperty);
1623 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
1625 logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode);
1627 return E_DATABASE_ERROR;
1630 //read out MainSoundProperties
1631 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
1632 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
1633 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
1635 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
1636 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
1637 sourceData.listMainSoundProperties.push_back(tempMainSoundProperty);
1640 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
1642 logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode);
1644 return E_DATABASE_ERROR;
1647 else if (eCode != SQLITE_DONE)
1649 logError("DatabaseHandler::getSourceInfoDB SQLITE error code:", eCode);
1651 return E_DATABASE_ERROR;
1654 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1656 logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode);
1658 return E_DATABASE_ERROR;
1664 am_Error_e am::DatabaseHandler::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const
1666 assert(mainConnectionID!=0);
1667 if (!existMainConnection(mainConnectionID))
1669 return E_NON_EXISTENT;
1671 sqlite3_stmt *query = NULL, *query1 = NULL;
1673 am_MainConnection_s temp;
1674 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1675 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
1676 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1678 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1680 mainConnectionData.mainConnectionID = sqlite3_column_int(query, 0);
1681 mainConnectionData.sourceID = sqlite3_column_int(query, 1);
1682 mainConnectionData.sinkID = sqlite3_column_int(query, 2);
1683 mainConnectionData.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
1684 mainConnectionData.delay = sqlite3_column_int(query, 4);
1685 std::string statement = command1 + i2s(mainConnectionID);
1686 sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL);
1687 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW)
1689 mainConnectionData.listConnectionID.push_back(sqlite3_column_int(query1, 0));
1693 if (eCode != SQLITE_DONE)
1695 logError("DatabaseHandler::getMainConnectionInfoDB SQLITE error code:", eCode);
1696 return E_DATABASE_ERROR;
1699 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1701 logError("DatabaseHandler::getMainConnectionInfoDB SQLITE Finalize error code:", eCode);
1702 return E_DATABASE_ERROR;
1708 am_Error_e DatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1710 assert(sinkClass.sinkClassID!=0);
1711 assert(!sinkClass.listClassProperties.empty());
1713 sqlite3_stmt* query = NULL;
1716 //check if the ID already exists
1717 if (!existSinkClass(sinkClass.sinkClassID))
1718 return E_NON_EXISTENT;
1720 //fill ConnectionFormats
1721 std::string command = "UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1722 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1723 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
1724 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
1726 sqlite3_bind_int(query, 1, Iterator->value);
1727 sqlite3_bind_int(query, 2, Iterator->classProperty);
1728 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1730 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode);
1731 return E_DATABASE_ERROR;
1733 sqlite3_reset(query);
1736 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1738 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:", eCode);
1739 return E_DATABASE_ERROR;
1742 logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo");
1746 am_Error_e DatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1748 assert(sourceClass.sourceClassID!=0);
1749 assert(!sourceClass.listClassProperties.empty());
1751 sqlite3_stmt* query = NULL;
1754 //check if the ID already exists
1755 if (!existSourceClass(sourceClass.sourceClassID))
1756 return E_NON_EXISTENT;
1758 //fill ConnectionFormats
1759 std::string command = "UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1760 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1761 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
1762 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
1764 sqlite3_bind_int(query, 1, Iterator->value);
1765 sqlite3_bind_int(query, 2, Iterator->classProperty);
1766 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1768 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode);
1769 return E_DATABASE_ERROR;
1771 sqlite3_reset(query);
1774 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1776 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:", eCode);
1777 return E_DATABASE_ERROR;
1780 logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo");
1784 am_Error_e DatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1788 if (!existSink(sinkID))
1790 return E_NON_EXISTENT;
1792 sqlite3_stmt* query = NULL;
1794 am_ClassProperty_s propertyTemp;
1795 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + (i2s(sinkID));
1796 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1798 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1800 sinkClass.sinkClassID = sqlite3_column_int(query, 0);
1803 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1805 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1806 return E_DATABASE_ERROR;
1809 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1811 logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode);
1812 return E_DATABASE_ERROR;
1815 command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1816 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1818 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1820 sinkClass.name = std::string((const char*) sqlite3_column_text(query, 0));
1823 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1825 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1826 return E_DATABASE_ERROR;
1829 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1831 logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode);
1832 return E_DATABASE_ERROR;
1835 //read out Properties
1836 command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID);
1837 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1838 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1840 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1841 propertyTemp.value = sqlite3_column_int(query, 1);
1842 sinkClass.listClassProperties.push_back(propertyTemp);
1845 if (eCode != SQLITE_DONE)
1847 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1848 return E_DATABASE_ERROR;
1851 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1853 logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode);
1854 return E_DATABASE_ERROR;
1859 am_Error_e DatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1861 assert(gatewayID!=0);
1862 if (!existGateway(gatewayID))
1864 return E_NON_EXISTENT;
1866 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
1868 am_ConnectionFormat_e tempConnectionFormat;
1869 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1870 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1872 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1874 gatewayData.name = std::string((const char*) sqlite3_column_text(query, 0));
1875 gatewayData.sinkID = sqlite3_column_int(query, 1);
1876 gatewayData.sourceID = sqlite3_column_int(query, 2);
1877 gatewayData.domainSinkID = sqlite3_column_int(query, 3);
1878 gatewayData.domainSourceID = sqlite3_column_int(query, 4);
1879 gatewayData.controlDomainID = sqlite3_column_int(query, 5);
1880 gatewayData.gatewayID = sqlite3_column_int(query, 6);
1883 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
1884 iter = mListConnectionFormat.find(gatewayData.gatewayID);
1885 if (iter == mListConnectionFormat.end())
1887 logError("DatabaseHandler::getGatewayInfoDB database error with convertionFormat");
1888 return E_DATABASE_ERROR;
1890 gatewayData.convertionMatrix = iter->second;
1892 //read out the connectionFormats
1893 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
1894 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL);
1895 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
1897 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
1898 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
1901 if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK)
1903 logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode);
1904 return E_DATABASE_ERROR;
1907 //read out sound properties
1908 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
1909 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL);
1910 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
1912 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
1913 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
1916 if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK)
1918 logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode);
1919 return E_DATABASE_ERROR;
1924 if (eCode != SQLITE_DONE)
1926 logError("DatabaseHandler::getGatewayInfoDB SQLITE error code:", eCode);
1927 return E_DATABASE_ERROR;
1930 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1932 logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode);
1933 return E_DATABASE_ERROR;
1940 am_Error_e DatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
1942 assert(crossfaderID!=0);
1943 if (!existcrossFader(crossfaderID))
1945 return E_NON_EXISTENT;
1947 sqlite3_stmt* query = NULL;
1949 std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID);
1950 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1952 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1954 crossfaderData.name = std::string((const char*) sqlite3_column_text(query, 0));
1955 crossfaderData.sinkID_A = sqlite3_column_int(query, 1);
1956 crossfaderData.sinkID_B = sqlite3_column_int(query, 2);
1957 crossfaderData.sourceID = sqlite3_column_int(query, 3);
1958 crossfaderData.hotSink = static_cast<am_HotSink_e>(sqlite3_column_int(query, 4));
1959 crossfaderData.crossfaderID = sqlite3_column_int(query, 5);
1962 if (eCode != SQLITE_DONE)
1964 logError("DatabaseHandler::getCrossfaderInfoDB SQLITE error code:", eCode);
1965 return E_DATABASE_ERROR;
1968 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1970 logError("DatabaseHandler::getCrossfaderInfoDB SQLITE Finalize error code:", eCode);
1971 return E_DATABASE_ERROR;
1977 am_Error_e DatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
1979 assert(domainID!=0);
1981 if (!existDomain(domainID))
1983 return E_NON_EXISTENT;
1985 sqlite3_stmt* query = NULL;
1988 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND domainID=" + (i2s(domainID));
1989 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1991 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1993 temp = sqlite3_column_int(query, 0);
1994 listSinkID.push_back(temp);
1997 if (eCode != SQLITE_DONE)
1999 logError("DatabaseHandler::getListSinksOfDomain SQLITE error code:", eCode);
2000 return E_DATABASE_ERROR;
2003 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2005 logError("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:", eCode);
2006 return E_DATABASE_ERROR;
2012 am_Error_e DatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
2014 assert(domainID!=0);
2015 listSourceID.clear();
2016 if (!existDomain(domainID))
2018 return E_NON_EXISTENT;
2020 sqlite3_stmt* query = NULL;
2023 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
2025 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2027 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2029 temp = sqlite3_column_int(query, 0);
2030 listSourceID.push_back(temp);
2033 if (eCode != SQLITE_DONE)
2035 logError("DatabaseHandler::getListSourcesOfDomain SQLITE error code:", eCode);
2036 return E_DATABASE_ERROR;
2039 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2041 logError("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:", eCode);
2042 return E_DATABASE_ERROR;
2048 am_Error_e DatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listCrossfader) const
2050 assert(domainID!=0);
2051 listCrossfader.clear();
2052 if (!existDomain(domainID))
2054 return E_NON_EXISTENT;
2056 sqlite3_stmt* query = NULL;
2058 am_crossfaderID_t temp;
2060 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);
2061 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2063 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2065 temp = sqlite3_column_int(query, 0);
2066 listCrossfader.push_back(temp);
2069 if (eCode != SQLITE_DONE)
2071 logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE error code:", eCode);
2072 return E_DATABASE_ERROR;
2075 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2077 logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE Finalize error code:", eCode);
2078 return E_DATABASE_ERROR;
2085 am_Error_e DatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
2087 assert(domainID!=0);
2088 listGatewaysID.clear();
2089 if (!existDomain(domainID))
2091 return E_NON_EXISTENT;
2093 sqlite3_stmt* query = NULL;
2095 am_gatewayID_t temp;
2097 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" + i2s(domainID);
2098 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2100 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2102 temp = sqlite3_column_int(query, 0);
2103 listGatewaysID.push_back(temp);
2106 if (eCode != SQLITE_DONE)
2108 logError("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:", eCode);
2109 return E_DATABASE_ERROR;
2112 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2114 logError("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:", eCode);
2115 return E_DATABASE_ERROR;
2121 am_Error_e DatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
2123 listMainConnections.clear();
2124 sqlite3_stmt *query = NULL, *query1 = NULL;
2126 am_MainConnection_s temp;
2127 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2128 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
2129 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2131 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2133 temp.mainConnectionID = sqlite3_column_int(query, 0);
2134 temp.sourceID = sqlite3_column_int(query, 1);
2135 temp.sinkID = sqlite3_column_int(query, 2);
2136 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2137 temp.delay = sqlite3_column_int(query, 4);
2138 std::string statement = command1 + i2s(temp.mainConnectionID);
2139 sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL);
2140 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW)
2142 temp.listConnectionID.push_back(sqlite3_column_int(query1, 0));
2144 listMainConnections.push_back(temp);
2147 if (eCode != SQLITE_DONE)
2149 logError("DatabaseHandler::getListMainConnections SQLITE error code:", eCode);
2150 return E_DATABASE_ERROR;
2153 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2155 logError("DatabaseHandler::getListMainConnections SQLITE Finalize error code:", eCode);
2156 return E_DATABASE_ERROR;
2162 am_Error_e DatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
2164 listDomains.clear();
2165 sqlite3_stmt* query = NULL;
2168 std::string command = "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
2169 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2171 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2173 temp.domainID = sqlite3_column_int(query, 0);
2174 temp.name = std::string((const char*) sqlite3_column_text(query, 1));
2175 temp.busname = std::string((const char*) sqlite3_column_text(query, 2));
2176 temp.nodename = std::string((const char*) sqlite3_column_text(query, 3));
2177 temp.early = sqlite3_column_int(query, 4);
2178 temp.complete = sqlite3_column_int(query, 5);
2179 temp.state = (am_DomainState_e) sqlite3_column_int(query, 6);
2180 listDomains.push_back(temp);
2183 if (eCode != SQLITE_DONE)
2185 logError("DatabaseHandler::getListDomains SQLITE error code:", eCode);
2187 return E_DATABASE_ERROR;
2190 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2192 logError("DatabaseHandler::getListDomains SQLITE Finalize error code:", eCode);
2194 return E_DATABASE_ERROR;
2200 am_Error_e DatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
2202 listConnections.clear();
2203 sqlite3_stmt* query = NULL;
2205 am_Connection_s temp;
2206 std::string command = "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE reserved=0";
2207 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2209 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2211 temp.connectionID = sqlite3_column_int(query, 0);
2212 temp.sourceID = sqlite3_column_int(query, 1);
2213 temp.sinkID = sqlite3_column_int(query, 2);
2214 temp.delay = sqlite3_column_int(query, 3);
2215 temp.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query, 4);
2216 listConnections.push_back(temp);
2219 if (eCode != SQLITE_DONE)
2221 logError("DatabaseHandler::getListConnections SQLITE error code:", eCode);
2222 return E_DATABASE_ERROR;
2225 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2227 logError("DatabaseHandler::getListConnections SQLITE Finalize error code:", eCode);
2228 return E_DATABASE_ERROR;
2234 am_Error_e DatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
2237 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
2240 am_ConnectionFormat_e tempConnectionFormat;
2241 am_SoundProperty_s tempSoundProperty;
2242 am_MainSoundProperty_s tempMainSoundProperty;
2243 std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0";
2244 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2246 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2248 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2249 temp.domainID = sqlite3_column_int(query, 1);
2250 temp.sinkClassID = sqlite3_column_int(query, 2);
2251 temp.volume = sqlite3_column_int(query, 3);
2252 temp.visible = sqlite3_column_int(query, 4);
2253 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5);
2254 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
2255 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
2256 temp.mainVolume = sqlite3_column_int(query, 8);
2257 temp.sinkID = sqlite3_column_int(query, 9);
2259 //read out the connectionFormats
2260 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID);
2261 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2262 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2264 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2265 temp.listConnectionFormats.push_back(tempConnectionFormat);
2268 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2270 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2272 return E_DATABASE_ERROR;
2275 //read out sound properties
2276 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
2277 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
2278 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
2280 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
2281 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
2282 temp.listSoundProperties.push_back(tempSoundProperty);
2285 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
2287 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2289 return E_DATABASE_ERROR;
2292 //read out MainSoundProperties
2293 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID);
2294 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
2295 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
2297 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
2298 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2299 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2302 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
2304 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2306 return E_DATABASE_ERROR;
2308 listSinks.push_back(temp);
2309 temp.listConnectionFormats.clear();
2310 temp.listMainSoundProperties.clear();
2311 temp.listSoundProperties.clear();
2314 if (eCode != SQLITE_DONE)
2316 logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
2318 return E_DATABASE_ERROR;
2321 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2323 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2325 return E_DATABASE_ERROR;
2331 am_Error_e DatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
2333 listSources.clear();
2334 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
2337 am_ConnectionFormat_e tempConnectionFormat;
2338 am_SoundProperty_s tempSoundProperty;
2339 am_MainSoundProperty_s tempMainSoundProperty;
2340 std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0";
2341 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2343 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2345 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2346 temp.domainID = sqlite3_column_int(query, 1);
2347 temp.sourceClassID = sqlite3_column_int(query, 2);
2348 temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
2349 temp.volume = sqlite3_column_int(query, 4);
2350 temp.visible = sqlite3_column_int(query, 5);
2351 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6);
2352 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
2353 temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
2354 temp.sourceID = sqlite3_column_int(query, 9);
2356 //read out the connectionFormats
2357 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID);
2358 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2359 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2361 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2362 temp.listConnectionFormats.push_back(tempConnectionFormat);
2365 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2367 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2369 return E_DATABASE_ERROR;
2372 //read out sound properties
2373 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
2374 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
2375 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
2377 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
2378 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
2379 temp.listSoundProperties.push_back(tempSoundProperty);
2382 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
2384 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2386 return E_DATABASE_ERROR;
2389 //read out MainSoundProperties
2390 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID);
2391 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
2392 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
2394 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
2395 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2396 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2399 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
2401 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2403 return E_DATABASE_ERROR;
2405 listSources.push_back(temp);
2406 temp.listConnectionFormats.clear();
2407 temp.listMainSoundProperties.clear();
2408 temp.listSoundProperties.clear();
2411 if (eCode != SQLITE_DONE)
2413 logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
2415 return E_DATABASE_ERROR;
2418 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2420 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2422 return E_DATABASE_ERROR;
2428 am_Error_e DatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
2430 listSourceClasses.clear();
2432 sqlite3_stmt* query = NULL, *subQuery = NULL;
2433 int eCode = 0, eCode1;
2434 am_SourceClass_s classTemp;
2435 am_ClassProperty_s propertyTemp;
2437 std::string command = "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
2438 std::string command2;
2439 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2441 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2443 classTemp.sourceClassID = sqlite3_column_int(query, 0);
2444 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2446 //read out Properties
2447 command2 = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classTemp.sourceClassID);
2448 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL);
2450 while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW)
2452 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2453 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2454 classTemp.listClassProperties.push_back(propertyTemp);
2457 if (eCode1 != SQLITE_DONE)
2459 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode1);
2461 return E_DATABASE_ERROR;
2464 if ((eCode1 = sqlite3_finalize(subQuery)) != SQLITE_OK)
2466 logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode1);
2468 return E_DATABASE_ERROR;
2470 listSourceClasses.push_back(classTemp);
2473 if (eCode != SQLITE_DONE)
2475 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2477 return E_DATABASE_ERROR;
2480 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2482 logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode);
2484 return E_DATABASE_ERROR;
2490 am_Error_e DatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2492 listCrossfaders.clear();
2493 sqlite3_stmt* query = NULL;
2495 am_Crossfader_s tempData;
2496 std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE);
2497 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2499 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2501 tempData.name = std::string((const char*) sqlite3_column_text(query, 0));
2502 tempData.sinkID_A = sqlite3_column_int(query, 1);
2503 tempData.sinkID_B = sqlite3_column_int(query, 2);
2504 tempData.sourceID = sqlite3_column_int(query, 3);
2505 tempData.hotSink = static_cast<am_HotSink_e>(sqlite3_column_int(query, 4));
2506 tempData.crossfaderID = sqlite3_column_int(query, 5);
2507 listCrossfaders.push_back(tempData);
2510 if (eCode != SQLITE_DONE)
2512 logError("DatabaseHandler::getListCrossfaders SQLITE error code:", eCode);
2513 return E_DATABASE_ERROR;
2516 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2518 logError("DatabaseHandler::getListCrossfaders SQLITE Finalize error code:", eCode);
2519 return E_DATABASE_ERROR;
2525 am_Error_e DatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2527 listGateways.clear();
2528 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
2531 am_ConnectionFormat_e tempConnectionFormat;
2533 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2534 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2536 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2538 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2539 temp.sinkID = sqlite3_column_int(query, 1);
2540 temp.sourceID = sqlite3_column_int(query, 2);
2541 temp.domainSinkID = sqlite3_column_int(query, 3);
2542 temp.domainSourceID = sqlite3_column_int(query, 4);
2543 temp.controlDomainID = sqlite3_column_int(query, 5);
2544 temp.gatewayID = sqlite3_column_int(query, 6);
2547 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2548 iter = mListConnectionFormat.find(temp.gatewayID);
2549 if (iter == mListConnectionFormat.end())
2551 logError("DatabaseHandler::getListGateways database error with convertionFormat");
2553 return E_DATABASE_ERROR;
2555 temp.convertionMatrix = iter->second;
2557 //read out the connectionFormats
2558 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2559 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL);
2560 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
2562 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
2563 temp.listSourceFormats.push_back(tempConnectionFormat);
2566 if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK)
2568 logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode);
2570 return E_DATABASE_ERROR;
2573 //read out sound properties
2574 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2575 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL);
2576 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
2578 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
2579 temp.listSinkFormats.push_back(tempConnectionFormat);
2582 if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK)
2584 logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode);
2586 return E_DATABASE_ERROR;
2589 listGateways.push_back(temp);
2590 temp.listSinkFormats.clear();
2591 temp.listSourceFormats.clear();
2594 if (eCode != SQLITE_DONE)
2596 logError("DatabaseHandler::getListGateways SQLITE error code:", eCode);
2598 return E_DATABASE_ERROR;
2601 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2603 logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode);
2605 return E_DATABASE_ERROR;
2611 am_Error_e DatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2613 listSinkClasses.clear();
2615 sqlite3_stmt* query = NULL, *subQuery = NULL;
2617 am_SinkClass_s classTemp;
2618 am_ClassProperty_s propertyTemp;
2620 std::string command = "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2621 std::string command2;
2622 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2624 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2626 classTemp.sinkClassID = sqlite3_column_int(query, 0);
2627 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2629 //read out Properties
2630 command2 = "SELECT classProperty, value FROM SinkClassProperties" + i2s(classTemp.sinkClassID);
2631 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL);
2633 while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW)
2635 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2636 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2637 classTemp.listClassProperties.push_back(propertyTemp);
2640 if (eCode != SQLITE_DONE)
2642 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2644 return E_DATABASE_ERROR;
2647 if ((eCode = sqlite3_finalize(subQuery)) != SQLITE_OK)
2649 logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode);
2651 return E_DATABASE_ERROR;
2653 listSinkClasses.push_back(classTemp);
2656 if (eCode != SQLITE_DONE)
2658 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2660 return E_DATABASE_ERROR;
2663 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2665 logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode);
2667 return E_DATABASE_ERROR;
2673 am_Error_e DatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2675 listConnections.clear();
2676 sqlite3_stmt *query = NULL;
2678 am_MainConnectionType_s temp;
2680 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2681 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2683 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2685 temp.mainConnectionID = sqlite3_column_int(query, 0);
2686 temp.sourceID = sqlite3_column_int(query, 1);
2687 temp.sinkID = sqlite3_column_int(query, 2);
2688 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2689 temp.delay = sqlite3_column_int(query, 4);
2690 listConnections.push_back(temp);
2693 if (eCode != SQLITE_DONE)
2695 logError("DatabaseHandler::getListVisibleMainConnections SQLITE error code:", eCode);
2697 return E_DATABASE_ERROR;
2700 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2702 logError("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:", eCode);
2704 return E_DATABASE_ERROR;
2710 am_Error_e DatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2712 listMainSinks.clear();
2713 sqlite3_stmt* query = NULL;
2717 std::string command = "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2718 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2720 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2722 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2723 temp.sinkID = sqlite3_column_int(query, 1);
2724 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2725 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2726 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 4);
2727 temp.volume = sqlite3_column_int(query, 5);
2728 temp.sinkClassID = sqlite3_column_int(query, 6);
2729 listMainSinks.push_back(temp);
2732 if (eCode != SQLITE_DONE)
2734 logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
2736 return E_DATABASE_ERROR;
2739 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2741 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2743 return E_DATABASE_ERROR;
2749 am_Error_e DatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2751 listMainSources.clear();
2752 sqlite3_stmt* query = NULL;
2754 am_SourceType_s temp;
2755 std::string command = "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2756 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2758 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2760 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2761 temp.sourceClassID = sqlite3_column_int(query, 1);
2762 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2763 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2764 temp.sourceID = sqlite3_column_int(query, 4);
2766 listMainSources.push_back(temp);
2769 if (eCode != SQLITE_DONE)
2771 logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
2773 return E_DATABASE_ERROR;
2776 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2778 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2780 return E_DATABASE_ERROR;
2786 am_Error_e DatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2789 if (!existSink(sinkID))
2790 return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2791 listSoundProperties.clear();
2793 sqlite3_stmt* query = NULL;
2795 am_MainSoundProperty_s temp;
2796 std::string command = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2797 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2799 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2801 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2802 temp.value = sqlite3_column_int(query, 1);
2803 listSoundProperties.push_back(temp);
2806 if (eCode != SQLITE_DONE)
2808 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode);
2810 return E_DATABASE_ERROR;
2813 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2815 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:", eCode);
2817 return E_DATABASE_ERROR;
2823 am_Error_e DatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2825 assert(sourceID!=0);
2826 if (!existSource(sourceID))
2827 return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2828 listSourceProperties.clear();
2830 sqlite3_stmt* query = NULL;
2832 am_MainSoundProperty_s temp;
2833 std::string command = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2834 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2836 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2838 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2839 temp.value = sqlite3_column_int(query, 1);
2840 listSourceProperties.push_back(temp);
2843 if (eCode != SQLITE_DONE)
2845 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode);
2847 return E_DATABASE_ERROR;
2850 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2852 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:", eCode);
2854 return E_DATABASE_ERROR;
2860 am_Error_e DatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2862 listSystemProperties.clear();
2864 sqlite3_stmt* query = NULL;
2866 am_SystemProperty_s temp;
2867 std::string command = "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2868 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2870 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2872 temp.type = (am_SystemPropertyType_e) sqlite3_column_int(query, 0);
2873 temp.value = sqlite3_column_int(query, 1);
2874 listSystemProperties.push_back(temp);
2877 if (eCode != SQLITE_DONE)
2879 logError("DatabaseHandler::getListSystemProperties SQLITE error code:", eCode);
2881 return E_DATABASE_ERROR;
2884 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2886 logError("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:", eCode);
2888 return E_DATABASE_ERROR;
2894 am_Error_e am::DatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2896 listConnectionFormats.clear();
2897 sqlite3_stmt *qConnectionFormat = NULL;
2899 am_ConnectionFormat_e tempConnectionFormat;
2900 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
2901 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2902 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2904 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2905 listConnectionFormats.push_back(tempConnectionFormat);
2908 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2910 logError("DatabaseHandler::getListSinkConnectionFormats SQLITE Finalize error code:", eCode);
2912 return E_DATABASE_ERROR;
2918 am_Error_e am::DatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2920 listConnectionFormats.clear();
2921 sqlite3_stmt* qConnectionFormat = NULL;
2923 am_ConnectionFormat_e tempConnectionFormat;
2925 //read out the connectionFormats
2926 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
2927 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2928 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2930 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2931 listConnectionFormats.push_back(tempConnectionFormat);
2934 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2936 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2938 return E_DATABASE_ERROR;
2944 am_Error_e am::DatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const
2946 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2947 iter = mListConnectionFormat.find(gatewayID);
2948 if (iter == mListConnectionFormat.end())
2950 logError("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat");
2952 return (E_DATABASE_ERROR);
2954 listConnectionFormat = iter->second;
2959 am_Error_e DatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2961 assert(mainConnectionID!=0);
2963 sqlite3_stmt *query = NULL;
2966 std::string command = "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2967 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2969 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2971 delay = sqlite3_column_int(query, 0);
2974 if (eCode != SQLITE_DONE)
2976 logError("DatabaseHandler::getTimingInformation SQLITE error code:", eCode);
2978 return E_DATABASE_ERROR;
2981 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2983 logError("DatabaseHandler::getTimingInformation SQLITE Finalize error code:", eCode);
2985 return E_DATABASE_ERROR;
2989 return E_NOT_POSSIBLE;
2994 bool DatabaseHandler::sqQuery(const std::string& query)
2996 sqlite3_stmt* statement;
2998 if ((eCode = sqlite3_exec(mDatabase, query.c_str(), NULL, &statement, NULL)) != SQLITE_OK)
3000 logError("DatabaseHandler::sqQuery SQL Query failed:", query.c_str(), "error code:", eCode);
3006 bool DatabaseHandler::openDatabase()
3008 if (sqlite3_open_v2(mPath.c_str(), &mDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
3010 logInfo("DatabaseHandler::openDatabase opened database");
3013 logError("DatabaseHandler::openDatabase failed to open database");
3017 am_Error_e DatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
3019 assert(connectionID!=0);
3021 sqlite3_stmt* query = NULL;
3023 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE delay=? AND mainConnectionID=?";
3024 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3025 sqlite3_bind_int(query, 1, delay);
3026 sqlite3_bind_int(query, 2, connectionID);
3027 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3029 sqlite3_finalize(query);
3032 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
3033 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3034 sqlite3_bind_int(query, 1, delay);
3035 sqlite3_bind_int(query, 2, connectionID);
3037 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3039 logError("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:", eCode);
3041 return E_DATABASE_ERROR;
3044 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3046 logError("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:", eCode);
3048 return E_DATABASE_ERROR;
3051 if (mDatabaseObserver)
3052 mDatabaseObserver->timingInformationChanged(connectionID, delay);
3057 am_Error_e DatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
3059 assert(connection.connectionID==0);
3060 assert(connection.sinkID!=0);
3061 assert(connection.sourceID!=0);
3062 //connection format is not checked, because it's project specific
3064 sqlite3_stmt* query = NULL;
3066 std::string command = "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
3068 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3069 sqlite3_bind_int(query, 1, connection.sinkID);
3070 sqlite3_bind_int(query, 2, connection.sourceID);
3071 sqlite3_bind_int(query, 3, connection.delay);
3072 sqlite3_bind_int(query, 4, connection.connectionFormat);
3073 sqlite3_bind_int(query, 5, true);
3075 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3077 logError("DatabaseHandler::enterConnectionDB SQLITE Step error code:", eCode);
3079 return E_DATABASE_ERROR;
3082 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3084 logError("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:", eCode);
3086 return E_DATABASE_ERROR;
3089 connectionID = sqlite3_last_insert_rowid(mDatabase);
3091 logInfo("DatabaseHandler::enterConnectionDB entered new connection sourceID=", connection.sourceID, "sinkID=", connection.sinkID, "sourceID=", connection.sourceID, "connectionFormat=", connection.connectionFormat, "assigned ID=", connectionID);
3095 am_Error_e DatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
3097 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
3098 assert(!sinkClass.name.empty());
3100 sqlite3_stmt* query = NULL;
3102 std::string command;
3104 //if sinkID is zero and the first Static Sink was already entered, the ID is created
3105 if (sinkClass.sinkClassID == 0 && !mFirstStaticSinkClass)
3107 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
3111 //check if the ID already exists
3112 if (existSinkClass(sinkClass.sinkClassID))
3113 return E_ALREADY_EXISTS;
3114 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
3117 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3118 sqlite3_bind_text(query, 1, sinkClass.name.c_str(), sinkClass.name.size(), SQLITE_STATIC);
3120 //if the ID is not created, we add it to the query
3121 if (sinkClass.sinkClassID != 0)
3123 sqlite3_bind_int(query, 2, sinkClass.sinkClassID);
3126 //if the first static sink is entered, we need to set it onto the boundary
3127 else if (mFirstStaticSinkClass)
3129 sqlite3_bind_int(query, 2, DYNAMIC_ID_BOUNDARY);
3130 mFirstStaticSinkClass = false;
3133 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3135 logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode);
3137 return E_DATABASE_ERROR;
3140 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3142 logError("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:", eCode);
3144 return E_DATABASE_ERROR;
3147 sinkClassID = sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
3149 //now we need to create the additional tables:
3150 command = "CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
3151 assert(this->sqQuery(command));
3153 //fill ConnectionFormats
3154 command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
3155 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3156 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
3157 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
3159 sqlite3_bind_int(query, 1, Iterator->classProperty);
3160 sqlite3_bind_int(query, 2, Iterator->value);
3161 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3163 logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode);
3165 return E_DATABASE_ERROR;
3167 sqlite3_reset(query);
3170 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3172 logError("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:", eCode);
3174 return E_DATABASE_ERROR;
3177 logInfo("DatabaseHandler::enterSinkClassDB entered new sinkClass");
3178 if (mDatabaseObserver)
3179 mDatabaseObserver->numberOfSinkClassesChanged();
3183 am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
3185 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
3186 assert(!sourceClass.name.empty());
3188 sqlite3_stmt* query = NULL;
3190 std::string command;
3192 //if sinkID is zero and the first Static Sink was already entered, the ID is created
3193 if (sourceClass.sourceClassID == 0 && !mFirstStaticSourceClass)
3195 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
3199 //check if the ID already exists
3200 if (existSourceClass(sourceClass.sourceClassID))
3201 return E_ALREADY_EXISTS;
3202 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
3205 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3206 sqlite3_bind_text(query, 1, sourceClass.name.c_str(), sourceClass.name.size(), SQLITE_STATIC);
3208 //if the ID is not created, we add it to the query
3209 if (sourceClass.sourceClassID != 0)
3211 sqlite3_bind_int(query, 2, sourceClass.sourceClassID);
3214 //if the first static sink is entered, we need to set it onto the boundary
3215 else if (mFirstStaticSourceClass)
3217 sqlite3_bind_int(query, 2, DYNAMIC_ID_BOUNDARY);
3218 mFirstStaticSourceClass = false;
3221 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3223 logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode);
3225 return E_DATABASE_ERROR;
3228 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3230 logError("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:", eCode);
3232 return E_DATABASE_ERROR;
3235 sourceClassID = sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
3237 //now we need to create the additional tables:
3238 command = "CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
3239 assert(sqQuery(command));
3241 //fill ConnectionFormats
3242 command = "INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
3243 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3244 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
3245 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
3247 sqlite3_bind_int(query, 1, Iterator->classProperty);
3248 sqlite3_bind_int(query, 2, Iterator->value);
3249 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3251 logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode);
3253 return E_DATABASE_ERROR;
3255 sqlite3_reset(query);
3258 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3260 logError("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:", eCode);
3262 return E_DATABASE_ERROR;
3265 logInfo("DatabaseHandler::enterSourceClassDB entered new sourceClass");
3267 if (mDatabaseObserver)
3268 mDatabaseObserver->numberOfSourceClassesChanged();
3272 am_Error_e DatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
3274 assert(!listSystemProperties.empty());
3275 sqlite3_stmt* query = NULL;
3277 std::vector<am_SystemProperty_s>::const_iterator listIterator = listSystemProperties.begin();
3278 std::string command = "DELETE * FROM " + std::string(SYSTEM_TABLE);
3281 command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
3283 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3284 for (; listIterator < listSystemProperties.end(); ++listIterator)
3286 sqlite3_bind_int(query, 1, listIterator->type);
3287 sqlite3_bind_int(query, 2, listIterator->value);
3289 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3291 logError("DatabaseHandler::enterSystemProperties SQLITE Step error code:", eCode);
3293 return E_DATABASE_ERROR;
3296 sqlite3_reset(query);
3299 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3301 logError("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:", eCode);
3303 return E_DATABASE_ERROR;
3306 logInfo("DatabaseHandler::enterSystemProperties entered system properties");
3310 bool DatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
3312 sqlite3_stmt* query = NULL;
3313 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
3315 bool returnVal = true;
3316 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3317 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3319 else if (eCode != SQLITE_ROW)
3322 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3324 sqlite3_finalize(query);
3328 bool DatabaseHandler::existSource(const am_sourceID_t sourceID) const
3330 sqlite3_stmt* query = NULL;
3331 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
3333 bool returnVal = true;
3334 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3335 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3337 else if (eCode != SQLITE_ROW)
3340 logError("DatabaseHandler::existSource database error!:", eCode);
3342 sqlite3_finalize(query);
3346 bool DatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
3348 sqlite3_stmt* query = NULL;
3349 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
3351 bool returnVal = true;
3352 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3353 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3354 sqlite3_bind_int(query, 2, sourceID);
3355 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3357 else if (eCode != SQLITE_ROW)
3360 logError("DatabaseHandler::existSource database error!:", eCode);
3362 sqlite3_finalize(query);
3366 bool DatabaseHandler::existSourceName(const std::string & name) const
3368 sqlite3_stmt* query = NULL;
3369 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
3371 bool returnVal = true;
3372 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3373 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3374 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3376 else if (eCode != SQLITE_ROW)
3379 logError("DatabaseHandler::existSource database error!:", eCode);
3381 sqlite3_finalize(query);
3385 bool DatabaseHandler::existSink(const am_sinkID_t sinkID) const
3387 sqlite3_stmt* query = NULL;
3388 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3390 bool returnVal = true;
3391 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3392 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3394 else if (eCode != SQLITE_ROW)
3397 logError("DatabaseHandler::existSink database error!:", eCode);
3399 sqlite3_finalize(query);
3403 bool DatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
3405 sqlite3_stmt* query = NULL;
3406 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
3408 bool returnVal = true;
3409 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3410 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3411 sqlite3_bind_int(query, 2, sinkID);
3412 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3414 else if (eCode != SQLITE_ROW)
3417 logError("DatabaseHandler::existSink database error!:", eCode);
3419 sqlite3_finalize(query);
3423 bool DatabaseHandler::existSinkName(const std::string & name) const
3425 sqlite3_stmt* query = NULL;
3426 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
3428 bool returnVal = true;
3429 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3430 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3431 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3433 else if (eCode != SQLITE_ROW)
3436 logError("DatabaseHandler::existSink database error!:", eCode);
3438 sqlite3_finalize(query);
3442 bool DatabaseHandler::existDomain(const am_domainID_t domainID) const
3444 sqlite3_stmt* query = NULL;
3445 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
3447 bool returnVal = true;
3448 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3449 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3451 else if (eCode != SQLITE_ROW)
3454 logError("DatabaseHandler::existDomain database error!:", eCode);
3456 sqlite3_finalize(query);
3460 bool DatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
3462 sqlite3_stmt* query = NULL;
3463 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
3465 bool returnVal = true;
3466 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3467 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3469 else if (eCode != SQLITE_ROW)
3472 logError("DatabaseHandler::existGateway database error!:", eCode);
3474 sqlite3_finalize(query);
3478 am_Error_e DatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
3480 assert(sourceID!=0);
3482 sqlite3_stmt* query = NULL;
3483 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3485 am_Error_e returnVal = E_DATABASE_ERROR;
3486 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3487 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3489 domainID = sqlite3_column_int(query, 0);
3494 logError("DatabaseHandler::getDomainOfSource database error!:", eCode);
3496 sqlite3_finalize(query);
3500 am_Error_e am::DatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const
3504 sqlite3_stmt* query = NULL;
3505 std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3507 am_Error_e returnVal = E_DATABASE_ERROR;
3508 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3509 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3511 domainID = sqlite3_column_int(query, 0);
3516 logError("DatabaseHandler::getDomainOfSink database error!:", eCode);
3518 sqlite3_finalize(query);
3522 bool DatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3524 sqlite3_stmt* query = NULL;
3525 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
3527 bool returnVal = true;
3528 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3529 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3531 else if (eCode != SQLITE_ROW)
3534 logError("DatabaseHandler::existSinkClass database error!:", eCode);
3536 sqlite3_finalize(query);
3540 bool DatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3542 sqlite3_stmt* query = NULL;
3543 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
3545 bool returnVal = true;
3546 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3547 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3549 else if (eCode != SQLITE_ROW)
3552 logError("DatabaseHandler::existSinkClass database error!:", eCode);
3554 sqlite3_finalize(query);
3558 am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3560 assert(connectionID!=0);
3562 sqlite3_stmt *query = NULL, *queryMainConnections, *queryMainConnectionSubIDs;
3563 int eCode = 0, eCode1 = 0;
3564 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3566 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3567 sqlite3_bind_int(query, 1, delay);
3568 sqlite3_bind_int(query, 2, connectionID);
3570 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3572 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:", eCode);
3574 return E_DATABASE_ERROR;
3577 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3579 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:", eCode);
3581 return E_DATABASE_ERROR;
3584 //now we need to find all mainConnections that use the changed connection and update their timing
3586 int tempMainConnectionID;
3587 //first get all route tables for all mainconnections
3588 command = "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'";
3589 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryMainConnections, NULL);
3591 while ((eCode = sqlite3_step(queryMainConnections)) == SQLITE_ROW)
3593 //now check if the connection ID is in this table
3594 std::string tablename = std::string((const char*) sqlite3_column_text(queryMainConnections, 0));
3595 std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID);
3596 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &queryMainConnectionSubIDs, NULL);
3597 if ((eCode1 = sqlite3_step(queryMainConnectionSubIDs)) == SQLITE_ROW)
3599 //if the connection ID is in, recalculate the mainconnection delay
3600 std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID;
3601 changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID), tempMainConnectionID);
3603 else if (eCode1 != SQLITE_DONE)
3605 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode1);
3607 return E_DATABASE_ERROR;
3611 if (eCode != SQLITE_DONE)
3613 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode);
3615 return E_DATABASE_ERROR;
3618 if ((eCode = sqlite3_finalize(queryMainConnections)) != SQLITE_OK)
3620 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:", eCode);
3622 return E_DATABASE_ERROR;
3628 am_Error_e DatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3630 assert(connectionID!=0);
3632 sqlite3_stmt *query = NULL;
3634 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3636 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3637 sqlite3_bind_int(query, 1, connectionID);
3639 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3641 logError("DatabaseHandler::changeConnectionFinal SQLITE Step error code:", eCode);
3643 return E_DATABASE_ERROR;
3646 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3648 logError("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:", eCode);
3650 return E_DATABASE_ERROR;
3655 am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3657 assert(mainConnectionID!=0);
3658 sqlite3_stmt* query = NULL;
3659 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";
3661 am_timeSync_t delay = 0;
3662 am_timeSync_t min = 0;
3663 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3664 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3666 delay = sqlite3_column_int(query, 0);
3667 min = sqlite3_column_int(query, 1);
3669 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3671 logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:", eCode);
3673 return E_DATABASE_ERROR;
3676 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3678 logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:", eCode);
3680 return E_DATABASE_ERROR;
3688 void DatabaseHandler::registerObserver(DatabaseObserver *iObserver)
3690 assert(iObserver!=NULL);
3691 mDatabaseObserver = iObserver;
3694 bool DatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3696 assert(sourceID!=0);
3697 sqlite3_stmt* query = NULL;
3698 std::string command = "SELECT visible FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3700 bool returnVal = false;
3701 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3702 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3704 returnVal = (bool) sqlite3_column_int(query, 0);
3706 else if (eCode != SQLITE_ROW)
3709 logError("DatabaseHandler::sourceVisible database error!:", eCode);
3711 sqlite3_finalize(query);
3715 bool DatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3717 sqlite3_stmt* query = NULL;
3718 std::string command = "SELECT visible FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3720 bool returnVal = false;
3721 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3722 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3724 returnVal = sqlite3_column_int(query, 0);
3726 else if (eCode != SQLITE_ROW)
3729 logError("DatabaseHandler::sinkVisible database error!:", eCode);
3731 sqlite3_finalize(query);
3735 bool DatabaseHandler::existConnection(const am_Connection_s connection)
3737 sqlite3_stmt* query = NULL;
3738 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3740 bool returnVal = true;
3741 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3742 sqlite3_bind_int(query, 1, connection.sinkID);
3743 sqlite3_bind_int(query, 2, connection.sourceID);
3744 sqlite3_bind_int(query, 3, connection.connectionFormat);
3745 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3747 else if (eCode != SQLITE_ROW)
3750 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3752 sqlite3_finalize(query);
3756 bool DatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3758 sqlite3_stmt* query = NULL;
3759 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3761 bool returnVal = true;
3762 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3763 sqlite3_bind_int(query, 1, connectionID);
3764 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3766 else if (eCode != SQLITE_ROW)
3769 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3771 sqlite3_finalize(query);
3775 bool DatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3777 sqlite3_stmt* query = NULL;
3778 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3780 bool returnVal = true;
3781 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3782 sqlite3_bind_int(query, 1, crossfaderID);
3783 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3785 else if (eCode != SQLITE_ROW)
3788 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3790 sqlite3_finalize(query);
3794 am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3796 assert(sourceID!=0);
3797 sqlite3_stmt* query = NULL;
3798 sourceState = SS_UNKNNOWN;
3799 std::string command = "SELECT sourceState FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3801 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3802 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3804 sourceState = (am_SourceState_e) sqlite3_column_int(query, 0);
3806 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3808 logError("DatabaseHandler::getSoureState database error!:", eCode);
3810 sqlite3_finalize(query);
3814 am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3816 assert(sourceID!=0);
3817 assert(sourceState>=SS_UNKNNOWN && sourceState<=SS_MAX);
3818 sqlite3_stmt* query = NULL;
3819 std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID);
3821 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3822 sqlite3_bind_int(query, 1, sourceState);
3823 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3825 logError("DatabaseHandler::changeSourceState SQLITE Step error code:", eCode);
3827 return E_DATABASE_ERROR;
3830 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3832 logError("DatabaseHandler::changeSourceState SQLITE Finalize error code:", eCode);
3834 return E_DATABASE_ERROR;
3839 am_Error_e DatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3842 sqlite3_stmt* query = NULL;
3844 std::string command = "SELECT volume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3846 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3847 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3849 volume = sqlite3_column_int(query, 0);
3851 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3853 logError("DatabaseHandler::getSinkVolume database error!:", eCode);
3855 sqlite3_finalize(query);
3859 am_Error_e DatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
3861 assert(sourceID!=0);
3862 sqlite3_stmt* query = NULL;
3864 std::string command = "SELECT volume FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3866 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3867 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3869 volume = sqlite3_column_int(query, 0);
3871 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3873 logError("DatabaseHandler::getSourceVolume database error!:", eCode);
3875 sqlite3_finalize(query);
3879 am_Error_e DatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3882 if (!existSink(sinkID))
3883 return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3885 sqlite3_stmt* query = NULL;
3887 std::string command = "SELECT value FROM SinkSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType);
3888 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3890 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3892 value = sqlite3_column_int(query, 0);
3895 if (eCode != SQLITE_DONE)
3897 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode);
3899 return E_DATABASE_ERROR;
3902 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3904 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:", eCode);
3906 return E_DATABASE_ERROR;
3912 am_Error_e DatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3914 assert(sourceID!=0);
3915 if (!existSource(sourceID))
3916 return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3918 sqlite3_stmt* query = NULL;
3920 std::string command = "SELECT value FROM SourceSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType);
3921 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3923 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3925 value = sqlite3_column_int(query, 0);
3928 if (eCode != SQLITE_DONE)
3930 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode);
3932 return E_DATABASE_ERROR;
3935 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3937 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:", eCode);
3939 return E_DATABASE_ERROR;
3945 am_Error_e DatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
3947 assert(domainID!=0);
3948 sqlite3_stmt* query = NULL;
3950 std::string command = "SELECT domainState FROM " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
3952 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3953 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3955 state = (am_DomainState_e) sqlite3_column_int(query, 0);
3957 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3959 logError("DatabaseHandler::getDomainState database error!:", eCode);
3961 sqlite3_finalize(query);
3966 am_Error_e DatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
3968 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3969 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
3970 int eCode = 0, eCode1 = 0;
3971 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3972 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3973 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3975 domainID = sqlite3_column_int(query, 0);
3977 else if (eCode != SQLITE_DONE)
3979 logError("DatabaseHandler::peekDomain database error!:", eCode);
3980 return E_DATABASE_ERROR;
3984 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
3985 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3986 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3987 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3988 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3990 logError("DatabaseHandler::peekDomain SQLITE Step error code:", eCode1);
3991 return E_DATABASE_ERROR;
3994 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3996 logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1);
3997 return E_DATABASE_ERROR;
3999 domainID = sqlite3_last_insert_rowid(mDatabase);
4001 sqlite3_finalize(query);
4005 am_Error_e DatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
4007 sqlite3_stmt* query = NULL, *queryInsert = NULL;
4008 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
4009 int eCode = 0, eCode1 = 0;
4010 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4011 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
4012 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4014 sinkID = sqlite3_column_int(query, 0);
4016 else if (eCode != SQLITE_DONE)
4018 logError("DatabaseHandler::peekSink database error!:", eCode);
4019 return E_DATABASE_ERROR;
4023 if (mFirstStaticSink)
4025 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
4026 mFirstStaticSink = false;
4030 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
4032 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
4033 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
4034 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
4035 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
4037 logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1);
4038 return E_DATABASE_ERROR;
4041 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
4043 logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1);
4044 return E_DATABASE_ERROR;
4046 sinkID = sqlite3_last_insert_rowid(mDatabase);
4048 sqlite3_finalize(query);
4052 am_Error_e DatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
4054 sqlite3_stmt* query = NULL, *queryInsert = NULL;
4055 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
4056 int eCode = 0, eCode1 = 0;
4057 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4058 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
4059 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4061 sourceID = sqlite3_column_int(query, 0);
4063 else if (eCode != SQLITE_DONE)
4065 logError("DatabaseHandler::peekSink database error!:", eCode);
4066 return E_DATABASE_ERROR;
4070 if (mFirstStaticSource)
4072 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
4073 mFirstStaticSource = false;
4077 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
4079 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
4080 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
4081 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
4082 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
4084 logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1);
4085 return E_DATABASE_ERROR;
4088 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
4090 logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1);
4091 return E_DATABASE_ERROR;
4093 sourceID = sqlite3_last_insert_rowid(mDatabase);
4095 sqlite3_finalize(query);
4099 am_Error_e DatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
4103 sqlite3_stmt* query = NULL;
4105 std::string command;
4107 if (!existSink(sinkID))
4109 return E_NON_EXISTENT;
4111 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
4112 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4113 sqlite3_bind_int(query, 1, volume);
4114 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4116 logError("DatabaseHandler::changeSinkVolume SQLITE Step error code:", eCode);
4118 return E_DATABASE_ERROR;
4120 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4122 logError("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:", eCode);
4124 return E_DATABASE_ERROR;
4127 logInfo("DatabaseHandler::changeSinkVolume changed volume of sink:", sinkID, "to:", volume);
4132 am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
4134 assert(sourceID!=0);
4136 sqlite3_stmt* query = NULL;
4138 std::string command;
4140 if (!existSource(sourceID))
4142 return E_NON_EXISTENT;
4144 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
4145 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4146 sqlite3_bind_int(query, 1, volume);
4147 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4149 logError("DatabaseHandler::changeSourceVolume SQLITE Step error code:", eCode);
4151 return E_DATABASE_ERROR;
4153 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4155 logError("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:", eCode);
4157 return E_DATABASE_ERROR;
4160 logInfo("DatabaseHandler::changeSourceVolume changed volume of source=:", sourceID, "to:", volume);
4165 am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
4167 assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX);
4168 assert(sourceID!=0);
4170 sqlite3_stmt* query = NULL;
4172 std::string command;
4174 if (!existSource(sourceID))
4176 return E_NON_EXISTENT;
4178 command = "UPDATE SourceSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
4179 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4180 sqlite3_bind_int(query, 1, soundProperty.value);
4181 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4183 logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:", eCode);
4185 return E_DATABASE_ERROR;
4188 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4190 logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:", eCode);
4192 return E_DATABASE_ERROR;
4195 logInfo("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value);
4200 am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
4202 assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX);
4205 sqlite3_stmt* query = NULL;
4207 std::string command;
4209 if (!existSink(sinkID))
4211 return E_NON_EXISTENT;
4213 command = "UPDATE SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
4214 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4215 sqlite3_bind_int(query, 1, soundProperty.value);
4216 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4218 logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:", eCode);
4219 return E_DATABASE_ERROR;
4222 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4224 logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:", eCode);
4225 return E_DATABASE_ERROR;
4228 logInfo("DatabaseHandler::changeSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value);
4233 am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
4235 assert(crossfaderID!=0);
4236 assert(hotsink>=HS_UNKNOWN && hotsink>=HS_MAX);
4238 sqlite3_stmt* query = NULL;
4240 std::string command;
4242 if (!existcrossFader(crossfaderID))
4244 return E_NON_EXISTENT;
4246 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
4247 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4248 sqlite3_bind_int(query, 1, hotsink);
4249 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4251 logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:", eCode);
4253 return E_DATABASE_ERROR;
4255 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4257 logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:", eCode);
4259 return E_DATABASE_ERROR;
4262 logInfo("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader=", crossfaderID, "to:", hotsink);
4266 am_Error_e DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree& tree, std::vector<RoutingTreeItem*>& flatTree)
4268 sqlite3_stmt* query = NULL;
4271 std::string command;
4272 am_domainID_t rootID = tree.returnRootDomainID();
4273 RoutingTreeItem *parent = tree.returnRootItem();
4277 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 )";
4281 command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=?";
4288 parent = flatTree.at(i - 1);
4289 rootID = parent->returnDomainID();
4291 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4292 sqlite3_bind_int(query, 1, rootID);
4294 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4296 flatTree.push_back(tree.insertItem(sqlite3_column_int(query, 0), sqlite3_column_int(query, 1), parent));
4299 if (eCode != SQLITE_DONE)
4301 logError("DatabaseHandler::getRoutingTree SQLITE error code:", eCode);
4303 return (E_DATABASE_ERROR);
4306 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4308 logError("DatabaseHandler::getRoutingTree SQLITE Finalize error code:", eCode);
4310 return (E_DATABASE_ERROR);
4313 } while (flatTree.size() > (i - 1));
4318 am_Error_e am::DatabaseHandler::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID)
4321 return E_NON_EXISTENT;
4323 am_Error_e returnVal = E_NON_EXISTENT;
4324 sqlite3_stmt* query = NULL;
4326 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE name=?";
4327 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4328 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
4330 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4332 sinkClassID = sqlite3_column_int(query, 0);
4335 else if (eCode != SQLITE_DONE)
4338 logError("DatabaseHandler::peekSinkClassID SQLITE error code:", eCode);
4339 returnVal = E_DATABASE_ERROR;
4342 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4344 logError("DatabaseHandler::peekSinkClassID SQLITE Finalize error code:", eCode);
4345 returnVal = E_DATABASE_ERROR;
4350 am_Error_e am::DatabaseHandler::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID)
4353 return E_NON_EXISTENT;
4355 am_Error_e returnVal = E_NON_EXISTENT;
4356 sqlite3_stmt* query = NULL;
4358 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE name=?";
4359 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4360 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
4362 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4364 sourceClassID = sqlite3_column_int(query, 0);
4367 else if (eCode != SQLITE_DONE)
4370 logError("DatabaseHandler::peekSourceClassID SQLITE error code:", eCode);
4371 returnVal = E_DATABASE_ERROR;
4374 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4376 logError("DatabaseHandler::peekSourceClassID SQLITE Finalize error code:", eCode);
4377 returnVal = E_DATABASE_ERROR;
4382 void DatabaseHandler::createTables()
4384 for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++)
4386 assert(sqQuery("CREATE TABLE " + databaseTables[i]));