2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file Databasehandler.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG Christian Mueller Christian.ei.mueller@bmw.de
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
25 #include "DatabaseHandler.h"
26 #include "DatabaseObserver.h"
35 #define DOMAIN_TABLE "Domains"
36 #define SOURCE_CLASS_TABLE "SourceClasses"
37 #define SINK_CLASS_TABLE "SinkClasses"
38 #define SOURCE_TABLE "Sources"
39 #define SINK_TABLE "Sinks"
40 #define GATEWAY_TABLE "Gateways"
41 #define CROSSFADER_TABLE "Crossfaders"
42 #define CONNECTION_TABLE "Connections"
43 #define MAINCONNECTION_TABLE "MainConnections"
44 #define INTERRUPT_TABLE "Interrupts"
45 #define MAIN_TABLE "MainTable"
46 #define SYSTEM_TABLE "SystemProperties"
48 DLT_IMPORT_CONTEXT(AudioManager)
52 const std::string databaseTables[]={
53 " 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);",
54 " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));",
55 " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));",
56 " 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);",
57 " 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);",
58 " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER, inUse BOOL);",
59 " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);",
60 " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);",
61 " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);",
62 " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);"
66 * template to converts T to std::string
67 * @param i the value to be converted
71 inline std::string i2s(T const& x)
78 DatabaseHandler::DatabaseHandler(std::string databasePath)
81 mDatabaseObserver(NULL),
82 mFirstStaticSink(true),
83 mFirstStaticSource(true),
84 mFirstStaticGateway(true),
85 mFirstStaticSinkClass(true),
86 mFirstStaticSourceClass(true),
87 mListConnectionFormat()
91 *\todo: this erases the database. just for testing!
93 std::ifstream infile(mPath.c_str());
97 remove(mPath.c_str());
98 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::DatabaseHandler Knocked down database"));
101 bool dbOpen=openDatabase();
104 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::DatabaseHandler problems opening the database!"));
113 DatabaseHandler::~DatabaseHandler()
115 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("Closed Database"));
116 sqlite3_close(mDatabase);
119 am_Error_e DatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
121 assert(domainData.domainID==0);
122 assert(!domainData.name.empty());
123 assert(!domainData.busname.empty());
124 assert(domainData.state>=DS_CONTROLLED && domainData.state<=DS_INDEPENDENT_RUNDOWN);
126 //first check for a reserved domain
127 sqlite3_stmt* query=NULL, *queryFinal;
129 std::string command="SELECT domainID FROM "+ std::string(DOMAIN_TABLE) + " WHERE name=?";
130 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
131 sqlite3_bind_text(query,1, domainData.name.c_str(),domainData.name.size(),SQLITE_STATIC);
132 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
134 command= "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" +i2s(sqlite3_column_int(query,0));
136 else if (eCode==SQLITE_DONE)
139 command= "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)";
143 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Step error code:"),DLT_INT(eCode));
144 return E_DATABASE_ERROR;
147 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
149 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Finalize error code:"),DLT_INT(eCode));
150 return E_DATABASE_ERROR;
153 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
154 sqlite3_bind_text(queryFinal,1, domainData.name.c_str(),domainData.name.size(),SQLITE_STATIC);
155 sqlite3_bind_text(queryFinal,2, domainData.busname.c_str(),domainData.busname.size(),SQLITE_STATIC);
156 sqlite3_bind_text(queryFinal,3, domainData.nodename.c_str(),domainData.nodename.size(),SQLITE_STATIC);
157 sqlite3_bind_int(queryFinal,4, domainData.early);
158 sqlite3_bind_int(queryFinal,5, domainData.complete);
159 sqlite3_bind_int(queryFinal,6, domainData.state);
160 sqlite3_bind_int(queryFinal,7, 0);
162 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
164 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Step error code:"),DLT_INT(eCode));
165 return E_DATABASE_ERROR;
168 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
170 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Finalize error code:"),DLT_INT(eCode));
171 return E_DATABASE_ERROR;
174 domainID=sqlite3_last_insert_rowid(mDatabase);
175 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterDomainDB entered new domain with name"), DLT_STRING(domainData.name.c_str()),
176 DLT_STRING("busname:"),DLT_STRING(domainData.busname.c_str()),
177 DLT_STRING("nodename:"),DLT_STRING(domainData.nodename.c_str()),
178 DLT_STRING("early:"), DLT_BOOL(domainData.early),
179 DLT_STRING("complete:"),DLT_BOOL(domainData.complete),
180 DLT_STRING("state:"),DLT_INT(domainData.state),
181 DLT_STRING("assigned ID:"),DLT_INT16(domainID));
183 am_Domain_s domain=domainData;
184 domain.domainID=domainID;
185 if(mDatabaseObserver) mDatabaseObserver->newDomain(domain);
192 am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
194 assert(mainConnectionData.connectionID==0);
195 assert(mainConnectionData.connectionState>=CS_CONNECTING && mainConnectionData.connectionState<=CS_SUSPENDED);
196 assert(mainConnectionData.route.sinkID!=0);
197 assert(mainConnectionData.route.sourceID!=0);
199 sqlite3_stmt* query=NULL;
201 std::string command= "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)";
202 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
203 sqlite3_bind_int(query,1, mainConnectionData.route.sourceID);
204 sqlite3_bind_int(query,2, mainConnectionData.route.sinkID);
205 sqlite3_bind_int(query,3, mainConnectionData.connectionState);
207 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
209 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
210 return E_DATABASE_ERROR;
214 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
216 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
217 return E_DATABASE_ERROR;
220 connectionID=sqlite3_last_insert_rowid(mDatabase);
222 //now check the connectionTable for all connections in the route. IF a particular route is not found, we return with error
223 std::vector<uint16_t> listOfConnections;
225 command="SELECT connectionID, delay FROM "+std::string(CONNECTION_TABLE)+(" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
226 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
227 std::vector<am_RoutingElement_s>::const_iterator elementIterator=mainConnectionData.route.route.begin();
228 for (;elementIterator<mainConnectionData.route.route.end();++elementIterator)
230 sqlite3_bind_int(query,1, elementIterator->sourceID);
231 sqlite3_bind_int(query,2, elementIterator->sinkID);
232 sqlite3_bind_int(query,3, elementIterator->connectionFormat);
234 if((eCode=sqlite3_step(query))==SQLITE_ROW)
236 listOfConnections.push_back(sqlite3_column_int(query,0));
237 int16_t temp_delay=sqlite3_column_int(query,1);
238 if (temp_delay!=-1 && delay!=-1) delay+=temp_delay;
243 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:"),DLT_INT(eCode));
244 return E_DATABASE_ERROR;
246 sqlite3_reset(query);
249 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
251 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
252 return E_DATABASE_ERROR;
255 //now we create a table with references to the connections;
256 command="CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
257 assert(this->sqQuery(command));
259 command= "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
260 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
261 std::vector<uint16_t>::iterator listConnectionIterator=listOfConnections.begin();
262 for(;listConnectionIterator<listOfConnections.end();++listConnectionIterator)
264 sqlite3_bind_int(query,1, *listConnectionIterator);
265 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
267 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
268 return E_DATABASE_ERROR;
270 sqlite3_reset(query);
273 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
275 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
276 return E_DATABASE_ERROR;
279 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID"), DLT_INT(mainConnectionData.route.sourceID),
280 DLT_STRING("sinkID:"),DLT_INT16(mainConnectionData.route.sinkID),
281 DLT_STRING("delay:"),DLT_INT16(delay),
282 DLT_STRING("assigned ID:"),DLT_INT16(connectionID));
284 if (mDatabaseObserver)
286 mDatabaseObserver->numberOfMainConnectionsChanged();
287 mDatabaseObserver->mainConnectionStateChanged(connectionID,mainConnectionData.connectionState);
290 //finally, we update the delay value for the maintable
291 if (delay==0) delay=-1;
292 return changeDelayMainConnection(delay,connectionID);
297 am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
299 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
300 assert(sinkData.domainID!=0);
301 assert(!sinkData.name.empty());
302 assert(sinkData.sinkClassID!=0); // \todo: need to check if class exists?
303 assert(!sinkData.listConnectionFormats.empty());
304 assert(sinkData.muteState>=MS_MUTED && sinkData.muteState<=MS_UNMUTED);
306 sqlite3_stmt *query=NULL, *queryFinal=NULL;
308 std::string command="SELECT sinkID FROM "+ std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
310 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
311 sqlite3_bind_text(query,1, sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
313 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
315 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));
317 else if (eCode==SQLITE_DONE)
319 //if sinkID is zero and the first Static Sink was already entered, the ID is created
320 if (sinkData.sinkID==0 && !mFirstStaticSink && !existSinkName(sinkData.name))
322 command= "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
326 //check if the ID already exists
327 if(existSinkNameOrID(sinkData.sinkID,sinkData.name))
329 sqlite3_finalize(query);
330 return E_ALREADY_EXISTS;
332 command= "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
337 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
338 sqlite3_finalize(query);
339 return E_DATABASE_ERROR;
342 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
344 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"),DLT_INT(eCode));
345 return E_DATABASE_ERROR;
348 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
349 sqlite3_bind_text(queryFinal,1, sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
350 sqlite3_bind_int(queryFinal,2, sinkData.domainID);
351 sqlite3_bind_int(queryFinal,3, sinkData.sinkClassID);
352 sqlite3_bind_int(queryFinal,4, sinkData.volume);
353 sqlite3_bind_int(queryFinal,5, sinkData.visible);
354 sqlite3_bind_int(queryFinal,6, sinkData.available.availability);
355 sqlite3_bind_int(queryFinal,7, sinkData.available.availabilityReason);
356 sqlite3_bind_int(queryFinal,8, sinkData.muteState);
357 sqlite3_bind_int(queryFinal,9, sinkData.mainVolume);
358 sqlite3_bind_int(queryFinal,10, 0);
360 //if the ID is not created, we add it to the query
361 if(sinkData.sinkID!=0)
363 sqlite3_bind_int(queryFinal,11, sinkData.sinkID);
366 //if the first static sink is entered, we need to set it onto the boundary
367 else if(mFirstStaticSink)
369 sqlite3_bind_int(queryFinal,11, DYNAMIC_ID_BOUNDARY);
370 mFirstStaticSink=false;
373 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
375 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
376 sqlite3_finalize(queryFinal);
377 return E_DATABASE_ERROR;
380 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
382 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"),DLT_INT(eCode));
383 return E_DATABASE_ERROR;
386 //now read back the sinkID
387 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
388 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
389 sqlite3_bind_text(query,1,sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
390 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
392 sinkID=sqlite3_column_int(query,0);
397 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
398 sqlite3_finalize(query);
399 return E_DATABASE_ERROR;
401 sqlite3_finalize(query);
403 //now we need to create the additional tables:
404 command="CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
405 assert(this->sqQuery(command));
406 command="CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
407 assert(this->sqQuery(command));
408 command="CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
409 assert(this->sqQuery(command));
411 //fill ConnectionFormats
412 command="INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
413 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
414 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=sinkData.listConnectionFormats.begin();
415 for(;connectionFormatIterator<sinkData.listConnectionFormats.end();++connectionFormatIterator)
417 sqlite3_bind_int(query,1, *connectionFormatIterator);
418 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
420 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
421 sqlite3_finalize(query);
422 return E_DATABASE_ERROR;
424 sqlite3_reset(query);
427 //Fill MainSinkSoundProperties
428 command="INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
429 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
430 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator=sinkData.listMainSoundProperties.begin();
431 for(;mainSoundPropertyIterator<sinkData.listMainSoundProperties.end();++mainSoundPropertyIterator)
433 sqlite3_bind_int(query,1, mainSoundPropertyIterator->type);
434 sqlite3_bind_int(query,2, mainSoundPropertyIterator->value);
435 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
437 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
438 sqlite3_finalize(query);
439 return E_DATABASE_ERROR;
441 sqlite3_reset(query);
444 //Fill SinkSoundProperties
445 command="INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
446 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
447 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator=sinkData.listSoundProperties.begin();
448 for(;SoundPropertyIterator<sinkData.listSoundProperties.end();++SoundPropertyIterator)
450 sqlite3_bind_int(query,1, SoundPropertyIterator->type);
451 sqlite3_bind_int(query,2, SoundPropertyIterator->value);
452 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
454 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
455 sqlite3_finalize(query);
456 return E_DATABASE_ERROR;
458 sqlite3_reset(query);
461 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkDB entered new sink with name"), DLT_STRING(sinkData.name.c_str()),
462 DLT_STRING("domainID:"),DLT_INT(sinkData.domainID),
463 DLT_STRING("classID:"),DLT_INT(sinkData.sinkClassID),
464 DLT_STRING("volume:"),DLT_INT(sinkData.volume),
465 DLT_STRING("visible:"),DLT_BOOL(sinkData.visible),
466 DLT_STRING("available.availability:"),DLT_INT(sinkData.available.availability),
467 DLT_STRING("available.availabilityReason:"),DLT_INT(sinkData.available.availabilityReason),
468 DLT_STRING("muteState:"),DLT_INT(sinkData.muteState),
469 DLT_STRING("mainVolume:"),DLT_INT(sinkData.mainVolume),
470 DLT_STRING("assigned ID:"),DLT_INT16(sinkID));
472 am_Sink_s sink=sinkData;
474 if (mDatabaseObserver!=NULL) mDatabaseObserver->newSink(sink);
481 am_Error_e DatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
483 //todo: implement crossfader
484 (void)crossfaderData;
491 am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
493 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
494 assert(gatewayData.sinkID!=0);
495 assert(gatewayData.sourceID!=0);
496 assert(gatewayData.controlDomainID!=0);
497 assert(gatewayData.domainSinkID!=0);
498 assert(gatewayData.domainSourceID!=0);
499 assert(!gatewayData.name.empty());
500 assert(!gatewayData.convertionMatrix.empty());
501 assert(!gatewayData.listSinkFormats.empty());
502 assert(!gatewayData.listSourceFormats.empty());
504 sqlite3_stmt* query=NULL;
508 //if sinkID is zero and the first Static Sink was already entered, the ID is created
509 if (gatewayData.gatewayID==0 && !mFirstStaticGateway)
511 command= "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID) VALUES (?,?,?,?,?,?)";
515 //check if the ID already exists
516 if (existGateway(gatewayData.gatewayID)) return E_ALREADY_EXISTS;
517 command= "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID) VALUES (?,?,?,?,?,?,?)";
520 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
521 sqlite3_bind_text(query,1, gatewayData.name.c_str(),gatewayData.name.size(),SQLITE_STATIC);
522 sqlite3_bind_int(query,2, gatewayData.sinkID);
523 sqlite3_bind_int(query,3, gatewayData.sourceID);
524 sqlite3_bind_int(query,4, gatewayData.domainSinkID);
525 sqlite3_bind_int(query,5, gatewayData.domainSourceID);
526 sqlite3_bind_int(query,6, gatewayData.controlDomainID);
528 //if the ID is not created, we add it to the query
529 if(gatewayData.gatewayID!=0)
531 sqlite3_bind_int(query,7, gatewayData.gatewayID);
534 //if the first static sink is entered, we need to set it onto the boundary
535 else if(mFirstStaticGateway)
537 sqlite3_bind_int(query,7, DYNAMIC_ID_BOUNDARY);
538 mFirstStaticGateway=false;
541 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
543 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
544 return E_DATABASE_ERROR;
547 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
549 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Finalize error code:"),DLT_INT(eCode));
550 return E_DATABASE_ERROR;
553 gatewayID=sqlite3_last_insert_rowid(mDatabase);
555 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
556 mListConnectionFormat.insert(std::make_pair(gatewayID,gatewayData.convertionMatrix));
558 command="CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
559 assert(this->sqQuery(command));
560 command="CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
561 assert(this->sqQuery(command));
563 //fill ConnectionFormats
564 command="INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
565 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
566 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=gatewayData.listSourceFormats.begin();
567 for(;connectionFormatIterator<gatewayData.listSourceFormats.end();++connectionFormatIterator)
569 sqlite3_bind_int(query,1, *connectionFormatIterator);
570 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
572 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
573 return E_DATABASE_ERROR;
575 sqlite3_reset(query);
578 command="INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
579 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
580 connectionFormatIterator=gatewayData.listSinkFormats.begin();
581 for(;connectionFormatIterator<gatewayData.listSinkFormats.end();++connectionFormatIterator)
583 sqlite3_bind_int(query,1, *connectionFormatIterator);
584 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
586 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
587 return E_DATABASE_ERROR;
589 sqlite3_reset(query);
593 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterGatewayDB entered new gateway with name"), DLT_STRING(gatewayData.name.c_str()),
594 DLT_STRING("sourceID:"),DLT_INT(gatewayData.sourceID),
595 DLT_STRING("sinkID:"),DLT_INT(gatewayData.sinkID),
596 DLT_STRING("domainSinkID:"),DLT_INT(gatewayData.domainSinkID),
597 DLT_STRING("domainSourceID:"),DLT_BOOL(gatewayData.domainSourceID),
598 DLT_STRING("controlDomainID:"),DLT_INT(gatewayData.controlDomainID),
599 DLT_STRING("assigned ID:"),DLT_INT16(gatewayID));
601 am_Gateway_s gateway=gatewayData;
602 gateway.gatewayID=gatewayID;
603 if(mDatabaseObserver) mDatabaseObserver->newGateway(gateway);
609 am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
611 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
612 assert(sourceData.domainID!=0);
613 assert(!sourceData.name.empty());
614 assert(sourceData.sourceClassID!=0); // \todo: need to check if class exists?
615 assert(!sourceData.listConnectionFormats.empty());
616 assert(sourceData.sourceState>=SS_ON && sourceData.sourceState<=SS_PAUSED);
618 sqlite3_stmt* query=NULL, *queryFinal=NULL;;
620 std::string command="SELECT sourceID FROM "+ std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
622 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
623 sqlite3_bind_text(query,1, sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
625 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
627 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));
629 else if (eCode==SQLITE_DONE)
631 //if sinkID is zero and the first Static Sink was already entered, the ID is created
632 if (sourceData.sourceID==0 && !mFirstStaticSource && !existSourceName(sourceData.name))
634 command= "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
638 //check if the ID already exists
639 if (existSourceNameOrID(sourceData.sourceID,sourceData.name))
641 sqlite3_finalize(query);
642 return E_ALREADY_EXISTS;
644 command= "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
649 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
650 sqlite3_finalize(query);
651 return E_DATABASE_ERROR;
654 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
656 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"),DLT_INT(eCode));
657 return E_DATABASE_ERROR;
659 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
660 sqlite3_bind_text(queryFinal,1, sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
661 sqlite3_bind_int(queryFinal,2, sourceData.domainID);
662 sqlite3_bind_int(queryFinal,3, sourceData.sourceClassID);
663 sqlite3_bind_int(queryFinal,4, sourceData.sourceState);
664 sqlite3_bind_int(queryFinal,5, sourceData.volume);
665 sqlite3_bind_int(queryFinal,6, sourceData.visible);
666 sqlite3_bind_int(queryFinal,7, sourceData.available.availability);
667 sqlite3_bind_int(queryFinal,8, sourceData.available.availabilityReason);
668 sqlite3_bind_int(queryFinal,9, sourceData.interruptState);
669 sqlite3_bind_int(queryFinal,10, 0);
671 //if the ID is not created, we add it to the query
672 if(sourceData.sourceID!=0)
674 sqlite3_bind_int(queryFinal,11, sourceData.sourceID);
677 //if the first static sink is entered, we need to set it onto the boundary
678 else if(mFirstStaticSource)
680 sqlite3_bind_int(queryFinal,11, DYNAMIC_ID_BOUNDARY);
681 mFirstStaticSource=false;
684 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
686 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
687 sqlite3_finalize(queryFinal);
688 return E_DATABASE_ERROR;
691 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
693 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"),DLT_INT(eCode));
694 sqlite3_finalize(queryFinal);
695 return E_DATABASE_ERROR;
698 //now read back the sinkID
699 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
700 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
701 sqlite3_bind_text(query,1,sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
702 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
704 sourceID=sqlite3_column_int(query,0);
709 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
710 sqlite3_finalize(query);
711 return E_DATABASE_ERROR;
713 sqlite3_finalize(query);
716 //now we need to create the additional tables:
717 command="CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
718 assert(this->sqQuery(command));
719 command="CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
720 assert(this->sqQuery(command));
721 command="CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
722 assert(this->sqQuery(command));
724 //fill ConnectionFormats
725 command="INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
726 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
727 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=sourceData.listConnectionFormats.begin();
728 for(;connectionFormatIterator<sourceData.listConnectionFormats.end();++connectionFormatIterator)
730 sqlite3_bind_int(query,1, *connectionFormatIterator);
731 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
733 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
734 sqlite3_finalize(query);
735 return E_DATABASE_ERROR;
737 sqlite3_reset(query);
740 //Fill MainSinkSoundProperties
741 command="INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
742 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
743 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator=sourceData.listMainSoundProperties.begin();
744 for(;mainSoundPropertyIterator<sourceData.listMainSoundProperties.end();++mainSoundPropertyIterator)
746 sqlite3_bind_int(query,1, mainSoundPropertyIterator->type);
747 sqlite3_bind_int(query,2, mainSoundPropertyIterator->value);
748 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
750 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
751 sqlite3_finalize(query);
752 return E_DATABASE_ERROR;
754 sqlite3_reset(query);
757 //Fill SinkSoundProperties
758 command="INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
759 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
760 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator=sourceData.listSoundProperties.begin();
761 for(;SoundPropertyIterator<sourceData.listSoundProperties.end();++SoundPropertyIterator)
763 sqlite3_bind_int(query,1, SoundPropertyIterator->type);
764 sqlite3_bind_int(query,2, SoundPropertyIterator->value);
765 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
767 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
768 sqlite3_finalize(query);
769 return E_DATABASE_ERROR;
771 sqlite3_reset(query);
774 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkDB entered new source with name"), DLT_STRING(sourceData.name.c_str()),
775 DLT_STRING("domainID:"),DLT_INT(sourceData.domainID),
776 DLT_STRING("classID:"),DLT_INT(sourceData.sourceClassID),
777 DLT_STRING("volume:"),DLT_INT(sourceData.volume),
778 DLT_STRING("visible:"),DLT_BOOL(sourceData.visible),
779 DLT_STRING("available.availability:"),DLT_INT(sourceData.available.availability),
780 DLT_STRING("available.availabilityReason:"),DLT_INT(sourceData.available.availabilityReason),
781 DLT_STRING("interruptState:"),DLT_INT(sourceData.interruptState),
782 DLT_STRING("assigned ID:"),DLT_INT16(sourceID));
784 am_Source_s source=sourceData;
785 source.sourceID=sourceID;
786 if(mDatabaseObserver) mDatabaseObserver->newSource(source);
792 am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
794 assert(mainconnectionID!=0);
795 if(!existMainConnection(mainconnectionID))
797 return E_NON_EXISTENT;
799 sqlite3_stmt* query=NULL;
803 std::vector<uint16_t> listOfConnections;
805 command="SELECT connectionID, delay FROM "+std::string(CONNECTION_TABLE)+(" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
806 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
807 std::vector<am_RoutingElement_s>::const_iterator elementIterator=route.route.begin();
808 for (;elementIterator<route.route.end();++elementIterator)
810 sqlite3_bind_int(query,1, elementIterator->sourceID);
811 sqlite3_bind_int(query,2, elementIterator->sinkID);
812 sqlite3_bind_int(query,3, elementIterator->connectionFormat);
814 if((eCode=sqlite3_step(query))==SQLITE_ROW)
816 listOfConnections.push_back(sqlite3_column_int(query,0));
817 int16_t temp_delay=sqlite3_column_int(query,1);
818 if (temp_delay!=-1 && delay!=-1) delay+=temp_delay;
823 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:"),DLT_INT(eCode));
824 return E_DATABASE_ERROR;
826 sqlite3_reset(query);
829 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
831 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"),DLT_INT(eCode));
832 return E_DATABASE_ERROR;
835 //now we delete the data in the table
836 command="DELETE from MainConnectionRoute" + i2s(mainconnectionID);
837 assert(this->sqQuery(command));
839 command= "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
840 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
841 std::vector<uint16_t>::iterator listConnectionIterator=listOfConnections.begin();
842 for(;listConnectionIterator<listOfConnections.end();++listConnectionIterator)
844 sqlite3_bind_int(query,1, *listConnectionIterator);
845 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
847 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:"),DLT_INT(eCode));
848 return E_DATABASE_ERROR;
850 sqlite3_reset(query);
853 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
855 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"),DLT_INT(eCode));
856 return E_DATABASE_ERROR;
858 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB entered new route:"),DLT_INT(mainconnectionID));
862 am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
864 assert(mainconnectionID!=0);
866 sqlite3_stmt* query=NULL;
870 if (!existMainConnection(mainconnectionID))
872 return E_NON_EXISTENT;
874 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
875 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
876 sqlite3_bind_int(query,1, connectionState);
877 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
879 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:"),DLT_INT(eCode));
880 return E_DATABASE_ERROR;
882 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
884 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
885 return E_DATABASE_ERROR;
887 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:"),DLT_INT(mainconnectionID),DLT_STRING("to:"),DLT_INT(connectionState));
889 if (mDatabaseObserver) mDatabaseObserver->mainConnectionStateChanged(mainconnectionID,connectionState);
895 am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
899 sqlite3_stmt* query=NULL;
903 if (!existSink(sinkID))
905 return E_NON_EXISTENT;
907 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
908 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
909 sqlite3_bind_int(query,1, mainVolume);
910 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
912 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:"),DLT_INT(eCode));
913 return E_DATABASE_ERROR;
915 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
917 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:"),DLT_INT(eCode));
918 return E_DATABASE_ERROR;
921 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(mainVolume));
923 if(mDatabaseObserver) mDatabaseObserver->volumeChanged(sinkID,mainVolume);
930 am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
934 sqlite3_stmt* query=NULL;
938 if (!existSink(sinkID))
940 return E_NON_EXISTENT;
942 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
943 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
944 sqlite3_bind_int(query,1, availability.availability);
945 sqlite3_bind_int(query,2, availability.availabilityReason);
946 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
948 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:"),DLT_INT(eCode));
949 return E_DATABASE_ERROR;
952 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
954 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:"),DLT_INT(eCode));
955 return E_DATABASE_ERROR;
958 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(availability.availability), DLT_STRING("Reason:"),DLT_INT(availability.availabilityReason));
960 if (mDatabaseObserver && sourceVisible(sinkID)) mDatabaseObserver->sinkAvailabilityChanged(sinkID,availability);
966 am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
970 sqlite3_stmt* query=NULL;
974 if (!existDomain(domainID))
976 return E_NON_EXISTENT;
978 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
979 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
980 sqlite3_bind_int(query,1, domainState);
981 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
983 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Step error code:"),DLT_INT(eCode));
984 return E_DATABASE_ERROR;
987 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
989 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
990 return E_DATABASE_ERROR;
993 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changDomainStateDB changed domainState of domain:"),DLT_INT(domainID),DLT_STRING("to:"),DLT_INT(domainState));
999 am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
1003 sqlite3_stmt* query=NULL;
1005 std::string command;
1007 if (!existSink(sinkID))
1009 return E_NON_EXISTENT;
1011 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
1012 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1013 sqlite3_bind_int(query,1, muteState);
1014 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1016 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:"),DLT_INT(eCode));
1017 return E_DATABASE_ERROR;
1018 } assert(sinkID!=0);
1020 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1022 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
1023 return E_DATABASE_ERROR;
1026 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(muteState));
1028 if(mDatabaseObserver) mDatabaseObserver->sinkMuteStateChanged(sinkID,muteState);
1035 am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
1037 //todo: add checks if soundproperty exists!
1040 sqlite3_stmt* query=NULL;
1042 std::string command;
1044 if (!existSink(sinkID))
1046 return E_NON_EXISTENT;
1048 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1049 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1050 sqlite3_bind_int(query,1, soundProperty.value);
1051 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1053 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1054 return E_DATABASE_ERROR;
1055 } assert(sinkID!=0);
1057 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1059 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1060 return E_DATABASE_ERROR;
1063 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:"),DLT_INT(sinkID),DLT_STRING("type:"),DLT_INT(soundProperty.type),DLT_STRING("to:"),DLT_INT(soundProperty.value));
1064 if (mDatabaseObserver) mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID,soundProperty);
1070 am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1072 //todo: add checks if soundproperty exists!
1073 assert(sourceID!=0);
1075 sqlite3_stmt* query=NULL;
1077 std::string command;
1079 if (!existSource(sourceID))
1081 return E_NON_EXISTENT;
1083 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1084 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1085 sqlite3_bind_int(query,1, soundProperty.value);
1086 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1088 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1089 return E_DATABASE_ERROR;
1092 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1094 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1095 return E_DATABASE_ERROR;
1098 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:"),DLT_INT(sourceID),DLT_STRING("type:"),DLT_INT(soundProperty.type),DLT_STRING("to:"),DLT_INT(soundProperty.value));
1100 if(mDatabaseObserver) mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID,soundProperty);
1106 am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1108 assert(sourceID!=0);
1110 sqlite3_stmt* query=NULL;
1112 std::string command;
1114 if (!existSource(sourceID))
1116 return E_NON_EXISTENT;
1118 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1119 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1120 sqlite3_bind_int(query,1, availability.availability);
1121 sqlite3_bind_int(query,2, availability.availabilityReason);
1122 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1124 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:"),DLT_INT(eCode));
1125 return E_DATABASE_ERROR;
1128 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1130 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:"),DLT_INT(eCode));
1131 return E_DATABASE_ERROR;
1134 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:"),DLT_INT(sourceID),DLT_STRING("to:"),DLT_INT(availability.availability), DLT_STRING("Reason:"),DLT_INT(availability.availabilityReason));
1136 if (mDatabaseObserver && sourceVisible(sourceID)) mDatabaseObserver->sourceAvailabilityChanged(sourceID,availability);
1142 am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1144 sqlite3_stmt* query=NULL;
1146 std::string command="UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1148 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1149 sqlite3_bind_int(query,1, property.value);
1150 sqlite3_bind_int(query,2, property.type);
1152 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1154 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1155 return E_DATABASE_ERROR;
1159 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1161 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1162 return E_DATABASE_ERROR;
1165 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSystemPropertyDB changed system property"));
1167 if(mDatabaseObserver) mDatabaseObserver->systemPropertyChanged(property);
1174 am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1176 assert(mainConnectionID!=0);
1178 if (!existMainConnection(mainConnectionID))
1180 return E_NON_EXISTENT;
1182 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1183 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1184 if(!sqQuery(command)) return E_DATABASE_ERROR;
1185 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1186 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeMainConnectionDB removed:"),DLT_INT(mainConnectionID));
1187 if (mDatabaseObserver) {
1188 mDatabaseObserver->mainConnectionStateChanged(mainConnectionID,CS_DISCONNECTED);
1189 mDatabaseObserver->numberOfMainConnectionsChanged();
1196 am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1200 if (!existSink(sinkID))
1202 return E_NON_EXISTENT;
1204 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1205 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1206 std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1207 std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID);
1208 if(!sqQuery(command)) return E_DATABASE_ERROR;
1209 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1210 if(!sqQuery(command2)) return E_DATABASE_ERROR;
1211 if(!sqQuery(command3)) return E_DATABASE_ERROR;
1212 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkDB removed:"),DLT_INT(sinkID));
1214 if (mDatabaseObserver!=NULL) mDatabaseObserver->removedSink(sinkID);
1221 am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1223 assert(sourceID!=0);
1225 if (!existSource(sourceID))
1227 return E_NON_EXISTENT;
1229 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1230 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1231 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1232 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1233 if(!sqQuery(command)) return E_DATABASE_ERROR;
1234 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1235 if(!sqQuery(command2)) return E_DATABASE_ERROR;
1236 if(!sqQuery(command3)) return E_DATABASE_ERROR;
1237 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceDB removed:"),DLT_INT(sourceID));
1238 if(mDatabaseObserver) mDatabaseObserver->removedSource(sourceID);
1244 am_Error_e DatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1246 assert(gatewayID!=0);
1248 if (!existGateway(gatewayID))
1250 return E_NON_EXISTENT;
1252 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1253 if(!sqQuery(command)) return E_DATABASE_ERROR;
1254 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeGatewayDB removed:"),DLT_INT(gatewayID));
1255 if(mDatabaseObserver) mDatabaseObserver->removeGateway(gatewayID);
1261 am_Error_e DatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1263 //todo: implement crossdfader
1270 am_Error_e DatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1272 assert(domainID!=0);
1274 if (!existDomain(domainID))
1276 return E_NON_EXISTENT;
1278 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1279 if(!sqQuery(command)) return E_DATABASE_ERROR;
1280 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeDomainDB removed:"),DLT_INT(domainID));
1281 if(mDatabaseObserver) mDatabaseObserver->removeDomain(domainID);
1285 am_Error_e DatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1287 assert(sinkClassID!=0);
1289 if (!existSinkClass(sinkClassID))
1291 return E_NON_EXISTENT;
1293 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1294 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1295 if(!sqQuery(command)) return E_DATABASE_ERROR;
1296 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1298 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkClassDB removed:"),DLT_INT(sinkClassID));
1299 if (mDatabaseObserver) mDatabaseObserver->numberOfSinkClassesChanged();
1304 am_Error_e DatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1306 assert(sourceClassID!=0);
1308 if (!existSourceClass(sourceClassID))
1310 return E_NON_EXISTENT;
1312 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1313 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1314 if(!sqQuery(command)) return E_DATABASE_ERROR;
1315 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1316 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceClassDB removed:"),DLT_INT(sourceClassID));
1318 if (mDatabaseObserver) mDatabaseObserver->numberOfSourceClassesChanged();
1322 am_Error_e DatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1324 assert(connectionID!=0);
1326 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1327 std::string command1 = "DROP table SourceClassProperties" + i2s(connectionID);
1328 if(!sqQuery(command)) return E_DATABASE_ERROR;
1329 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1330 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeConnection removed:"),DLT_INT(connectionID));
1336 am_Error_e DatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1338 assert(sourceID!=0);
1340 if (!existSource(sourceID))
1342 return E_NON_EXISTENT;
1344 sqlite3_stmt* query=NULL;
1346 am_ClassProperty_s propertyTemp;
1347 std::string command= "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE)+ " WHERE sourceID=" + (i2s(sourceID));
1348 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1350 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1352 classInfo.sourceClassID=sqlite3_column_int(query,0);
1355 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1357 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1358 return E_DATABASE_ERROR;
1361 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1363 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1364 return E_DATABASE_ERROR;
1367 command= "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE)+ " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1368 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1370 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1372 classInfo.name=std::string((const char*)sqlite3_column_text(query,0));
1375 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1377 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1378 return E_DATABASE_ERROR;
1381 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1383 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1384 return E_DATABASE_ERROR;
1387 //read out Properties
1388 command= "SELECT classProperty, value FROM SourceClassProperties"+ i2s(classInfo.sourceClassID);
1389 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1390 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1392 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(query,0);
1393 propertyTemp.value=sqlite3_column_int(query,1);
1394 classInfo.listClassProperties.push_back(propertyTemp);
1397 if(eCode!=SQLITE_DONE)
1399 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1400 return E_DATABASE_ERROR;
1403 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1405 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1406 return E_DATABASE_ERROR;
1413 am_Error_e DatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1415 assert(sinkClass.sinkClassID!=0);
1416 assert(!sinkClass.listClassProperties.empty());
1419 sqlite3_stmt* query=NULL;
1422 //check if the ID already exists
1423 if(!existSinkClass(sinkClass.sinkClassID)) return E_NON_EXISTENT;
1425 //fill ConnectionFormats
1426 std::string command="UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1427 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1428 std::vector<am_ClassProperty_s>::const_iterator Iterator=sinkClass.listClassProperties.begin();
1429 for(;Iterator<sinkClass.listClassProperties.end();++Iterator)
1431 sqlite3_bind_int(query,1, Iterator->value);
1432 sqlite3_bind_int(query,2, Iterator->classProperty);
1433 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1435 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"),DLT_INT(eCode));
1436 return E_DATABASE_ERROR;
1438 sqlite3_reset(query);
1441 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1443 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1444 return E_DATABASE_ERROR;
1447 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1453 am_Error_e DatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1455 assert(sourceClass.sourceClassID!=0);
1456 assert(!sourceClass.listClassProperties.empty());
1459 sqlite3_stmt* query=NULL;
1462 //check if the ID already exists
1463 if(!existSourceClass(sourceClass.sourceClassID)) return E_NON_EXISTENT;
1465 //fill ConnectionFormats
1466 std::string command="UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1467 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1468 std::vector<am_ClassProperty_s>::const_iterator Iterator=sourceClass.listClassProperties.begin();
1469 for(;Iterator<sourceClass.listClassProperties.end();++Iterator)
1471 sqlite3_bind_int(query,1, Iterator->value);
1472 sqlite3_bind_int(query,2, Iterator->classProperty);
1473 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1475 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"),DLT_INT(eCode));
1476 return E_DATABASE_ERROR;
1478 sqlite3_reset(query);
1481 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1483 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1484 return E_DATABASE_ERROR;
1487 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1493 am_Error_e DatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1497 if (!existSink(sinkID))
1499 return E_NON_EXISTENT;
1501 sqlite3_stmt* query=NULL;
1503 am_ClassProperty_s propertyTemp;
1504 std::string command= "SELECT sinkClassID FROM " + std::string(SINK_TABLE)+ " WHERE sinkID=" + (i2s(sinkID));
1505 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1507 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1509 sinkClass.sinkClassID=sqlite3_column_int(query,0);
1512 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1514 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1515 return E_DATABASE_ERROR;
1518 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1520 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1521 return E_DATABASE_ERROR;
1524 command= "SELECT name FROM " + std::string(SINK_CLASS_TABLE)+ " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1525 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1527 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1529 sinkClass.name=std::string((const char*)sqlite3_column_text(query,0));
1532 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1534 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1535 return E_DATABASE_ERROR;
1538 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1540 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1541 return E_DATABASE_ERROR;
1544 //read out Properties
1545 command= "SELECT classProperty, value FROM SinkClassProperties"+ i2s(sinkClass.sinkClassID);
1546 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1547 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1549 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(query,0);
1550 propertyTemp.value=sqlite3_column_int(query,1);
1551 sinkClass.listClassProperties.push_back(propertyTemp);
1554 if(eCode!=SQLITE_DONE)
1556 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1557 return E_DATABASE_ERROR;
1560 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1562 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1563 return E_DATABASE_ERROR;
1570 am_Error_e DatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1572 assert(gatewayID!=0);
1573 if (!existGateway(gatewayID))
1575 return E_NON_EXISTENT;
1577 sqlite3_stmt* query=NULL, *qSinkConnectionFormat=NULL, *qSourceConnectionFormat=NULL;
1579 am_ConnectionFormat_e tempConnectionFormat;
1580 std::string command= "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID="+i2s(gatewayID);
1581 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1583 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1585 gatewayData.name=std::string((const char*)sqlite3_column_text(query,0));
1586 gatewayData.sinkID=sqlite3_column_int(query,1);
1587 gatewayData.sourceID=sqlite3_column_int(query,2);
1588 gatewayData.domainSinkID=sqlite3_column_int(query,3);
1589 gatewayData.domainSourceID=sqlite3_column_int(query,4);
1590 gatewayData.controlDomainID=sqlite3_column_int(query,5);
1591 gatewayData.gatewayID=sqlite3_column_int(query,6);
1594 ListConnectionFormat::const_iterator iter=mListConnectionFormat.begin();
1595 iter=mListConnectionFormat.find(gatewayData.gatewayID);
1596 if (iter == mListConnectionFormat.end())
1598 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB database error with convertionFormat"));
1599 return E_DATABASE_ERROR;
1601 gatewayData.convertionMatrix=iter->second;
1603 //read out the connectionFormats
1604 std::string commandConnectionFormat= "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
1605 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSourceConnectionFormat,NULL);
1606 while((eCode=sqlite3_step(qSourceConnectionFormat))==SQLITE_ROW)
1608 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSourceConnectionFormat,0);
1609 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
1612 if((eCode=sqlite3_finalize(qSourceConnectionFormat))!=SQLITE_OK)
1614 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1615 return E_DATABASE_ERROR;
1618 //read out sound properties
1619 commandConnectionFormat= "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
1620 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSinkConnectionFormat,NULL);
1621 while((eCode=sqlite3_step(qSinkConnectionFormat))==SQLITE_ROW)
1623 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSinkConnectionFormat,0);
1624 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
1627 if((eCode=sqlite3_finalize(qSinkConnectionFormat))!=SQLITE_OK)
1629 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1630 return E_DATABASE_ERROR;
1635 if(eCode!=SQLITE_DONE)
1637 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE error code:"),DLT_INT(eCode));
1638 return E_DATABASE_ERROR;
1641 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1643 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1644 return E_DATABASE_ERROR;
1653 am_Error_e DatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
1655 //todo: implement crossfader
1657 (void)crossfaderData;
1663 am_Error_e DatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
1665 assert(domainID!=0);
1667 if (!existDomain(domainID))
1669 return E_NON_EXISTENT;
1671 sqlite3_stmt* query=NULL;
1674 std::string command= "SELECT sinkID FROM " + std::string(SINK_TABLE)+ " WHERE reserved=0 AND domainID=" + (i2s(domainID));
1675 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1677 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1679 temp=sqlite3_column_int(query,0);
1680 listSinkID.push_back(temp);
1683 if(eCode!=SQLITE_DONE)
1685 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE error code:"),DLT_INT(eCode));
1686 return E_DATABASE_ERROR;
1689 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1691 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1692 return E_DATABASE_ERROR;
1700 am_Error_e DatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
1702 assert(domainID!=0);
1703 listSourceID.clear();
1704 if (!existDomain(domainID))
1706 return E_NON_EXISTENT;
1708 sqlite3_stmt* query=NULL;
1711 std::string command= "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
1713 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1715 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1717 temp=sqlite3_column_int(query,0);
1718 listSourceID.push_back(temp);
1721 if(eCode!=SQLITE_DONE)
1723 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE error code:"),DLT_INT(eCode));
1724 return E_DATABASE_ERROR;
1727 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1729 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1730 return E_DATABASE_ERROR;
1738 am_Error_e DatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listGatewaysID) const
1740 //todo: implement crossfader
1741 (void)listGatewaysID;
1749 am_Error_e DatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
1751 assert(domainID!=0);
1752 listGatewaysID.clear();
1753 if (!existDomain(domainID))
1755 return E_NON_EXISTENT;
1757 sqlite3_stmt* query=NULL;
1759 am_gatewayID_t temp;
1761 std::string command= "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" +i2s(domainID);
1762 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1764 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1766 temp=sqlite3_column_int(query,0);
1767 listGatewaysID.push_back(temp);
1770 if(eCode!=SQLITE_DONE)
1772 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:"),DLT_INT(eCode));
1773 return E_DATABASE_ERROR;
1776 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1778 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1779 return E_DATABASE_ERROR;
1787 am_Error_e DatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
1789 listMainConnections.clear();
1790 sqlite3_stmt *query=NULL, *query1=NULL, *query2=NULL;
1792 am_MainConnection_s temp;
1793 am_RoutingElement_s tempRoute;
1795 std::string command= "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
1796 std::string command1= "SELECT connectionID FROM MainConnectionRoute";
1797 std::string command2= "SELECT sourceID, sinkID, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=?";
1798 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1799 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&query2,NULL);
1801 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1803 temp.connectionID=sqlite3_column_int(query,0);
1804 temp.route.sourceID=sqlite3_column_int(query,1);
1805 temp.route.sinkID=sqlite3_column_int(query,2);
1806 temp.connectionState=(am_ConnectionState_e)sqlite3_column_int(query,3);
1807 temp.delay=sqlite3_column_int(query,4);
1808 std::string statement=command1 + i2s(temp.connectionID);
1809 sqlite3_prepare_v2(mDatabase,statement.c_str(),-1,&query1,NULL);
1810 while((eCode=sqlite3_step(query1))==SQLITE_ROW) //todo: check results of eCode1, eCode2
1812 int k=sqlite3_column_int(query1,0);
1813 sqlite3_bind_int(query2,1,k);
1814 while((eCode=sqlite3_step(query2))==SQLITE_ROW)
1816 tempRoute.sourceID=sqlite3_column_int(query2,0);
1817 tempRoute.sinkID=sqlite3_column_int(query2,1);
1818 tempRoute.connectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(query2,2);
1819 getDomainOfSource(tempRoute.sourceID,tempRoute.domainID);
1820 temp.route.route.push_back(tempRoute);
1822 sqlite3_reset(query2);
1824 listMainConnections.push_back(temp);
1827 if(eCode!=SQLITE_DONE)
1829 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE error code:"),DLT_INT(eCode));
1830 return E_DATABASE_ERROR;
1833 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1835 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE Finalize error code:"),DLT_INT(eCode));
1836 return E_DATABASE_ERROR;
1844 am_Error_e DatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
1846 listDomains.clear();
1847 sqlite3_stmt* query=NULL;
1850 std::string command= "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
1851 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1853 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1855 temp.domainID=sqlite3_column_int(query,0);
1856 temp.name=std::string((const char*)sqlite3_column_text(query,1));
1857 temp.busname=std::string((const char*)sqlite3_column_text(query,2));
1858 temp.nodename=std::string((const char*)sqlite3_column_text(query,3));
1859 temp.early=sqlite3_column_int(query,4);
1860 temp.complete=sqlite3_column_int(query,5);
1861 temp.state=(am_DomainState_e)sqlite3_column_int(query,6);
1862 listDomains.push_back(temp);
1865 if(eCode!=SQLITE_DONE)
1867 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE error code:"),DLT_INT(eCode));
1868 return E_DATABASE_ERROR;
1871 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1873 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE Finalize error code:"),DLT_INT(eCode));
1874 return E_DATABASE_ERROR;
1882 am_Error_e DatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
1884 listConnections.clear();
1885 sqlite3_stmt* query=NULL;
1887 am_Connection_s temp;
1888 std::string command= "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE)+" WHERE reserved=0";
1889 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1891 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1893 temp.connectionID=sqlite3_column_int(query,0);
1894 temp.sourceID=sqlite3_column_int(query,1);
1895 temp.sinkID=sqlite3_column_int(query,2);
1896 temp.delay=sqlite3_column_int(query,3);
1897 temp.connectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(query,4);
1898 listConnections.push_back(temp);
1901 if(eCode!=SQLITE_DONE)
1903 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE error code:"),DLT_INT(eCode));
1904 return E_DATABASE_ERROR;
1907 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1909 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE Finalize error code:"),DLT_INT(eCode));
1910 return E_DATABASE_ERROR;
1918 am_Error_e DatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
1921 sqlite3_stmt* query=NULL, *qConnectionFormat=NULL, *qSoundProperty=NULL, *qMAinSoundProperty=NULL;
1924 am_ConnectionFormat_e tempConnectionFormat;
1925 am_SoundProperty_s tempSoundProperty;
1926 am_MainSoundProperty_s tempMainSoundProperty;
1927 std::string command= "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE)+ " WHERE reserved=0";
1928 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1930 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1932 temp.name=std::string((const char*)sqlite3_column_text(query,0));
1933 temp.domainID=sqlite3_column_int(query,1);
1934 temp.sinkClassID=sqlite3_column_int(query,2);
1935 temp.volume=sqlite3_column_int(query,3);
1936 temp.visible=sqlite3_column_int(query,4);
1937 temp.available.availability=(am_Availablility_e)sqlite3_column_int(query,5);
1938 temp.available.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,6);
1939 temp.muteState=(am_MuteState_e)sqlite3_column_int(query,7);
1940 temp.mainVolume=sqlite3_column_int(query,8);
1941 temp.sinkID=sqlite3_column_int(query,9);
1943 //read out the connectionFormats
1944 std::string commandConnectionFormat= "SELECT soundFormat FROM SinkConnectionFormat"+ i2s(temp.sinkID);
1945 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qConnectionFormat,NULL);
1946 while((eCode=sqlite3_step(qConnectionFormat))==SQLITE_ROW)
1948 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qConnectionFormat,0);
1949 temp.listConnectionFormats.push_back(tempConnectionFormat);
1952 if((eCode=sqlite3_finalize(qConnectionFormat))!=SQLITE_OK)
1954 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1955 return E_DATABASE_ERROR;
1958 //read out sound properties
1959 std::string commandSoundProperty= "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
1960 sqlite3_prepare_v2(mDatabase,commandSoundProperty.c_str(),-1,&qSoundProperty,NULL);
1961 while((eCode=sqlite3_step(qSoundProperty))==SQLITE_ROW)
1963 tempSoundProperty.type=(am_SoundPropertyType_e)sqlite3_column_int(qSoundProperty,0);
1964 tempSoundProperty.value=sqlite3_column_int(qSoundProperty,1);
1965 temp.listSoundProperties.push_back(tempSoundProperty);
1968 if((eCode=sqlite3_finalize(qSoundProperty))!=SQLITE_OK)
1970 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1971 return E_DATABASE_ERROR;
1974 //read out MainSoundProperties
1975 std::string commandMainSoundProperty= "SELECT soundPropertyType, value FROM SinkMainSoundProperty"+ i2s(temp.sinkID);
1976 sqlite3_prepare_v2(mDatabase,commandMainSoundProperty.c_str(),-1,&qMAinSoundProperty,NULL);
1977 while((eCode=sqlite3_step(qMAinSoundProperty))==SQLITE_ROW)
1979 tempMainSoundProperty.type=(am_MainSoundPropertyType_e)sqlite3_column_int(qMAinSoundProperty,0);
1980 tempMainSoundProperty.value=sqlite3_column_int(qMAinSoundProperty,1);
1981 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
1984 if((eCode=sqlite3_finalize(qMAinSoundProperty))!=SQLITE_OK)
1986 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1987 return E_DATABASE_ERROR;
1989 listSinks.push_back(temp);
1990 temp.listConnectionFormats.clear();
1991 temp.listMainSoundProperties.clear();
1992 temp.listSoundProperties.clear();
1995 if(eCode!=SQLITE_DONE)
1997 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"),DLT_INT(eCode));
1998 return E_DATABASE_ERROR;
2001 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2003 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
2004 return E_DATABASE_ERROR;
2012 am_Error_e DatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
2014 listSources.clear();
2015 sqlite3_stmt* query=NULL, *qConnectionFormat=NULL, *qSoundProperty=NULL, *qMAinSoundProperty=NULL;
2018 am_ConnectionFormat_e tempConnectionFormat;
2019 am_SoundProperty_s tempSoundProperty;
2020 am_MainSoundProperty_s tempMainSoundProperty;
2021 std::string command= "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) +" WHERE reserved=0";
2022 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2024 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2026 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2027 temp.domainID=sqlite3_column_int(query,1);
2028 temp.sourceClassID=sqlite3_column_int(query,2);
2029 temp.sourceState=(am_SourceState_e)sqlite3_column_int(query,3);
2030 temp.volume=sqlite3_column_int(query,4);
2031 temp.visible=sqlite3_column_int(query,5);
2032 temp.available.availability=(am_Availablility_e)sqlite3_column_int(query,6);
2033 temp.available.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,7);
2034 temp.interruptState=(am_InterruptState_e)sqlite3_column_int(query,8);
2035 temp.sourceID=sqlite3_column_int(query,9);
2037 //read out the connectionFormats
2038 std::string commandConnectionFormat= "SELECT soundFormat FROM SourceConnectionFormat"+ i2s(temp.sourceID);
2039 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qConnectionFormat,NULL);
2040 while((eCode=sqlite3_step(qConnectionFormat))==SQLITE_ROW)
2042 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qConnectionFormat,0);
2043 temp.listConnectionFormats.push_back(tempConnectionFormat);
2046 if((eCode=sqlite3_finalize(qConnectionFormat))!=SQLITE_OK)
2048 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2049 return E_DATABASE_ERROR;
2052 //read out sound properties
2053 std::string commandSoundProperty= "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
2054 sqlite3_prepare_v2(mDatabase,commandSoundProperty.c_str(),-1,&qSoundProperty,NULL);
2055 while((eCode=sqlite3_step(qSoundProperty))==SQLITE_ROW)
2057 tempSoundProperty.type=(am_SoundPropertyType_e)sqlite3_column_int(qSoundProperty,0);
2058 tempSoundProperty.value=sqlite3_column_int(qSoundProperty,1);
2059 temp.listSoundProperties.push_back(tempSoundProperty);
2062 if((eCode=sqlite3_finalize(qSoundProperty))!=SQLITE_OK)
2064 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2065 return E_DATABASE_ERROR;
2068 //read out MainSoundProperties
2069 std::string commandMainSoundProperty= "SELECT soundPropertyType, value FROM SourceMainSoundProperty"+ i2s(temp.sourceID);
2070 sqlite3_prepare_v2(mDatabase,commandMainSoundProperty.c_str(),-1,&qMAinSoundProperty,NULL);
2071 while((eCode=sqlite3_step(qMAinSoundProperty))==SQLITE_ROW)
2073 tempMainSoundProperty.type=(am_MainSoundPropertyType_e)sqlite3_column_int(qMAinSoundProperty,0);
2074 tempMainSoundProperty.value=sqlite3_column_int(qMAinSoundProperty,1);
2075 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2078 if((eCode=sqlite3_finalize(qMAinSoundProperty))!=SQLITE_OK)
2080 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2081 return E_DATABASE_ERROR;
2083 listSources.push_back(temp);
2084 temp.listConnectionFormats.clear();
2085 temp.listMainSoundProperties.clear();
2086 temp.listSoundProperties.clear();
2089 if(eCode!=SQLITE_DONE)
2091 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"),DLT_INT(eCode));
2092 return E_DATABASE_ERROR;
2095 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2097 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2098 return E_DATABASE_ERROR;
2106 am_Error_e DatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
2108 listSourceClasses.clear();
2110 sqlite3_stmt* query=NULL, *subQuery=NULL;
2111 int eCode=0, eCode1;
2112 am_SourceClass_s classTemp;
2113 am_ClassProperty_s propertyTemp;
2115 std::string command= "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
2116 std::string command2;
2117 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2119 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2121 classTemp.sourceClassID=sqlite3_column_int(query,0);
2122 classTemp.name=std::string((const char*)sqlite3_column_text(query,1));
2124 //read out Properties
2125 command2="SELECT classProperty, value FROM SourceClassProperties"+ i2s(classTemp.sourceClassID);
2126 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&subQuery,NULL);
2128 while((eCode1=sqlite3_step(subQuery))==SQLITE_ROW)
2130 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(subQuery,0);
2131 propertyTemp.value=sqlite3_column_int(subQuery,1);
2132 classTemp.listClassProperties.push_back(propertyTemp);
2135 if(eCode1!=SQLITE_DONE)
2137 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode1));
2138 return E_DATABASE_ERROR;
2141 if((eCode1=sqlite3_finalize(subQuery))!=SQLITE_OK)
2143 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode1));
2144 return E_DATABASE_ERROR;
2146 listSourceClasses.push_back(classTemp);
2149 if(eCode!=SQLITE_DONE)
2151 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2152 return E_DATABASE_ERROR;
2155 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2157 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2158 return E_DATABASE_ERROR;
2166 am_Error_e DatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2168 //todo: implement crossfaders
2169 (void)listCrossfaders;
2175 am_Error_e DatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2177 listGateways.clear();
2178 sqlite3_stmt* query=NULL, *qSinkConnectionFormat=NULL, *qSourceConnectionFormat=NULL;
2181 am_ConnectionFormat_e tempConnectionFormat;
2183 std::string command= "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2184 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2186 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2188 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2189 temp.sinkID=sqlite3_column_int(query,1);
2190 temp.sourceID=sqlite3_column_int(query,2);
2191 temp.domainSinkID=sqlite3_column_int(query,3);
2192 temp.domainSourceID=sqlite3_column_int(query,4);
2193 temp.controlDomainID=sqlite3_column_int(query,5);
2194 temp.gatewayID=sqlite3_column_int(query,6);
2197 ListConnectionFormat::const_iterator iter=mListConnectionFormat.begin();
2198 iter=mListConnectionFormat.find(temp.gatewayID);
2199 if (iter == mListConnectionFormat.end())
2201 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways database error with convertionFormat"));
2202 return E_DATABASE_ERROR;
2204 temp.convertionMatrix=iter->second;
2206 //read out the connectionFormats
2207 std::string commandConnectionFormat= "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2208 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSourceConnectionFormat,NULL);
2209 while((eCode=sqlite3_step(qSourceConnectionFormat))==SQLITE_ROW)
2211 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSourceConnectionFormat,0);
2212 temp.listSourceFormats.push_back(tempConnectionFormat);
2215 if((eCode=sqlite3_finalize(qSourceConnectionFormat))!=SQLITE_OK)
2217 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2218 return E_DATABASE_ERROR;
2221 //read out sound properties
2222 commandConnectionFormat= "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2223 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSinkConnectionFormat,NULL);
2224 while((eCode=sqlite3_step(qSinkConnectionFormat))==SQLITE_ROW)
2226 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSinkConnectionFormat,0);
2227 temp.listSinkFormats.push_back(tempConnectionFormat);
2230 if((eCode=sqlite3_finalize(qSinkConnectionFormat))!=SQLITE_OK)
2232 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2233 return E_DATABASE_ERROR;
2236 listGateways.push_back(temp);
2237 temp.listSinkFormats.clear();
2238 temp.listSourceFormats.clear();
2241 if(eCode!=SQLITE_DONE)
2243 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE error code:"),DLT_INT(eCode));
2244 return E_DATABASE_ERROR;
2247 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2249 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2250 return E_DATABASE_ERROR;
2258 am_Error_e DatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2260 listSinkClasses.clear();
2262 sqlite3_stmt* query=NULL, *subQuery=NULL;
2264 am_SinkClass_s classTemp;
2265 am_ClassProperty_s propertyTemp;
2267 std::string command= "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2268 std::string command2;
2269 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2271 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2273 classTemp.sinkClassID=sqlite3_column_int(query,0);
2274 classTemp.name=std::string((const char*)sqlite3_column_text(query,1));
2276 //read out Properties
2277 command2="SELECT classProperty, value FROM SinkClassProperties"+ i2s(classTemp.sinkClassID);
2278 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&subQuery,NULL);
2280 while((eCode=sqlite3_step(subQuery))==SQLITE_ROW)
2282 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(subQuery,0);
2283 propertyTemp.value=sqlite3_column_int(subQuery,1);
2284 classTemp.listClassProperties.push_back(propertyTemp);
2287 if(eCode!=SQLITE_DONE)
2289 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2290 return E_DATABASE_ERROR;
2293 if((eCode=sqlite3_finalize(subQuery))!=SQLITE_OK)
2295 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2296 return E_DATABASE_ERROR;
2298 listSinkClasses.push_back(classTemp);
2301 if(eCode!=SQLITE_DONE)
2303 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2304 return E_DATABASE_ERROR;
2307 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2309 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2310 return E_DATABASE_ERROR;
2318 am_Error_e DatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2320 listConnections.clear();
2321 sqlite3_stmt *query=NULL;
2323 am_MainConnectionType_s temp;
2325 std::string command= "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2326 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2328 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2330 temp.mainConnectionID=sqlite3_column_int(query,0);
2331 temp.sourceID=sqlite3_column_int(query,1);
2332 temp.sinkID=sqlite3_column_int(query,2);
2333 temp.connectionState=(am_ConnectionState_e)sqlite3_column_int(query,3);
2334 temp.delay=sqlite3_column_int(query,4);
2335 listConnections.push_back(temp);
2338 if(eCode!=SQLITE_DONE)
2340 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE error code:"),DLT_INT(eCode));
2341 return E_DATABASE_ERROR;
2344 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2346 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:"),DLT_INT(eCode));
2347 return E_DATABASE_ERROR;
2355 am_Error_e DatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2357 listMainSinks.clear();
2358 sqlite3_stmt* query=NULL;
2362 std::string command= "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2363 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2365 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2367 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2368 temp.sinkID=sqlite3_column_int(query,1);
2369 temp.availability.availability=(am_Availablility_e)sqlite3_column_int(query,2);
2370 temp.availability.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,3);
2371 temp.muteState=(am_MuteState_e)sqlite3_column_int(query,4);
2372 temp.volume=sqlite3_column_int(query,5);
2373 temp.sinkClassID=sqlite3_column_int(query,6);
2374 listMainSinks.push_back(temp);
2377 if(eCode!=SQLITE_DONE)
2379 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"),DLT_INT(eCode));
2380 return E_DATABASE_ERROR;
2383 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2385 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
2386 return E_DATABASE_ERROR;
2394 am_Error_e DatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2396 listMainSources.clear();
2397 sqlite3_stmt* query=NULL;
2399 am_SourceType_s temp;
2400 std::string command= "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2401 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2403 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2405 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2406 temp.sourceClassID=sqlite3_column_int(query,1);
2407 temp.availability.availability=(am_Availablility_e)sqlite3_column_int(query,2);
2408 temp.availability.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,3);
2409 temp.sourceID=sqlite3_column_int(query,4);
2411 listMainSources.push_back(temp);
2414 if(eCode!=SQLITE_DONE)
2416 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"),DLT_INT(eCode));
2417 return E_DATABASE_ERROR;
2420 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2422 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2423 return E_DATABASE_ERROR;
2431 am_Error_e DatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2434 if (!existSink(sinkID)) return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2435 listSoundProperties.clear();
2437 sqlite3_stmt* query=NULL;
2439 am_MainSoundProperty_s temp;
2440 std::string command= "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2441 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2443 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2445 temp.type=(am_MainSoundPropertyType_e)sqlite3_column_int(query,0);
2446 temp.value=sqlite3_column_int(query,1);
2447 listSoundProperties.push_back(temp);
2450 if(eCode!=SQLITE_DONE)
2452 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"),DLT_INT(eCode));
2453 return E_DATABASE_ERROR;
2456 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2458 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2459 return E_DATABASE_ERROR;
2467 am_Error_e DatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2469 assert(sourceID!=0);
2470 if (!existSource(sourceID)) return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2471 listSourceProperties.clear();
2473 sqlite3_stmt* query=NULL;
2475 am_MainSoundProperty_s temp;
2476 std::string command= "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2477 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2479 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2481 temp.type=(am_MainSoundPropertyType_e)sqlite3_column_int(query,0);
2482 temp.value=sqlite3_column_int(query,1);
2483 listSourceProperties.push_back(temp);
2486 if(eCode!=SQLITE_DONE)
2488 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"),DLT_INT(eCode));
2489 return E_DATABASE_ERROR;
2492 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2494 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2495 return E_DATABASE_ERROR;
2503 am_Error_e DatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2505 listSystemProperties.clear();
2507 sqlite3_stmt* query=NULL;
2509 am_SystemProperty_s temp;
2510 std::string command= "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2511 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2513 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2515 temp.type=(am_SystemPropertyType_e)sqlite3_column_int(query,0);
2516 temp.value=sqlite3_column_int(query,1);
2517 listSystemProperties.push_back(temp);
2520 if(eCode!=SQLITE_DONE)
2522 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE error code:"),DLT_INT(eCode));
2523 return E_DATABASE_ERROR;
2526 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2528 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2529 return E_DATABASE_ERROR;
2535 am_Error_e am::DatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2537 listConnectionFormats.clear();
2538 sqlite3_stmt *qConnectionFormat=NULL;
2540 am_ConnectionFormat_e tempConnectionFormat;
2541 std::string commandConnectionFormat= "SELECT soundFormat FROM SinkConnectionFormat"+ i2s(sinkID);
2542 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qConnectionFormat,NULL);
2543 while((eCode=sqlite3_step(qConnectionFormat))==SQLITE_ROW)
2545 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qConnectionFormat,0);
2546 listConnectionFormats.push_back(tempConnectionFormat);
2549 if((eCode=sqlite3_finalize(qConnectionFormat))!=SQLITE_OK)
2551 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinkConnectionFormats SQLITE Finalize error code:"),DLT_INT(eCode));
2552 return E_DATABASE_ERROR;
2560 am_Error_e am::DatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_ConnectionFormat_e> & listConnectionFormats) const
2562 listConnectionFormats.clear();
2563 sqlite3_stmt* query=NULL, *qConnectionFormat=NULL, *qSoundProperty=NULL, *qMAinSoundProperty=NULL;
2565 am_ConnectionFormat_e tempConnectionFormat;
2567 //read out the connectionFormats
2568 std::string commandConnectionFormat= "SELECT soundFormat FROM SourceConnectionFormat"+ i2s(sourceID);
2569 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qConnectionFormat,NULL);
2570 while((eCode=sqlite3_step(qConnectionFormat))==SQLITE_ROW)
2572 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qConnectionFormat,0);
2573 listConnectionFormats.push_back(tempConnectionFormat);
2576 if((eCode=sqlite3_finalize(qConnectionFormat))!=SQLITE_OK)
2578 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2579 return E_DATABASE_ERROR;
2585 am_Error_e am::DatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const
2587 ListConnectionFormat::const_iterator iter=mListConnectionFormat.begin();
2588 iter=mListConnectionFormat.find(gatewayID);
2589 if (iter == mListConnectionFormat.end())
2591 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat"));
2592 return (E_DATABASE_ERROR);
2594 listConnectionFormat=iter->second;
2601 am_Error_e DatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2603 assert(mainConnectionID!=0);
2605 sqlite3_stmt *query=NULL;
2608 std::string command= "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2609 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2611 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2613 delay=sqlite3_column_int(query,0);
2616 if(eCode!=SQLITE_DONE)
2618 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE error code:"),DLT_INT(eCode));
2619 return E_DATABASE_ERROR;
2622 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2624 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
2625 return E_DATABASE_ERROR;
2628 if (delay==-1) return E_NOT_POSSIBLE;
2633 bool DatabaseHandler::sqQuery(const std::string& query)
2635 sqlite3_stmt* statement;
2637 if ((eCode=sqlite3_exec(mDatabase,query.c_str(),NULL,&statement,NULL))!= SQLITE_OK)
2639 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sqQuery SQL Query failed:"), DLT_STRING(query.c_str()), DLT_STRING("error code:"),DLT_INT(eCode));
2645 bool DatabaseHandler::openDatabase()
2647 if (sqlite3_open_v2(mPath.c_str(),&mDatabase,SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
2649 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::openDatabase opened database"));
2652 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::openDatabase failed to open database"));
2656 am_Error_e DatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
2658 assert(connectionID!=0);
2660 sqlite3_stmt* query=NULL;
2662 std::string command ="SELECT mainConnectionID FROM "+ std::string(MAINCONNECTION_TABLE) +" WHERE delay=? AND mainConnectionID=?";
2663 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2664 sqlite3_bind_int(query,1, delay);
2665 sqlite3_bind_int(query,2, connectionID);
2666 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2668 sqlite3_finalize(query);
2671 command="UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
2672 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2673 sqlite3_bind_int(query,1, delay);
2674 sqlite3_bind_int(query,2, connectionID);
2676 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2678 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:"),DLT_INT(eCode));
2679 return E_DATABASE_ERROR;
2682 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2684 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:"),DLT_INT(eCode));
2685 return E_DATABASE_ERROR;
2688 if(mDatabaseObserver) mDatabaseObserver->timingInformationChanged(connectionID,delay);
2693 am_Error_e DatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
2695 assert(connection.connectionID==0);
2696 assert(connection.sinkID!=0);
2697 assert(connection.sourceID!=0);
2698 //connection format is not checked, because it's project specific
2700 sqlite3_stmt* query=NULL;
2702 std::string command= "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
2704 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2705 sqlite3_bind_int(query,1, connection.sinkID);
2706 sqlite3_bind_int(query,2, connection.sourceID);
2707 sqlite3_bind_int(query,3, connection.delay);
2708 sqlite3_bind_int(query,4, connection.connectionFormat);
2709 sqlite3_bind_int(query,5, true);
2711 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2713 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
2714 return E_DATABASE_ERROR;
2717 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2719 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
2720 return E_DATABASE_ERROR;
2723 connectionID=sqlite3_last_insert_rowid(mDatabase);
2725 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterConnectionDB entered new connection sourceID:"), DLT_INT16(connection.sourceID),
2726 DLT_STRING("sinkID:"),DLT_INT16(connection.sinkID),
2727 DLT_STRING("sourceID:"),DLT_INT16(connection.sourceID),
2728 DLT_STRING("delay:"), DLT_INT16(connection.delay),
2729 DLT_STRING("connectionFormat:"),DLT_INT16(connection.connectionFormat),
2730 DLT_STRING("assigned ID:"),DLT_INT16(connectionID));
2734 am_Error_e DatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
2736 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
2737 assert(!sinkClass.listClassProperties.empty());
2738 assert(!sinkClass.name.empty());
2740 sqlite3_stmt* query=NULL;
2742 std::string command;
2744 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2745 if (sinkClass.sinkClassID==0 && !mFirstStaticSinkClass)
2747 command= "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
2751 //check if the ID already exists
2752 if(existSinkClass(sinkClass.sinkClassID)) return E_ALREADY_EXISTS;
2753 command= "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
2756 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2757 sqlite3_bind_text(query,1, sinkClass.name.c_str(),sinkClass.name.size(),SQLITE_STATIC);
2759 //if the ID is not created, we add it to the query
2760 if(sinkClass.sinkClassID!=0)
2762 sqlite3_bind_int(query,2, sinkClass.sinkClassID);
2765 //if the first static sink is entered, we need to set it onto the boundary
2766 else if(mFirstStaticSinkClass)
2768 sqlite3_bind_int(query,2, DYNAMIC_ID_BOUNDARY);
2769 mFirstStaticSinkClass=false;
2772 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2774 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"),DLT_INT(eCode));
2775 return E_DATABASE_ERROR;
2778 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2780 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2781 return E_DATABASE_ERROR;
2784 sinkClassID=sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2786 //now we need to create the additional tables:
2787 command="CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2788 assert(this->sqQuery(command));
2790 //fill ConnectionFormats
2791 command="INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
2792 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2793 std::vector<am_ClassProperty_s>::const_iterator Iterator=sinkClass.listClassProperties.begin();
2794 for(;Iterator<sinkClass.listClassProperties.end();++Iterator)
2796 sqlite3_bind_int(query,1, Iterator->classProperty);
2797 sqlite3_bind_int(query,2, Iterator->value);
2798 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2800 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"),DLT_INT(eCode));
2801 return E_DATABASE_ERROR;
2803 sqlite3_reset(query);
2806 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2808 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2809 return E_DATABASE_ERROR;
2812 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkClassDB entered new sinkClass"));
2813 if (mDatabaseObserver) mDatabaseObserver->numberOfSinkClassesChanged();
2817 am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
2819 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
2820 assert(!sourceClass.listClassProperties.empty());
2821 assert(!sourceClass.name.empty());
2823 sqlite3_stmt* query=NULL;
2825 std::string command;
2827 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2828 if (sourceClass.sourceClassID==0 && !mFirstStaticSourceClass)
2830 command= "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
2834 //check if the ID already exists
2835 if(existSourceClass(sourceClass.sourceClassID)) return E_ALREADY_EXISTS;
2836 command= "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
2839 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2840 sqlite3_bind_text(query,1, sourceClass.name.c_str(),sourceClass.name.size(),SQLITE_STATIC);
2842 //if the ID is not created, we add it to the query
2843 if(sourceClass.sourceClassID!=0)
2845 sqlite3_bind_int(query,2, sourceClass.sourceClassID);
2848 //if the first static sink is entered, we need to set it onto the boundary
2849 else if(mFirstStaticSourceClass)
2851 sqlite3_bind_int(query,2, DYNAMIC_ID_BOUNDARY);
2852 mFirstStaticSourceClass=false;
2855 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2857 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"),DLT_INT(eCode));
2858 return E_DATABASE_ERROR;
2861 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2863 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2864 return E_DATABASE_ERROR;
2867 sourceClassID=sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2869 //now we need to create the additional tables:
2870 command="CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2871 assert(sqQuery(command));
2873 //fill ConnectionFormats
2874 command="INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
2875 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2876 std::vector<am_ClassProperty_s>::const_iterator Iterator=sourceClass.listClassProperties.begin();
2877 for(;Iterator<sourceClass.listClassProperties.end();++Iterator)
2879 sqlite3_bind_int(query,1, Iterator->classProperty);
2880 sqlite3_bind_int(query,2, Iterator->value);
2881 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2883 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"),DLT_INT(eCode));
2884 return E_DATABASE_ERROR;
2886 sqlite3_reset(query);
2889 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2891 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2892 return E_DATABASE_ERROR;
2895 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSourceClassDB entered new sourceClass"));
2897 if (mDatabaseObserver) mDatabaseObserver->numberOfSourceClassesChanged();
2901 am_Error_e DatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
2903 sqlite3_stmt* query=NULL;
2905 std::vector<am_SystemProperty_s>::const_iterator listIterator =listSystemProperties.begin();
2906 std::string command= "DELETE * FROM " + std::string(SYSTEM_TABLE);
2909 command="INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
2911 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2912 for(;listIterator<listSystemProperties.end();++listIterator)
2914 sqlite3_bind_int(query,1, listIterator->type);
2915 sqlite3_bind_int(query,2, listIterator->value);
2917 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2919 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Step error code:"),DLT_INT(eCode));
2920 return E_DATABASE_ERROR;
2923 sqlite3_reset(query);
2926 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2928 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2929 return E_DATABASE_ERROR;
2932 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSystemProperties entered system properties"));
2936 bool DatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
2938 sqlite3_stmt* query=NULL;
2939 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2941 bool returnVal=true;
2942 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2943 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2944 else if (eCode!=SQLITE_ROW)
2947 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
2949 sqlite3_finalize(query);
2953 bool DatabaseHandler::existSource(const am_sourceID_t sourceID) const
2955 sqlite3_stmt* query=NULL;
2956 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
2958 bool returnVal=true;
2959 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2960 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2961 else if (eCode!=SQLITE_ROW)
2964 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2966 sqlite3_finalize(query);
2970 bool DatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
2972 sqlite3_stmt* query=NULL;
2973 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
2975 bool returnVal=true;
2976 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2977 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2978 sqlite3_bind_int(query,2,sourceID);
2979 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2980 else if (eCode!=SQLITE_ROW)
2983 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2985 sqlite3_finalize(query);
2989 bool DatabaseHandler::existSourceName(const std::string & name) const
2991 sqlite3_stmt* query=NULL;
2992 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
2994 bool returnVal=true;
2995 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2996 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2997 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2998 else if (eCode!=SQLITE_ROW)
3001 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
3003 sqlite3_finalize(query);
3007 bool DatabaseHandler::existSink(const am_sinkID_t sinkID) const
3009 sqlite3_stmt* query=NULL;
3010 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
3012 bool returnVal=true;
3013 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3014 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3015 else if (eCode!=SQLITE_ROW)
3018 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
3020 sqlite3_finalize(query);
3024 bool DatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
3026 sqlite3_stmt* query=NULL;
3027 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
3029 bool returnVal=true;
3030 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3031 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3032 sqlite3_bind_int(query,2,sinkID);
3033 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3034 else if (eCode!=SQLITE_ROW)
3037 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
3039 sqlite3_finalize(query);
3043 bool DatabaseHandler::existSinkName(const std::string & name) const
3045 sqlite3_stmt* query=NULL;
3046 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
3048 bool returnVal=true;
3049 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3050 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3051 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3052 else if (eCode!=SQLITE_ROW)
3055 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
3057 sqlite3_finalize(query);
3061 bool DatabaseHandler::existDomain(const am_domainID_t domainID) const
3063 sqlite3_stmt* query=NULL;
3064 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
3066 bool returnVal=true;
3067 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3068 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3069 else if (eCode!=SQLITE_ROW)
3072 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existDomain database error!:"), DLT_INT(eCode))
3074 sqlite3_finalize(query);
3078 bool DatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
3080 sqlite3_stmt* query=NULL;
3081 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
3083 bool returnVal=true;
3084 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3085 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3086 else if (eCode!=SQLITE_ROW)
3089 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existGateway database error!:"), DLT_INT(eCode))
3091 sqlite3_finalize(query);
3095 am_Error_e DatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
3097 assert(sourceID!=0);
3099 sqlite3_stmt* query=NULL;
3100 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3102 am_Error_e returnVal=E_DATABASE_ERROR;
3103 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3104 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3106 domainID=sqlite3_column_int(query,0);
3111 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainOfSource database error!:"), DLT_INT(eCode))
3113 sqlite3_finalize(query);
3117 am_Error_e am::DatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const
3121 sqlite3_stmt* query=NULL;
3122 std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
3124 am_Error_e returnVal=E_DATABASE_ERROR;
3125 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3126 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3128 domainID=sqlite3_column_int(query,0);
3133 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainOfSink database error!:"), DLT_INT(eCode))
3135 sqlite3_finalize(query);
3140 bool DatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3142 sqlite3_stmt* query=NULL;
3143 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
3145 bool returnVal=true;
3146 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3147 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3148 else if (eCode!=SQLITE_ROW)
3151 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3153 sqlite3_finalize(query);
3157 bool DatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3159 sqlite3_stmt* query=NULL;
3160 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
3162 bool returnVal=true;
3163 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3164 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3165 else if (eCode!=SQLITE_ROW)
3168 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3170 sqlite3_finalize(query);
3174 am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3176 assert(connectionID!=0);
3178 sqlite3_stmt *query=NULL, *queryMainConnections, *queryMainConnectionSubIDs;
3179 int eCode=0, eCode1=0;
3180 std::string command= "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3182 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3183 sqlite3_bind_int(query,1, delay);
3184 sqlite3_bind_int(query,2, connectionID);
3186 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3188 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:"),DLT_INT(eCode));
3189 return E_DATABASE_ERROR;
3192 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3194 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
3195 return E_DATABASE_ERROR;
3198 //now we need to find all mainConnections that use the changed connection and update their timing
3199 am_timeSync_t tempDelay=0;
3202 int tempMainConnectionID;
3203 //first get all route tables for all mainconnections
3204 command= "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'";
3205 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryMainConnections,NULL);
3207 while((eCode=sqlite3_step(queryMainConnections))==SQLITE_ROW)
3209 //now check if the connection ID is in this table
3210 std::string tablename=std::string((const char*)sqlite3_column_text(queryMainConnections,0));
3211 std::string command2="SELECT connectionID FROM " + tablename + " WHERE connectionID="+i2s(connectionID);
3212 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&queryMainConnectionSubIDs,NULL);
3213 if((eCode1=sqlite3_step(queryMainConnectionSubIDs))==SQLITE_ROW)
3215 //if the connection ID is in, recalculate the mainconnection delay
3216 std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID;
3217 changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID),tempMainConnectionID);
3219 else if(eCode1!=SQLITE_DONE)
3221 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"),DLT_INT(eCode1));
3222 return E_DATABASE_ERROR;
3226 if(eCode!=SQLITE_DONE)
3228 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"),DLT_INT(eCode));
3229 return E_DATABASE_ERROR;
3232 if((eCode=sqlite3_finalize(queryMainConnections))!=SQLITE_OK)
3234 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
3235 return E_DATABASE_ERROR;
3241 am_Error_e DatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3243 assert(connectionID!=0);
3245 sqlite3_stmt *query=NULL;
3247 std::string command= "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3249 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3250 sqlite3_bind_int(query,1, connectionID);
3252 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3254 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Step error code:"),DLT_INT(eCode));
3255 return E_DATABASE_ERROR;
3258 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3260 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:"),DLT_INT(eCode));
3261 return E_DATABASE_ERROR;
3266 am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3268 assert (mainConnectionID!=0);
3269 sqlite3_stmt* query=NULL;
3270 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" ;
3272 am_timeSync_t delay=0;
3273 am_timeSync_t min=0;
3274 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3275 if((eCode=sqlite3_step(query))==SQLITE_ROW)
3277 delay=sqlite3_column_int(query,0);
3278 min=sqlite3_column_int(query,1);
3280 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3282 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:"),DLT_INT(eCode));
3283 return E_DATABASE_ERROR;
3286 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3288 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:"),DLT_INT(eCode));
3289 return E_DATABASE_ERROR;
3291 if (min<0) delay=-1;
3296 void DatabaseHandler::registerObserver(DatabaseObserver *iObserver)
3298 assert(iObserver!=NULL);
3299 mDatabaseObserver=iObserver;
3302 bool DatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3304 assert(sourceID!=0);
3305 sqlite3_stmt* query=NULL;
3306 std::string command = "SELECT visible FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3308 bool returnVal=false;
3309 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3310 if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3312 returnVal=(bool)sqlite3_column_int(query,0);
3314 else if (eCode!=SQLITE_ROW)
3317 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sourceVisible database error!:"), DLT_INT(eCode))
3319 sqlite3_finalize(query);
3323 bool DatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3325 sqlite3_stmt* query=NULL;
3326 std::string command = "SELECT visible FROM "+ std::string(SINK_TABLE) +" WHERE reserved=0 AND sinkID="+ i2s(sinkID);
3328 bool returnVal=false;
3329 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3330 if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3332 returnVal=sqlite3_column_int(query,0);
3334 else if (eCode!=SQLITE_ROW)
3337 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sinkVisible database error!:"), DLT_INT(eCode))
3339 sqlite3_finalize(query);
3343 bool DatabaseHandler::existConnection(const am_Connection_s connection)
3345 sqlite3_stmt* query=NULL;
3346 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3348 bool returnVal=true;
3349 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3350 sqlite3_bind_int(query,1, connection.sinkID);
3351 sqlite3_bind_int(query,2, connection.sourceID);
3352 sqlite3_bind_int(query,3, connection.connectionFormat);
3353 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3354 else if (eCode!=SQLITE_ROW)
3357 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3359 sqlite3_finalize(query);
3364 bool DatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3366 sqlite3_stmt* query=NULL;
3367 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3369 bool returnVal=true;
3370 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3371 sqlite3_bind_int(query,1, connectionID);
3372 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3373 else if (eCode!=SQLITE_ROW)
3376 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3378 sqlite3_finalize(query);
3382 bool DatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3384 sqlite3_stmt* query=NULL;
3385 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3387 bool returnVal=true;
3388 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3389 sqlite3_bind_int(query,1, crossfaderID);
3390 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3391 else if (eCode!=SQLITE_ROW)
3394 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3396 sqlite3_finalize(query);
3400 am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3402 assert(sourceID!=0);
3403 sqlite3_stmt* query=NULL;
3405 std::string command = "SELECT sourceState FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3407 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3408 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3410 sourceState=(am_SourceState_e)sqlite3_column_int(query,0);
3412 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3414 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSoureState database error!:"), DLT_INT(eCode))
3417 sqlite3_finalize(query);
3421 am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3423 assert(sourceID!=0);
3424 sqlite3_stmt* query=NULL;
3425 std::string command = "UPDATE " + std::string(SOURCE_TABLE) +" SET sourceState=? WHERE sourceID="+ i2s(sourceID);
3427 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3428 sqlite3_bind_int(query,1,sourceState);
3429 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3431 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Step error code:"),DLT_INT(eCode));
3432 return E_DATABASE_ERROR;
3435 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3437 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Finalize error code:"),DLT_INT(eCode));
3438 return E_DATABASE_ERROR;
3443 am_Error_e DatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3446 sqlite3_stmt* query=NULL;
3448 std::string command = "SELECT volume FROM "+ std::string(SINK_TABLE) +" WHERE sinkID="+ i2s(sinkID);
3450 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3451 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3453 volume=sqlite3_column_int(query,0);
3455 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3457 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkVolume database error!:"), DLT_INT(eCode))
3460 sqlite3_finalize(query);
3464 am_Error_e DatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
3466 assert(sourceID!=0);
3467 sqlite3_stmt* query=NULL;
3469 std::string command = "SELECT volume FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3471 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3472 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3474 volume=sqlite3_column_int(query,0);
3476 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3478 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceVolume database error!:"), DLT_INT(eCode))
3480 sqlite3_finalize(query);
3485 am_Error_e DatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3488 if (!existSink(sinkID)) return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3490 sqlite3_stmt* query=NULL;
3492 std::string command= "SELECT value FROM SinkSoundProperty" + i2s(sinkID) +" WHERE soundPropertyType=" +i2s(propertyType);
3493 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3495 while((eCode=sqlite3_step(query))==SQLITE_ROW)
3497 value=sqlite3_column_int(query,0);
3500 if(eCode!=SQLITE_DONE)
3502 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"),DLT_INT(eCode));
3503 return E_DATABASE_ERROR;
3506 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3508 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"),DLT_INT(eCode));
3509 return E_DATABASE_ERROR;
3515 am_Error_e DatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3517 assert(sourceID!=0);
3518 if (!existSource(sourceID)) return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3520 sqlite3_stmt* query=NULL;
3522 std::string command= "SELECT value FROM SourceSoundProperty" + i2s(sourceID) +" WHERE soundPropertyType=" +i2s(propertyType);
3523 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3525 while((eCode=sqlite3_step(query))==SQLITE_ROW)
3527 value=sqlite3_column_int(query,0);
3530 if(eCode!=SQLITE_DONE)
3532 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"),DLT_INT(eCode));
3533 return E_DATABASE_ERROR;
3536 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3538 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"),DLT_INT(eCode));
3539 return E_DATABASE_ERROR;
3545 am_Error_e DatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
3547 assert(domainID!=0);
3548 sqlite3_stmt* query=NULL;
3550 std::string command = "SELECT domainState FROM "+ std::string(DOMAIN_TABLE) +" WHERE domainID="+ i2s(domainID);
3552 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3553 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3555 state=(am_DomainState_e)sqlite3_column_int(query,0);
3557 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3559 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainState database error!:"), DLT_INT(eCode))
3562 sqlite3_finalize(query);
3567 am_Error_e DatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
3569 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3570 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
3571 int eCode=0, eCode1=0;
3572 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3573 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3574 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3576 domainID=sqlite3_column_int(query,0);
3578 else if (eCode!=SQLITE_DONE)
3580 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain database error!:"), DLT_INT(eCode))
3581 return E_DATABASE_ERROR;
3585 command= "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
3586 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3587 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3588 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3589 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3591 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Step error code:"),DLT_INT(eCode1));
3592 return E_DATABASE_ERROR;
3595 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3597 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3598 return E_DATABASE_ERROR;
3600 domainID=sqlite3_last_insert_rowid(mDatabase);
3602 sqlite3_finalize(query);
3606 am_Error_e DatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
3608 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3609 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
3610 int eCode=0, eCode1=0;
3611 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3612 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3613 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3615 sinkID=sqlite3_column_int(query,0);
3617 else if (eCode!=SQLITE_DONE)
3619 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3620 return E_DATABASE_ERROR;
3624 if (mFirstStaticSink)
3626 command= "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3627 mFirstStaticSink=false;
3631 command= "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
3633 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3634 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3635 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3636 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3638 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"),DLT_INT(eCode1));
3639 return E_DATABASE_ERROR;
3642 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3644 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3645 return E_DATABASE_ERROR;
3647 sinkID=sqlite3_last_insert_rowid(mDatabase);
3649 sqlite3_finalize(query);
3655 am_Error_e DatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
3657 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3658 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
3659 int eCode=0, eCode1=0;
3660 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3661 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3662 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3664 sourceID=sqlite3_column_int(query,0);
3666 else if (eCode!=SQLITE_DONE)
3668 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3669 return E_DATABASE_ERROR;
3673 if (mFirstStaticSource)
3675 command= "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3676 mFirstStaticSource=false;
3680 command= "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
3682 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3683 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3684 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3685 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3687 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"),DLT_INT(eCode1));
3688 return E_DATABASE_ERROR;
3691 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3693 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3694 return E_DATABASE_ERROR;
3696 sourceID=sqlite3_last_insert_rowid(mDatabase);
3698 sqlite3_finalize(query);
3702 am_Error_e DatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
3706 sqlite3_stmt* query=NULL;
3708 std::string command;
3710 if (!existSink(sinkID))
3712 return E_NON_EXISTENT;
3714 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
3715 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3716 sqlite3_bind_int(query,1, volume);
3717 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3719 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Step error code:"),DLT_INT(eCode));
3720 return E_DATABASE_ERROR;
3722 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3724 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:"),DLT_INT(eCode));
3725 return E_DATABASE_ERROR;
3728 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkVolume changed volume of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(volume));
3733 am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
3735 assert(sourceID!=0);
3737 sqlite3_stmt* query=NULL;
3739 std::string command;
3741 if (!existSource(sourceID))
3743 return E_NON_EXISTENT;
3745 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
3746 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3747 sqlite3_bind_int(query,1, volume);
3748 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3750 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Step error code:"),DLT_INT(eCode));
3751 return E_DATABASE_ERROR;
3753 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3755 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:"),DLT_INT(eCode));
3756 return E_DATABASE_ERROR;
3759 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceVolume changed volume of source=:"),DLT_INT(sourceID),DLT_STRING("to:"),DLT_INT(volume));
3764 am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
3766 //todo: add checks if soundproperty exists!
3767 assert(sourceID!=0);
3769 sqlite3_stmt* query=NULL;
3771 std::string command;
3773 if (!existSource(sourceID))
3775 return E_NON_EXISTENT;
3777 command = "UPDATE SourceSoundProperty" + i2s(sourceID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3778 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3779 sqlite3_bind_int(query,1, soundProperty.value);
3780 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3782 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
3783 return E_DATABASE_ERROR;
3786 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3788 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
3789 return E_DATABASE_ERROR;
3792 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:"),DLT_INT(sourceID),DLT_STRING("type:"),DLT_INT(soundProperty.type),DLT_STRING("to:"),DLT_INT(soundProperty.value));
3797 am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
3799 //todo: add checks if soundproperty exists!
3802 sqlite3_stmt* query=NULL;
3804 std::string command;
3806 if (!existSink(sinkID))
3808 return E_NON_EXISTENT;
3810 command = "UPDATE SinkSoundProperty" + i2s(sinkID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3811 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3812 sqlite3_bind_int(query,1, soundProperty.value);
3813 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3815 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
3816 return E_DATABASE_ERROR;
3817 } assert(sinkID!=0);
3819 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3821 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
3822 return E_DATABASE_ERROR;
3825 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB changed MainSinkSoundProperty of sink:"),DLT_INT(sinkID),DLT_STRING("type:"),DLT_INT(soundProperty.type),DLT_STRING("to:"),DLT_INT(soundProperty.value));
3830 am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
3832 assert(crossfaderID!=0);
3834 sqlite3_stmt* query=NULL;
3836 std::string command;
3838 if (!existcrossFader(crossfaderID))
3840 return E_NON_EXISTENT;
3842 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
3843 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3844 sqlite3_bind_int(query,1, hotsink);
3845 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3847 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:"),DLT_INT(eCode));
3848 return E_DATABASE_ERROR;
3850 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3852 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:"),DLT_INT(eCode));
3853 return E_DATABASE_ERROR;
3856 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader="),DLT_INT(crossfaderID),DLT_STRING("to:"),DLT_INT(hotsink));
3861 am_Error_e am::DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree *tree, std::vector<RoutingTreeItem*> *flatTree)
3863 sqlite3_stmt* query=NULL;
3866 std::string command;
3867 am_domainID_t rootID = tree->returnRootDomainID();
3868 RoutingTreeItem *parent = tree->returnRootItem();
3870 command="SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE)+ " WHERE domainSinkID=? AND IsBlocked=?";
3872 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3874 sqlite3_bind_int(query,1, rootID);
3875 sqlite3_bind_int(query,2, onlyfree);
3876 while((eCode=sqlite3_step(query))==SQLITE_ROW)
3878 flatTree->push_back(tree->insertItem(sqlite3_column_int(query,0),sqlite3_column_int(query,1),parent));
3881 if(eCode!=SQLITE_DONE)
3883 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getRoutingTree SQLITE error code:"),DLT_INT(eCode));
3884 return (E_DATABASE_ERROR);
3886 parent = flatTree->at(i);
3887 rootID = parent->returnDomainID();
3889 } while (flatTree->size() > i);
3891 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3893 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getRoutingTree SQLITE Finalize error code:"),DLT_INT(eCode));
3894 return (E_DATABASE_ERROR);
3900 void DatabaseHandler::createTables()
3902 for(uint16_t i=0;i<sizeof(databaseTables)/sizeof(databaseTables[0]);i++)
3904 assert(sqQuery("CREATE TABLE " + databaseTables[i]));