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"
33 #define DOMAIN_TABLE "Domains"
34 #define SOURCE_CLASS_TABLE "SourceClasses"
35 #define SINK_CLASS_TABLE "SinkClasses"
36 #define SOURCE_TABLE "Sources"
37 #define SINK_TABLE "Sinks"
38 #define GATEWAY_TABLE "Gateways"
39 #define CROSSFADER_TABLE "Crossfaders"
40 #define CONNECTION_TABLE "Connections"
41 #define MAINCONNECTION_TABLE "MainConnections"
42 #define INTERRUPT_TABLE "Interrupts"
43 #define MAIN_TABLE "MainTable"
44 #define SYSTEM_TABLE "SystemProperties"
46 DLT_IMPORT_CONTEXT(AudioManager)
48 const std::string databaseTables[]={
49 " 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);",
50 " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));",
51 " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));",
52 " 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);",
53 " 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);",
54 " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER);",
55 " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);",
56 " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);",
57 " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);",
58 " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);"
62 * template to converts T to std::string
63 * @param i the value to be converted
67 inline std::string i2s(T const& x)
74 DatabaseHandler::DatabaseHandler(std::string databasePath)
77 mDatabaseObserver(NULL),
78 mFirstStaticSink(true),
79 mFirstStaticSource(true),
80 mFirstStaticGateway(true),
81 mFirstStaticSinkClass(true),
82 mFirstStaticSourceClass(true),
83 mListConnectionFormat()
87 *\todo: this erases the database. just for testing!
89 std::ifstream infile(mPath.c_str());
93 remove(mPath.c_str());
94 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::DatabaseHandler Knocked down database"));
97 bool dbOpen=openDatabase();
100 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::DatabaseHandler problems opening the database!"));
109 DatabaseHandler::~DatabaseHandler()
111 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("Closed Database"));
112 sqlite3_close(mDatabase);
115 am_Error_e DatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
117 assert(domainData.domainID==0);
118 assert(!domainData.name.empty());
119 assert(!domainData.busname.empty());
120 assert(domainData.state>=DS_CONTROLLED && domainData.state<=DS_INDEPENDENT_RUNDOWN);
122 //first check for a reserved domain
123 sqlite3_stmt* query=NULL, *queryFinal;
125 std::string command="SELECT domainID FROM "+ std::string(DOMAIN_TABLE) + " WHERE name=?";
126 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
127 sqlite3_bind_text(query,1, domainData.name.c_str(),domainData.name.size(),SQLITE_STATIC);
128 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
130 command= "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" +i2s(sqlite3_column_int(query,0));
132 else if (eCode==SQLITE_DONE)
135 command= "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)";
139 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Step error code:"),DLT_INT(eCode));
140 return E_DATABASE_ERROR;
143 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
145 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Finalize error code:"),DLT_INT(eCode));
146 return E_DATABASE_ERROR;
149 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
150 sqlite3_bind_text(queryFinal,1, domainData.name.c_str(),domainData.name.size(),SQLITE_STATIC);
151 sqlite3_bind_text(queryFinal,2, domainData.busname.c_str(),domainData.busname.size(),SQLITE_STATIC);
152 sqlite3_bind_text(queryFinal,3, domainData.nodename.c_str(),domainData.nodename.size(),SQLITE_STATIC);
153 sqlite3_bind_int(queryFinal,4, domainData.early);
154 sqlite3_bind_int(queryFinal,5, domainData.complete);
155 sqlite3_bind_int(queryFinal,6, domainData.state);
156 sqlite3_bind_int(queryFinal,7, 0);
158 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
160 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Step error code:"),DLT_INT(eCode));
161 return E_DATABASE_ERROR;
164 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
166 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Finalize error code:"),DLT_INT(eCode));
167 return E_DATABASE_ERROR;
170 domainID=sqlite3_last_insert_rowid(mDatabase);
171 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterDomainDB entered new domain with name"), DLT_STRING(domainData.name.c_str()),
172 DLT_STRING("busname:"),DLT_STRING(domainData.busname.c_str()),
173 DLT_STRING("nodename:"),DLT_STRING(domainData.nodename.c_str()),
174 DLT_STRING("early:"), DLT_BOOL(domainData.early),
175 DLT_STRING("complete:"),DLT_BOOL(domainData.complete),
176 DLT_STRING("state:"),DLT_INT(domainData.state),
177 DLT_STRING("assigned ID:"),DLT_INT16(domainID));
179 am_Domain_s domain=domainData;
180 domain.domainID=domainID;
181 if(mDatabaseObserver) mDatabaseObserver->newDomain(domain);
188 am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
190 assert(mainConnectionData.connectionID==0);
191 assert(mainConnectionData.connectionState>=CS_CONNECTING && mainConnectionData.connectionState<=CS_SUSPENDED);
192 assert(mainConnectionData.route.sinkID!=0);
193 assert(mainConnectionData.route.sourceID!=0);
195 sqlite3_stmt* query=NULL;
197 std::string command= "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)";
198 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
199 sqlite3_bind_int(query,1, mainConnectionData.route.sourceID);
200 sqlite3_bind_int(query,2, mainConnectionData.route.sinkID);
201 sqlite3_bind_int(query,3, mainConnectionData.connectionState);
203 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
205 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
206 return E_DATABASE_ERROR;
210 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
212 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
213 return E_DATABASE_ERROR;
216 connectionID=sqlite3_last_insert_rowid(mDatabase);
218 //now check the connectionTable for all connections in the route. IF a particular route is not found, we return with error
219 std::vector<uint16_t> listOfConnections;
221 command="SELECT connectionID, delay FROM "+std::string(CONNECTION_TABLE)+(" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
222 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
223 std::vector<am_RoutingElement_s>::const_iterator elementIterator=mainConnectionData.route.route.begin();
224 for (;elementIterator<mainConnectionData.route.route.end();++elementIterator)
226 sqlite3_bind_int(query,1, elementIterator->sourceID);
227 sqlite3_bind_int(query,2, elementIterator->sinkID);
228 sqlite3_bind_int(query,3, elementIterator->connectionFormat);
230 if((eCode=sqlite3_step(query))==SQLITE_ROW)
232 listOfConnections.push_back(sqlite3_column_int(query,0));
233 int16_t temp_delay=sqlite3_column_int(query,1);
234 if (temp_delay!=-1 && delay!=-1) delay+=temp_delay;
239 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:"),DLT_INT(eCode));
240 return E_DATABASE_ERROR;
242 sqlite3_reset(query);
245 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
247 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
248 return E_DATABASE_ERROR;
251 //now we create a table with references to the connections;
252 command="CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
253 assert(this->sqQuery(command));
255 command= "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
256 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
257 std::vector<uint16_t>::iterator listConnectionIterator=listOfConnections.begin();
258 for(;listConnectionIterator<listOfConnections.end();++listConnectionIterator)
260 sqlite3_bind_int(query,1, *listConnectionIterator);
261 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
263 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
264 return E_DATABASE_ERROR;
266 sqlite3_reset(query);
269 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
271 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
272 return E_DATABASE_ERROR;
275 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID"), DLT_INT(mainConnectionData.route.sourceID),
276 DLT_STRING("sinkID:"),DLT_INT16(mainConnectionData.route.sinkID),
277 DLT_STRING("delay:"),DLT_INT16(delay),
278 DLT_STRING("assigned ID:"),DLT_INT16(connectionID));
280 if (mDatabaseObserver)
282 mDatabaseObserver->numberOfMainConnectionsChanged();
283 mDatabaseObserver->mainConnectionStateChanged(connectionID,mainConnectionData.connectionState);
286 //finally, we update the delay value for the maintable
287 if (delay==0) delay=-1;
288 return changeDelayMainConnection(delay,connectionID);
293 am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
295 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
296 assert(sinkData.domainID!=0);
297 assert(!sinkData.name.empty());
298 assert(sinkData.sinkClassID!=0); // \todo: need to check if class exists?
299 assert(!sinkData.listConnectionFormats.empty());
300 assert(sinkData.muteState>=MS_MUTED && sinkData.muteState<=MS_UNMUTED);
302 sqlite3_stmt *query=NULL, *queryFinal=NULL;
304 std::string command="SELECT sinkID FROM "+ std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
306 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
307 sqlite3_bind_text(query,1, sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
309 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
311 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));
313 else if (eCode==SQLITE_DONE)
315 //if sinkID is zero and the first Static Sink was already entered, the ID is created
316 if (sinkData.sinkID==0 && !mFirstStaticSink && !existSinkName(sinkData.name))
318 command= "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
322 //check if the ID already exists
323 if(existSinkNameOrID(sinkData.sinkID,sinkData.name))
325 sqlite3_finalize(query);
326 return E_ALREADY_EXISTS;
328 command= "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
333 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
334 sqlite3_finalize(query);
335 return E_DATABASE_ERROR;
338 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
340 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"),DLT_INT(eCode));
341 return E_DATABASE_ERROR;
344 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
345 sqlite3_bind_text(queryFinal,1, sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
346 sqlite3_bind_int(queryFinal,2, sinkData.domainID);
347 sqlite3_bind_int(queryFinal,3, sinkData.sinkClassID);
348 sqlite3_bind_int(queryFinal,4, sinkData.volume);
349 sqlite3_bind_int(queryFinal,5, sinkData.visible);
350 sqlite3_bind_int(queryFinal,6, sinkData.available.availability);
351 sqlite3_bind_int(queryFinal,7, sinkData.available.availabilityReason);
352 sqlite3_bind_int(queryFinal,8, sinkData.muteState);
353 sqlite3_bind_int(queryFinal,9, sinkData.mainVolume);
354 sqlite3_bind_int(queryFinal,10, 0);
356 //if the ID is not created, we add it to the query
357 if(sinkData.sinkID!=0)
359 sqlite3_bind_int(queryFinal,11, sinkData.sinkID);
362 //if the first static sink is entered, we need to set it onto the boundary
363 else if(mFirstStaticSink)
365 sqlite3_bind_int(queryFinal,11, DYNAMIC_ID_BOUNDARY);
366 mFirstStaticSink=false;
369 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
371 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
372 sqlite3_finalize(queryFinal);
373 return E_DATABASE_ERROR;
376 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
378 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"),DLT_INT(eCode));
379 return E_DATABASE_ERROR;
382 //now read back the sinkID
383 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
384 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
385 sqlite3_bind_text(query,1,sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
386 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
388 sinkID=sqlite3_column_int(query,0);
393 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
394 sqlite3_finalize(query);
395 return E_DATABASE_ERROR;
397 sqlite3_finalize(query);
399 //now we need to create the additional tables:
400 command="CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
401 assert(this->sqQuery(command));
402 command="CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
403 assert(this->sqQuery(command));
404 command="CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
405 assert(this->sqQuery(command));
407 //fill ConnectionFormats
408 command="INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
409 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
410 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=sinkData.listConnectionFormats.begin();
411 for(;connectionFormatIterator<sinkData.listConnectionFormats.end();++connectionFormatIterator)
413 sqlite3_bind_int(query,1, *connectionFormatIterator);
414 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
416 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
417 sqlite3_finalize(query);
418 return E_DATABASE_ERROR;
420 sqlite3_reset(query);
423 //Fill MainSinkSoundProperties
424 command="INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
425 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
426 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator=sinkData.listMainSoundProperties.begin();
427 for(;mainSoundPropertyIterator<sinkData.listMainSoundProperties.end();++mainSoundPropertyIterator)
429 sqlite3_bind_int(query,1, mainSoundPropertyIterator->type);
430 sqlite3_bind_int(query,2, mainSoundPropertyIterator->value);
431 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
433 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
434 sqlite3_finalize(query);
435 return E_DATABASE_ERROR;
437 sqlite3_reset(query);
440 //Fill SinkSoundProperties
441 command="INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
442 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
443 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator=sinkData.listSoundProperties.begin();
444 for(;SoundPropertyIterator<sinkData.listSoundProperties.end();++SoundPropertyIterator)
446 sqlite3_bind_int(query,1, SoundPropertyIterator->type);
447 sqlite3_bind_int(query,2, SoundPropertyIterator->value);
448 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
450 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
451 sqlite3_finalize(query);
452 return E_DATABASE_ERROR;
454 sqlite3_reset(query);
457 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkDB entered new sink with name"), DLT_STRING(sinkData.name.c_str()),
458 DLT_STRING("domainID:"),DLT_INT(sinkData.domainID),
459 DLT_STRING("classID:"),DLT_INT(sinkData.sinkClassID),
460 DLT_STRING("volume:"),DLT_INT(sinkData.volume),
461 DLT_STRING("visible:"),DLT_BOOL(sinkData.visible),
462 DLT_STRING("available.availability:"),DLT_INT(sinkData.available.availability),
463 DLT_STRING("available.availabilityReason:"),DLT_INT(sinkData.available.availabilityReason),
464 DLT_STRING("muteState:"),DLT_INT(sinkData.muteState),
465 DLT_STRING("mainVolume:"),DLT_INT(sinkData.mainVolume),
466 DLT_STRING("assigned ID:"),DLT_INT16(sinkID));
468 am_Sink_s sink=sinkData;
470 if (mDatabaseObserver!=NULL) mDatabaseObserver->newSink(sink);
477 am_Error_e DatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
479 //todo: implement crossfader
480 (void)crossfaderData;
487 am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
489 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
490 assert(gatewayData.sinkID!=0);
491 assert(gatewayData.sourceID!=0);
492 assert(gatewayData.controlDomainID!=0);
493 assert(gatewayData.domainSinkID!=0);
494 assert(gatewayData.domainSourceID!=0);
495 assert(!gatewayData.name.empty());
496 assert(!gatewayData.convertionMatrix.empty());
497 assert(!gatewayData.listSinkFormats.empty());
498 assert(!gatewayData.listSourceFormats.empty());
500 sqlite3_stmt* query=NULL;
504 //if sinkID is zero and the first Static Sink was already entered, the ID is created
505 if (gatewayData.gatewayID==0 && !mFirstStaticGateway)
507 command= "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID) VALUES (?,?,?,?,?,?)";
511 //check if the ID already exists
512 if (existGateway(gatewayData.gatewayID)) return E_ALREADY_EXISTS;
513 command= "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID) VALUES (?,?,?,?,?,?,?)";
516 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
517 sqlite3_bind_text(query,1, gatewayData.name.c_str(),gatewayData.name.size(),SQLITE_STATIC);
518 sqlite3_bind_int(query,2, gatewayData.sinkID);
519 sqlite3_bind_int(query,3, gatewayData.sourceID);
520 sqlite3_bind_int(query,4, gatewayData.domainSinkID);
521 sqlite3_bind_int(query,5, gatewayData.domainSourceID);
522 sqlite3_bind_int(query,6, gatewayData.controlDomainID);
524 //if the ID is not created, we add it to the query
525 if(gatewayData.gatewayID!=0)
527 sqlite3_bind_int(query,7, gatewayData.gatewayID);
530 //if the first static sink is entered, we need to set it onto the boundary
531 else if(mFirstStaticGateway)
533 sqlite3_bind_int(query,7, DYNAMIC_ID_BOUNDARY);
534 mFirstStaticGateway=false;
537 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
539 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
540 return E_DATABASE_ERROR;
543 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
545 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Finalize error code:"),DLT_INT(eCode));
546 return E_DATABASE_ERROR;
549 gatewayID=sqlite3_last_insert_rowid(mDatabase);
551 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
552 mListConnectionFormat.insert(std::make_pair(gatewayID,gatewayData.convertionMatrix));
554 command="CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
555 assert(this->sqQuery(command));
556 command="CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
557 assert(this->sqQuery(command));
559 //fill ConnectionFormats
560 command="INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
561 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
562 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=gatewayData.listSourceFormats.begin();
563 for(;connectionFormatIterator<gatewayData.listSourceFormats.end();++connectionFormatIterator)
565 sqlite3_bind_int(query,1, *connectionFormatIterator);
566 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
568 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
569 return E_DATABASE_ERROR;
571 sqlite3_reset(query);
574 command="INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
575 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
576 connectionFormatIterator=gatewayData.listSinkFormats.begin();
577 for(;connectionFormatIterator<gatewayData.listSinkFormats.end();++connectionFormatIterator)
579 sqlite3_bind_int(query,1, *connectionFormatIterator);
580 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
582 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
583 return E_DATABASE_ERROR;
585 sqlite3_reset(query);
589 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterGatewayDB entered new gateway with name"), DLT_STRING(gatewayData.name.c_str()),
590 DLT_STRING("sourceID:"),DLT_INT(gatewayData.sourceID),
591 DLT_STRING("sinkID:"),DLT_INT(gatewayData.sinkID),
592 DLT_STRING("domainSinkID:"),DLT_INT(gatewayData.domainSinkID),
593 DLT_STRING("domainSourceID:"),DLT_BOOL(gatewayData.domainSourceID),
594 DLT_STRING("controlDomainID:"),DLT_INT(gatewayData.controlDomainID),
595 DLT_STRING("assigned ID:"),DLT_INT16(gatewayID));
597 am_Gateway_s gateway=gatewayData;
598 gateway.gatewayID=gatewayID;
599 if(mDatabaseObserver) mDatabaseObserver->newGateway(gateway);
605 am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
607 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
608 assert(sourceData.domainID!=0);
609 assert(!sourceData.name.empty());
610 assert(sourceData.sourceClassID!=0); // \todo: need to check if class exists?
611 assert(!sourceData.listConnectionFormats.empty());
612 assert(sourceData.sourceState>=SS_ON && sourceData.sourceState<=SS_PAUSED);
614 sqlite3_stmt* query=NULL, *queryFinal=NULL;;
616 std::string command="SELECT sourceID FROM "+ std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
618 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
619 sqlite3_bind_text(query,1, sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
621 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
623 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));
625 else if (eCode==SQLITE_DONE)
627 //if sinkID is zero and the first Static Sink was already entered, the ID is created
628 if (sourceData.sourceID==0 && !mFirstStaticSource && !existSourceName(sourceData.name))
630 command= "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
634 //check if the ID already exists
635 if (existSourceNameOrID(sourceData.sourceID,sourceData.name))
637 sqlite3_finalize(query);
638 return E_ALREADY_EXISTS;
640 command= "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
645 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
646 sqlite3_finalize(query);
647 return E_DATABASE_ERROR;
650 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
652 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"),DLT_INT(eCode));
653 return E_DATABASE_ERROR;
655 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
656 sqlite3_bind_text(queryFinal,1, sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
657 sqlite3_bind_int(queryFinal,2, sourceData.domainID);
658 sqlite3_bind_int(queryFinal,3, sourceData.sourceClassID);
659 sqlite3_bind_int(queryFinal,4, sourceData.sourceState);
660 sqlite3_bind_int(queryFinal,5, sourceData.volume);
661 sqlite3_bind_int(queryFinal,6, sourceData.visible);
662 sqlite3_bind_int(queryFinal,7, sourceData.available.availability);
663 sqlite3_bind_int(queryFinal,8, sourceData.available.availabilityReason);
664 sqlite3_bind_int(queryFinal,9, sourceData.interruptState);
665 sqlite3_bind_int(queryFinal,10, 0);
667 //if the ID is not created, we add it to the query
668 if(sourceData.sourceID!=0)
670 sqlite3_bind_int(queryFinal,11, sourceData.sourceID);
673 //if the first static sink is entered, we need to set it onto the boundary
674 else if(mFirstStaticSource)
676 sqlite3_bind_int(queryFinal,11, DYNAMIC_ID_BOUNDARY);
677 mFirstStaticSource=false;
680 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
682 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
683 sqlite3_finalize(queryFinal);
684 return E_DATABASE_ERROR;
687 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
689 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"),DLT_INT(eCode));
690 sqlite3_finalize(queryFinal);
691 return E_DATABASE_ERROR;
694 //now read back the sinkID
695 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
696 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
697 sqlite3_bind_text(query,1,sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
698 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
700 sourceID=sqlite3_column_int(query,0);
705 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
706 sqlite3_finalize(query);
707 return E_DATABASE_ERROR;
709 sqlite3_finalize(query);
712 //now we need to create the additional tables:
713 command="CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
714 assert(this->sqQuery(command));
715 command="CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
716 assert(this->sqQuery(command));
717 command="CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
718 assert(this->sqQuery(command));
720 //fill ConnectionFormats
721 command="INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
722 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
723 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=sourceData.listConnectionFormats.begin();
724 for(;connectionFormatIterator<sourceData.listConnectionFormats.end();++connectionFormatIterator)
726 sqlite3_bind_int(query,1, *connectionFormatIterator);
727 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
729 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
730 sqlite3_finalize(query);
731 return E_DATABASE_ERROR;
733 sqlite3_reset(query);
736 //Fill MainSinkSoundProperties
737 command="INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
738 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
739 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator=sourceData.listMainSoundProperties.begin();
740 for(;mainSoundPropertyIterator<sourceData.listMainSoundProperties.end();++mainSoundPropertyIterator)
742 sqlite3_bind_int(query,1, mainSoundPropertyIterator->type);
743 sqlite3_bind_int(query,2, mainSoundPropertyIterator->value);
744 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
746 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
747 sqlite3_finalize(query);
748 return E_DATABASE_ERROR;
750 sqlite3_reset(query);
753 //Fill SinkSoundProperties
754 command="INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
755 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
756 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator=sourceData.listSoundProperties.begin();
757 for(;SoundPropertyIterator<sourceData.listSoundProperties.end();++SoundPropertyIterator)
759 sqlite3_bind_int(query,1, SoundPropertyIterator->type);
760 sqlite3_bind_int(query,2, SoundPropertyIterator->value);
761 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
763 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
764 sqlite3_finalize(query);
765 return E_DATABASE_ERROR;
767 sqlite3_reset(query);
770 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkDB entered new source with name"), DLT_STRING(sourceData.name.c_str()),
771 DLT_STRING("domainID:"),DLT_INT(sourceData.domainID),
772 DLT_STRING("classID:"),DLT_INT(sourceData.sourceClassID),
773 DLT_STRING("volume:"),DLT_INT(sourceData.volume),
774 DLT_STRING("visible:"),DLT_BOOL(sourceData.visible),
775 DLT_STRING("available.availability:"),DLT_INT(sourceData.available.availability),
776 DLT_STRING("available.availabilityReason:"),DLT_INT(sourceData.available.availabilityReason),
777 DLT_STRING("interruptState:"),DLT_INT(sourceData.interruptState),
778 DLT_STRING("assigned ID:"),DLT_INT16(sourceID));
780 am_Source_s source=sourceData;
781 source.sourceID=sourceID;
782 if(mDatabaseObserver) mDatabaseObserver->newSource(source);
788 am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
790 assert(mainconnectionID!=0);
791 if(!existMainConnection(mainconnectionID))
793 return E_NON_EXISTENT;
795 sqlite3_stmt* query=NULL;
799 std::vector<uint16_t> listOfConnections;
801 command="SELECT connectionID, delay FROM "+std::string(CONNECTION_TABLE)+(" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
802 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
803 std::vector<am_RoutingElement_s>::const_iterator elementIterator=route.route.begin();
804 for (;elementIterator<route.route.end();++elementIterator)
806 sqlite3_bind_int(query,1, elementIterator->sourceID);
807 sqlite3_bind_int(query,2, elementIterator->sinkID);
808 sqlite3_bind_int(query,3, elementIterator->connectionFormat);
810 if((eCode=sqlite3_step(query))==SQLITE_ROW)
812 listOfConnections.push_back(sqlite3_column_int(query,0));
813 int16_t temp_delay=sqlite3_column_int(query,1);
814 if (temp_delay!=-1 && delay!=-1) delay+=temp_delay;
819 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:"),DLT_INT(eCode));
820 return E_DATABASE_ERROR;
822 sqlite3_reset(query);
825 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
827 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"),DLT_INT(eCode));
828 return E_DATABASE_ERROR;
831 //now we delete the data in the table
832 command="DELETE from MainConnectionRoute" + i2s(mainconnectionID);
833 assert(this->sqQuery(command));
835 command= "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
836 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
837 std::vector<uint16_t>::iterator listConnectionIterator=listOfConnections.begin();
838 for(;listConnectionIterator<listOfConnections.end();++listConnectionIterator)
840 sqlite3_bind_int(query,1, *listConnectionIterator);
841 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
843 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:"),DLT_INT(eCode));
844 return E_DATABASE_ERROR;
846 sqlite3_reset(query);
849 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
851 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"),DLT_INT(eCode));
852 return E_DATABASE_ERROR;
854 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB entered new route:"),DLT_INT(mainconnectionID));
858 am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
860 assert(mainconnectionID!=0);
862 sqlite3_stmt* query=NULL;
866 if (!existMainConnection(mainconnectionID))
868 return E_NON_EXISTENT;
870 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
871 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
872 sqlite3_bind_int(query,1, connectionState);
873 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
875 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:"),DLT_INT(eCode));
876 return E_DATABASE_ERROR;
878 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
880 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
881 return E_DATABASE_ERROR;
883 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:"),DLT_INT(mainconnectionID),DLT_STRING("to:"),DLT_INT(connectionState));
885 if (mDatabaseObserver) mDatabaseObserver->mainConnectionStateChanged(mainconnectionID,connectionState);
891 am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
895 sqlite3_stmt* query=NULL;
899 if (!existSink(sinkID))
901 return E_NON_EXISTENT;
903 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
904 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
905 sqlite3_bind_int(query,1, mainVolume);
906 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
908 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:"),DLT_INT(eCode));
909 return E_DATABASE_ERROR;
911 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
913 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:"),DLT_INT(eCode));
914 return E_DATABASE_ERROR;
917 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(mainVolume));
919 if(mDatabaseObserver) mDatabaseObserver->volumeChanged(sinkID,mainVolume);
926 am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
930 sqlite3_stmt* query=NULL;
934 if (!existSink(sinkID))
936 return E_NON_EXISTENT;
938 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
939 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
940 sqlite3_bind_int(query,1, availability.availability);
941 sqlite3_bind_int(query,2, availability.availabilityReason);
942 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
944 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:"),DLT_INT(eCode));
945 return E_DATABASE_ERROR;
948 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
950 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:"),DLT_INT(eCode));
951 return E_DATABASE_ERROR;
954 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));
956 if (mDatabaseObserver && sourceVisible(sinkID)) mDatabaseObserver->sinkAvailabilityChanged(sinkID,availability);
962 am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
966 sqlite3_stmt* query=NULL;
970 if (!existDomain(domainID))
972 return E_NON_EXISTENT;
974 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
975 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
976 sqlite3_bind_int(query,1, domainState);
977 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
979 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Step error code:"),DLT_INT(eCode));
980 return E_DATABASE_ERROR;
983 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
985 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
986 return E_DATABASE_ERROR;
989 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changDomainStateDB changed domainState of domain:"),DLT_INT(domainID),DLT_STRING("to:"),DLT_INT(domainState));
995 am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
999 sqlite3_stmt* query=NULL;
1001 std::string command;
1003 if (!existSink(sinkID))
1005 return E_NON_EXISTENT;
1007 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
1008 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1009 sqlite3_bind_int(query,1, muteState);
1010 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1012 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:"),DLT_INT(eCode));
1013 return E_DATABASE_ERROR;
1014 } assert(sinkID!=0);
1016 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1018 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
1019 return E_DATABASE_ERROR;
1022 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(muteState));
1024 if(mDatabaseObserver) mDatabaseObserver->sinkMuteStateChanged(sinkID,muteState);
1031 am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
1033 //todo: add checks if soundproperty exists!
1036 sqlite3_stmt* query=NULL;
1038 std::string command;
1040 if (!existSink(sinkID))
1042 return E_NON_EXISTENT;
1044 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1045 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1046 sqlite3_bind_int(query,1, soundProperty.value);
1047 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1049 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1050 return E_DATABASE_ERROR;
1051 } assert(sinkID!=0);
1053 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1055 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1056 return E_DATABASE_ERROR;
1059 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));
1060 if (mDatabaseObserver) mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID,soundProperty);
1066 am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1068 //todo: add checks if soundproperty exists!
1069 assert(sourceID!=0);
1071 sqlite3_stmt* query=NULL;
1073 std::string command;
1075 if (!existSource(sourceID))
1077 return E_NON_EXISTENT;
1079 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1080 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1081 sqlite3_bind_int(query,1, soundProperty.value);
1082 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1084 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1085 return E_DATABASE_ERROR;
1088 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1090 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1091 return E_DATABASE_ERROR;
1094 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));
1096 if(mDatabaseObserver) mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID,soundProperty);
1102 am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1104 assert(sourceID!=0);
1106 sqlite3_stmt* query=NULL;
1108 std::string command;
1110 if (!existSource(sourceID))
1112 return E_NON_EXISTENT;
1114 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1115 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1116 sqlite3_bind_int(query,1, availability.availability);
1117 sqlite3_bind_int(query,2, availability.availabilityReason);
1118 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1120 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:"),DLT_INT(eCode));
1121 return E_DATABASE_ERROR;
1124 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1126 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:"),DLT_INT(eCode));
1127 return E_DATABASE_ERROR;
1130 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));
1132 if (mDatabaseObserver && sourceVisible(sourceID)) mDatabaseObserver->sourceAvailabilityChanged(sourceID,availability);
1138 am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1140 sqlite3_stmt* query=NULL;
1142 std::string command="UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1144 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1145 sqlite3_bind_int(query,1, property.value);
1146 sqlite3_bind_int(query,2, property.type);
1148 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1150 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1151 return E_DATABASE_ERROR;
1155 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1157 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1158 return E_DATABASE_ERROR;
1161 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSystemPropertyDB changed system property"));
1163 if(mDatabaseObserver) mDatabaseObserver->systemPropertyChanged(property);
1170 am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1172 assert(mainConnectionID!=0);
1174 if (!existMainConnection(mainConnectionID))
1176 return E_NON_EXISTENT;
1178 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1179 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1180 if(!sqQuery(command)) return E_DATABASE_ERROR;
1181 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1182 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeMainConnectionDB removed:"),DLT_INT(mainConnectionID));
1183 if (mDatabaseObserver) {
1184 mDatabaseObserver->mainConnectionStateChanged(mainConnectionID,CS_DISCONNECTED);
1185 mDatabaseObserver->numberOfMainConnectionsChanged();
1192 am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1196 if (!existSink(sinkID))
1198 return E_NON_EXISTENT;
1200 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1201 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1202 std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1203 std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID);
1204 if(!sqQuery(command)) return E_DATABASE_ERROR;
1205 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1206 if(!sqQuery(command2)) return E_DATABASE_ERROR;
1207 if(!sqQuery(command3)) return E_DATABASE_ERROR;
1208 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkDB removed:"),DLT_INT(sinkID));
1210 if (mDatabaseObserver!=NULL) mDatabaseObserver->removedSink(sinkID);
1217 am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1219 assert(sourceID!=0);
1221 if (!existSource(sourceID))
1223 return E_NON_EXISTENT;
1225 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1226 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1227 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1228 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1229 if(!sqQuery(command)) return E_DATABASE_ERROR;
1230 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1231 if(!sqQuery(command2)) return E_DATABASE_ERROR;
1232 if(!sqQuery(command3)) return E_DATABASE_ERROR;
1233 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceDB removed:"),DLT_INT(sourceID));
1234 if(mDatabaseObserver) mDatabaseObserver->removedSource(sourceID);
1240 am_Error_e DatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1242 assert(gatewayID!=0);
1244 if (!existGateway(gatewayID))
1246 return E_NON_EXISTENT;
1248 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1249 if(!sqQuery(command)) return E_DATABASE_ERROR;
1250 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeGatewayDB removed:"),DLT_INT(gatewayID));
1251 if(mDatabaseObserver) mDatabaseObserver->removeGateway(gatewayID);
1257 am_Error_e DatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1259 //todo: implement crossdfader
1266 am_Error_e DatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1268 assert(domainID!=0);
1270 if (!existDomain(domainID))
1272 return E_NON_EXISTENT;
1274 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1275 if(!sqQuery(command)) return E_DATABASE_ERROR;
1276 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeDomainDB removed:"),DLT_INT(domainID));
1277 if(mDatabaseObserver) mDatabaseObserver->removeDomain(domainID);
1281 am_Error_e DatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1283 assert(sinkClassID!=0);
1285 if (!existSinkClass(sinkClassID))
1287 return E_NON_EXISTENT;
1289 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1290 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1291 if(!sqQuery(command)) return E_DATABASE_ERROR;
1292 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1294 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkClassDB removed:"),DLT_INT(sinkClassID));
1295 if (mDatabaseObserver) mDatabaseObserver->numberOfSinkClassesChanged();
1300 am_Error_e DatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1302 assert(sourceClassID!=0);
1304 if (!existSourceClass(sourceClassID))
1306 return E_NON_EXISTENT;
1308 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1309 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1310 if(!sqQuery(command)) return E_DATABASE_ERROR;
1311 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1312 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceClassDB removed:"),DLT_INT(sourceClassID));
1314 if (mDatabaseObserver) mDatabaseObserver->numberOfSourceClassesChanged();
1318 am_Error_e DatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1320 assert(connectionID!=0);
1322 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1323 std::string command1 = "DROP table SourceClassProperties" + i2s(connectionID);
1324 if(!sqQuery(command)) return E_DATABASE_ERROR;
1325 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1326 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeConnection removed:"),DLT_INT(connectionID));
1332 am_Error_e DatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1334 assert(sourceID!=0);
1336 if (!existSource(sourceID))
1338 return E_NON_EXISTENT;
1340 sqlite3_stmt* query=NULL;
1342 am_ClassProperty_s propertyTemp;
1343 std::string command= "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE)+ " WHERE sourceID=" + (i2s(sourceID));
1344 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1346 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1348 classInfo.sourceClassID=sqlite3_column_int(query,0);
1351 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1353 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1354 return E_DATABASE_ERROR;
1357 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1359 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1360 return E_DATABASE_ERROR;
1363 command= "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE)+ " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1364 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1366 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1368 classInfo.name=std::string((const char*)sqlite3_column_text(query,0));
1371 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1373 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1374 return E_DATABASE_ERROR;
1377 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1379 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1380 return E_DATABASE_ERROR;
1383 //read out Properties
1384 command= "SELECT classProperty, value FROM SourceClassProperties"+ i2s(classInfo.sourceClassID);
1385 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1386 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1388 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(query,0);
1389 propertyTemp.value=sqlite3_column_int(query,1);
1390 classInfo.listClassProperties.push_back(propertyTemp);
1393 if(eCode!=SQLITE_DONE)
1395 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1396 return E_DATABASE_ERROR;
1399 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1401 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1402 return E_DATABASE_ERROR;
1409 am_Error_e DatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1411 assert(sinkClass.sinkClassID!=0);
1412 assert(!sinkClass.listClassProperties.empty());
1415 sqlite3_stmt* query=NULL;
1418 //check if the ID already exists
1419 if(!existSinkClass(sinkClass.sinkClassID)) return E_NON_EXISTENT;
1421 //fill ConnectionFormats
1422 std::string command="UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1423 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1424 std::vector<am_ClassProperty_s>::const_iterator Iterator=sinkClass.listClassProperties.begin();
1425 for(;Iterator<sinkClass.listClassProperties.end();++Iterator)
1427 sqlite3_bind_int(query,1, Iterator->value);
1428 sqlite3_bind_int(query,2, Iterator->classProperty);
1429 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1431 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"),DLT_INT(eCode));
1432 return E_DATABASE_ERROR;
1434 sqlite3_reset(query);
1437 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1439 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1440 return E_DATABASE_ERROR;
1443 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1449 am_Error_e DatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1451 assert(sourceClass.sourceClassID!=0);
1452 assert(!sourceClass.listClassProperties.empty());
1455 sqlite3_stmt* query=NULL;
1458 //check if the ID already exists
1459 if(!existSourceClass(sourceClass.sourceClassID)) return E_NON_EXISTENT;
1461 //fill ConnectionFormats
1462 std::string command="UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1463 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1464 std::vector<am_ClassProperty_s>::const_iterator Iterator=sourceClass.listClassProperties.begin();
1465 for(;Iterator<sourceClass.listClassProperties.end();++Iterator)
1467 sqlite3_bind_int(query,1, Iterator->value);
1468 sqlite3_bind_int(query,2, Iterator->classProperty);
1469 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1471 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"),DLT_INT(eCode));
1472 return E_DATABASE_ERROR;
1474 sqlite3_reset(query);
1477 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1479 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1480 return E_DATABASE_ERROR;
1483 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1489 am_Error_e DatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1493 if (!existSink(sinkID))
1495 return E_NON_EXISTENT;
1497 sqlite3_stmt* query=NULL;
1499 am_ClassProperty_s propertyTemp;
1500 std::string command= "SELECT sinkClassID FROM " + std::string(SINK_TABLE)+ " WHERE sinkID=" + (i2s(sinkID));
1501 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1503 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1505 sinkClass.sinkClassID=sqlite3_column_int(query,0);
1508 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1510 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1511 return E_DATABASE_ERROR;
1514 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1516 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1517 return E_DATABASE_ERROR;
1520 command= "SELECT name FROM " + std::string(SINK_CLASS_TABLE)+ " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1521 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1523 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1525 sinkClass.name=std::string((const char*)sqlite3_column_text(query,0));
1528 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1530 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1531 return E_DATABASE_ERROR;
1534 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1536 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1537 return E_DATABASE_ERROR;
1540 //read out Properties
1541 command= "SELECT classProperty, value FROM SinkClassProperties"+ i2s(sinkClass.sinkClassID);
1542 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1543 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1545 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(query,0);
1546 propertyTemp.value=sqlite3_column_int(query,1);
1547 sinkClass.listClassProperties.push_back(propertyTemp);
1550 if(eCode!=SQLITE_DONE)
1552 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1553 return E_DATABASE_ERROR;
1556 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1558 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1559 return E_DATABASE_ERROR;
1566 am_Error_e DatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1568 assert(gatewayID!=0);
1569 if (!existGateway(gatewayID))
1571 return E_NON_EXISTENT;
1573 sqlite3_stmt* query=NULL, *qSinkConnectionFormat=NULL, *qSourceConnectionFormat=NULL;
1575 am_ConnectionFormat_e tempConnectionFormat;
1576 std::string command= "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID="+i2s(gatewayID);
1577 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1579 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1581 gatewayData.name=std::string((const char*)sqlite3_column_text(query,0));
1582 gatewayData.sinkID=sqlite3_column_int(query,1);
1583 gatewayData.sourceID=sqlite3_column_int(query,2);
1584 gatewayData.domainSinkID=sqlite3_column_int(query,3);
1585 gatewayData.domainSourceID=sqlite3_column_int(query,4);
1586 gatewayData.controlDomainID=sqlite3_column_int(query,5);
1587 gatewayData.gatewayID=sqlite3_column_int(query,6);
1590 ListConnectionFormat::const_iterator iter=mListConnectionFormat.begin();
1591 iter=mListConnectionFormat.find(gatewayData.gatewayID);
1592 if (iter == mListConnectionFormat.end())
1594 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB database error with convertionFormat"));
1595 return E_DATABASE_ERROR;
1597 gatewayData.convertionMatrix=iter->second;
1599 //read out the connectionFormats
1600 std::string commandConnectionFormat= "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
1601 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSourceConnectionFormat,NULL);
1602 while((eCode=sqlite3_step(qSourceConnectionFormat))==SQLITE_ROW)
1604 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSourceConnectionFormat,0);
1605 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
1608 if((eCode=sqlite3_finalize(qSourceConnectionFormat))!=SQLITE_OK)
1610 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1611 return E_DATABASE_ERROR;
1614 //read out sound properties
1615 commandConnectionFormat= "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
1616 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSinkConnectionFormat,NULL);
1617 while((eCode=sqlite3_step(qSinkConnectionFormat))==SQLITE_ROW)
1619 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSinkConnectionFormat,0);
1620 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
1623 if((eCode=sqlite3_finalize(qSinkConnectionFormat))!=SQLITE_OK)
1625 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1626 return E_DATABASE_ERROR;
1631 if(eCode!=SQLITE_DONE)
1633 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE error code:"),DLT_INT(eCode));
1634 return E_DATABASE_ERROR;
1637 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1639 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1640 return E_DATABASE_ERROR;
1649 am_Error_e DatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
1651 //todo: implement crossfader
1653 (void)crossfaderData;
1659 am_Error_e DatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
1661 assert(domainID!=0);
1663 if (!existDomain(domainID))
1665 return E_NON_EXISTENT;
1667 sqlite3_stmt* query=NULL;
1670 std::string command= "SELECT sinkID FROM " + std::string(SINK_TABLE)+ " WHERE reserved=0 AND domainID=" + (i2s(domainID));
1671 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1673 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1675 temp=sqlite3_column_int(query,0);
1676 listSinkID.push_back(temp);
1679 if(eCode!=SQLITE_DONE)
1681 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE error code:"),DLT_INT(eCode));
1682 return E_DATABASE_ERROR;
1685 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1687 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1688 return E_DATABASE_ERROR;
1696 am_Error_e DatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
1698 assert(domainID!=0);
1699 listSourceID.clear();
1700 if (!existDomain(domainID))
1702 return E_NON_EXISTENT;
1704 sqlite3_stmt* query=NULL;
1707 std::string command= "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
1709 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1711 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1713 temp=sqlite3_column_int(query,0);
1714 listSourceID.push_back(temp);
1717 if(eCode!=SQLITE_DONE)
1719 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE error code:"),DLT_INT(eCode));
1720 return E_DATABASE_ERROR;
1723 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1725 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1726 return E_DATABASE_ERROR;
1734 am_Error_e DatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listGatewaysID) const
1736 //todo: implement crossfader
1737 (void)listGatewaysID;
1745 am_Error_e DatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
1747 assert(domainID!=0);
1748 listGatewaysID.clear();
1749 if (!existDomain(domainID))
1751 return E_NON_EXISTENT;
1753 sqlite3_stmt* query=NULL;
1755 am_gatewayID_t temp;
1757 std::string command= "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" +i2s(domainID);
1758 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1760 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1762 temp=sqlite3_column_int(query,0);
1763 listGatewaysID.push_back(temp);
1766 if(eCode!=SQLITE_DONE)
1768 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:"),DLT_INT(eCode));
1769 return E_DATABASE_ERROR;
1772 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1774 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1775 return E_DATABASE_ERROR;
1783 am_Error_e DatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
1785 listMainConnections.clear();
1786 sqlite3_stmt *query=NULL, *query1=NULL, *query2=NULL;
1787 int eCode=0, eCode1=0, eCode2=0;
1788 am_MainConnection_s temp;
1789 am_RoutingElement_s tempRoute;
1791 std::string command= "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
1792 std::string command1= "SELECT connectionID FROM MainConnectionRoute";
1793 std::string command2= "SELECT sourceID, sinkID, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=?";
1794 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1795 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&query2,NULL);
1797 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1799 temp.connectionID=sqlite3_column_int(query,0);
1800 temp.route.sourceID=sqlite3_column_int(query,1);
1801 temp.route.sinkID=sqlite3_column_int(query,2);
1802 temp.connectionState=(am_ConnectionState_e)sqlite3_column_int(query,3);
1803 temp.delay=sqlite3_column_int(query,4);
1804 std::string statement=command1 + i2s(temp.connectionID);
1805 sqlite3_prepare_v2(mDatabase,statement.c_str(),-1,&query1,NULL);
1806 while((eCode1=sqlite3_step(query1))==SQLITE_ROW) //todo: check results of eCode1, eCode2
1808 int k=sqlite3_column_int(query1,0);
1809 sqlite3_bind_int(query2,1,k);
1810 while((eCode2=sqlite3_step(query2))==SQLITE_ROW)
1812 tempRoute.sourceID=sqlite3_column_int(query2,0);
1813 tempRoute.sinkID=sqlite3_column_int(query2,1);
1814 tempRoute.connectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(query2,2);
1815 getDomainOfSource(tempRoute.sourceID,tempRoute.domainID);
1816 temp.route.route.push_back(tempRoute);
1818 sqlite3_reset(query2);
1820 listMainConnections.push_back(temp);
1823 if(eCode!=SQLITE_DONE)
1825 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE error code:"),DLT_INT(eCode));
1826 return E_DATABASE_ERROR;
1829 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1831 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE Finalize error code:"),DLT_INT(eCode));
1832 return E_DATABASE_ERROR;
1840 am_Error_e DatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
1842 listDomains.clear();
1843 sqlite3_stmt* query=NULL;
1846 std::string command= "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
1847 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1849 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1851 temp.domainID=sqlite3_column_int(query,0);
1852 temp.name=std::string((const char*)sqlite3_column_text(query,1));
1853 temp.busname=std::string((const char*)sqlite3_column_text(query,2));
1854 temp.nodename=std::string((const char*)sqlite3_column_text(query,3));
1855 temp.early=sqlite3_column_int(query,4);
1856 temp.complete=sqlite3_column_int(query,5);
1857 temp.state=(am_DomainState_e)sqlite3_column_int(query,6);
1858 listDomains.push_back(temp);
1861 if(eCode!=SQLITE_DONE)
1863 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE error code:"),DLT_INT(eCode));
1864 return E_DATABASE_ERROR;
1867 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1869 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE Finalize error code:"),DLT_INT(eCode));
1870 return E_DATABASE_ERROR;
1878 am_Error_e DatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
1880 listConnections.clear();
1881 sqlite3_stmt* query=NULL;
1883 am_Connection_s temp;
1884 std::string command= "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE)+" WHERE reserved=0";
1885 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1887 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1889 temp.connectionID=sqlite3_column_int(query,0);
1890 temp.sourceID=sqlite3_column_int(query,1);
1891 temp.sinkID=sqlite3_column_int(query,2);
1892 temp.delay=sqlite3_column_int(query,3);
1893 temp.connectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(query,4);
1894 listConnections.push_back(temp);
1897 if(eCode!=SQLITE_DONE)
1899 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE error code:"),DLT_INT(eCode));
1900 return E_DATABASE_ERROR;
1903 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1905 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE Finalize error code:"),DLT_INT(eCode));
1906 return E_DATABASE_ERROR;
1914 am_Error_e DatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
1917 sqlite3_stmt* query=NULL, *qConnectionFormat=NULL, *qSoundProperty=NULL, *qMAinSoundProperty=NULL;
1920 am_ConnectionFormat_e tempConnectionFormat;
1921 am_SoundProperty_s tempSoundProperty;
1922 am_MainSoundProperty_s tempMainSoundProperty;
1923 std::string command= "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE)+ " WHERE reserved=0";
1924 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1926 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1928 temp.name=std::string((const char*)sqlite3_column_text(query,0));
1929 temp.domainID=sqlite3_column_int(query,1);
1930 temp.sinkClassID=sqlite3_column_int(query,2);
1931 temp.volume=sqlite3_column_int(query,3);
1932 temp.visible=sqlite3_column_int(query,4);
1933 temp.available.availability=(am_Availablility_e)sqlite3_column_int(query,5);
1934 temp.available.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,6);
1935 temp.muteState=(am_MuteState_e)sqlite3_column_int(query,7);
1936 temp.mainVolume=sqlite3_column_int(query,8);
1937 temp.sinkID=sqlite3_column_int(query,9);
1939 //read out the connectionFormats
1940 std::string commandConnectionFormat= "SELECT soundFormat FROM SinkConnectionFormat"+ i2s(temp.sinkID);
1941 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qConnectionFormat,NULL);
1942 while((eCode=sqlite3_step(qConnectionFormat))==SQLITE_ROW)
1944 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qConnectionFormat,0);
1945 temp.listConnectionFormats.push_back(tempConnectionFormat);
1948 if((eCode=sqlite3_finalize(qConnectionFormat))!=SQLITE_OK)
1950 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1951 return E_DATABASE_ERROR;
1954 //read out sound properties
1955 std::string commandSoundProperty= "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
1956 sqlite3_prepare_v2(mDatabase,commandSoundProperty.c_str(),-1,&qSoundProperty,NULL);
1957 while((eCode=sqlite3_step(qSoundProperty))==SQLITE_ROW)
1959 tempSoundProperty.type=(am_SoundPropertyType_e)sqlite3_column_int(qSoundProperty,0);
1960 tempSoundProperty.value=sqlite3_column_int(qSoundProperty,1);
1961 temp.listSoundProperties.push_back(tempSoundProperty);
1964 if((eCode=sqlite3_finalize(qSoundProperty))!=SQLITE_OK)
1966 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1967 return E_DATABASE_ERROR;
1970 //read out MainSoundProperties
1971 std::string commandMainSoundProperty= "SELECT soundPropertyType, value FROM SinkMainSoundProperty"+ i2s(temp.sinkID);
1972 sqlite3_prepare_v2(mDatabase,commandMainSoundProperty.c_str(),-1,&qMAinSoundProperty,NULL);
1973 while((eCode=sqlite3_step(qMAinSoundProperty))==SQLITE_ROW)
1975 tempMainSoundProperty.type=(am_MainSoundPropertyType_e)sqlite3_column_int(qMAinSoundProperty,0);
1976 tempMainSoundProperty.value=sqlite3_column_int(qMAinSoundProperty,1);
1977 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
1980 if((eCode=sqlite3_finalize(qMAinSoundProperty))!=SQLITE_OK)
1982 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1983 return E_DATABASE_ERROR;
1985 listSinks.push_back(temp);
1986 temp.listConnectionFormats.clear();
1987 temp.listMainSoundProperties.clear();
1988 temp.listSoundProperties.clear();
1991 if(eCode!=SQLITE_DONE)
1993 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"),DLT_INT(eCode));
1994 return E_DATABASE_ERROR;
1997 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1999 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
2000 return E_DATABASE_ERROR;
2008 am_Error_e DatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
2010 listSources.clear();
2011 sqlite3_stmt* query=NULL, *qConnectionFormat=NULL, *qSoundProperty=NULL, *qMAinSoundProperty=NULL;
2014 am_ConnectionFormat_e tempConnectionFormat;
2015 am_SoundProperty_s tempSoundProperty;
2016 am_MainSoundProperty_s tempMainSoundProperty;
2017 std::string command= "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) +" WHERE reserved=0";
2018 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2020 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2022 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2023 temp.domainID=sqlite3_column_int(query,1);
2024 temp.sourceClassID=sqlite3_column_int(query,2);
2025 temp.sourceState=(am_SourceState_e)sqlite3_column_int(query,3);
2026 temp.volume=sqlite3_column_int(query,4);
2027 temp.visible=sqlite3_column_int(query,5);
2028 temp.available.availability=(am_Availablility_e)sqlite3_column_int(query,6);
2029 temp.available.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,7);
2030 temp.interruptState=(am_InterruptState_e)sqlite3_column_int(query,8);
2031 temp.sourceID=sqlite3_column_int(query,9);
2033 //read out the connectionFormats
2034 std::string commandConnectionFormat= "SELECT soundFormat FROM SourceConnectionFormat"+ i2s(temp.sourceID);
2035 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qConnectionFormat,NULL);
2036 while((eCode=sqlite3_step(qConnectionFormat))==SQLITE_ROW)
2038 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qConnectionFormat,0);
2039 temp.listConnectionFormats.push_back(tempConnectionFormat);
2042 if((eCode=sqlite3_finalize(qConnectionFormat))!=SQLITE_OK)
2044 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2045 return E_DATABASE_ERROR;
2048 //read out sound properties
2049 std::string commandSoundProperty= "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
2050 sqlite3_prepare_v2(mDatabase,commandSoundProperty.c_str(),-1,&qSoundProperty,NULL);
2051 while((eCode=sqlite3_step(qSoundProperty))==SQLITE_ROW)
2053 tempSoundProperty.type=(am_SoundPropertyType_e)sqlite3_column_int(qSoundProperty,0);
2054 tempSoundProperty.value=sqlite3_column_int(qSoundProperty,1);
2055 temp.listSoundProperties.push_back(tempSoundProperty);
2058 if((eCode=sqlite3_finalize(qSoundProperty))!=SQLITE_OK)
2060 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2061 return E_DATABASE_ERROR;
2064 //read out MainSoundProperties
2065 std::string commandMainSoundProperty= "SELECT soundPropertyType, value FROM SourceMainSoundProperty"+ i2s(temp.sourceID);
2066 sqlite3_prepare_v2(mDatabase,commandMainSoundProperty.c_str(),-1,&qMAinSoundProperty,NULL);
2067 while((eCode=sqlite3_step(qMAinSoundProperty))==SQLITE_ROW)
2069 tempMainSoundProperty.type=(am_MainSoundPropertyType_e)sqlite3_column_int(qMAinSoundProperty,0);
2070 tempMainSoundProperty.value=sqlite3_column_int(qMAinSoundProperty,1);
2071 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2074 if((eCode=sqlite3_finalize(qMAinSoundProperty))!=SQLITE_OK)
2076 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2077 return E_DATABASE_ERROR;
2079 listSources.push_back(temp);
2080 temp.listConnectionFormats.clear();
2081 temp.listMainSoundProperties.clear();
2082 temp.listSoundProperties.clear();
2085 if(eCode!=SQLITE_DONE)
2087 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"),DLT_INT(eCode));
2088 return E_DATABASE_ERROR;
2091 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2093 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2094 return E_DATABASE_ERROR;
2102 am_Error_e DatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
2104 listSourceClasses.clear();
2106 sqlite3_stmt* query=NULL, *subQuery=NULL;
2107 int eCode=0, eCode1;
2108 am_SourceClass_s classTemp;
2109 am_ClassProperty_s propertyTemp;
2111 std::string command= "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
2112 std::string command2;
2113 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2115 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2117 classTemp.sourceClassID=sqlite3_column_int(query,0);
2118 classTemp.name=std::string((const char*)sqlite3_column_text(query,1));
2120 //read out Properties
2121 command2="SELECT classProperty, value FROM SourceClassProperties"+ i2s(classTemp.sourceClassID);
2122 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&subQuery,NULL);
2124 while((eCode1=sqlite3_step(subQuery))==SQLITE_ROW)
2126 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(subQuery,0);
2127 propertyTemp.value=sqlite3_column_int(subQuery,1);
2128 classTemp.listClassProperties.push_back(propertyTemp);
2131 if(eCode1!=SQLITE_DONE)
2133 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode1));
2134 return E_DATABASE_ERROR;
2137 if((eCode1=sqlite3_finalize(subQuery))!=SQLITE_OK)
2139 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode1));
2140 return E_DATABASE_ERROR;
2142 listSourceClasses.push_back(classTemp);
2145 if(eCode!=SQLITE_DONE)
2147 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2148 return E_DATABASE_ERROR;
2151 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2153 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2154 return E_DATABASE_ERROR;
2162 am_Error_e DatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2164 //todo: implement crossfaders
2165 (void)listCrossfaders;
2171 am_Error_e DatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2173 listGateways.clear();
2174 sqlite3_stmt* query=NULL, *qSinkConnectionFormat=NULL, *qSourceConnectionFormat=NULL;
2177 am_ConnectionFormat_e tempConnectionFormat;
2179 std::string command= "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2180 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2182 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2184 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2185 temp.sinkID=sqlite3_column_int(query,1);
2186 temp.sourceID=sqlite3_column_int(query,2);
2187 temp.domainSinkID=sqlite3_column_int(query,3);
2188 temp.domainSourceID=sqlite3_column_int(query,4);
2189 temp.controlDomainID=sqlite3_column_int(query,5);
2190 temp.gatewayID=sqlite3_column_int(query,6);
2193 ListConnectionFormat::const_iterator iter=mListConnectionFormat.begin();
2194 iter=mListConnectionFormat.find(temp.gatewayID);
2195 if (iter == mListConnectionFormat.end())
2197 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways database error with convertionFormat"));
2198 return E_DATABASE_ERROR;
2200 temp.convertionMatrix=iter->second;
2202 //read out the connectionFormats
2203 std::string commandConnectionFormat= "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2204 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSourceConnectionFormat,NULL);
2205 while((eCode=sqlite3_step(qSourceConnectionFormat))==SQLITE_ROW)
2207 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSourceConnectionFormat,0);
2208 temp.listSourceFormats.push_back(tempConnectionFormat);
2211 if((eCode=sqlite3_finalize(qSourceConnectionFormat))!=SQLITE_OK)
2213 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2214 return E_DATABASE_ERROR;
2217 //read out sound properties
2218 commandConnectionFormat= "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2219 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSinkConnectionFormat,NULL);
2220 while((eCode=sqlite3_step(qSinkConnectionFormat))==SQLITE_ROW)
2222 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSinkConnectionFormat,0);
2223 temp.listSinkFormats.push_back(tempConnectionFormat);
2226 if((eCode=sqlite3_finalize(qSinkConnectionFormat))!=SQLITE_OK)
2228 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2229 return E_DATABASE_ERROR;
2232 listGateways.push_back(temp);
2233 temp.listSinkFormats.clear();
2234 temp.listSourceFormats.clear();
2237 if(eCode!=SQLITE_DONE)
2239 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE error code:"),DLT_INT(eCode));
2240 return E_DATABASE_ERROR;
2243 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2245 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2246 return E_DATABASE_ERROR;
2254 am_Error_e DatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2256 listSinkClasses.clear();
2258 sqlite3_stmt* query=NULL, *subQuery=NULL;
2260 am_SinkClass_s classTemp;
2261 am_ClassProperty_s propertyTemp;
2263 std::string command= "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2264 std::string command2;
2265 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2267 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2269 classTemp.sinkClassID=sqlite3_column_int(query,0);
2270 classTemp.name=std::string((const char*)sqlite3_column_text(query,1));
2272 //read out Properties
2273 command2="SELECT classProperty, value FROM SinkClassProperties"+ i2s(classTemp.sinkClassID);
2274 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&subQuery,NULL);
2276 while((eCode=sqlite3_step(subQuery))==SQLITE_ROW)
2278 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(subQuery,0);
2279 propertyTemp.value=sqlite3_column_int(subQuery,1);
2280 classTemp.listClassProperties.push_back(propertyTemp);
2283 if(eCode!=SQLITE_DONE)
2285 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2286 return E_DATABASE_ERROR;
2289 if((eCode=sqlite3_finalize(subQuery))!=SQLITE_OK)
2291 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2292 return E_DATABASE_ERROR;
2294 listSinkClasses.push_back(classTemp);
2297 if(eCode!=SQLITE_DONE)
2299 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2300 return E_DATABASE_ERROR;
2303 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2305 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2306 return E_DATABASE_ERROR;
2314 am_Error_e DatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2316 listConnections.clear();
2317 sqlite3_stmt *query=NULL;
2319 am_MainConnectionType_s temp;
2321 std::string command= "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2322 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2324 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2326 temp.mainConnectionID=sqlite3_column_int(query,0);
2327 temp.sourceID=sqlite3_column_int(query,1);
2328 temp.sinkID=sqlite3_column_int(query,2);
2329 temp.connectionState=(am_ConnectionState_e)sqlite3_column_int(query,3);
2330 temp.delay=sqlite3_column_int(query,4);
2331 listConnections.push_back(temp);
2334 if(eCode!=SQLITE_DONE)
2336 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE error code:"),DLT_INT(eCode));
2337 return E_DATABASE_ERROR;
2340 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2342 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:"),DLT_INT(eCode));
2343 return E_DATABASE_ERROR;
2351 am_Error_e DatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2353 listMainSinks.clear();
2354 sqlite3_stmt* query=NULL;
2358 std::string command= "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2359 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2361 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2363 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2364 temp.sinkID=sqlite3_column_int(query,1);
2365 temp.availability.availability=(am_Availablility_e)sqlite3_column_int(query,2);
2366 temp.availability.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,3);
2367 temp.muteState=(am_MuteState_e)sqlite3_column_int(query,4);
2368 temp.volume=sqlite3_column_int(query,5);
2369 temp.sinkClassID=sqlite3_column_int(query,6);
2370 listMainSinks.push_back(temp);
2373 if(eCode!=SQLITE_DONE)
2375 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"),DLT_INT(eCode));
2376 return E_DATABASE_ERROR;
2379 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2381 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
2382 return E_DATABASE_ERROR;
2390 am_Error_e DatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2392 listMainSources.clear();
2393 sqlite3_stmt* query=NULL;
2395 am_SourceType_s temp;
2396 std::string command= "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2397 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2399 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2401 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2402 temp.sourceClassID=sqlite3_column_int(query,1);
2403 temp.availability.availability=(am_Availablility_e)sqlite3_column_int(query,2);
2404 temp.availability.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,3);
2405 temp.sourceID=sqlite3_column_int(query,4);
2407 listMainSources.push_back(temp);
2410 if(eCode!=SQLITE_DONE)
2412 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"),DLT_INT(eCode));
2413 return E_DATABASE_ERROR;
2416 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2418 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2419 return E_DATABASE_ERROR;
2427 am_Error_e DatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2430 if (!existSink(sinkID)) return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2431 listSoundProperties.clear();
2433 sqlite3_stmt* query=NULL;
2435 am_MainSoundProperty_s temp;
2436 std::string command= "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2437 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2439 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2441 temp.type=(am_MainSoundPropertyType_e)sqlite3_column_int(query,0);
2442 temp.value=sqlite3_column_int(query,1);
2443 listSoundProperties.push_back(temp);
2446 if(eCode!=SQLITE_DONE)
2448 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"),DLT_INT(eCode));
2449 return E_DATABASE_ERROR;
2452 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2454 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2455 return E_DATABASE_ERROR;
2463 am_Error_e DatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2465 assert(sourceID!=0);
2466 if (!existSource(sourceID)) return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2467 listSourceProperties.clear();
2469 sqlite3_stmt* query=NULL;
2471 am_MainSoundProperty_s temp;
2472 std::string command= "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2473 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2475 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2477 temp.type=(am_MainSoundPropertyType_e)sqlite3_column_int(query,0);
2478 temp.value=sqlite3_column_int(query,1);
2479 listSourceProperties.push_back(temp);
2482 if(eCode!=SQLITE_DONE)
2484 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"),DLT_INT(eCode));
2485 return E_DATABASE_ERROR;
2488 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2490 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2491 return E_DATABASE_ERROR;
2499 am_Error_e DatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2501 listSystemProperties.clear();
2503 sqlite3_stmt* query=NULL;
2505 am_SystemProperty_s temp;
2506 std::string command= "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2507 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2509 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2511 temp.type=(am_SystemPropertyType_e)sqlite3_column_int(query,0);
2512 temp.value=sqlite3_column_int(query,1);
2513 listSystemProperties.push_back(temp);
2516 if(eCode!=SQLITE_DONE)
2518 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE error code:"),DLT_INT(eCode));
2519 return E_DATABASE_ERROR;
2522 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2524 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2525 return E_DATABASE_ERROR;
2533 am_Error_e DatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2535 assert(mainConnectionID!=0);
2537 sqlite3_stmt *query=NULL;
2540 std::string command= "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2541 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2543 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2545 delay=sqlite3_column_int(query,0);
2548 if(eCode!=SQLITE_DONE)
2550 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE error code:"),DLT_INT(eCode));
2551 return E_DATABASE_ERROR;
2554 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2556 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
2557 return E_DATABASE_ERROR;
2560 if (delay==-1) return E_NOT_POSSIBLE;
2565 bool DatabaseHandler::sqQuery(const std::string& query)
2567 sqlite3_stmt* statement;
2569 if ((eCode=sqlite3_exec(mDatabase,query.c_str(),NULL,&statement,NULL))!= SQLITE_OK)
2571 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));
2577 bool DatabaseHandler::openDatabase()
2579 if (sqlite3_open_v2(mPath.c_str(),&mDatabase,SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
2581 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::openDatabase opened database"));
2584 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::openDatabase failed to open database"));
2588 am_Error_e DatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
2590 assert(connectionID!=0);
2592 sqlite3_stmt* query=NULL;
2594 std::string command ="SELECT mainConnectionID FROM "+ std::string(MAINCONNECTION_TABLE) +" WHERE delay=? AND mainConnectionID=?";
2595 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2596 sqlite3_bind_int(query,1, delay);
2597 sqlite3_bind_int(query,2, connectionID);
2598 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2600 sqlite3_finalize(query);
2603 command="UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
2604 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2605 sqlite3_bind_int(query,1, delay);
2606 sqlite3_bind_int(query,2, connectionID);
2608 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2610 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:"),DLT_INT(eCode));
2611 return E_DATABASE_ERROR;
2614 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2616 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:"),DLT_INT(eCode));
2617 return E_DATABASE_ERROR;
2620 if(mDatabaseObserver) mDatabaseObserver->timingInformationChanged(connectionID,delay);
2625 am_Error_e DatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
2627 assert(connection.connectionID==0);
2628 assert(connection.sinkID!=0);
2629 assert(connection.sourceID!=0);
2630 //connection format is not checked, because it's project specific
2632 sqlite3_stmt* query=NULL;
2634 std::string command= "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
2636 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2637 sqlite3_bind_int(query,1, connection.sinkID);
2638 sqlite3_bind_int(query,2, connection.sourceID);
2639 sqlite3_bind_int(query,3, connection.delay);
2640 sqlite3_bind_int(query,4, connection.connectionFormat);
2641 sqlite3_bind_int(query,5, true);
2643 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2645 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
2646 return E_DATABASE_ERROR;
2649 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2651 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
2652 return E_DATABASE_ERROR;
2655 connectionID=sqlite3_last_insert_rowid(mDatabase);
2657 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterConnectionDB entered new connection sourceID:"), DLT_INT16(connection.sourceID),
2658 DLT_STRING("sinkID:"),DLT_INT16(connection.sinkID),
2659 DLT_STRING("sourceID:"),DLT_INT16(connection.sourceID),
2660 DLT_STRING("delay:"), DLT_INT16(connection.delay),
2661 DLT_STRING("connectionFormat:"),DLT_INT16(connection.connectionFormat),
2662 DLT_STRING("assigned ID:"),DLT_INT16(connectionID));
2666 am_Error_e DatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
2668 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
2669 assert(!sinkClass.listClassProperties.empty());
2670 assert(!sinkClass.name.empty());
2672 sqlite3_stmt* query=NULL;
2674 std::string command;
2676 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2677 if (sinkClass.sinkClassID==0 && !mFirstStaticSinkClass)
2679 command= "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
2683 //check if the ID already exists
2684 if(existSinkClass(sinkClass.sinkClassID)) return E_ALREADY_EXISTS;
2685 command= "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
2688 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2689 sqlite3_bind_text(query,1, sinkClass.name.c_str(),sinkClass.name.size(),SQLITE_STATIC);
2691 //if the ID is not created, we add it to the query
2692 if(sinkClass.sinkClassID!=0)
2694 sqlite3_bind_int(query,2, sinkClass.sinkClassID);
2697 //if the first static sink is entered, we need to set it onto the boundary
2698 else if(mFirstStaticSinkClass)
2700 sqlite3_bind_int(query,2, DYNAMIC_ID_BOUNDARY);
2701 mFirstStaticSinkClass=false;
2704 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2706 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"),DLT_INT(eCode));
2707 return E_DATABASE_ERROR;
2710 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2712 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2713 return E_DATABASE_ERROR;
2716 sinkClassID=sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2718 //now we need to create the additional tables:
2719 command="CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2720 assert(this->sqQuery(command));
2722 //fill ConnectionFormats
2723 command="INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
2724 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2725 std::vector<am_ClassProperty_s>::const_iterator Iterator=sinkClass.listClassProperties.begin();
2726 for(;Iterator<sinkClass.listClassProperties.end();++Iterator)
2728 sqlite3_bind_int(query,1, Iterator->classProperty);
2729 sqlite3_bind_int(query,2, Iterator->value);
2730 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2732 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"),DLT_INT(eCode));
2733 return E_DATABASE_ERROR;
2735 sqlite3_reset(query);
2738 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2740 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2741 return E_DATABASE_ERROR;
2744 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkClassDB entered new sinkClass"));
2745 if (mDatabaseObserver) mDatabaseObserver->numberOfSinkClassesChanged();
2749 am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
2751 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
2752 assert(!sourceClass.listClassProperties.empty());
2753 assert(!sourceClass.name.empty());
2755 sqlite3_stmt* query=NULL;
2757 std::string command;
2759 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2760 if (sourceClass.sourceClassID==0 && !mFirstStaticSourceClass)
2762 command= "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
2766 //check if the ID already exists
2767 if(existSourceClass(sourceClass.sourceClassID)) return E_ALREADY_EXISTS;
2768 command= "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
2771 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2772 sqlite3_bind_text(query,1, sourceClass.name.c_str(),sourceClass.name.size(),SQLITE_STATIC);
2774 //if the ID is not created, we add it to the query
2775 if(sourceClass.sourceClassID!=0)
2777 sqlite3_bind_int(query,2, sourceClass.sourceClassID);
2780 //if the first static sink is entered, we need to set it onto the boundary
2781 else if(mFirstStaticSourceClass)
2783 sqlite3_bind_int(query,2, DYNAMIC_ID_BOUNDARY);
2784 mFirstStaticSourceClass=false;
2787 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2789 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"),DLT_INT(eCode));
2790 return E_DATABASE_ERROR;
2793 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2795 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2796 return E_DATABASE_ERROR;
2799 sourceClassID=sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2801 //now we need to create the additional tables:
2802 command="CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2803 assert(sqQuery(command));
2805 //fill ConnectionFormats
2806 command="INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
2807 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2808 std::vector<am_ClassProperty_s>::const_iterator Iterator=sourceClass.listClassProperties.begin();
2809 for(;Iterator<sourceClass.listClassProperties.end();++Iterator)
2811 sqlite3_bind_int(query,1, Iterator->classProperty);
2812 sqlite3_bind_int(query,2, Iterator->value);
2813 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2815 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"),DLT_INT(eCode));
2816 return E_DATABASE_ERROR;
2818 sqlite3_reset(query);
2821 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2823 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2824 return E_DATABASE_ERROR;
2827 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSourceClassDB entered new sourceClass"));
2829 if (mDatabaseObserver) mDatabaseObserver->numberOfSourceClassesChanged();
2833 am_Error_e DatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
2835 sqlite3_stmt* query=NULL;
2837 std::vector<am_SystemProperty_s>::const_iterator listIterator =listSystemProperties.begin();
2838 std::string command= "DELETE * FROM " + std::string(SYSTEM_TABLE);
2841 command="INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
2843 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2844 for(;listIterator<listSystemProperties.end();++listIterator)
2846 sqlite3_bind_int(query,1, listIterator->type);
2847 sqlite3_bind_int(query,2, listIterator->value);
2849 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2851 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Step error code:"),DLT_INT(eCode));
2852 return E_DATABASE_ERROR;
2855 sqlite3_reset(query);
2858 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2860 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2861 return E_DATABASE_ERROR;
2864 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSystemProperties entered system properties"));
2868 bool DatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
2870 sqlite3_stmt* query=NULL;
2871 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2873 bool returnVal=true;
2874 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2875 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2876 else if (eCode!=SQLITE_ROW)
2879 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
2881 sqlite3_finalize(query);
2885 bool DatabaseHandler::existSource(const am_sourceID_t sourceID) const
2887 sqlite3_stmt* query=NULL;
2888 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
2890 bool returnVal=true;
2891 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2892 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2893 else if (eCode!=SQLITE_ROW)
2896 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2898 sqlite3_finalize(query);
2902 bool DatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
2904 sqlite3_stmt* query=NULL;
2905 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
2907 bool returnVal=true;
2908 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2909 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2910 sqlite3_bind_int(query,2,sourceID);
2911 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2912 else if (eCode!=SQLITE_ROW)
2915 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2917 sqlite3_finalize(query);
2921 bool DatabaseHandler::existSourceName(const std::string & name) const
2923 sqlite3_stmt* query=NULL;
2924 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
2926 bool returnVal=true;
2927 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2928 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2929 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2930 else if (eCode!=SQLITE_ROW)
2933 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2935 sqlite3_finalize(query);
2939 bool DatabaseHandler::existSink(const am_sinkID_t sinkID) const
2941 sqlite3_stmt* query=NULL;
2942 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
2944 bool returnVal=true;
2945 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2946 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2947 else if (eCode!=SQLITE_ROW)
2950 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2952 sqlite3_finalize(query);
2956 bool DatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
2958 sqlite3_stmt* query=NULL;
2959 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
2961 bool returnVal=true;
2962 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2963 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2964 sqlite3_bind_int(query,2,sinkID);
2965 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2966 else if (eCode!=SQLITE_ROW)
2969 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2971 sqlite3_finalize(query);
2975 bool DatabaseHandler::existSinkName(const std::string & name) const
2977 sqlite3_stmt* query=NULL;
2978 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
2980 bool returnVal=true;
2981 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2982 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2983 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2984 else if (eCode!=SQLITE_ROW)
2987 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2989 sqlite3_finalize(query);
2993 bool DatabaseHandler::existDomain(const am_domainID_t domainID) const
2995 sqlite3_stmt* query=NULL;
2996 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
2998 bool returnVal=true;
2999 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3000 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3001 else if (eCode!=SQLITE_ROW)
3004 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existDomain database error!:"), DLT_INT(eCode))
3006 sqlite3_finalize(query);
3010 bool DatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
3012 sqlite3_stmt* query=NULL;
3013 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
3015 bool returnVal=true;
3016 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3017 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3018 else if (eCode!=SQLITE_ROW)
3021 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existGateway database error!:"), DLT_INT(eCode))
3023 sqlite3_finalize(query);
3027 am_Error_e DatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
3029 assert(sourceID!=0);
3031 sqlite3_stmt* query=NULL;
3032 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3034 am_Error_e returnVal=E_DATABASE_ERROR;
3035 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3036 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3038 domainID=sqlite3_column_int(query,0);
3043 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainOfSource database error!:"), DLT_INT(eCode))
3045 sqlite3_finalize(query);
3050 bool DatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3052 sqlite3_stmt* query=NULL;
3053 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
3055 bool returnVal=true;
3056 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3057 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3058 else if (eCode!=SQLITE_ROW)
3061 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3063 sqlite3_finalize(query);
3067 bool DatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3069 sqlite3_stmt* query=NULL;
3070 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
3072 bool returnVal=true;
3073 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3074 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3075 else if (eCode!=SQLITE_ROW)
3078 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3080 sqlite3_finalize(query);
3084 am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3086 assert(connectionID!=0);
3088 sqlite3_stmt *query=NULL, *queryMainConnections, *queryMainConnectionSubIDs;
3090 std::string command= "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3092 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3093 sqlite3_bind_int(query,1, delay);
3094 sqlite3_bind_int(query,2, connectionID);
3096 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3098 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:"),DLT_INT(eCode));
3099 return E_DATABASE_ERROR;
3102 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3104 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
3105 return E_DATABASE_ERROR;
3108 //now we need to find all mainConnections that use the changed connection and update their timing
3109 am_timeSync_t tempDelay=0;
3112 std::string command2;
3113 int tempMainConnectionID;
3115 //first get all route tables for all mainconnections
3116 command= "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'";
3117 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryMainConnections,NULL);
3119 while((eCode=sqlite3_step(queryMainConnections))==SQLITE_ROW)
3121 //now check if the connection ID is in this table
3122 std::string tablename=std::string((const char*)sqlite3_column_text(queryMainConnections,0));
3123 command2="(SELECT connectionID FROM " + tablename + " WHERE connectionID="+i2s(connectionID)+")";
3124 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryMainConnectionSubIDs,NULL);
3125 if((eCode=sqlite3_step(queryMainConnectionSubIDs))==SQLITE_ROW)
3127 //if the connection ID is in, recalculate the mainconnection delay
3128 std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID;
3129 changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID),tempMainConnectionID);
3133 if(eCode!=SQLITE_DONE)
3135 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"),DLT_INT(eCode));
3136 return E_DATABASE_ERROR;
3139 if((eCode=sqlite3_finalize(queryMainConnections))!=SQLITE_OK)
3141 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
3142 return E_DATABASE_ERROR;
3145 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&queryMainConnectionSubIDs,NULL);
3146 while((eCode=sqlite3_step(queryMainConnectionSubIDs))==SQLITE_ROW)
3148 std::string temp=std::string((const char*)sqlite3_column_text(queryMainConnections,0));
3154 am_Error_e DatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3156 assert(connectionID!=0);
3158 sqlite3_stmt *query=NULL;
3160 std::string command= "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3162 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3163 sqlite3_bind_int(query,1, connectionID);
3165 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3167 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Step error code:"),DLT_INT(eCode));
3168 return E_DATABASE_ERROR;
3171 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3173 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:"),DLT_INT(eCode));
3174 return E_DATABASE_ERROR;
3179 am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3181 assert (mainConnectionID!=0);
3182 sqlite3_stmt* query=NULL;
3183 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" ;
3185 am_timeSync_t delay=0;
3186 am_timeSync_t min=0;
3187 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3188 if((eCode=sqlite3_step(query))==SQLITE_ROW)
3190 delay=sqlite3_column_int(query,0);
3191 min=sqlite3_column_int(query,1);
3193 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3195 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:"),DLT_INT(eCode));
3196 return E_DATABASE_ERROR;
3199 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3201 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:"),DLT_INT(eCode));
3202 return E_DATABASE_ERROR;
3204 if (min<0) delay=-1;
3209 void DatabaseHandler::registerObserver(DatabaseObserver *iObserver)
3211 assert(iObserver!=NULL);
3212 mDatabaseObserver=iObserver;
3215 bool DatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3217 assert(sourceID!=0);
3218 sqlite3_stmt* query=NULL;
3219 std::string command = "SELECT visible FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3221 bool returnVal=false;
3222 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3223 if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3225 returnVal=(bool)sqlite3_column_int(query,0);
3227 else if (eCode!=SQLITE_ROW)
3230 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sourceVisible database error!:"), DLT_INT(eCode))
3232 sqlite3_finalize(query);
3236 bool DatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3238 sqlite3_stmt* query=NULL;
3239 std::string command = "SELECT visible FROM "+ std::string(SINK_TABLE) +" WHERE reserved=0 AND sinkID="+ i2s(sinkID);
3241 bool returnVal=false;
3242 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3243 if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3245 returnVal=sqlite3_column_int(query,0);
3247 else if (eCode!=SQLITE_ROW)
3250 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sinkVisible database error!:"), DLT_INT(eCode))
3252 sqlite3_finalize(query);
3256 bool DatabaseHandler::existConnection(const am_Connection_s connection)
3258 sqlite3_stmt* query=NULL;
3259 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3261 bool returnVal=true;
3262 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3263 sqlite3_bind_int(query,1, connection.sinkID);
3264 sqlite3_bind_int(query,2, connection.sourceID);
3265 sqlite3_bind_int(query,3, connection.connectionFormat);
3266 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3267 else if (eCode!=SQLITE_ROW)
3270 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3272 sqlite3_finalize(query);
3277 bool DatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3279 sqlite3_stmt* query=NULL;
3280 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3282 bool returnVal=true;
3283 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3284 sqlite3_bind_int(query,1, connectionID);
3285 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3286 else if (eCode!=SQLITE_ROW)
3289 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3291 sqlite3_finalize(query);
3295 bool DatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3297 sqlite3_stmt* query=NULL;
3298 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3300 bool returnVal=true;
3301 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3302 sqlite3_bind_int(query,1, crossfaderID);
3303 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3304 else if (eCode!=SQLITE_ROW)
3307 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3309 sqlite3_finalize(query);
3313 am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3315 assert(sourceID!=0);
3316 sqlite3_stmt* query=NULL;
3318 std::string command = "SELECT sourceState FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3320 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3321 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3323 sourceState=(am_SourceState_e)sqlite3_column_int(query,0);
3325 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3327 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSoureState database error!:"), DLT_INT(eCode))
3330 sqlite3_finalize(query);
3334 am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3336 assert(sourceID!=0);
3337 sqlite3_stmt* query=NULL;
3338 std::string command = "UPDATE " + std::string(SOURCE_TABLE) +" SET sourceState=? WHERE sourceID="+ i2s(sourceID);
3340 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3341 sqlite3_bind_int(query,1,sourceState);
3342 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3344 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Step error code:"),DLT_INT(eCode));
3345 return E_DATABASE_ERROR;
3348 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3350 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Finalize error code:"),DLT_INT(eCode));
3351 return E_DATABASE_ERROR;
3356 am_Error_e DatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3359 sqlite3_stmt* query=NULL;
3361 std::string command = "SELECT volume FROM "+ std::string(SINK_TABLE) +" WHERE sinkID="+ i2s(sinkID);
3363 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3364 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3366 volume=sqlite3_column_int(query,0);
3368 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3370 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkVolume database error!:"), DLT_INT(eCode))
3373 sqlite3_finalize(query);
3377 am_Error_e DatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
3379 assert(sourceID!=0);
3380 sqlite3_stmt* query=NULL;
3382 std::string command = "SELECT volume FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3384 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3385 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3387 volume=sqlite3_column_int(query,0);
3389 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3391 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceVolume database error!:"), DLT_INT(eCode))
3393 sqlite3_finalize(query);
3398 am_Error_e DatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3401 if (!existSink(sinkID)) return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3403 sqlite3_stmt* query=NULL;
3405 std::string command= "SELECT value FROM SinkSoundProperty" + i2s(sinkID) +" WHERE soundPropertyType=" +i2s(propertyType);
3406 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3408 while((eCode=sqlite3_step(query))==SQLITE_ROW)
3410 value=sqlite3_column_int(query,0);
3413 if(eCode!=SQLITE_DONE)
3415 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"),DLT_INT(eCode));
3416 return E_DATABASE_ERROR;
3419 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3421 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"),DLT_INT(eCode));
3422 return E_DATABASE_ERROR;
3428 am_Error_e DatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3430 assert(sourceID!=0);
3431 if (!existSource(sourceID)) return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3433 sqlite3_stmt* query=NULL;
3435 std::string command= "SELECT value FROM SourceSoundProperty" + i2s(sourceID) +" WHERE soundPropertyType=" +i2s(propertyType);
3436 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3438 while((eCode=sqlite3_step(query))==SQLITE_ROW)
3440 value=sqlite3_column_int(query,0);
3443 if(eCode!=SQLITE_DONE)
3445 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"),DLT_INT(eCode));
3446 return E_DATABASE_ERROR;
3449 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3451 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"),DLT_INT(eCode));
3452 return E_DATABASE_ERROR;
3458 am_Error_e DatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
3460 assert(domainID!=0);
3461 sqlite3_stmt* query=NULL;
3463 std::string command = "SELECT domainState FROM "+ std::string(DOMAIN_TABLE) +" WHERE domainID="+ i2s(domainID);
3465 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3466 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3468 state=(am_DomainState_e)sqlite3_column_int(query,0);
3470 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3472 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainState database error!:"), DLT_INT(eCode))
3475 sqlite3_finalize(query);
3480 am_Error_e DatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
3482 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3483 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
3484 int eCode=0, eCode1=0;
3485 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3486 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3487 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3489 domainID=sqlite3_column_int(query,0);
3491 else if (eCode!=SQLITE_DONE)
3493 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain database error!:"), DLT_INT(eCode))
3494 return E_DATABASE_ERROR;
3498 command= "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
3499 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3500 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3501 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3502 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3504 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Step error code:"),DLT_INT(eCode1));
3505 return E_DATABASE_ERROR;
3508 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3510 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3511 return E_DATABASE_ERROR;
3513 domainID=sqlite3_last_insert_rowid(mDatabase);
3515 sqlite3_finalize(query);
3519 am_Error_e DatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
3521 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3522 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
3523 int eCode=0, eCode1=0;
3524 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3525 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3526 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3528 sinkID=sqlite3_column_int(query,0);
3530 else if (eCode!=SQLITE_DONE)
3532 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3533 return E_DATABASE_ERROR;
3537 if (mFirstStaticSink)
3539 command= "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3540 mFirstStaticSink=false;
3544 command= "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
3546 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3547 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3548 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3549 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3551 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"),DLT_INT(eCode1));
3552 return E_DATABASE_ERROR;
3555 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3557 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3558 return E_DATABASE_ERROR;
3560 sinkID=sqlite3_last_insert_rowid(mDatabase);
3562 sqlite3_finalize(query);
3568 am_Error_e DatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
3570 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3571 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
3572 int eCode=0, eCode1=0;
3573 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3574 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3575 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3577 sourceID=sqlite3_column_int(query,0);
3579 else if (eCode!=SQLITE_DONE)
3581 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3582 return E_DATABASE_ERROR;
3586 if (mFirstStaticSource)
3588 command= "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3589 mFirstStaticSource=false;
3593 command= "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
3595 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3596 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3597 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3598 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3600 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"),DLT_INT(eCode1));
3601 return E_DATABASE_ERROR;
3604 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3606 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3607 return E_DATABASE_ERROR;
3609 sourceID=sqlite3_last_insert_rowid(mDatabase);
3611 sqlite3_finalize(query);
3615 am_Error_e DatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
3619 sqlite3_stmt* query=NULL;
3621 std::string command;
3623 if (!existSink(sinkID))
3625 return E_NON_EXISTENT;
3627 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
3628 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3629 sqlite3_bind_int(query,1, volume);
3630 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3632 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Step error code:"),DLT_INT(eCode));
3633 return E_DATABASE_ERROR;
3635 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3637 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:"),DLT_INT(eCode));
3638 return E_DATABASE_ERROR;
3641 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkVolume changed volume of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(volume));
3646 am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
3648 assert(sourceID!=0);
3650 sqlite3_stmt* query=NULL;
3652 std::string command;
3654 if (!existSource(sourceID))
3656 return E_NON_EXISTENT;
3658 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
3659 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3660 sqlite3_bind_int(query,1, volume);
3661 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3663 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Step error code:"),DLT_INT(eCode));
3664 return E_DATABASE_ERROR;
3666 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3668 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:"),DLT_INT(eCode));
3669 return E_DATABASE_ERROR;
3672 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceVolume changed volume of source=:"),DLT_INT(sourceID),DLT_STRING("to:"),DLT_INT(volume));
3677 am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
3679 //todo: add checks if soundproperty exists!
3680 assert(sourceID!=0);
3682 sqlite3_stmt* query=NULL;
3684 std::string command;
3686 if (!existSource(sourceID))
3688 return E_NON_EXISTENT;
3690 command = "UPDATE SourceSoundProperty" + i2s(sourceID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3691 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3692 sqlite3_bind_int(query,1, soundProperty.value);
3693 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3695 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
3696 return E_DATABASE_ERROR;
3699 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3701 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
3702 return E_DATABASE_ERROR;
3705 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));
3710 am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
3712 //todo: add checks if soundproperty exists!
3715 sqlite3_stmt* query=NULL;
3717 std::string command;
3719 if (!existSink(sinkID))
3721 return E_NON_EXISTENT;
3723 command = "UPDATE SinkSoundProperty" + i2s(sinkID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3724 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3725 sqlite3_bind_int(query,1, soundProperty.value);
3726 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3728 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
3729 return E_DATABASE_ERROR;
3730 } assert(sinkID!=0);
3732 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3734 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
3735 return E_DATABASE_ERROR;
3738 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));
3743 am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
3745 assert(crossfaderID!=0);
3747 sqlite3_stmt* query=NULL;
3749 std::string command;
3751 if (!existcrossFader(crossfaderID))
3753 return E_NON_EXISTENT;
3755 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
3756 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3757 sqlite3_bind_int(query,1, hotsink);
3758 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3760 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:"),DLT_INT(eCode));
3761 return E_DATABASE_ERROR;
3763 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3765 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:"),DLT_INT(eCode));
3766 return E_DATABASE_ERROR;
3769 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader="),DLT_INT(crossfaderID),DLT_STRING("to:"),DLT_INT(hotsink));
3774 void DatabaseHandler::createTables()
3776 for(uint16_t i=0;i<sizeof(databaseTables)/sizeof(databaseTables[0]);i++)
3778 assert(sqQuery("CREATE TABLE " + databaseTables[i]));