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_MIN && 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.connectionID==0);
180 assert(mainConnectionData.connectionState>=CS_MIN && mainConnectionData.connectionState<=CS_MAX);
181 assert(mainConnectionData.route.sinkID!=0);
182 assert(mainConnectionData.route.sourceID!=0);
184 sqlite3_stmt* query = NULL;
186 std::string command = "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)";
187 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
188 sqlite3_bind_int(query, 1, mainConnectionData.route.sourceID);
189 sqlite3_bind_int(query, 2, mainConnectionData.route.sinkID);
190 sqlite3_bind_int(query, 3, mainConnectionData.connectionState);
192 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
194 logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode);
195 return E_DATABASE_ERROR;
198 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
200 logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode);
201 return E_DATABASE_ERROR;
204 connectionID = sqlite3_last_insert_rowid(mDatabase);
206 //now check the connectionTable for all connections in the route. IF a particular route is not found, we return with error
207 std::vector<uint16_t> listOfConnections;
209 command = "SELECT connectionID, delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
210 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
211 std::vector<am_RoutingElement_s>::const_iterator elementIterator = mainConnectionData.route.route.begin();
212 for (; elementIterator < mainConnectionData.route.route.end(); ++elementIterator)
214 sqlite3_bind_int(query, 1, elementIterator->sourceID);
215 sqlite3_bind_int(query, 2, elementIterator->sinkID);
216 sqlite3_bind_int(query, 3, elementIterator->connectionFormat);
218 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
220 listOfConnections.push_back(sqlite3_column_int(query, 0));
221 int16_t temp_delay = sqlite3_column_int(query, 1);
222 if (temp_delay != -1 && delay != -1)
229 logError("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:", eCode);
231 return E_DATABASE_ERROR;
233 sqlite3_reset(query);
236 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
238 logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode);
239 return E_DATABASE_ERROR;
242 //now we create a table with references to the connections;
243 command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
244 assert(this->sqQuery(command));
246 command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
247 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
248 std::vector<uint16_t>::iterator listConnectionIterator = listOfConnections.begin();
249 for (; listConnectionIterator < listOfConnections.end(); ++listConnectionIterator)
251 sqlite3_bind_int(query, 1, *listConnectionIterator);
252 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
254 logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode);
255 return E_DATABASE_ERROR;
257 sqlite3_reset(query);
260 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
262 logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode);
263 return E_DATABASE_ERROR;
266 logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.route.sourceID, "sinkID:", mainConnectionData.route.sinkID, "delay:", delay, "assigned ID:", connectionID);
268 if (mDatabaseObserver)
270 mDatabaseObserver->numberOfMainConnectionsChanged();
271 mDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState);
274 //finally, we update the delay value for the maintable
277 return changeDelayMainConnection(delay, connectionID);
280 am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
282 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
283 assert(sinkData.domainID!=0);
284 assert(!sinkData.name.empty());
285 assert(sinkData.sinkClassID!=0);
286 // \todo: need to check if class exists?
287 assert(!sinkData.listConnectionFormats.empty());
288 assert(sinkData.muteState>=MS_MIN && sinkData.muteState<=MS_MAX);
290 sqlite3_stmt *query = NULL, *queryFinal = NULL;
292 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
294 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
295 sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
297 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
299 command = "UPDATE " + std::string(SINK_TABLE) + " SET name=?, domainID=?, sinkClassID=?, volume=?, visible=?, availability=?, availabilityReason=?, muteState=?, mainVolume=?, reserved=? WHERE sinkID=" + i2s(sqlite3_column_int(query, 0));
301 else if (eCode == SQLITE_DONE)
303 //if sinkID is zero and the first Static Sink was already entered, the ID is created
304 if (sinkData.sinkID == 0 && !mFirstStaticSink && !existSinkName(sinkData.name))
306 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
310 //check if the ID already exists
311 if (existSinkNameOrID(sinkData.sinkID, sinkData.name))
313 sqlite3_finalize(query);
314 return E_ALREADY_EXISTS;
316 command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
321 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
322 sqlite3_finalize(query);
323 return E_DATABASE_ERROR;
326 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
328 logError("DatabaseHandler::enterSinkDB SQLITE Finalize error code:", eCode);
329 return E_DATABASE_ERROR;
332 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
333 sqlite3_bind_text(queryFinal, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
334 sqlite3_bind_int(queryFinal, 2, sinkData.domainID);
335 sqlite3_bind_int(queryFinal, 3, sinkData.sinkClassID);
336 sqlite3_bind_int(queryFinal, 4, sinkData.volume);
337 sqlite3_bind_int(queryFinal, 5, sinkData.visible);
338 sqlite3_bind_int(queryFinal, 6, sinkData.available.availability);
339 sqlite3_bind_int(queryFinal, 7, sinkData.available.availabilityReason);
340 sqlite3_bind_int(queryFinal, 8, sinkData.muteState);
341 sqlite3_bind_int(queryFinal, 9, sinkData.mainVolume);
342 sqlite3_bind_int(queryFinal, 10, 0);
344 //if the ID is not created, we add it to the query
345 if (sinkData.sinkID != 0)
347 sqlite3_bind_int(queryFinal, 11, sinkData.sinkID);
350 //if the first static sink is entered, we need to set it onto the boundary
351 else if (mFirstStaticSink)
353 sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY);
354 mFirstStaticSink = false;
357 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
359 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
360 sqlite3_finalize(queryFinal);
361 return E_DATABASE_ERROR;
364 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
366 logError("DatabaseHandler::enterSinkDB SQLITE Finalize error code:", eCode);
367 return E_DATABASE_ERROR;
370 //now read back the sinkID
371 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
372 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
373 sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC);
374 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
376 sinkID = sqlite3_column_int(query, 0);
381 logError("DatabaseHandler::existSink database error!:", eCode);
382 sqlite3_finalize(query);
383 return E_DATABASE_ERROR;
385 sqlite3_finalize(query);
387 //now we need to create the additional tables:
388 command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
389 assert(this->sqQuery(command));
390 command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
391 assert(this->sqQuery(command));
393 //fill ConnectionFormats
394 command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
395 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
396 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin();
397 for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator)
399 sqlite3_bind_int(query, 1, *connectionFormatIterator);
400 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
402 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
403 sqlite3_finalize(query);
404 return E_DATABASE_ERROR;
406 sqlite3_reset(query);
409 //Fill SinkSoundProperties
410 command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
411 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
412 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin();
413 for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator)
415 sqlite3_bind_int(query, 1, SoundPropertyIterator->type);
416 sqlite3_bind_int(query, 2, SoundPropertyIterator->value);
417 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
419 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
420 sqlite3_finalize(query);
421 return E_DATABASE_ERROR;
423 sqlite3_reset(query);
426 if (sinkData.visible == true)
428 command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
429 assert(this->sqQuery(command));
431 //Fill MainSinkSoundProperties
432 command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
433 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
434 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin();
435 for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
437 sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type);
438 sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value);
439 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
441 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
442 sqlite3_finalize(query);
443 return E_DATABASE_ERROR;
445 sqlite3_reset(query);
449 logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sinkData.name, "domainID:", sinkData.domainID, "classID:", sinkData.sinkClassID, "volume:", sinkData.volume, "assigned ID:", sinkID);
450 am_Sink_s sink = sinkData;
451 sink.sinkID = sinkID;
452 if (mDatabaseObserver != NULL)
453 mDatabaseObserver->newSink(sink);
457 am_Error_e DatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
459 assert(crossfaderData.crossfaderID<DYNAMIC_ID_BOUNDARY);
460 assert(crossfaderData.hotSink>=HS_MIN && crossfaderData.hotSink<=HS_MAX);
461 assert(!crossfaderData.name.empty());
462 assert(existSink(crossfaderData.sinkID_A));
463 assert(existSink(crossfaderData.sinkID_B));
464 assert(existSource(crossfaderData.sourceID));
466 sqlite3_stmt* query = NULL;
470 //if gatewayData is zero and the first Static Sink was already entered, the ID is created
471 if (crossfaderData.crossfaderID == 0 && !mFirstStaticCrossfader)
473 command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink) VALUES (?,?,?,?,?)";
477 //check if the ID already exists
478 if (existcrossFader(crossfaderData.crossfaderID))
479 return E_ALREADY_EXISTS;
480 command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink, crossfaderID) VALUES (?,?,?,?,?,?)";
483 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
485 sqlite3_bind_text(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC);
486 sqlite3_bind_int(query, 2, crossfaderData.sinkID_A);
487 sqlite3_bind_int(query, 3, crossfaderData.sinkID_B);
488 sqlite3_bind_int(query, 4, crossfaderData.sourceID);
489 sqlite3_bind_int(query, 5, crossfaderData.hotSink);
491 //if the ID is not created, we add it to the query
492 if (crossfaderData.crossfaderID != 0)
494 sqlite3_bind_int(query, 6, crossfaderData.crossfaderID);
497 //if the first static sink is entered, we need to set it onto the boundary
498 else if (mFirstStaticCrossfader)
500 sqlite3_bind_int(query, 6, DYNAMIC_ID_BOUNDARY);
501 mFirstStaticCrossfader = false;
504 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
506 logError("DatabaseHandler::enterCrossfaderDB SQLITE Step error code:", eCode);
507 sqlite3_finalize(query);
508 return E_DATABASE_ERROR;
511 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
513 logError("DatabaseHandler::enterCrossfaderDB SQLITE Finalize error code:", eCode);
514 sqlite3_finalize(query);
515 return E_DATABASE_ERROR;
518 //now read back the crossfaderID
519 command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE name=?";
520 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
521 sqlite3_bind_text(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC);
522 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
524 crossfaderID = sqlite3_column_int(query, 0);
529 logError("DatabaseHandler::enterCrossfaderDB database error!:", eCode);
530 sqlite3_finalize(query);
531 return E_DATABASE_ERROR;
533 sqlite3_finalize(query);
535 logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID);
537 am_Crossfader_s crossfader(crossfaderData);
538 crossfader.crossfaderID = crossfaderID;
539 if (mDatabaseObserver)
540 mDatabaseObserver->newCrossfader(crossfader);
544 am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
546 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
547 assert(gatewayData.sinkID!=0);
548 assert(gatewayData.sourceID!=0);
549 assert(gatewayData.controlDomainID!=0);
550 assert(gatewayData.domainSinkID!=0);
551 assert(gatewayData.domainSourceID!=0);
552 assert(!gatewayData.name.empty());
553 assert(!gatewayData.convertionMatrix.empty());
554 assert(!gatewayData.listSinkFormats.empty());
555 assert(!gatewayData.listSourceFormats.empty());
556 assert(existSink(gatewayData.sinkID));
557 assert(existSource(gatewayData.sourceID));
559 sqlite3_stmt* query = NULL;
563 //if gatewayData is zero and the first Static Sink was already entered, the ID is created
564 if (gatewayData.gatewayID == 0 && !mFirstStaticGateway)
566 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID) VALUES (?,?,?,?,?,?)";
570 //check if the ID already exists
571 if (existGateway(gatewayData.gatewayID))
572 return E_ALREADY_EXISTS;
573 command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID) VALUES (?,?,?,?,?,?,?)";
576 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
577 sqlite3_bind_text(query, 1, gatewayData.name.c_str(), gatewayData.name.size(), SQLITE_STATIC);
578 sqlite3_bind_int(query, 2, gatewayData.sinkID);
579 sqlite3_bind_int(query, 3, gatewayData.sourceID);
580 sqlite3_bind_int(query, 4, gatewayData.domainSinkID);
581 sqlite3_bind_int(query, 5, gatewayData.domainSourceID);
582 sqlite3_bind_int(query, 6, gatewayData.controlDomainID);
584 //if the ID is not created, we add it to the query
585 if (gatewayData.gatewayID != 0)
587 sqlite3_bind_int(query, 7, gatewayData.gatewayID);
590 //if the first static sink is entered, we need to set it onto the boundary
591 else if (mFirstStaticGateway)
593 sqlite3_bind_int(query, 7, DYNAMIC_ID_BOUNDARY);
594 mFirstStaticGateway = false;
597 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
599 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
600 return E_DATABASE_ERROR;
603 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
605 logError("DatabaseHandler::enterGatewayDB SQLITE Finalize error code:", eCode);
606 return E_DATABASE_ERROR;
609 gatewayID = sqlite3_last_insert_rowid(mDatabase);
611 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
612 mListConnectionFormat.insert(std::make_pair(gatewayID, gatewayData.convertionMatrix));
614 command = "CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
615 assert(this->sqQuery(command));
616 command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
617 assert(this->sqQuery(command));
619 //fill ConnectionFormats
620 command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
621 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
622 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin();
623 for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator)
625 sqlite3_bind_int(query, 1, *connectionFormatIterator);
626 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
628 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
629 return E_DATABASE_ERROR;
631 sqlite3_reset(query);
634 command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
635 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
636 connectionFormatIterator = gatewayData.listSinkFormats.begin();
637 for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator)
639 sqlite3_bind_int(query, 1, *connectionFormatIterator);
640 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
642 logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode);
643 return E_DATABASE_ERROR;
645 sqlite3_reset(query);
648 logInfo("DatabaseHandler::enterGatewayDB entered new gateway with name", gatewayData.name, "sourceID:", gatewayData.sourceID, "sinkID:", gatewayData.sinkID, "assigned ID:", gatewayID);
649 am_Gateway_s gateway = gatewayData;
650 gateway.gatewayID = gatewayID;
651 if (mDatabaseObserver)
652 mDatabaseObserver->newGateway(gateway);
656 am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
658 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
659 assert(sourceData.domainID!=0);
660 assert(!sourceData.name.empty());
661 assert(sourceData.sourceClassID!=0);
662 // \todo: need to check if class exists?
663 assert(!sourceData.listConnectionFormats.empty());
664 assert(sourceData.sourceState>=SS_MIN && sourceData.sourceState<=SS_MAX);
666 sqlite3_stmt* query = NULL, *queryFinal = NULL;
669 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
671 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
672 sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
674 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
676 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));
678 else if (eCode == SQLITE_DONE)
680 //if sinkID is zero and the first Static Sink was already entered, the ID is created
681 if (sourceData.sourceID == 0 && !mFirstStaticSource && !existSourceName(sourceData.name))
683 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
687 //check if the ID already exists
688 if (existSourceNameOrID(sourceData.sourceID, sourceData.name))
690 sqlite3_finalize(query);
691 return E_ALREADY_EXISTS;
693 command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
698 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
699 sqlite3_finalize(query);
700 return E_DATABASE_ERROR;
703 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
705 logError("DatabaseHandler::enterSourceDB SQLITE Finalize error code:", eCode);
706 return E_DATABASE_ERROR;
708 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL);
709 sqlite3_bind_text(queryFinal, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
710 sqlite3_bind_int(queryFinal, 2, sourceData.domainID);
711 sqlite3_bind_int(queryFinal, 3, sourceData.sourceClassID);
712 sqlite3_bind_int(queryFinal, 4, sourceData.sourceState);
713 sqlite3_bind_int(queryFinal, 5, sourceData.volume);
714 sqlite3_bind_int(queryFinal, 6, sourceData.visible);
715 sqlite3_bind_int(queryFinal, 7, sourceData.available.availability);
716 sqlite3_bind_int(queryFinal, 8, sourceData.available.availabilityReason);
717 sqlite3_bind_int(queryFinal, 9, sourceData.interruptState);
718 sqlite3_bind_int(queryFinal, 10, 0);
720 //if the ID is not created, we add it to the query
721 if (sourceData.sourceID != 0)
723 sqlite3_bind_int(queryFinal, 11, sourceData.sourceID);
726 //if the first static sink is entered, we need to set it onto the boundary
727 else if (mFirstStaticSource)
729 sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY);
730 mFirstStaticSource = false;
733 if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE)
735 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
736 sqlite3_finalize(queryFinal);
737 return E_DATABASE_ERROR;
740 if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK)
742 logError("DatabaseHandler::enterSourceDB SQLITE Finalize error code:", eCode);
743 sqlite3_finalize(queryFinal);
744 return E_DATABASE_ERROR;
747 //now read back the sinkID
748 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
749 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
750 sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC);
751 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
753 sourceID = sqlite3_column_int(query, 0);
758 logError("DatabaseHandler::existSink database error!:", eCode);
759 sqlite3_finalize(query);
760 return E_DATABASE_ERROR;
762 sqlite3_finalize(query);
764 //now we need to create the additional tables:
765 command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
766 assert(this->sqQuery(command));
767 command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
768 assert(this->sqQuery(command));
770 //fill ConnectionFormats
771 command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
772 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
773 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin();
774 for (; connectionFormatIterator < sourceData.listConnectionFormats.end(); ++connectionFormatIterator)
776 sqlite3_bind_int(query, 1, *connectionFormatIterator);
777 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
779 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
780 sqlite3_finalize(query);
781 return E_DATABASE_ERROR;
783 sqlite3_reset(query);
786 //Fill SinkSoundProperties
787 command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
788 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
789 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin();
790 for (; SoundPropertyIterator < sourceData.listSoundProperties.end(); ++SoundPropertyIterator)
792 sqlite3_bind_int(query, 1, SoundPropertyIterator->type);
793 sqlite3_bind_int(query, 2, SoundPropertyIterator->value);
794 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
796 logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode);
797 sqlite3_finalize(query);
798 return E_DATABASE_ERROR;
800 sqlite3_reset(query);
803 if (sourceData.visible == true)
805 command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
806 assert(this->sqQuery(command));
808 //Fill MainSinkSoundProperties
809 command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
810 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
811 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin();
812 for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator)
814 sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type);
815 sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value);
816 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
818 logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode);
819 sqlite3_finalize(query);
820 return E_DATABASE_ERROR;
822 sqlite3_reset(query);
826 logInfo("DatabaseHandler::enterSinkDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID);
828 am_Source_s source = sourceData;
829 source.sourceID = sourceID;
830 if (mDatabaseObserver)
831 mDatabaseObserver->newSource(source);
835 am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
837 assert(mainconnectionID!=0);
838 if (!existMainConnection(mainconnectionID))
840 return E_NON_EXISTENT;
842 sqlite3_stmt* query = NULL;
846 std::vector<uint16_t> listOfConnections;
848 command = "SELECT connectionID, delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
849 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
850 std::vector<am_RoutingElement_s>::const_iterator elementIterator = route.route.begin();
851 for (; elementIterator < route.route.end(); ++elementIterator)
853 sqlite3_bind_int(query, 1, elementIterator->sourceID);
854 sqlite3_bind_int(query, 2, elementIterator->sinkID);
855 sqlite3_bind_int(query, 3, elementIterator->connectionFormat);
857 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
859 listOfConnections.push_back(sqlite3_column_int(query, 0));
860 int16_t temp_delay = sqlite3_column_int(query, 1);
861 if (temp_delay != -1 && delay != -1)
868 logError("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:", eCode);
870 return E_DATABASE_ERROR;
872 sqlite3_reset(query);
875 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
877 logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:", eCode);
879 return E_DATABASE_ERROR;
882 //now we delete the data in the table
883 command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID);
884 assert(this->sqQuery(command));
886 command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
887 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
888 std::vector<uint16_t>::iterator listConnectionIterator = listOfConnections.begin();
889 for (; listConnectionIterator < listOfConnections.end(); ++listConnectionIterator)
891 sqlite3_bind_int(query, 1, *listConnectionIterator);
892 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
894 logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:", eCode);
896 return E_DATABASE_ERROR;
898 sqlite3_reset(query);
901 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
903 logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:", eCode);
905 return E_DATABASE_ERROR;
907 logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID);
911 am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
913 assert(mainconnectionID!=0);
914 assert(connectionState>=CS_MIN && connectionState<=CS_MAX);
916 sqlite3_stmt* query = NULL;
920 if (!existMainConnection(mainconnectionID))
922 return E_NON_EXISTENT;
924 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
925 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
926 sqlite3_bind_int(query, 1, connectionState);
927 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
929 logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:", eCode);
930 return E_DATABASE_ERROR;
932 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
934 logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:", eCode);
935 return E_DATABASE_ERROR;
937 logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState);
939 if (mDatabaseObserver)
940 mDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState);
944 am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
948 sqlite3_stmt* query = NULL;
952 if (!existSink(sinkID))
954 return E_NON_EXISTENT;
956 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
957 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
958 sqlite3_bind_int(query, 1, mainVolume);
959 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
961 logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:", eCode);
962 return E_DATABASE_ERROR;
964 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
966 logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:", eCode);
967 return E_DATABASE_ERROR;
970 logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume);
972 if (mDatabaseObserver)
973 mDatabaseObserver->volumeChanged(sinkID, mainVolume);
978 am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
981 assert(availability.availability>=A_MIN && availability.availability<=A_MAX);
982 assert(availability.availabilityReason>=AR_MIN && availability.availabilityReason<=AR_MAX);
984 sqlite3_stmt* query = NULL;
988 if (!existSink(sinkID))
990 return E_NON_EXISTENT;
992 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
993 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
994 sqlite3_bind_int(query, 1, availability.availability);
995 sqlite3_bind_int(query, 2, availability.availabilityReason);
996 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
998 logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:", eCode);
999 return E_DATABASE_ERROR;
1002 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1004 logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:", eCode);
1005 return E_DATABASE_ERROR;
1008 logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason);
1010 if (mDatabaseObserver && sourceVisible(sinkID))
1011 mDatabaseObserver->sinkAvailabilityChanged(sinkID, availability);
1015 am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
1017 assert(domainID!=0);
1018 assert(domainState>=DS_MIN && domainState<=DS_MAX);
1020 sqlite3_stmt* query = NULL;
1022 std::string command;
1024 if (!existDomain(domainID))
1026 return E_NON_EXISTENT;
1028 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
1029 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1030 sqlite3_bind_int(query, 1, domainState);
1031 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1033 logError("DatabaseHandler::changDomainStateDB SQLITE Step error code:", eCode);
1035 return E_DATABASE_ERROR;
1038 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1040 logError("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:", eCode);
1041 return E_DATABASE_ERROR;
1044 logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState);
1048 am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
1051 assert(muteState>=MS_MIN && muteState<=MS_MAX);
1053 sqlite3_stmt* query = NULL;
1055 std::string command;
1057 if (!existSink(sinkID))
1059 return E_NON_EXISTENT;
1061 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
1062 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1063 sqlite3_bind_int(query, 1, muteState);
1064 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1066 logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:", eCode);
1067 return E_DATABASE_ERROR;
1070 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1072 logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:", eCode);
1073 return E_DATABASE_ERROR;
1076 logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState);
1078 if (mDatabaseObserver)
1079 mDatabaseObserver->sinkMuteStateChanged(sinkID, muteState);
1084 am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
1086 assert(soundProperty.type>=MSP_MIN && soundProperty.type<=MSP_MAX);
1089 sqlite3_stmt* query = NULL;
1091 std::string command;
1093 if (!existSink(sinkID))
1095 return E_NON_EXISTENT;
1097 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1098 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1099 sqlite3_bind_int(query, 1, soundProperty.value);
1100 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1102 logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:", eCode);
1103 return E_DATABASE_ERROR;
1106 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1108 logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:", eCode);
1109 return E_DATABASE_ERROR;
1112 logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value);
1113 if (mDatabaseObserver)
1114 mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty);
1118 am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1120 assert(soundProperty.type>=MSP_MIN && soundProperty.type<=MSP_MAX);
1121 assert(sourceID!=0);
1123 sqlite3_stmt* query = NULL;
1125 std::string command;
1127 if (!existSource(sourceID))
1129 return E_NON_EXISTENT;
1131 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1132 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1133 sqlite3_bind_int(query, 1, soundProperty.value);
1134 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1136 logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:", eCode);
1137 return E_DATABASE_ERROR;
1140 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1142 logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:", eCode);
1143 return E_DATABASE_ERROR;
1146 logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value);
1148 if (mDatabaseObserver)
1149 mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty);
1153 am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1155 assert(sourceID!=0);
1156 assert(availability.availability>=A_MIN && availability.availability<=A_MAX);
1157 assert(availability.availabilityReason>=AR_MIN && availability.availabilityReason<=AR_MAX);
1159 sqlite3_stmt* query = NULL;
1161 std::string command;
1163 if (!existSource(sourceID))
1165 return E_NON_EXISTENT;
1167 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1168 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1169 sqlite3_bind_int(query, 1, availability.availability);
1170 sqlite3_bind_int(query, 2, availability.availabilityReason);
1171 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1173 logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:", eCode);
1174 return E_DATABASE_ERROR;
1177 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1179 logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:", eCode);
1180 return E_DATABASE_ERROR;
1183 logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason);
1185 if (mDatabaseObserver && sourceVisible(sourceID))
1186 mDatabaseObserver->sourceAvailabilityChanged(sourceID, availability);
1190 am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1192 assert(property.type>=SYP_MIN && property.type<=SYP_MAX);
1193 sqlite3_stmt* query = NULL;
1195 std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1197 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1198 sqlite3_bind_int(query, 1, property.value);
1199 sqlite3_bind_int(query, 2, property.type);
1201 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1203 logError("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:", eCode);
1204 return E_DATABASE_ERROR;
1207 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1209 logError("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:", eCode);
1210 return E_DATABASE_ERROR;
1213 logInfo("DatabaseHandler::changeSystemPropertyDB changed system property");
1215 if (mDatabaseObserver)
1216 mDatabaseObserver->systemPropertyChanged(property);
1221 am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1223 assert(mainConnectionID!=0);
1225 if (!existMainConnection(mainConnectionID))
1227 return E_NON_EXISTENT;
1229 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1230 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1231 if (!sqQuery(command))
1232 return E_DATABASE_ERROR;
1233 if (!sqQuery(command1))
1234 return E_DATABASE_ERROR;
1235 logInfo("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID);
1236 if (mDatabaseObserver)
1238 mDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED);
1239 mDatabaseObserver->numberOfMainConnectionsChanged();
1244 am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1248 if (!existSink(sinkID))
1250 return E_NON_EXISTENT;
1252 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1253 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1254 std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1255 std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID);
1256 if (!sqQuery(command))
1257 return E_DATABASE_ERROR;
1258 if (!sqQuery(command1))
1259 return E_DATABASE_ERROR;
1260 if (!sqQuery(command2))
1261 return E_DATABASE_ERROR;
1262 if (!sqQuery(command3))
1263 return E_DATABASE_ERROR;
1264 logInfo("DatabaseHandler::removeSinkDB removed:", sinkID);
1266 if (mDatabaseObserver != NULL)
1267 mDatabaseObserver->removedSink(sinkID);
1272 am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1274 assert(sourceID!=0);
1276 if (!existSource(sourceID))
1278 return E_NON_EXISTENT;
1280 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1281 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1282 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1283 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1284 if (!sqQuery(command))
1285 return E_DATABASE_ERROR;
1286 if (!sqQuery(command1))
1287 return E_DATABASE_ERROR;
1288 if (!sqQuery(command2))
1289 return E_DATABASE_ERROR;
1290 if (!sqQuery(command3))
1291 return E_DATABASE_ERROR;
1292 logInfo("DatabaseHandler::removeSourceDB removed:", sourceID);
1293 if (mDatabaseObserver)
1294 mDatabaseObserver->removedSource(sourceID);
1298 am_Error_e DatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1300 assert(gatewayID!=0);
1302 if (!existGateway(gatewayID))
1304 return E_NON_EXISTENT;
1306 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1307 if (!sqQuery(command))
1308 return E_DATABASE_ERROR;
1309 logInfo("DatabaseHandler::removeGatewayDB removed:", gatewayID);
1310 if (mDatabaseObserver)
1311 mDatabaseObserver->removeGateway(gatewayID);
1315 am_Error_e DatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1317 assert(crossfaderID!=0);
1319 if (!existcrossFader(crossfaderID))
1321 return E_NON_EXISTENT;
1323 std::string command = "DELETE from " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID);
1324 if (!sqQuery(command))
1325 return E_DATABASE_ERROR;
1326 logInfo("DatabaseHandler::removeDomainDB removed:", crossfaderID);
1327 if (mDatabaseObserver)
1328 mDatabaseObserver->removeCrossfader(crossfaderID);
1332 am_Error_e DatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1334 assert(domainID!=0);
1336 if (!existDomain(domainID))
1338 return E_NON_EXISTENT;
1340 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1341 if (!sqQuery(command))
1342 return E_DATABASE_ERROR;
1343 logInfo("DatabaseHandler::removeDomainDB removed:", domainID);
1344 if (mDatabaseObserver)
1345 mDatabaseObserver->removeDomain(domainID);
1349 am_Error_e DatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1351 assert(sinkClassID!=0);
1353 if (!existSinkClass(sinkClassID))
1355 return E_NON_EXISTENT;
1357 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1358 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1359 if (!sqQuery(command))
1360 return E_DATABASE_ERROR;
1361 if (!sqQuery(command1))
1362 return E_DATABASE_ERROR;
1364 logInfo("DatabaseHandler::removeSinkClassDB removed:", sinkClassID);
1365 if (mDatabaseObserver)
1366 mDatabaseObserver->numberOfSinkClassesChanged();
1371 am_Error_e DatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1373 assert(sourceClassID!=0);
1375 if (!existSourceClass(sourceClassID))
1377 return E_NON_EXISTENT;
1379 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1380 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1381 if (!sqQuery(command))
1382 return E_DATABASE_ERROR;
1383 if (!sqQuery(command1))
1384 return E_DATABASE_ERROR;
1385 logInfo("DatabaseHandler::removeSourceClassDB removed:", sourceClassID);
1386 if (mDatabaseObserver)
1387 mDatabaseObserver->numberOfSourceClassesChanged();
1391 am_Error_e DatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1393 assert(connectionID!=0);
1395 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1396 std::string command1 = "DROP table SourceClassProperties" + i2s(connectionID);
1397 if (!sqQuery(command))
1398 return E_DATABASE_ERROR;
1399 if (!sqQuery(command1))
1400 return E_DATABASE_ERROR;
1401 logInfo("DatabaseHandler::removeConnection removed:", connectionID);
1405 am_Error_e DatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1407 assert(sourceID!=0);
1409 if (!existSource(sourceID))
1411 return E_NON_EXISTENT;
1413 sqlite3_stmt* query = NULL;
1415 am_ClassProperty_s propertyTemp;
1416 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + (i2s(sourceID));
1417 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1419 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1421 classInfo.sourceClassID = sqlite3_column_int(query, 0);
1424 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1426 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1427 return E_DATABASE_ERROR;
1430 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1432 logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode);
1433 return E_DATABASE_ERROR;
1436 command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1437 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1439 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1441 classInfo.name = std::string((const char*) sqlite3_column_text(query, 0));
1444 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1446 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1447 return E_DATABASE_ERROR;
1450 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1452 logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode);
1453 return E_DATABASE_ERROR;
1456 //read out Properties
1457 command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID);
1458 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1459 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1461 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1462 propertyTemp.value = sqlite3_column_int(query, 1);
1463 classInfo.listClassProperties.push_back(propertyTemp);
1466 if (eCode != SQLITE_DONE)
1468 logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode);
1469 return E_DATABASE_ERROR;
1472 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1474 logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode);
1475 return E_DATABASE_ERROR;
1480 am_Error_e DatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1482 assert(sinkClass.sinkClassID!=0);
1483 assert(!sinkClass.listClassProperties.empty());
1485 sqlite3_stmt* query = NULL;
1488 //check if the ID already exists
1489 if (!existSinkClass(sinkClass.sinkClassID))
1490 return E_NON_EXISTENT;
1492 //fill ConnectionFormats
1493 std::string command = "UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1494 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1495 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
1496 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
1498 sqlite3_bind_int(query, 1, Iterator->value);
1499 sqlite3_bind_int(query, 2, Iterator->classProperty);
1500 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1502 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode);
1503 return E_DATABASE_ERROR;
1505 sqlite3_reset(query);
1508 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1510 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:", eCode);
1511 return E_DATABASE_ERROR;
1514 logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo");
1518 am_Error_e DatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1520 assert(sourceClass.sourceClassID!=0);
1521 assert(!sourceClass.listClassProperties.empty());
1523 sqlite3_stmt* query = NULL;
1526 //check if the ID already exists
1527 if (!existSourceClass(sourceClass.sourceClassID))
1528 return E_NON_EXISTENT;
1530 //fill ConnectionFormats
1531 std::string command = "UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1532 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1533 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
1534 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
1536 sqlite3_bind_int(query, 1, Iterator->value);
1537 sqlite3_bind_int(query, 2, Iterator->classProperty);
1538 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1540 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode);
1541 return E_DATABASE_ERROR;
1543 sqlite3_reset(query);
1546 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1548 logError("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:", eCode);
1549 return E_DATABASE_ERROR;
1552 logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo");
1556 am_Error_e DatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1560 if (!existSink(sinkID))
1562 return E_NON_EXISTENT;
1564 sqlite3_stmt* query = NULL;
1566 am_ClassProperty_s propertyTemp;
1567 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + (i2s(sinkID));
1568 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1570 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1572 sinkClass.sinkClassID = sqlite3_column_int(query, 0);
1575 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1577 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1578 return E_DATABASE_ERROR;
1581 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1583 logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode);
1584 return E_DATABASE_ERROR;
1587 command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1588 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1590 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1592 sinkClass.name = std::string((const char*) sqlite3_column_text(query, 0));
1595 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
1597 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1598 return E_DATABASE_ERROR;
1601 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1603 logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode);
1604 return E_DATABASE_ERROR;
1607 //read out Properties
1608 command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID);
1609 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1610 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1612 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0);
1613 propertyTemp.value = sqlite3_column_int(query, 1);
1614 sinkClass.listClassProperties.push_back(propertyTemp);
1617 if (eCode != SQLITE_DONE)
1619 logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode);
1620 return E_DATABASE_ERROR;
1623 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1625 logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode);
1626 return E_DATABASE_ERROR;
1631 am_Error_e DatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1633 assert(gatewayID!=0);
1634 if (!existGateway(gatewayID))
1636 return E_NON_EXISTENT;
1638 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
1640 am_ConnectionFormat_e tempConnectionFormat;
1641 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1642 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1644 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1646 gatewayData.name = std::string((const char*) sqlite3_column_text(query, 0));
1647 gatewayData.sinkID = sqlite3_column_int(query, 1);
1648 gatewayData.sourceID = sqlite3_column_int(query, 2);
1649 gatewayData.domainSinkID = sqlite3_column_int(query, 3);
1650 gatewayData.domainSourceID = sqlite3_column_int(query, 4);
1651 gatewayData.controlDomainID = sqlite3_column_int(query, 5);
1652 gatewayData.gatewayID = sqlite3_column_int(query, 6);
1655 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
1656 iter = mListConnectionFormat.find(gatewayData.gatewayID);
1657 if (iter == mListConnectionFormat.end())
1659 logError("DatabaseHandler::getGatewayInfoDB database error with convertionFormat");
1660 return E_DATABASE_ERROR;
1662 gatewayData.convertionMatrix = iter->second;
1664 //read out the connectionFormats
1665 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
1666 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL);
1667 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
1669 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
1670 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
1673 if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK)
1675 logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode);
1676 return E_DATABASE_ERROR;
1679 //read out sound properties
1680 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
1681 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL);
1682 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
1684 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
1685 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
1688 if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK)
1690 logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode);
1691 return E_DATABASE_ERROR;
1696 if (eCode != SQLITE_DONE)
1698 logError("DatabaseHandler::getGatewayInfoDB SQLITE error code:", eCode);
1699 return E_DATABASE_ERROR;
1702 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1704 logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode);
1705 return E_DATABASE_ERROR;
1712 am_Error_e DatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
1714 assert(crossfaderID!=0);
1715 if (!existcrossFader(crossfaderID))
1717 return E_NON_EXISTENT;
1719 sqlite3_stmt* query = NULL;
1721 std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID);
1722 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1724 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1726 crossfaderData.name = std::string((const char*) sqlite3_column_text(query, 0));
1727 crossfaderData.sinkID_A = sqlite3_column_int(query, 1);
1728 crossfaderData.sinkID_B = sqlite3_column_int(query, 2);
1729 crossfaderData.sourceID = sqlite3_column_int(query, 3);
1730 crossfaderData.hotSink = static_cast<am_HotSink_e>(sqlite3_column_int(query, 4));
1731 crossfaderData.crossfaderID = sqlite3_column_int(query, 5);
1734 if (eCode != SQLITE_DONE)
1736 logError("DatabaseHandler::getCrossfaderInfoDB SQLITE error code:", eCode);
1737 return E_DATABASE_ERROR;
1740 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1742 logError("DatabaseHandler::getCrossfaderInfoDB SQLITE Finalize error code:", eCode);
1743 return E_DATABASE_ERROR;
1749 am_Error_e DatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
1751 assert(domainID!=0);
1753 if (!existDomain(domainID))
1755 return E_NON_EXISTENT;
1757 sqlite3_stmt* query = NULL;
1760 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND domainID=" + (i2s(domainID));
1761 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1763 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1765 temp = sqlite3_column_int(query, 0);
1766 listSinkID.push_back(temp);
1769 if (eCode != SQLITE_DONE)
1771 logError("DatabaseHandler::getListSinksOfDomain SQLITE error code:", eCode);
1772 return E_DATABASE_ERROR;
1775 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1777 logError("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:", eCode);
1778 return E_DATABASE_ERROR;
1784 am_Error_e DatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
1786 assert(domainID!=0);
1787 listSourceID.clear();
1788 if (!existDomain(domainID))
1790 return E_NON_EXISTENT;
1792 sqlite3_stmt* query = NULL;
1795 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
1797 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1799 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1801 temp = sqlite3_column_int(query, 0);
1802 listSourceID.push_back(temp);
1805 if (eCode != SQLITE_DONE)
1807 logError("DatabaseHandler::getListSourcesOfDomain SQLITE error code:", eCode);
1808 return E_DATABASE_ERROR;
1811 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1813 logError("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:", eCode);
1814 return E_DATABASE_ERROR;
1820 am_Error_e DatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listCrossfader) const
1822 assert(domainID!=0);
1823 listCrossfader.clear();
1824 if (!existDomain(domainID))
1826 return E_NON_EXISTENT;
1828 sqlite3_stmt* query = NULL;
1830 am_crossfaderID_t temp;
1832 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);
1833 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1835 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1837 temp = sqlite3_column_int(query, 0);
1838 listCrossfader.push_back(temp);
1841 if (eCode != SQLITE_DONE)
1843 logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE error code:", eCode);
1844 return E_DATABASE_ERROR;
1847 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1849 logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE Finalize error code:", eCode);
1850 return E_DATABASE_ERROR;
1857 am_Error_e DatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
1859 assert(domainID!=0);
1860 listGatewaysID.clear();
1861 if (!existDomain(domainID))
1863 return E_NON_EXISTENT;
1865 sqlite3_stmt* query = NULL;
1867 am_gatewayID_t temp;
1869 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" + i2s(domainID);
1870 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1872 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1874 temp = sqlite3_column_int(query, 0);
1875 listGatewaysID.push_back(temp);
1878 if (eCode != SQLITE_DONE)
1880 logError("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:", eCode);
1881 return E_DATABASE_ERROR;
1884 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1886 logError("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:", eCode);
1887 return E_DATABASE_ERROR;
1893 am_Error_e DatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
1895 listMainConnections.clear();
1896 sqlite3_stmt *query = NULL, *query1 = NULL, *query2 = NULL;
1898 am_MainConnection_s temp;
1899 am_RoutingElement_s tempRoute;
1901 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
1902 std::string command1 = "SELECT connectionID FROM MainConnectionRoute";
1903 std::string command2 = "SELECT sourceID, sinkID, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=?";
1904 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1905 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &query2, NULL);
1907 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1909 temp.connectionID = sqlite3_column_int(query, 0);
1910 temp.route.sourceID = sqlite3_column_int(query, 1);
1911 temp.route.sinkID = sqlite3_column_int(query, 2);
1912 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
1913 temp.delay = sqlite3_column_int(query, 4);
1914 std::string statement = command1 + i2s(temp.connectionID);
1915 sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL);
1916 while ((eCode = sqlite3_step(query1)) == SQLITE_ROW)
1918 int k = sqlite3_column_int(query1, 0);
1919 sqlite3_bind_int(query2, 1, k);
1920 while ((eCode = sqlite3_step(query2)) == SQLITE_ROW)
1922 tempRoute.sourceID = sqlite3_column_int(query2, 0);
1923 tempRoute.sinkID = sqlite3_column_int(query2, 1);
1924 tempRoute.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query2, 2);
1925 getDomainOfSource(tempRoute.sourceID, tempRoute.domainID);
1926 temp.route.route.push_back(tempRoute);
1928 sqlite3_reset(query2);
1930 listMainConnections.push_back(temp);
1933 if (eCode != SQLITE_DONE)
1935 logError("DatabaseHandler::getListMainConnections SQLITE error code:", eCode);
1936 return E_DATABASE_ERROR;
1939 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1941 logError("DatabaseHandler::getListMainConnections SQLITE Finalize error code:", eCode);
1942 return E_DATABASE_ERROR;
1948 am_Error_e DatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
1950 listDomains.clear();
1951 sqlite3_stmt* query = NULL;
1954 std::string command = "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
1955 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1957 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1959 temp.domainID = sqlite3_column_int(query, 0);
1960 temp.name = std::string((const char*) sqlite3_column_text(query, 1));
1961 temp.busname = std::string((const char*) sqlite3_column_text(query, 2));
1962 temp.nodename = std::string((const char*) sqlite3_column_text(query, 3));
1963 temp.early = sqlite3_column_int(query, 4);
1964 temp.complete = sqlite3_column_int(query, 5);
1965 temp.state = (am_DomainState_e) sqlite3_column_int(query, 6);
1966 listDomains.push_back(temp);
1969 if (eCode != SQLITE_DONE)
1971 logError("DatabaseHandler::getListDomains SQLITE error code:", eCode);
1973 return E_DATABASE_ERROR;
1976 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
1978 logError("DatabaseHandler::getListDomains SQLITE Finalize error code:", eCode);
1980 return E_DATABASE_ERROR;
1986 am_Error_e DatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
1988 listConnections.clear();
1989 sqlite3_stmt* query = NULL;
1991 am_Connection_s temp;
1992 std::string command = "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE reserved=0";
1993 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
1995 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
1997 temp.connectionID = sqlite3_column_int(query, 0);
1998 temp.sourceID = sqlite3_column_int(query, 1);
1999 temp.sinkID = sqlite3_column_int(query, 2);
2000 temp.delay = sqlite3_column_int(query, 3);
2001 temp.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query, 4);
2002 listConnections.push_back(temp);
2005 if (eCode != SQLITE_DONE)
2007 logError("DatabaseHandler::getListConnections SQLITE error code:", eCode);
2008 return E_DATABASE_ERROR;
2011 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2013 logError("DatabaseHandler::getListConnections SQLITE Finalize error code:", eCode);
2014 return E_DATABASE_ERROR;
2020 am_Error_e DatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
2023 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
2026 am_ConnectionFormat_e tempConnectionFormat;
2027 am_SoundProperty_s tempSoundProperty;
2028 am_MainSoundProperty_s tempMainSoundProperty;
2029 std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0";
2030 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2032 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2034 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2035 temp.domainID = sqlite3_column_int(query, 1);
2036 temp.sinkClassID = sqlite3_column_int(query, 2);
2037 temp.volume = sqlite3_column_int(query, 3);
2038 temp.visible = sqlite3_column_int(query, 4);
2039 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5);
2040 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6);
2041 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
2042 temp.mainVolume = sqlite3_column_int(query, 8);
2043 temp.sinkID = sqlite3_column_int(query, 9);
2045 //read out the connectionFormats
2046 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID);
2047 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2048 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2050 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2051 temp.listConnectionFormats.push_back(tempConnectionFormat);
2054 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2056 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2058 return E_DATABASE_ERROR;
2061 //read out sound properties
2062 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
2063 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
2064 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
2066 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
2067 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
2068 temp.listSoundProperties.push_back(tempSoundProperty);
2071 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
2073 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2075 return E_DATABASE_ERROR;
2078 //read out MainSoundProperties
2079 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID);
2080 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
2081 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
2083 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
2084 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2085 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2088 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
2090 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2092 return E_DATABASE_ERROR;
2094 listSinks.push_back(temp);
2095 temp.listConnectionFormats.clear();
2096 temp.listMainSoundProperties.clear();
2097 temp.listSoundProperties.clear();
2100 if (eCode != SQLITE_DONE)
2102 logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
2104 return E_DATABASE_ERROR;
2107 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2109 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2111 return E_DATABASE_ERROR;
2117 am_Error_e DatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
2119 listSources.clear();
2120 sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL;
2123 am_ConnectionFormat_e tempConnectionFormat;
2124 am_SoundProperty_s tempSoundProperty;
2125 am_MainSoundProperty_s tempMainSoundProperty;
2126 std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0";
2127 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2129 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2131 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2132 temp.domainID = sqlite3_column_int(query, 1);
2133 temp.sourceClassID = sqlite3_column_int(query, 2);
2134 temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
2135 temp.volume = sqlite3_column_int(query, 4);
2136 temp.visible = sqlite3_column_int(query, 5);
2137 temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6);
2138 temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7);
2139 temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
2140 temp.sourceID = sqlite3_column_int(query, 9);
2142 //read out the connectionFormats
2143 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID);
2144 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2145 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2147 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2148 temp.listConnectionFormats.push_back(tempConnectionFormat);
2151 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2153 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2155 return E_DATABASE_ERROR;
2158 //read out sound properties
2159 std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
2160 sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL);
2161 while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
2163 tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0);
2164 tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
2165 temp.listSoundProperties.push_back(tempSoundProperty);
2168 if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK)
2170 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2172 return E_DATABASE_ERROR;
2175 //read out MainSoundProperties
2176 std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID);
2177 sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL);
2178 while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
2180 tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0);
2181 tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
2182 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2185 if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK)
2187 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2189 return E_DATABASE_ERROR;
2191 listSources.push_back(temp);
2192 temp.listConnectionFormats.clear();
2193 temp.listMainSoundProperties.clear();
2194 temp.listSoundProperties.clear();
2197 if (eCode != SQLITE_DONE)
2199 logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
2201 return E_DATABASE_ERROR;
2204 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2206 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2208 return E_DATABASE_ERROR;
2214 am_Error_e DatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
2216 listSourceClasses.clear();
2218 sqlite3_stmt* query = NULL, *subQuery = NULL;
2219 int eCode = 0, eCode1;
2220 am_SourceClass_s classTemp;
2221 am_ClassProperty_s propertyTemp;
2223 std::string command = "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
2224 std::string command2;
2225 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2227 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2229 classTemp.sourceClassID = sqlite3_column_int(query, 0);
2230 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2232 //read out Properties
2233 command2 = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classTemp.sourceClassID);
2234 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL);
2236 while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW)
2238 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2239 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2240 classTemp.listClassProperties.push_back(propertyTemp);
2243 if (eCode1 != SQLITE_DONE)
2245 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode1);
2247 return E_DATABASE_ERROR;
2250 if ((eCode1 = sqlite3_finalize(subQuery)) != SQLITE_OK)
2252 logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode1);
2254 return E_DATABASE_ERROR;
2256 listSourceClasses.push_back(classTemp);
2259 if (eCode != SQLITE_DONE)
2261 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2263 return E_DATABASE_ERROR;
2266 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2268 logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode);
2270 return E_DATABASE_ERROR;
2276 am_Error_e DatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2278 listCrossfaders.clear();
2279 sqlite3_stmt* query = NULL;
2281 am_Crossfader_s tempData;
2282 std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE);
2283 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2285 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2287 tempData.name = std::string((const char*) sqlite3_column_text(query, 0));
2288 tempData.sinkID_A = sqlite3_column_int(query, 1);
2289 tempData.sinkID_B = sqlite3_column_int(query, 2);
2290 tempData.sourceID = sqlite3_column_int(query, 3);
2291 tempData.hotSink = static_cast<am_HotSink_e>(sqlite3_column_int(query, 4));
2292 tempData.crossfaderID = sqlite3_column_int(query, 5);
2293 listCrossfaders.push_back(tempData);
2296 if (eCode != SQLITE_DONE)
2298 logError("DatabaseHandler::getListCrossfaders SQLITE error code:", eCode);
2299 return E_DATABASE_ERROR;
2302 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2304 logError("DatabaseHandler::getListCrossfaders SQLITE Finalize error code:", eCode);
2305 return E_DATABASE_ERROR;
2311 am_Error_e DatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2313 listGateways.clear();
2314 sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
2317 am_ConnectionFormat_e tempConnectionFormat;
2319 std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2320 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2322 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2324 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2325 temp.sinkID = sqlite3_column_int(query, 1);
2326 temp.sourceID = sqlite3_column_int(query, 2);
2327 temp.domainSinkID = sqlite3_column_int(query, 3);
2328 temp.domainSourceID = sqlite3_column_int(query, 4);
2329 temp.controlDomainID = sqlite3_column_int(query, 5);
2330 temp.gatewayID = sqlite3_column_int(query, 6);
2333 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2334 iter = mListConnectionFormat.find(temp.gatewayID);
2335 if (iter == mListConnectionFormat.end())
2337 logError("DatabaseHandler::getListGateways database error with convertionFormat");
2339 return E_DATABASE_ERROR;
2341 temp.convertionMatrix = iter->second;
2343 //read out the connectionFormats
2344 std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2345 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL);
2346 while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
2348 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0);
2349 temp.listSourceFormats.push_back(tempConnectionFormat);
2352 if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK)
2354 logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode);
2356 return E_DATABASE_ERROR;
2359 //read out sound properties
2360 commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2361 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL);
2362 while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
2364 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0);
2365 temp.listSinkFormats.push_back(tempConnectionFormat);
2368 if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK)
2370 logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode);
2372 return E_DATABASE_ERROR;
2375 listGateways.push_back(temp);
2376 temp.listSinkFormats.clear();
2377 temp.listSourceFormats.clear();
2380 if (eCode != SQLITE_DONE)
2382 logError("DatabaseHandler::getListGateways SQLITE error code:", eCode);
2384 return E_DATABASE_ERROR;
2387 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2389 logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode);
2391 return E_DATABASE_ERROR;
2397 am_Error_e DatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2399 listSinkClasses.clear();
2401 sqlite3_stmt* query = NULL, *subQuery = NULL;
2403 am_SinkClass_s classTemp;
2404 am_ClassProperty_s propertyTemp;
2406 std::string command = "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2407 std::string command2;
2408 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2410 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2412 classTemp.sinkClassID = sqlite3_column_int(query, 0);
2413 classTemp.name = std::string((const char*) sqlite3_column_text(query, 1));
2415 //read out Properties
2416 command2 = "SELECT classProperty, value FROM SinkClassProperties" + i2s(classTemp.sinkClassID);
2417 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL);
2419 while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW)
2421 propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0);
2422 propertyTemp.value = sqlite3_column_int(subQuery, 1);
2423 classTemp.listClassProperties.push_back(propertyTemp);
2426 if (eCode != SQLITE_DONE)
2428 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2430 return E_DATABASE_ERROR;
2433 if ((eCode = sqlite3_finalize(subQuery)) != SQLITE_OK)
2435 logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode);
2437 return E_DATABASE_ERROR;
2439 listSinkClasses.push_back(classTemp);
2442 if (eCode != SQLITE_DONE)
2444 logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode);
2446 return E_DATABASE_ERROR;
2449 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2451 logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode);
2453 return E_DATABASE_ERROR;
2459 am_Error_e DatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2461 listConnections.clear();
2462 sqlite3_stmt *query = NULL;
2464 am_MainConnectionType_s temp;
2466 std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2467 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2469 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2471 temp.mainConnectionID = sqlite3_column_int(query, 0);
2472 temp.sourceID = sqlite3_column_int(query, 1);
2473 temp.sinkID = sqlite3_column_int(query, 2);
2474 temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3);
2475 temp.delay = sqlite3_column_int(query, 4);
2476 listConnections.push_back(temp);
2479 if (eCode != SQLITE_DONE)
2481 logError("DatabaseHandler::getListVisibleMainConnections SQLITE error code:", eCode);
2483 return E_DATABASE_ERROR;
2486 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2488 logError("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:", eCode);
2490 return E_DATABASE_ERROR;
2496 am_Error_e DatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2498 listMainSinks.clear();
2499 sqlite3_stmt* query = NULL;
2503 std::string command = "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2504 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2506 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2508 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2509 temp.sinkID = sqlite3_column_int(query, 1);
2510 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2511 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2512 temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 4);
2513 temp.volume = sqlite3_column_int(query, 5);
2514 temp.sinkClassID = sqlite3_column_int(query, 6);
2515 listMainSinks.push_back(temp);
2518 if (eCode != SQLITE_DONE)
2520 logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
2522 return E_DATABASE_ERROR;
2525 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2527 logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode);
2529 return E_DATABASE_ERROR;
2535 am_Error_e DatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2537 listMainSources.clear();
2538 sqlite3_stmt* query = NULL;
2540 am_SourceType_s temp;
2541 std::string command = "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2542 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2544 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2546 temp.name = std::string((const char*) sqlite3_column_text(query, 0));
2547 temp.sourceClassID = sqlite3_column_int(query, 1);
2548 temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2);
2549 temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3);
2550 temp.sourceID = sqlite3_column_int(query, 4);
2552 listMainSources.push_back(temp);
2555 if (eCode != SQLITE_DONE)
2557 logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
2559 return E_DATABASE_ERROR;
2562 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2564 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2566 return E_DATABASE_ERROR;
2572 am_Error_e DatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2575 if (!existSink(sinkID))
2576 return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2577 listSoundProperties.clear();
2579 sqlite3_stmt* query = NULL;
2581 am_MainSoundProperty_s temp;
2582 std::string command = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2583 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2585 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2587 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2588 temp.value = sqlite3_column_int(query, 1);
2589 listSoundProperties.push_back(temp);
2592 if (eCode != SQLITE_DONE)
2594 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode);
2596 return E_DATABASE_ERROR;
2599 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2601 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:", eCode);
2603 return E_DATABASE_ERROR;
2609 am_Error_e DatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2611 assert(sourceID!=0);
2612 if (!existSource(sourceID))
2613 return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2614 listSourceProperties.clear();
2616 sqlite3_stmt* query = NULL;
2618 am_MainSoundProperty_s temp;
2619 std::string command = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2620 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2622 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2624 temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0);
2625 temp.value = sqlite3_column_int(query, 1);
2626 listSourceProperties.push_back(temp);
2629 if (eCode != SQLITE_DONE)
2631 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode);
2633 return E_DATABASE_ERROR;
2636 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2638 logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:", eCode);
2640 return E_DATABASE_ERROR;
2646 am_Error_e DatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2648 listSystemProperties.clear();
2650 sqlite3_stmt* query = NULL;
2652 am_SystemProperty_s temp;
2653 std::string command = "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2654 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2656 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2658 temp.type = (am_SystemPropertyType_e) sqlite3_column_int(query, 0);
2659 temp.value = sqlite3_column_int(query, 1);
2660 listSystemProperties.push_back(temp);
2663 if (eCode != SQLITE_DONE)
2665 logError("DatabaseHandler::getListSystemProperties SQLITE error code:", eCode);
2667 return E_DATABASE_ERROR;
2670 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2672 logError("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:", eCode);
2674 return E_DATABASE_ERROR;
2680 am_Error_e am::DatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2682 listConnectionFormats.clear();
2683 sqlite3_stmt *qConnectionFormat = NULL;
2685 am_ConnectionFormat_e tempConnectionFormat;
2686 std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID);
2687 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2688 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2690 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2691 listConnectionFormats.push_back(tempConnectionFormat);
2694 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2696 logError("DatabaseHandler::getListSinkConnectionFormats SQLITE Finalize error code:", eCode);
2698 return E_DATABASE_ERROR;
2704 am_Error_e am::DatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2706 listConnectionFormats.clear();
2707 sqlite3_stmt* qConnectionFormat = NULL;
2709 am_ConnectionFormat_e tempConnectionFormat;
2711 //read out the connectionFormats
2712 std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID);
2713 sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL);
2714 while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
2716 tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0);
2717 listConnectionFormats.push_back(tempConnectionFormat);
2720 if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK)
2722 logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode);
2724 return E_DATABASE_ERROR;
2730 am_Error_e am::DatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const
2732 ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
2733 iter = mListConnectionFormat.find(gatewayID);
2734 if (iter == mListConnectionFormat.end())
2736 logError("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat");
2738 return (E_DATABASE_ERROR);
2740 listConnectionFormat = iter->second;
2745 am_Error_e DatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2747 assert(mainConnectionID!=0);
2749 sqlite3_stmt *query = NULL;
2752 std::string command = "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2753 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2755 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
2757 delay = sqlite3_column_int(query, 0);
2760 if (eCode != SQLITE_DONE)
2762 logError("DatabaseHandler::getTimingInformation SQLITE error code:", eCode);
2764 return E_DATABASE_ERROR;
2767 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2769 logError("DatabaseHandler::getTimingInformation SQLITE Finalize error code:", eCode);
2771 return E_DATABASE_ERROR;
2775 return E_NOT_POSSIBLE;
2780 bool DatabaseHandler::sqQuery(const std::string& query)
2782 sqlite3_stmt* statement;
2784 if ((eCode = sqlite3_exec(mDatabase, query.c_str(), NULL, &statement, NULL)) != SQLITE_OK)
2786 logError("DatabaseHandler::sqQuery SQL Query failed:", query.c_str(), "error code:", eCode);
2792 bool DatabaseHandler::openDatabase()
2794 if (sqlite3_open_v2(mPath.c_str(), &mDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
2796 logInfo("DatabaseHandler::openDatabase opened database");
2799 logError("DatabaseHandler::openDatabase failed to open database");
2803 am_Error_e DatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
2805 assert(connectionID!=0);
2807 sqlite3_stmt* query = NULL;
2809 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE delay=? AND mainConnectionID=?";
2810 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2811 sqlite3_bind_int(query, 1, delay);
2812 sqlite3_bind_int(query, 2, connectionID);
2813 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2815 sqlite3_finalize(query);
2818 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
2819 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2820 sqlite3_bind_int(query, 1, delay);
2821 sqlite3_bind_int(query, 2, connectionID);
2823 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2825 logError("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:", eCode);
2827 return E_DATABASE_ERROR;
2830 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2832 logError("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:", eCode);
2834 return E_DATABASE_ERROR;
2837 if (mDatabaseObserver)
2838 mDatabaseObserver->timingInformationChanged(connectionID, delay);
2843 am_Error_e DatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
2845 assert(connection.connectionID==0);
2846 assert(connection.sinkID!=0);
2847 assert(connection.sourceID!=0);
2848 //connection format is not checked, because it's project specific
2850 sqlite3_stmt* query = NULL;
2852 std::string command = "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
2854 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2855 sqlite3_bind_int(query, 1, connection.sinkID);
2856 sqlite3_bind_int(query, 2, connection.sourceID);
2857 sqlite3_bind_int(query, 3, connection.delay);
2858 sqlite3_bind_int(query, 4, connection.connectionFormat);
2859 sqlite3_bind_int(query, 5, true);
2861 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2863 logError("DatabaseHandler::enterConnectionDB SQLITE Step error code:", eCode);
2865 return E_DATABASE_ERROR;
2868 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2870 logError("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:", eCode);
2872 return E_DATABASE_ERROR;
2875 connectionID = sqlite3_last_insert_rowid(mDatabase);
2877 logInfo("DatabaseHandler::enterConnectionDB entered new connection sourceID=", connection.sourceID, "sinkID=", connection.sinkID, "sourceID=", connection.sourceID, "connectionFormat=", connection.connectionFormat, "assigned ID=", connectionID);
2881 am_Error_e DatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
2883 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
2884 assert(!sinkClass.listClassProperties.empty());
2885 assert(!sinkClass.name.empty());
2887 sqlite3_stmt* query = NULL;
2889 std::string command;
2891 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2892 if (sinkClass.sinkClassID == 0 && !mFirstStaticSinkClass)
2894 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
2898 //check if the ID already exists
2899 if (existSinkClass(sinkClass.sinkClassID))
2900 return E_ALREADY_EXISTS;
2901 command = "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
2904 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2905 sqlite3_bind_text(query, 1, sinkClass.name.c_str(), sinkClass.name.size(), SQLITE_STATIC);
2907 //if the ID is not created, we add it to the query
2908 if (sinkClass.sinkClassID != 0)
2910 sqlite3_bind_int(query, 2, sinkClass.sinkClassID);
2913 //if the first static sink is entered, we need to set it onto the boundary
2914 else if (mFirstStaticSinkClass)
2916 sqlite3_bind_int(query, 2, DYNAMIC_ID_BOUNDARY);
2917 mFirstStaticSinkClass = false;
2920 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2922 logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode);
2924 return E_DATABASE_ERROR;
2927 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2929 logError("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:", eCode);
2931 return E_DATABASE_ERROR;
2934 sinkClassID = sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2936 //now we need to create the additional tables:
2937 command = "CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2938 assert(this->sqQuery(command));
2940 //fill ConnectionFormats
2941 command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
2942 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2943 std::vector<am_ClassProperty_s>::const_iterator Iterator = sinkClass.listClassProperties.begin();
2944 for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator)
2946 sqlite3_bind_int(query, 1, Iterator->classProperty);
2947 sqlite3_bind_int(query, 2, Iterator->value);
2948 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
2950 logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode);
2952 return E_DATABASE_ERROR;
2954 sqlite3_reset(query);
2957 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
2959 logError("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:", eCode);
2961 return E_DATABASE_ERROR;
2964 logInfo("DatabaseHandler::enterSinkClassDB entered new sinkClass");
2965 if (mDatabaseObserver)
2966 mDatabaseObserver->numberOfSinkClassesChanged();
2970 am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
2972 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
2973 assert(!sourceClass.listClassProperties.empty());
2974 assert(!sourceClass.name.empty());
2976 sqlite3_stmt* query = NULL;
2978 std::string command;
2980 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2981 if (sourceClass.sourceClassID == 0 && !mFirstStaticSourceClass)
2983 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
2987 //check if the ID already exists
2988 if (existSourceClass(sourceClass.sourceClassID))
2989 return E_ALREADY_EXISTS;
2990 command = "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
2993 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
2994 sqlite3_bind_text(query, 1, sourceClass.name.c_str(), sourceClass.name.size(), SQLITE_STATIC);
2996 //if the ID is not created, we add it to the query
2997 if (sourceClass.sourceClassID != 0)
2999 sqlite3_bind_int(query, 2, sourceClass.sourceClassID);
3002 //if the first static sink is entered, we need to set it onto the boundary
3003 else if (mFirstStaticSourceClass)
3005 sqlite3_bind_int(query, 2, DYNAMIC_ID_BOUNDARY);
3006 mFirstStaticSourceClass = false;
3009 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3011 logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode);
3013 return E_DATABASE_ERROR;
3016 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3018 logError("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:", eCode);
3020 return E_DATABASE_ERROR;
3023 sourceClassID = sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
3025 //now we need to create the additional tables:
3026 command = "CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
3027 assert(sqQuery(command));
3029 //fill ConnectionFormats
3030 command = "INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
3031 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3032 std::vector<am_ClassProperty_s>::const_iterator Iterator = sourceClass.listClassProperties.begin();
3033 for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator)
3035 sqlite3_bind_int(query, 1, Iterator->classProperty);
3036 sqlite3_bind_int(query, 2, Iterator->value);
3037 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3039 logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode);
3041 return E_DATABASE_ERROR;
3043 sqlite3_reset(query);
3046 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3048 logError("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:", eCode);
3050 return E_DATABASE_ERROR;
3053 logInfo("DatabaseHandler::enterSourceClassDB entered new sourceClass");
3055 if (mDatabaseObserver)
3056 mDatabaseObserver->numberOfSourceClassesChanged();
3060 am_Error_e DatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
3062 assert(!listSystemProperties.empty());
3063 sqlite3_stmt* query = NULL;
3065 std::vector<am_SystemProperty_s>::const_iterator listIterator = listSystemProperties.begin();
3066 std::string command = "DELETE * FROM " + std::string(SYSTEM_TABLE);
3069 command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
3071 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3072 for (; listIterator < listSystemProperties.end(); ++listIterator)
3074 sqlite3_bind_int(query, 1, listIterator->type);
3075 sqlite3_bind_int(query, 2, listIterator->value);
3077 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3079 logError("DatabaseHandler::enterSystemProperties SQLITE Step error code:", eCode);
3081 return E_DATABASE_ERROR;
3084 sqlite3_reset(query);
3087 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3089 logError("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:", eCode);
3091 return E_DATABASE_ERROR;
3094 logInfo("DatabaseHandler::enterSystemProperties entered system properties");
3098 bool DatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
3100 sqlite3_stmt* query = NULL;
3101 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
3103 bool returnVal = true;
3104 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3105 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3107 else if (eCode != SQLITE_ROW)
3110 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3112 sqlite3_finalize(query);
3116 bool DatabaseHandler::existSource(const am_sourceID_t sourceID) const
3118 sqlite3_stmt* query = NULL;
3119 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
3121 bool returnVal = true;
3122 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3123 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3125 else if (eCode != SQLITE_ROW)
3128 logError("DatabaseHandler::existSource database error!:", eCode);
3130 sqlite3_finalize(query);
3134 bool DatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
3136 sqlite3_stmt* query = NULL;
3137 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
3139 bool returnVal = true;
3140 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3141 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3142 sqlite3_bind_int(query, 2, sourceID);
3143 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3145 else if (eCode != SQLITE_ROW)
3148 logError("DatabaseHandler::existSource database error!:", eCode);
3150 sqlite3_finalize(query);
3154 bool DatabaseHandler::existSourceName(const std::string & name) const
3156 sqlite3_stmt* query = NULL;
3157 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
3159 bool returnVal = true;
3160 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3161 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3162 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3164 else if (eCode != SQLITE_ROW)
3167 logError("DatabaseHandler::existSource database error!:", eCode);
3169 sqlite3_finalize(query);
3173 bool DatabaseHandler::existSink(const am_sinkID_t sinkID) const
3175 sqlite3_stmt* query = NULL;
3176 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3178 bool returnVal = true;
3179 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3180 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3182 else if (eCode != SQLITE_ROW)
3185 logError("DatabaseHandler::existSink database error!:", eCode);
3187 sqlite3_finalize(query);
3191 bool DatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
3193 sqlite3_stmt* query = NULL;
3194 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
3196 bool returnVal = true;
3197 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3198 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3199 sqlite3_bind_int(query, 2, sinkID);
3200 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3202 else if (eCode != SQLITE_ROW)
3205 logError("DatabaseHandler::existSink database error!:", eCode);
3207 sqlite3_finalize(query);
3211 bool DatabaseHandler::existSinkName(const std::string & name) const
3213 sqlite3_stmt* query = NULL;
3214 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
3216 bool returnVal = true;
3217 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3218 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3219 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3221 else if (eCode != SQLITE_ROW)
3224 logError("DatabaseHandler::existSink database error!:", eCode);
3226 sqlite3_finalize(query);
3230 bool DatabaseHandler::existDomain(const am_domainID_t domainID) const
3232 sqlite3_stmt* query = NULL;
3233 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
3235 bool returnVal = true;
3236 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3237 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3239 else if (eCode != SQLITE_ROW)
3242 logError("DatabaseHandler::existDomain database error!:", eCode);
3244 sqlite3_finalize(query);
3248 bool DatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
3250 sqlite3_stmt* query = NULL;
3251 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
3253 bool returnVal = true;
3254 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3255 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3257 else if (eCode != SQLITE_ROW)
3260 logError("DatabaseHandler::existGateway database error!:", eCode);
3262 sqlite3_finalize(query);
3266 am_Error_e DatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
3268 assert(sourceID!=0);
3270 sqlite3_stmt* query = NULL;
3271 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3273 am_Error_e returnVal = E_DATABASE_ERROR;
3274 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3275 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3277 domainID = sqlite3_column_int(query, 0);
3282 logError("DatabaseHandler::getDomainOfSource database error!:", eCode);
3284 sqlite3_finalize(query);
3288 am_Error_e am::DatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const
3292 sqlite3_stmt* query = NULL;
3293 std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3295 am_Error_e returnVal = E_DATABASE_ERROR;
3296 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3297 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3299 domainID = sqlite3_column_int(query, 0);
3304 logError("DatabaseHandler::getDomainOfSink database error!:", eCode);
3306 sqlite3_finalize(query);
3310 bool DatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3312 sqlite3_stmt* query = NULL;
3313 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
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::existSinkClass database error!:", eCode);
3324 sqlite3_finalize(query);
3328 bool DatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3330 sqlite3_stmt* query = NULL;
3331 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
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::existSinkClass database error!:", eCode);
3342 sqlite3_finalize(query);
3346 am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3348 assert(connectionID!=0);
3350 sqlite3_stmt *query = NULL, *queryMainConnections, *queryMainConnectionSubIDs;
3351 int eCode = 0, eCode1 = 0;
3352 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3354 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3355 sqlite3_bind_int(query, 1, delay);
3356 sqlite3_bind_int(query, 2, connectionID);
3358 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3360 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:", eCode);
3362 return E_DATABASE_ERROR;
3365 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3367 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:", eCode);
3369 return E_DATABASE_ERROR;
3372 //now we need to find all mainConnections that use the changed connection and update their timing
3374 int tempMainConnectionID;
3375 //first get all route tables for all mainconnections
3376 command = "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'";
3377 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryMainConnections, NULL);
3379 while ((eCode = sqlite3_step(queryMainConnections)) == SQLITE_ROW)
3381 //now check if the connection ID is in this table
3382 std::string tablename = std::string((const char*) sqlite3_column_text(queryMainConnections, 0));
3383 std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID);
3384 sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &queryMainConnectionSubIDs, NULL);
3385 if ((eCode1 = sqlite3_step(queryMainConnectionSubIDs)) == SQLITE_ROW)
3387 //if the connection ID is in, recalculate the mainconnection delay
3388 std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID;
3389 changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID), tempMainConnectionID);
3391 else if (eCode1 != SQLITE_DONE)
3393 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode1);
3395 return E_DATABASE_ERROR;
3399 if (eCode != SQLITE_DONE)
3401 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode);
3403 return E_DATABASE_ERROR;
3406 if ((eCode = sqlite3_finalize(queryMainConnections)) != SQLITE_OK)
3408 logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:", eCode);
3410 return E_DATABASE_ERROR;
3416 am_Error_e DatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3418 assert(connectionID!=0);
3420 sqlite3_stmt *query = NULL;
3422 std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3424 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3425 sqlite3_bind_int(query, 1, connectionID);
3427 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3429 logError("DatabaseHandler::changeConnectionFinal SQLITE Step error code:", eCode);
3431 return E_DATABASE_ERROR;
3434 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3436 logError("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:", eCode);
3438 return E_DATABASE_ERROR;
3443 am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3445 assert(mainConnectionID!=0);
3446 sqlite3_stmt* query = NULL;
3447 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";
3449 am_timeSync_t delay = 0;
3450 am_timeSync_t min = 0;
3451 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3452 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3454 delay = sqlite3_column_int(query, 0);
3455 min = sqlite3_column_int(query, 1);
3457 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3459 logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:", eCode);
3461 return E_DATABASE_ERROR;
3464 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3466 logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:", eCode);
3468 return E_DATABASE_ERROR;
3476 void DatabaseHandler::registerObserver(DatabaseObserver *iObserver)
3478 assert(iObserver!=NULL);
3479 mDatabaseObserver = iObserver;
3482 bool DatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3484 assert(sourceID!=0);
3485 sqlite3_stmt* query = NULL;
3486 std::string command = "SELECT visible FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3488 bool returnVal = false;
3489 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3490 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3492 returnVal = (bool) sqlite3_column_int(query, 0);
3494 else if (eCode != SQLITE_ROW)
3497 logError("DatabaseHandler::sourceVisible database error!:", eCode);
3499 sqlite3_finalize(query);
3503 bool DatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3505 sqlite3_stmt* query = NULL;
3506 std::string command = "SELECT visible FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3508 bool returnVal = false;
3509 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3510 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3512 returnVal = sqlite3_column_int(query, 0);
3514 else if (eCode != SQLITE_ROW)
3517 logError("DatabaseHandler::sinkVisible database error!:", eCode);
3519 sqlite3_finalize(query);
3523 bool DatabaseHandler::existConnection(const am_Connection_s connection)
3525 sqlite3_stmt* query = NULL;
3526 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3528 bool returnVal = true;
3529 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3530 sqlite3_bind_int(query, 1, connection.sinkID);
3531 sqlite3_bind_int(query, 2, connection.sourceID);
3532 sqlite3_bind_int(query, 3, connection.connectionFormat);
3533 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3535 else if (eCode != SQLITE_ROW)
3538 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3540 sqlite3_finalize(query);
3544 bool DatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3546 sqlite3_stmt* query = NULL;
3547 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3549 bool returnVal = true;
3550 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3551 sqlite3_bind_int(query, 1, connectionID);
3552 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3554 else if (eCode != SQLITE_ROW)
3557 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3559 sqlite3_finalize(query);
3563 bool DatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3565 sqlite3_stmt* query = NULL;
3566 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3568 bool returnVal = true;
3569 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3570 sqlite3_bind_int(query, 1, crossfaderID);
3571 if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3573 else if (eCode != SQLITE_ROW)
3576 logError("DatabaseHandler::existMainConnection database error!:", eCode);
3578 sqlite3_finalize(query);
3582 am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3584 assert(sourceID!=0);
3585 sqlite3_stmt* query = NULL;
3586 sourceState = SS_MIN;
3587 std::string command = "SELECT sourceState FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3589 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3590 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3592 sourceState = (am_SourceState_e) sqlite3_column_int(query, 0);
3594 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3596 logError("DatabaseHandler::getSoureState database error!:", eCode);
3598 sqlite3_finalize(query);
3602 am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3604 assert(sourceID!=0);
3605 assert(sourceState>=SS_MIN && sourceState<=SS_MAX);
3606 sqlite3_stmt* query = NULL;
3607 std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID);
3609 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3610 sqlite3_bind_int(query, 1, sourceState);
3611 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3613 logError("DatabaseHandler::changeSourceState SQLITE Step error code:", eCode);
3615 return E_DATABASE_ERROR;
3618 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3620 logError("DatabaseHandler::changeSourceState SQLITE Finalize error code:", eCode);
3622 return E_DATABASE_ERROR;
3627 am_Error_e DatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3630 sqlite3_stmt* query = NULL;
3632 std::string command = "SELECT volume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3634 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3635 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3637 volume = sqlite3_column_int(query, 0);
3639 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3641 logError("DatabaseHandler::getSinkVolume database error!:", eCode);
3643 sqlite3_finalize(query);
3647 am_Error_e DatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
3649 assert(sourceID!=0);
3650 sqlite3_stmt* query = NULL;
3652 std::string command = "SELECT volume FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3654 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3655 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3657 volume = sqlite3_column_int(query, 0);
3659 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3661 logError("DatabaseHandler::getSourceVolume database error!:", eCode);
3663 sqlite3_finalize(query);
3667 am_Error_e DatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3670 if (!existSink(sinkID))
3671 return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3673 sqlite3_stmt* query = NULL;
3675 std::string command = "SELECT value FROM SinkSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType);
3676 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3678 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3680 value = sqlite3_column_int(query, 0);
3683 if (eCode != SQLITE_DONE)
3685 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode);
3687 return E_DATABASE_ERROR;
3690 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3692 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:", eCode);
3694 return E_DATABASE_ERROR;
3700 am_Error_e DatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3702 assert(sourceID!=0);
3703 if (!existSource(sourceID))
3704 return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3706 sqlite3_stmt* query = NULL;
3708 std::string command = "SELECT value FROM SourceSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType);
3709 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3711 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3713 value = sqlite3_column_int(query, 0);
3716 if (eCode != SQLITE_DONE)
3718 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode);
3720 return E_DATABASE_ERROR;
3723 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3725 logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:", eCode);
3727 return E_DATABASE_ERROR;
3733 am_Error_e DatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
3735 assert(domainID!=0);
3736 sqlite3_stmt* query = NULL;
3738 std::string command = "SELECT domainState FROM " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
3740 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3741 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3743 state = (am_DomainState_e) sqlite3_column_int(query, 0);
3745 else if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
3747 logError("DatabaseHandler::getDomainState database error!:", eCode);
3749 sqlite3_finalize(query);
3754 am_Error_e DatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
3756 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3757 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
3758 int eCode = 0, eCode1 = 0;
3759 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3760 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3761 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3763 domainID = sqlite3_column_int(query, 0);
3765 else if (eCode != SQLITE_DONE)
3767 logError("DatabaseHandler::peekDomain database error!:", eCode);
3768 return E_DATABASE_ERROR;
3772 command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
3773 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3774 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3775 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3776 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3778 logError("DatabaseHandler::peekDomain SQLITE Step error code:", eCode1);
3779 return E_DATABASE_ERROR;
3782 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3784 logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1);
3785 return E_DATABASE_ERROR;
3787 domainID = sqlite3_last_insert_rowid(mDatabase);
3789 sqlite3_finalize(query);
3793 am_Error_e DatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
3795 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3796 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
3797 int eCode = 0, eCode1 = 0;
3798 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3799 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3800 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3802 sinkID = sqlite3_column_int(query, 0);
3804 else if (eCode != SQLITE_DONE)
3806 logError("DatabaseHandler::peekSink database error!:", eCode);
3807 return E_DATABASE_ERROR;
3811 if (mFirstStaticSink)
3813 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3814 mFirstStaticSink = false;
3818 command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
3820 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3821 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3822 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3823 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3825 logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1);
3826 return E_DATABASE_ERROR;
3829 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3831 logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1);
3832 return E_DATABASE_ERROR;
3834 sinkID = sqlite3_last_insert_rowid(mDatabase);
3836 sqlite3_finalize(query);
3840 am_Error_e DatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
3842 sqlite3_stmt* query = NULL, *queryInsert = NULL;
3843 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
3844 int eCode = 0, eCode1 = 0;
3845 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3846 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
3847 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
3849 sourceID = sqlite3_column_int(query, 0);
3851 else if (eCode != SQLITE_DONE)
3853 logError("DatabaseHandler::peekSink database error!:", eCode);
3854 return E_DATABASE_ERROR;
3858 if (mFirstStaticSource)
3860 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3861 mFirstStaticSource = false;
3865 command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
3867 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL);
3868 sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC);
3869 sqlite3_bind_int(queryInsert, 2, 1); //reservation flag
3870 if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE)
3872 logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1);
3873 return E_DATABASE_ERROR;
3876 if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK)
3878 logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1);
3879 return E_DATABASE_ERROR;
3881 sourceID = sqlite3_last_insert_rowid(mDatabase);
3883 sqlite3_finalize(query);
3887 am_Error_e DatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
3891 sqlite3_stmt* query = NULL;
3893 std::string command;
3895 if (!existSink(sinkID))
3897 return E_NON_EXISTENT;
3899 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
3900 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3901 sqlite3_bind_int(query, 1, volume);
3902 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3904 logError("DatabaseHandler::changeSinkVolume SQLITE Step error code:", eCode);
3906 return E_DATABASE_ERROR;
3908 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3910 logError("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:", eCode);
3912 return E_DATABASE_ERROR;
3915 logInfo("DatabaseHandler::changeSinkVolume changed volume of sink:", sinkID, "to:", volume);
3920 am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
3922 assert(sourceID!=0);
3924 sqlite3_stmt* query = NULL;
3926 std::string command;
3928 if (!existSource(sourceID))
3930 return E_NON_EXISTENT;
3932 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
3933 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3934 sqlite3_bind_int(query, 1, volume);
3935 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3937 logError("DatabaseHandler::changeSourceVolume SQLITE Step error code:", eCode);
3939 return E_DATABASE_ERROR;
3941 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3943 logError("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:", eCode);
3945 return E_DATABASE_ERROR;
3948 logInfo("DatabaseHandler::changeSourceVolume changed volume of source=:", sourceID, "to:", volume);
3953 am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
3955 assert(soundProperty.type>=SP_MIN && soundProperty.type<=SP_MAX);
3956 assert(sourceID!=0);
3958 sqlite3_stmt* query = NULL;
3960 std::string command;
3962 if (!existSource(sourceID))
3964 return E_NON_EXISTENT;
3966 command = "UPDATE SourceSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3967 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
3968 sqlite3_bind_int(query, 1, soundProperty.value);
3969 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
3971 logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:", eCode);
3973 return E_DATABASE_ERROR;
3976 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
3978 logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:", eCode);
3980 return E_DATABASE_ERROR;
3983 logInfo("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value);
3988 am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
3990 assert(soundProperty.type>=SP_MIN && soundProperty.type<=SP_MAX);
3993 sqlite3_stmt* query = NULL;
3995 std::string command;
3997 if (!existSink(sinkID))
3999 return E_NON_EXISTENT;
4001 command = "UPDATE SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
4002 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4003 sqlite3_bind_int(query, 1, soundProperty.value);
4004 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4006 logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:", eCode);
4007 return E_DATABASE_ERROR;
4010 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4012 logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:", eCode);
4013 return E_DATABASE_ERROR;
4016 logInfo("DatabaseHandler::changeSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value);
4021 am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
4023 assert(crossfaderID!=0);
4024 assert(hotsink>=HS_MIN && hotsink>=HS_MAX);
4026 sqlite3_stmt* query = NULL;
4028 std::string command;
4030 if (!existcrossFader(crossfaderID))
4032 return E_NON_EXISTENT;
4034 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
4035 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4036 sqlite3_bind_int(query, 1, hotsink);
4037 if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
4039 logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:", eCode);
4041 return E_DATABASE_ERROR;
4043 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4045 logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:", eCode);
4047 return E_DATABASE_ERROR;
4050 logInfo("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader=", crossfaderID, "to:", hotsink);
4054 am_Error_e DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree& tree, std::vector<RoutingTreeItem*>& flatTree)
4056 sqlite3_stmt* query = NULL;
4059 std::string command;
4060 am_domainID_t rootID = tree.returnRootDomainID();
4061 RoutingTreeItem *parent = tree.returnRootItem();
4065 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 )";
4069 command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=?";
4076 parent = flatTree.at(i - 1);
4077 rootID = parent->returnDomainID();
4079 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4080 sqlite3_bind_int(query, 1, rootID);
4082 while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4084 flatTree.push_back(tree.insertItem(sqlite3_column_int(query, 0), sqlite3_column_int(query, 1), parent));
4087 if (eCode != SQLITE_DONE)
4089 logError("DatabaseHandler::getRoutingTree SQLITE error code:", eCode);
4091 return (E_DATABASE_ERROR);
4094 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4096 logError("DatabaseHandler::getRoutingTree SQLITE Finalize error code:", eCode);
4098 return (E_DATABASE_ERROR);
4101 } while (flatTree.size() > (i - 1));
4106 am_Error_e am::DatabaseHandler::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID)
4109 return E_NON_EXISTENT;
4111 am_Error_e returnVal = E_NON_EXISTENT;
4112 sqlite3_stmt* query = NULL;
4114 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE name=?";
4115 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4116 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
4118 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4120 sinkClassID = sqlite3_column_int(query, 0);
4123 else if (eCode != SQLITE_DONE)
4126 logError("DatabaseHandler::peekSinkClassID SQLITE error code:", eCode);
4127 returnVal = E_DATABASE_ERROR;
4130 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4132 logError("DatabaseHandler::peekSinkClassID SQLITE Finalize error code:", eCode);
4133 returnVal = E_DATABASE_ERROR;
4138 am_Error_e am::DatabaseHandler::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID)
4141 return E_NON_EXISTENT;
4143 am_Error_e returnVal = E_NON_EXISTENT;
4144 sqlite3_stmt* query = NULL;
4146 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE name=?";
4147 sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL);
4148 sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC);
4150 if ((eCode = sqlite3_step(query)) == SQLITE_ROW)
4152 sourceClassID = sqlite3_column_int(query, 0);
4155 else if (eCode != SQLITE_DONE)
4158 logError("DatabaseHandler::peekSourceClassID SQLITE error code:", eCode);
4159 returnVal = E_DATABASE_ERROR;
4162 if ((eCode = sqlite3_finalize(query)) != SQLITE_OK)
4164 logError("DatabaseHandler::peekSourceClassID SQLITE Finalize error code:", eCode);
4165 returnVal = E_DATABASE_ERROR;
4170 void DatabaseHandler::createTables()
4172 for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++)
4174 assert(sqQuery("CREATE TABLE " + databaseTables[i]));