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"
32 #define DOMAIN_TABLE "Domains"
33 #define SOURCE_CLASS_TABLE "SourceClasses"
34 #define SINK_CLASS_TABLE "SinkClasses"
35 #define SOURCE_TABLE "Sources"
36 #define SINK_TABLE "Sinks"
37 #define GATEWAY_TABLE "Gateways"
38 #define CROSSFADER_TABLE "Crossfaders"
39 #define CONNECTION_TABLE "Connections"
40 #define MAINCONNECTION_TABLE "MainConnections"
41 #define INTERRUPT_TABLE "Interrupts"
42 #define MAIN_TABLE "MainTable"
43 #define SYSTEM_TABLE "SystemProperties"
45 DLT_IMPORT_CONTEXT(AudioManager)
47 const std::string databaseTables[]={
48 " 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);",
49 " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));",
50 " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));",
51 " 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);",
52 " 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);",
53 " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER);",
54 " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);",
55 " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);",
56 " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);",
57 " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);"
61 * template to converts T to std::string
62 * @param i the value to be converted
66 inline std::string i2s(T const& x)
73 DatabaseHandler::DatabaseHandler(std::string databasePath)
76 mDatabaseObserver(NULL),
77 mFirstStaticSink(true),
78 mFirstStaticSource(true),
79 mFirstStaticGateway(true),
80 mFirstStaticSinkClass(true),
81 mFirstStaticSourceClass(true),
82 mListConnectionFormat()
86 *\todo: this erases the database. just for testing!
88 std::ifstream infile(mPath.c_str());
92 remove(mPath.c_str());
93 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::DatabaseHandler Knocked down database"));
96 bool dbOpen=openDatabase();
99 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::DatabaseHandler problems opening the database!"));
108 DatabaseHandler::~DatabaseHandler()
110 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("Closed Database"));
111 sqlite3_close(mDatabase);
114 am_Error_e DatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
116 assert(domainData.domainID==0);
117 assert(!domainData.name.empty());
118 assert(!domainData.busname.empty());
119 assert(domainData.state>=DS_CONTROLLED && domainData.state<=DS_INDEPENDENT_RUNDOWN);
121 //first check for a reserved domain
122 sqlite3_stmt* query=NULL, *queryFinal;
124 std::string command="SELECT domainID FROM "+ std::string(DOMAIN_TABLE) + " WHERE name=?";
125 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
126 sqlite3_bind_text(query,1, domainData.name.c_str(),domainData.name.size(),SQLITE_STATIC);
127 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
129 command= "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" +i2s(sqlite3_column_int(query,0));
131 else if (eCode==SQLITE_DONE)
134 command= "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)";
138 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Step error code:"),DLT_INT(eCode));
139 return E_DATABASE_ERROR;
142 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
144 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Finalize error code:"),DLT_INT(eCode));
145 return E_DATABASE_ERROR;
148 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
149 sqlite3_bind_text(queryFinal,1, domainData.name.c_str(),domainData.name.size(),SQLITE_STATIC);
150 sqlite3_bind_text(queryFinal,2, domainData.busname.c_str(),domainData.busname.size(),SQLITE_STATIC);
151 sqlite3_bind_text(queryFinal,3, domainData.nodename.c_str(),domainData.nodename.size(),SQLITE_STATIC);
152 sqlite3_bind_int(queryFinal,4, domainData.early);
153 sqlite3_bind_int(queryFinal,5, domainData.complete);
154 sqlite3_bind_int(queryFinal,6, domainData.state);
155 sqlite3_bind_int(queryFinal,7, 0);
157 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
159 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Step error code:"),DLT_INT(eCode));
160 return E_DATABASE_ERROR;
163 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
165 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterDomainDB SQLITE Finalize error code:"),DLT_INT(eCode));
166 return E_DATABASE_ERROR;
169 domainID=sqlite3_last_insert_rowid(mDatabase);
170 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterDomainDB entered new domain with name"), DLT_STRING(domainData.name.c_str()),
171 DLT_STRING("busname:"),DLT_STRING(domainData.busname.c_str()),
172 DLT_STRING("nodename:"),DLT_STRING(domainData.nodename.c_str()),
173 DLT_STRING("early:"), DLT_BOOL(domainData.early),
174 DLT_STRING("complete:"),DLT_BOOL(domainData.complete),
175 DLT_STRING("state:"),DLT_INT(domainData.state),
176 DLT_STRING("assigned ID:"),DLT_INT16(domainID));
178 am_Domain_s domain=domainData;
179 domain.domainID=domainID;
180 if(mDatabaseObserver) mDatabaseObserver->newDomain(domain);
187 am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
189 assert(mainConnectionData.connectionID==0);
190 assert(mainConnectionData.connectionState>=CS_CONNECTING && mainConnectionData.connectionState<=CS_SUSPENDED);
191 assert(mainConnectionData.route.sinkID!=0);
192 assert(mainConnectionData.route.sourceID!=0);
194 sqlite3_stmt* query=NULL;
196 std::string command= "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState) VALUES (?,?,?)";
197 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
198 sqlite3_bind_int(query,1, mainConnectionData.route.sourceID);
199 sqlite3_bind_int(query,2, mainConnectionData.route.sinkID);
200 sqlite3_bind_int(query,3, mainConnectionData.connectionState);
202 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
204 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
205 return E_DATABASE_ERROR;
209 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
211 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
212 return E_DATABASE_ERROR;
215 connectionID=sqlite3_last_insert_rowid(mDatabase);
217 //now check the connectionTabel for all connections in the route. IF a particular route is not found, we return with error
218 std::vector<uint16_t> listOfConnections;
220 command="SELECT connectionID, delay FROM "+std::string(CONNECTION_TABLE)+(" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
221 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
222 std::vector<am_RoutingElement_s>::const_iterator elementIterator=mainConnectionData.route.route.begin();
223 for (;elementIterator<mainConnectionData.route.route.end();++elementIterator)
225 sqlite3_bind_int(query,1, elementIterator->sourceID);
226 sqlite3_bind_int(query,2, elementIterator->sinkID);
227 sqlite3_bind_int(query,3, elementIterator->connectionFormat);
229 if((eCode=sqlite3_step(query))==SQLITE_ROW)
231 listOfConnections.push_back(sqlite3_column_int(query,0));
232 int16_t temp_delay=sqlite3_column_int(query,1);
233 if (temp_delay!=-1 && delay!=-1) delay+=temp_delay;
238 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:"),DLT_INT(eCode));
239 return E_DATABASE_ERROR;
241 sqlite3_reset(query);
244 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
246 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
247 return E_DATABASE_ERROR;
250 //now we create a table with references to the connections;
251 command="CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)");
252 assert(this->sqQuery(command));
254 command= "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)";
255 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
256 std::vector<uint16_t>::iterator listConnectionIterator=listOfConnections.begin();
257 for(;listConnectionIterator<listOfConnections.end();++listConnectionIterator)
259 sqlite3_bind_int(query,1, *listConnectionIterator);
260 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
262 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
263 return E_DATABASE_ERROR;
265 sqlite3_reset(query);
268 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
270 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
271 return E_DATABASE_ERROR;
274 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID"), DLT_INT(mainConnectionData.route.sourceID),
275 DLT_STRING("sinkID:"),DLT_INT16(mainConnectionData.route.sinkID),
276 DLT_STRING("delay:"),DLT_INT16(delay),
277 DLT_STRING("assigned ID:"),DLT_INT16(connectionID));
279 if (mDatabaseObserver)
281 mDatabaseObserver->numberOfMainConnectionsChanged();
282 mDatabaseObserver->mainConnectionStateChanged(connectionID,mainConnectionData.connectionState);
285 //finally, we update the delay value for the maintable
286 if (delay==0) delay=-1;
287 return changeDelayMainConnection(delay,connectionID);
292 am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
294 assert(sinkData.sinkID<DYNAMIC_ID_BOUNDARY);
295 assert(sinkData.domainID!=0);
296 assert(!sinkData.name.empty());
297 assert(sinkData.sinkClassID!=0); // \todo: need to check if class exists?
298 assert(!sinkData.listConnectionFormats.empty());
299 assert(sinkData.muteState>=MS_MUTED && sinkData.muteState<=MS_UNMUTED);
301 sqlite3_stmt *query=NULL, *queryFinal=NULL;
303 std::string command="SELECT sinkID FROM "+ std::string(SINK_TABLE) + " WHERE name=? AND reserved=1";
305 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
306 sqlite3_bind_text(query,1, sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
308 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
310 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));
312 else if (eCode==SQLITE_DONE)
314 //if sinkID is zero and the first Static Sink was already entered, the ID is created
315 if (sinkData.sinkID==0 && !mFirstStaticSink && !existSinkName(sinkData.name))
317 command= "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
321 //check if the ID already exists
322 if(existSinkNameOrID(sinkData.sinkID,sinkData.name))
324 sqlite3_finalize(query);
325 return E_ALREADY_EXISTS;
327 command= "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
332 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
333 sqlite3_finalize(query);
334 return E_DATABASE_ERROR;
337 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
339 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"),DLT_INT(eCode));
340 return E_DATABASE_ERROR;
343 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
344 sqlite3_bind_text(queryFinal,1, sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
345 sqlite3_bind_int(queryFinal,2, sinkData.domainID);
346 sqlite3_bind_int(queryFinal,3, sinkData.sinkClassID);
347 sqlite3_bind_int(queryFinal,4, sinkData.volume);
348 sqlite3_bind_int(queryFinal,5, sinkData.visible);
349 sqlite3_bind_int(queryFinal,6, sinkData.available.availability);
350 sqlite3_bind_int(queryFinal,7, sinkData.available.availabilityReason);
351 sqlite3_bind_int(queryFinal,8, sinkData.muteState);
352 sqlite3_bind_int(queryFinal,9, sinkData.mainVolume);
353 sqlite3_bind_int(queryFinal,10, 0);
355 //if the ID is not created, we add it to the query
356 if(sinkData.sinkID!=0)
358 sqlite3_bind_int(queryFinal,11, sinkData.sinkID);
361 //if the first static sink is entered, we need to set it onto the boundary
362 else if(mFirstStaticSink)
364 sqlite3_bind_int(queryFinal,11, DYNAMIC_ID_BOUNDARY);
365 mFirstStaticSink=false;
368 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
370 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
371 sqlite3_finalize(queryFinal);
372 return E_DATABASE_ERROR;
375 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
377 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Finalize error code:"),DLT_INT(eCode));
378 return E_DATABASE_ERROR;
381 //now read back the sinkID
382 command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
383 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
384 sqlite3_bind_text(query,1,sinkData.name.c_str(),sinkData.name.size(),SQLITE_STATIC);
385 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
387 sinkID=sqlite3_column_int(query,0);
392 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
393 sqlite3_finalize(query);
394 return E_DATABASE_ERROR;
396 sqlite3_finalize(query);
398 //now we need to create the additional tables:
399 command="CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)");
400 assert(this->sqQuery(command));
401 command="CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
402 assert(this->sqQuery(command));
403 command="CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
404 assert(this->sqQuery(command));
406 //fill ConnectionFormats
407 command="INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)");
408 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
409 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=sinkData.listConnectionFormats.begin();
410 for(;connectionFormatIterator<sinkData.listConnectionFormats.end();++connectionFormatIterator)
412 sqlite3_bind_int(query,1, *connectionFormatIterator);
413 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
415 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
416 sqlite3_finalize(query);
417 return E_DATABASE_ERROR;
419 sqlite3_reset(query);
422 //Fill MainSinkSoundProperties
423 command="INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
424 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
425 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator=sinkData.listMainSoundProperties.begin();
426 for(;mainSoundPropertyIterator<sinkData.listMainSoundProperties.end();++mainSoundPropertyIterator)
428 sqlite3_bind_int(query,1, mainSoundPropertyIterator->type);
429 sqlite3_bind_int(query,2, mainSoundPropertyIterator->value);
430 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
432 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
433 sqlite3_finalize(query);
434 return E_DATABASE_ERROR;
436 sqlite3_reset(query);
439 //Fill SinkSoundProperties
440 command="INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)");
441 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
442 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator=sinkData.listSoundProperties.begin();
443 for(;SoundPropertyIterator<sinkData.listSoundProperties.end();++SoundPropertyIterator)
445 sqlite3_bind_int(query,1, SoundPropertyIterator->type);
446 sqlite3_bind_int(query,2, SoundPropertyIterator->value);
447 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
449 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
450 sqlite3_finalize(query);
451 return E_DATABASE_ERROR;
453 sqlite3_reset(query);
456 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkDB entered new sink with name"), DLT_STRING(sinkData.name.c_str()),
457 DLT_STRING("domainID:"),DLT_INT(sinkData.domainID),
458 DLT_STRING("classID:"),DLT_INT(sinkData.sinkClassID),
459 DLT_STRING("volume:"),DLT_INT(sinkData.volume),
460 DLT_STRING("visible:"),DLT_BOOL(sinkData.visible),
461 DLT_STRING("available.availability:"),DLT_INT(sinkData.available.availability),
462 DLT_STRING("available.availabilityReason:"),DLT_INT(sinkData.available.availabilityReason),
463 DLT_STRING("muteState:"),DLT_INT(sinkData.muteState),
464 DLT_STRING("mainVolume:"),DLT_INT(sinkData.mainVolume),
465 DLT_STRING("assigned ID:"),DLT_INT16(sinkID));
467 am_Sink_s sink=sinkData;
469 if (mDatabaseObserver!=NULL) mDatabaseObserver->newSink(sink);
476 am_Error_e DatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
478 //todo: implement crossfader
479 (void)crossfaderData;
486 am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
488 assert(gatewayData.gatewayID<DYNAMIC_ID_BOUNDARY);
489 assert(gatewayData.sinkID!=0);
490 assert(gatewayData.sourceID!=0);
491 assert(gatewayData.controlDomainID!=0);
492 assert(gatewayData.domainSinkID!=0);
493 assert(gatewayData.domainSourceID!=0);
494 assert(!gatewayData.name.empty());
495 assert(!gatewayData.convertionMatrix.empty());
496 assert(!gatewayData.listSinkFormats.empty());
497 assert(!gatewayData.listSourceFormats.empty());
499 sqlite3_stmt* query=NULL;
503 //if sinkID is zero and the first Static Sink was already entered, the ID is created
504 if (gatewayData.gatewayID==0 && !mFirstStaticGateway)
506 command= "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID) VALUES (?,?,?,?,?,?)";
510 //check if the ID already exists
511 if (existGateway(gatewayData.gatewayID)) return E_ALREADY_EXISTS;
512 command= "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID) VALUES (?,?,?,?,?,?,?)";
515 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
516 sqlite3_bind_text(query,1, gatewayData.name.c_str(),gatewayData.name.size(),SQLITE_STATIC);
517 sqlite3_bind_int(query,2, gatewayData.sinkID);
518 sqlite3_bind_int(query,3, gatewayData.sourceID);
519 sqlite3_bind_int(query,4, gatewayData.domainSinkID);
520 sqlite3_bind_int(query,5, gatewayData.domainSourceID);
521 sqlite3_bind_int(query,6, gatewayData.controlDomainID);
523 //if the ID is not created, we add it to the query
524 if(gatewayData.gatewayID!=0)
526 sqlite3_bind_int(query,7, gatewayData.gatewayID);
529 //if the first static sink is entered, we need to set it onto the boundary
530 else if(mFirstStaticGateway)
532 sqlite3_bind_int(query,7, DYNAMIC_ID_BOUNDARY);
533 mFirstStaticGateway=false;
536 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
538 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
539 return E_DATABASE_ERROR;
542 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
544 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Finalize error code:"),DLT_INT(eCode));
545 return E_DATABASE_ERROR;
548 gatewayID=sqlite3_last_insert_rowid(mDatabase);
550 //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
551 mListConnectionFormat.insert(std::make_pair(gatewayID,gatewayData.convertionMatrix));
553 command="CREATE TABLE GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
554 assert(this->sqQuery(command));
555 command="CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)");
556 assert(this->sqQuery(command));
558 //fill ConnectionFormats
559 command="INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
560 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
561 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=gatewayData.listSourceFormats.begin();
562 for(;connectionFormatIterator<gatewayData.listSourceFormats.end();++connectionFormatIterator)
564 sqlite3_bind_int(query,1, *connectionFormatIterator);
565 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
567 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
568 return E_DATABASE_ERROR;
570 sqlite3_reset(query);
573 command="INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)");
574 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
575 connectionFormatIterator=gatewayData.listSinkFormats.begin();
576 for(;connectionFormatIterator<gatewayData.listSinkFormats.end();++connectionFormatIterator)
578 sqlite3_bind_int(query,1, *connectionFormatIterator);
579 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
581 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterGatewayDB SQLITE Step error code:"),DLT_INT(eCode));
582 return E_DATABASE_ERROR;
584 sqlite3_reset(query);
588 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterGatewayDB entered new gateway with name"), DLT_STRING(gatewayData.name.c_str()),
589 DLT_STRING("sourceID:"),DLT_INT(gatewayData.sourceID),
590 DLT_STRING("sinkID:"),DLT_INT(gatewayData.sinkID),
591 DLT_STRING("domainSinkID:"),DLT_INT(gatewayData.domainSinkID),
592 DLT_STRING("domainSourceID:"),DLT_BOOL(gatewayData.domainSourceID),
593 DLT_STRING("controlDomainID:"),DLT_INT(gatewayData.controlDomainID),
594 DLT_STRING("assigned ID:"),DLT_INT16(gatewayID));
596 am_Gateway_s gateway=gatewayData;
597 gateway.gatewayID=gatewayID;
598 if(mDatabaseObserver) mDatabaseObserver->newGateway(gateway);
604 am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
606 assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
607 assert(sourceData.domainID!=0);
608 assert(!sourceData.name.empty());
609 assert(sourceData.sourceClassID!=0); // \todo: need to check if class exists?
610 assert(!sourceData.listConnectionFormats.empty());
611 assert(sourceData.sourceState>=SS_ON && sourceData.sourceState<=SS_PAUSED);
613 sqlite3_stmt* query=NULL, *queryFinal=NULL;;
615 std::string command="SELECT sourceID FROM "+ std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1";
617 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
618 sqlite3_bind_text(query,1, sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
620 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
622 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));
624 else if (eCode==SQLITE_DONE)
626 //if sinkID is zero and the first Static Sink was already entered, the ID is created
627 if (sourceData.sourceID==0 && !mFirstStaticSource && !existSourceName(sourceData.name))
629 command= "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)";
633 //check if the ID already exists
634 if (existSourceNameOrID(sourceData.sourceID,sourceData.name))
636 sqlite3_finalize(query);
637 return E_ALREADY_EXISTS;
639 command= "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
644 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
645 sqlite3_finalize(query);
646 return E_DATABASE_ERROR;
649 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
651 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"),DLT_INT(eCode));
652 return E_DATABASE_ERROR;
654 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryFinal,NULL);
655 sqlite3_bind_text(queryFinal,1, sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
656 sqlite3_bind_int(queryFinal,2, sourceData.domainID);
657 sqlite3_bind_int(queryFinal,3, sourceData.sourceClassID);
658 sqlite3_bind_int(queryFinal,4, sourceData.sourceState);
659 sqlite3_bind_int(queryFinal,5, sourceData.volume);
660 sqlite3_bind_int(queryFinal,6, sourceData.visible);
661 sqlite3_bind_int(queryFinal,7, sourceData.available.availability);
662 sqlite3_bind_int(queryFinal,8, sourceData.available.availabilityReason);
663 sqlite3_bind_int(queryFinal,9, sourceData.interruptState);
664 sqlite3_bind_int(queryFinal,10, 0);
666 //if the ID is not created, we add it to the query
667 if(sourceData.sourceID!=0)
669 sqlite3_bind_int(queryFinal,11, sourceData.sourceID);
672 //if the first static sink is entered, we need to set it onto the boundary
673 else if(mFirstStaticSource)
675 sqlite3_bind_int(queryFinal,11, DYNAMIC_ID_BOUNDARY);
676 mFirstStaticSource=false;
679 if((eCode=sqlite3_step(queryFinal))!=SQLITE_DONE)
681 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
682 sqlite3_finalize(queryFinal);
683 return E_DATABASE_ERROR;
686 if((eCode=sqlite3_finalize(queryFinal))!=SQLITE_OK)
688 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Finalize error code:"),DLT_INT(eCode));
689 sqlite3_finalize(queryFinal);
690 return E_DATABASE_ERROR;
693 //now read back the sinkID
694 command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
695 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
696 sqlite3_bind_text(query,1,sourceData.name.c_str(),sourceData.name.size(),SQLITE_STATIC);
697 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
699 sourceID=sqlite3_column_int(query,0);
704 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
705 sqlite3_finalize(query);
706 return E_DATABASE_ERROR;
708 sqlite3_finalize(query);
711 //now we need to create the additional tables:
712 command="CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)");
713 assert(this->sqQuery(command));
714 command="CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
715 assert(this->sqQuery(command));
716 command="CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)");
717 assert(this->sqQuery(command));
719 //fill ConnectionFormats
720 command="INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)");
721 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
722 std::vector<am_ConnectionFormat_e>::const_iterator connectionFormatIterator=sourceData.listConnectionFormats.begin();
723 for(;connectionFormatIterator<sourceData.listConnectionFormats.end();++connectionFormatIterator)
725 sqlite3_bind_int(query,1, *connectionFormatIterator);
726 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
728 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
729 sqlite3_finalize(query);
730 return E_DATABASE_ERROR;
732 sqlite3_reset(query);
735 //Fill MainSinkSoundProperties
736 command="INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
737 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
738 std::vector<am_MainSoundProperty_s>::const_iterator mainSoundPropertyIterator=sourceData.listMainSoundProperties.begin();
739 for(;mainSoundPropertyIterator<sourceData.listMainSoundProperties.end();++mainSoundPropertyIterator)
741 sqlite3_bind_int(query,1, mainSoundPropertyIterator->type);
742 sqlite3_bind_int(query,2, mainSoundPropertyIterator->value);
743 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
745 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceDB SQLITE Step error code:"),DLT_INT(eCode));
746 sqlite3_finalize(query);
747 return E_DATABASE_ERROR;
749 sqlite3_reset(query);
752 //Fill SinkSoundProperties
753 command="INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)");
754 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
755 std::vector<am_SoundProperty_s>::const_iterator SoundPropertyIterator=sourceData.listSoundProperties.begin();
756 for(;SoundPropertyIterator<sourceData.listSoundProperties.end();++SoundPropertyIterator)
758 sqlite3_bind_int(query,1, SoundPropertyIterator->type);
759 sqlite3_bind_int(query,2, SoundPropertyIterator->value);
760 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
762 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkDB SQLITE Step error code:"),DLT_INT(eCode));
763 sqlite3_finalize(query);
764 return E_DATABASE_ERROR;
766 sqlite3_reset(query);
769 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkDB entered new source with name"), DLT_STRING(sourceData.name.c_str()),
770 DLT_STRING("domainID:"),DLT_INT(sourceData.domainID),
771 DLT_STRING("classID:"),DLT_INT(sourceData.sourceClassID),
772 DLT_STRING("volume:"),DLT_INT(sourceData.volume),
773 DLT_STRING("visible:"),DLT_BOOL(sourceData.visible),
774 DLT_STRING("available.availability:"),DLT_INT(sourceData.available.availability),
775 DLT_STRING("available.availabilityReason:"),DLT_INT(sourceData.available.availabilityReason),
776 DLT_STRING("interruptState:"),DLT_INT(sourceData.interruptState),
777 DLT_STRING("assigned ID:"),DLT_INT16(sourceID));
779 am_Source_s source=sourceData;
780 source.sourceID=sourceID;
781 if(mDatabaseObserver) mDatabaseObserver->newSource(source);
787 am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
789 assert(mainconnectionID!=0);
790 if(!existMainConnection(mainconnectionID))
792 return E_NON_EXISTENT;
794 sqlite3_stmt* query=NULL;
798 std::vector<uint16_t> listOfConnections;
800 command="SELECT connectionID, delay FROM "+std::string(CONNECTION_TABLE)+(" WHERE sourceID=? AND sinkID=? AND connectionFormat=?");
801 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
802 std::vector<am_RoutingElement_s>::const_iterator elementIterator=route.route.begin();
803 for (;elementIterator<route.route.end();++elementIterator)
805 sqlite3_bind_int(query,1, elementIterator->sourceID);
806 sqlite3_bind_int(query,2, elementIterator->sinkID);
807 sqlite3_bind_int(query,3, elementIterator->connectionFormat);
809 if((eCode=sqlite3_step(query))==SQLITE_ROW)
811 listOfConnections.push_back(sqlite3_column_int(query,0));
812 int16_t temp_delay=sqlite3_column_int(query,1);
813 if (temp_delay!=-1 && delay!=-1) delay+=temp_delay;
818 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:"),DLT_INT(eCode));
819 return E_DATABASE_ERROR;
821 sqlite3_reset(query);
824 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
826 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"),DLT_INT(eCode));
827 return E_DATABASE_ERROR;
830 //now we delete the data in the table
831 command="DELETE from MainConnectionRoute" + i2s(mainconnectionID);
832 assert(this->sqQuery(command));
834 command= "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)";
835 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
836 std::vector<uint16_t>::iterator listConnectionIterator=listOfConnections.begin();
837 for(;listConnectionIterator<listOfConnections.end();++listConnectionIterator)
839 sqlite3_bind_int(query,1, *listConnectionIterator);
840 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
842 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:"),DLT_INT(eCode));
843 return E_DATABASE_ERROR;
845 sqlite3_reset(query);
848 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
850 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:"),DLT_INT(eCode));
851 return E_DATABASE_ERROR;
853 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionRouteDB entered new route:"),DLT_INT(mainconnectionID));
857 am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
859 assert(mainconnectionID!=0);
861 sqlite3_stmt* query=NULL;
865 if (!existMainConnection(mainconnectionID))
867 return E_NON_EXISTENT;
869 command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID);
870 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
871 sqlite3_bind_int(query,1, connectionState);
872 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
874 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:"),DLT_INT(eCode));
875 return E_DATABASE_ERROR;
877 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
879 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
880 return E_DATABASE_ERROR;
882 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:"),DLT_INT(mainconnectionID),DLT_STRING("to:"),DLT_INT(connectionState));
884 if (mDatabaseObserver) mDatabaseObserver->mainConnectionStateChanged(mainconnectionID,connectionState);
890 am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
894 sqlite3_stmt* query=NULL;
898 if (!existSink(sinkID))
900 return E_NON_EXISTENT;
902 command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID);
903 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
904 sqlite3_bind_int(query,1, mainVolume);
905 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
907 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:"),DLT_INT(eCode));
908 return E_DATABASE_ERROR;
910 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
912 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:"),DLT_INT(eCode));
913 return E_DATABASE_ERROR;
916 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(mainVolume));
918 if(mDatabaseObserver) mDatabaseObserver->volumeChanged(sinkID,mainVolume);
925 am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
929 sqlite3_stmt* query=NULL;
933 if (!existSink(sinkID))
935 return E_NON_EXISTENT;
937 command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID);
938 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
939 sqlite3_bind_int(query,1, availability.availability);
940 sqlite3_bind_int(query,2, availability.availabilityReason);
941 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
943 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:"),DLT_INT(eCode));
944 return E_DATABASE_ERROR;
947 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
949 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:"),DLT_INT(eCode));
950 return E_DATABASE_ERROR;
953 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));
955 if (mDatabaseObserver && sourceVisible(sinkID)) mDatabaseObserver->sinkAvailabilityChanged(sinkID,availability);
961 am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
965 sqlite3_stmt* query=NULL;
969 if (!existDomain(domainID))
971 return E_NON_EXISTENT;
973 command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID);
974 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
975 sqlite3_bind_int(query,1, domainState);
976 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
978 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Step error code:"),DLT_INT(eCode));
979 return E_DATABASE_ERROR;
982 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
984 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
985 return E_DATABASE_ERROR;
988 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changDomainStateDB changed domainState of domain:"),DLT_INT(domainID),DLT_STRING("to:"),DLT_INT(domainState));
994 am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
998 sqlite3_stmt* query=NULL;
1000 std::string command;
1002 if (!existSink(sinkID))
1004 return E_NON_EXISTENT;
1006 command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID);
1007 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1008 sqlite3_bind_int(query,1, muteState);
1009 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1011 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:"),DLT_INT(eCode));
1012 return E_DATABASE_ERROR;
1013 } assert(sinkID!=0);
1015 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1017 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:"),DLT_INT(eCode));
1018 return E_DATABASE_ERROR;
1021 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(muteState));
1023 if(mDatabaseObserver) mDatabaseObserver->sinkMuteStateChanged(sinkID,muteState);
1030 am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
1032 //todo: add checks if soundproperty exists!
1035 sqlite3_stmt* query=NULL;
1037 std::string command;
1039 if (!existSink(sinkID))
1041 return E_NON_EXISTENT;
1043 command = "UPDATE SinkMainSoundProperty" + i2s(sinkID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1044 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1045 sqlite3_bind_int(query,1, soundProperty.value);
1046 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1048 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1049 return E_DATABASE_ERROR;
1050 } assert(sinkID!=0);
1052 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1054 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1055 return E_DATABASE_ERROR;
1058 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));
1059 if (mDatabaseObserver) mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID,soundProperty);
1065 am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
1067 //todo: add checks if soundproperty exists!
1068 assert(sourceID!=0);
1070 sqlite3_stmt* query=NULL;
1072 std::string command;
1074 if (!existSource(sourceID))
1076 return E_NON_EXISTENT;
1078 command = "UPDATE SourceMainSoundProperty" + i2s(sourceID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
1079 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1080 sqlite3_bind_int(query,1, soundProperty.value);
1081 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1083 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1084 return E_DATABASE_ERROR;
1087 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1089 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1090 return E_DATABASE_ERROR;
1093 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));
1095 if(mDatabaseObserver) mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID,soundProperty);
1101 am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
1103 assert(sourceID!=0);
1105 sqlite3_stmt* query=NULL;
1107 std::string command;
1109 if (!existSource(sourceID))
1111 return E_NON_EXISTENT;
1113 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID);
1114 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1115 sqlite3_bind_int(query,1, availability.availability);
1116 sqlite3_bind_int(query,2, availability.availabilityReason);
1117 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1119 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:"),DLT_INT(eCode));
1120 return E_DATABASE_ERROR;
1123 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1125 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:"),DLT_INT(eCode));
1126 return E_DATABASE_ERROR;
1129 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));
1131 if (mDatabaseObserver && sourceVisible(sourceID)) mDatabaseObserver->sourceAvailabilityChanged(sourceID,availability);
1137 am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property)
1139 sqlite3_stmt* query=NULL;
1141 std::string command="UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?";
1143 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1144 sqlite3_bind_int(query,1, property.value);
1145 sqlite3_bind_int(query,2, property.type);
1147 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1149 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
1150 return E_DATABASE_ERROR;
1154 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1156 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
1157 return E_DATABASE_ERROR;
1160 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSystemPropertyDB changed system property"));
1162 if(mDatabaseObserver) mDatabaseObserver->systemPropertyChanged(property);
1169 am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
1171 assert(mainConnectionID!=0);
1173 if (!existMainConnection(mainConnectionID))
1175 return E_NON_EXISTENT;
1177 std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
1178 std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID);
1179 if(!sqQuery(command)) return E_DATABASE_ERROR;
1180 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1181 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeMainConnectionDB removed:"),DLT_INT(mainConnectionID));
1182 if (mDatabaseObserver) mDatabaseObserver->numberOfMainConnectionsChanged();
1188 am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID)
1192 if (!existSink(sinkID))
1194 return E_NON_EXISTENT;
1196 std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID);
1197 std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID);
1198 std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID);
1199 std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID);
1200 if(!sqQuery(command)) return E_DATABASE_ERROR;
1201 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1202 if(!sqQuery(command2)) return E_DATABASE_ERROR;
1203 if(!sqQuery(command3)) return E_DATABASE_ERROR;
1204 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkDB removed:"),DLT_INT(sinkID));
1206 if (mDatabaseObserver!=NULL) mDatabaseObserver->removedSink(sinkID);
1213 am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID)
1215 assert(sourceID!=0);
1217 if (!existSource(sourceID))
1219 return E_NON_EXISTENT;
1221 std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
1222 std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID);
1223 std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID);
1224 std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID);
1225 if(!sqQuery(command)) return E_DATABASE_ERROR;
1226 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1227 if(!sqQuery(command2)) return E_DATABASE_ERROR;
1228 if(!sqQuery(command3)) return E_DATABASE_ERROR;
1229 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceDB removed:"),DLT_INT(sourceID));
1230 if(mDatabaseObserver) mDatabaseObserver->removedSource(sourceID);
1236 am_Error_e DatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID)
1238 assert(gatewayID!=0);
1240 if (!existGateway(gatewayID))
1242 return E_NON_EXISTENT;
1244 std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
1245 if(!sqQuery(command)) return E_DATABASE_ERROR;
1246 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeGatewayDB removed:"),DLT_INT(gatewayID));
1247 if(mDatabaseObserver) mDatabaseObserver->removeGateway(gatewayID);
1253 am_Error_e DatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
1255 //todo: implement crossdfader
1262 am_Error_e DatabaseHandler::removeDomainDB(const am_domainID_t domainID)
1264 assert(domainID!=0);
1266 if (!existDomain(domainID))
1268 return E_NON_EXISTENT;
1270 std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID);
1271 if(!sqQuery(command)) return E_DATABASE_ERROR;
1272 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeDomainDB removed:"),DLT_INT(domainID));
1273 if(mDatabaseObserver) mDatabaseObserver->removeDomain(domainID);
1277 am_Error_e DatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID)
1279 assert(sinkClassID!=0);
1281 if (!existSinkClass(sinkClassID))
1283 return E_NON_EXISTENT;
1285 std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
1286 std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID);
1287 if(!sqQuery(command)) return E_DATABASE_ERROR;
1288 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1290 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSinkClassDB removed:"),DLT_INT(sinkClassID));
1291 if (mDatabaseObserver) mDatabaseObserver->numberOfSinkClassesChanged();
1296 am_Error_e DatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID)
1298 assert(sourceClassID!=0);
1300 if (!existSourceClass(sourceClassID))
1302 return E_NON_EXISTENT;
1304 std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
1305 std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID);
1306 if(!sqQuery(command)) return E_DATABASE_ERROR;
1307 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1308 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeSourceClassDB removed:"),DLT_INT(sourceClassID));
1310 if (mDatabaseObserver) mDatabaseObserver->numberOfSourceClassesChanged();
1314 am_Error_e DatabaseHandler::removeConnection(const am_connectionID_t connectionID)
1316 assert(connectionID!=0);
1318 std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID);
1319 std::string command1 = "DROP table SourceClassProperties" + i2s(connectionID);
1320 if(!sqQuery(command)) return E_DATABASE_ERROR;
1321 if(!sqQuery(command1)) return E_DATABASE_ERROR;
1322 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::removeConnection removed:"),DLT_INT(connectionID));
1328 am_Error_e DatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
1330 assert(sourceID!=0);
1332 if (!existSource(sourceID))
1334 return E_NON_EXISTENT;
1336 sqlite3_stmt* query=NULL;
1338 am_ClassProperty_s propertyTemp;
1339 std::string command= "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE)+ " WHERE sourceID=" + (i2s(sourceID));
1340 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1342 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1344 classInfo.sourceClassID=sqlite3_column_int(query,0);
1347 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1349 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1350 return E_DATABASE_ERROR;
1353 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1355 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1356 return E_DATABASE_ERROR;
1359 command= "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE)+ " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID));
1360 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1362 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1364 classInfo.name=std::string((const char*)sqlite3_column_text(query,0));
1367 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1369 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1370 return E_DATABASE_ERROR;
1373 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1375 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1376 return E_DATABASE_ERROR;
1379 //read out Properties
1380 command= "SELECT classProperty, value FROM SourceClassProperties"+ i2s(classInfo.sourceClassID);
1381 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1382 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1384 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(query,0);
1385 propertyTemp.value=sqlite3_column_int(query,1);
1386 classInfo.listClassProperties.push_back(propertyTemp);
1389 if(eCode!=SQLITE_DONE)
1391 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1392 return E_DATABASE_ERROR;
1395 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1397 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1398 return E_DATABASE_ERROR;
1405 am_Error_e DatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass)
1407 assert(sinkClass.sinkClassID!=0);
1408 assert(!sinkClass.listClassProperties.empty());
1411 sqlite3_stmt* query=NULL;
1414 //check if the ID already exists
1415 if(!existSinkClass(sinkClass.sinkClassID)) return E_NON_EXISTENT;
1417 //fill ConnectionFormats
1418 std::string command="UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;";
1419 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1420 std::vector<am_ClassProperty_s>::const_iterator Iterator=sinkClass.listClassProperties.begin();
1421 for(;Iterator<sinkClass.listClassProperties.end();++Iterator)
1423 sqlite3_bind_int(query,1, Iterator->value);
1424 sqlite3_bind_int(query,2, Iterator->classProperty);
1425 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1427 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"),DLT_INT(eCode));
1428 return E_DATABASE_ERROR;
1430 sqlite3_reset(query);
1433 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1435 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1436 return E_DATABASE_ERROR;
1439 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1445 am_Error_e DatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass)
1447 assert(sourceClass.sourceClassID!=0);
1448 assert(!sourceClass.listClassProperties.empty());
1451 sqlite3_stmt* query=NULL;
1454 //check if the ID already exists
1455 if(!existSourceClass(sourceClass.sourceClassID)) return E_NON_EXISTENT;
1457 //fill ConnectionFormats
1458 std::string command="UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;";
1459 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1460 std::vector<am_ClassProperty_s>::const_iterator Iterator=sourceClass.listClassProperties.begin();
1461 for(;Iterator<sourceClass.listClassProperties.end();++Iterator)
1463 sqlite3_bind_int(query,1, Iterator->value);
1464 sqlite3_bind_int(query,2, Iterator->classProperty);
1465 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1467 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:"),DLT_INT(eCode));
1468 return E_DATABASE_ERROR;
1470 sqlite3_reset(query);
1473 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1475 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1476 return E_DATABASE_ERROR;
1479 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"));
1485 am_Error_e DatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
1489 if (!existSink(sinkID))
1491 return E_NON_EXISTENT;
1493 sqlite3_stmt* query=NULL;
1495 am_ClassProperty_s propertyTemp;
1496 std::string command= "SELECT sinkClassID FROM " + std::string(SINK_TABLE)+ " WHERE sinkID=" + (i2s(sinkID));
1497 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1499 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1501 sinkClass.sinkClassID=sqlite3_column_int(query,0);
1504 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1506 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1507 return E_DATABASE_ERROR;
1510 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1512 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1513 return E_DATABASE_ERROR;
1516 command= "SELECT name FROM " + std::string(SINK_CLASS_TABLE)+ " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID));
1517 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1519 if((eCode=sqlite3_step(query))==SQLITE_ROW)
1521 sinkClass.name=std::string((const char*)sqlite3_column_text(query,0));
1524 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
1526 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1527 return E_DATABASE_ERROR;
1530 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1532 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1533 return E_DATABASE_ERROR;
1536 //read out Properties
1537 command= "SELECT classProperty, value FROM SinkClassProperties"+ i2s(sinkClass.sinkClassID);
1538 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1539 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1541 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(query,0);
1542 propertyTemp.value=sqlite3_column_int(query,1);
1543 sinkClass.listClassProperties.push_back(propertyTemp);
1546 if(eCode!=SQLITE_DONE)
1548 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE error code:"),DLT_INT(eCode));
1549 return E_DATABASE_ERROR;
1552 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1554 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1555 return E_DATABASE_ERROR;
1562 am_Error_e DatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
1564 assert(gatewayID!=0);
1565 if (!existGateway(gatewayID))
1567 return E_NON_EXISTENT;
1569 sqlite3_stmt* query=NULL, *qSinkConnectionFormat=NULL, *qSourceConnectionFormat=NULL;
1571 am_ConnectionFormat_e tempConnectionFormat;
1572 std::string command= "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID="+i2s(gatewayID);
1573 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1575 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1577 gatewayData.name=std::string((const char*)sqlite3_column_text(query,0));
1578 gatewayData.sinkID=sqlite3_column_int(query,1);
1579 gatewayData.sourceID=sqlite3_column_int(query,2);
1580 gatewayData.domainSinkID=sqlite3_column_int(query,3);
1581 gatewayData.domainSourceID=sqlite3_column_int(query,4);
1582 gatewayData.controlDomainID=sqlite3_column_int(query,5);
1583 gatewayData.gatewayID=sqlite3_column_int(query,6);
1586 ListConnectionFormat::const_iterator iter=mListConnectionFormat.begin();
1587 iter=mListConnectionFormat.find(gatewayData.gatewayID);
1588 if (iter == mListConnectionFormat.end())
1590 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB database error with convertionFormat"));
1591 return E_DATABASE_ERROR;
1593 gatewayData.convertionMatrix=iter->second;
1595 //read out the connectionFormats
1596 std::string commandConnectionFormat= "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID);
1597 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSourceConnectionFormat,NULL);
1598 while((eCode=sqlite3_step(qSourceConnectionFormat))==SQLITE_ROW)
1600 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSourceConnectionFormat,0);
1601 gatewayData.listSourceFormats.push_back(tempConnectionFormat);
1604 if((eCode=sqlite3_finalize(qSourceConnectionFormat))!=SQLITE_OK)
1606 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1607 return E_DATABASE_ERROR;
1610 //read out sound properties
1611 commandConnectionFormat= "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID);
1612 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSinkConnectionFormat,NULL);
1613 while((eCode=sqlite3_step(qSinkConnectionFormat))==SQLITE_ROW)
1615 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSinkConnectionFormat,0);
1616 gatewayData.listSinkFormats.push_back(tempConnectionFormat);
1619 if((eCode=sqlite3_finalize(qSinkConnectionFormat))!=SQLITE_OK)
1621 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1622 return E_DATABASE_ERROR;
1627 if(eCode!=SQLITE_DONE)
1629 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE error code:"),DLT_INT(eCode));
1630 return E_DATABASE_ERROR;
1633 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1635 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:"),DLT_INT(eCode));
1636 return E_DATABASE_ERROR;
1645 am_Error_e DatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
1647 //todo: implement crossfader
1649 (void)crossfaderData;
1655 am_Error_e DatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
1657 assert(domainID!=0);
1659 if (!existDomain(domainID))
1661 return E_NON_EXISTENT;
1663 sqlite3_stmt* query=NULL;
1666 std::string command= "SELECT sinkID FROM " + std::string(SINK_TABLE)+ " WHERE reserved=0 AND domainID=" + (i2s(domainID));
1667 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1669 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1671 temp=sqlite3_column_int(query,0);
1672 listSinkID.push_back(temp);
1675 if(eCode!=SQLITE_DONE)
1677 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE error code:"),DLT_INT(eCode));
1678 return E_DATABASE_ERROR;
1681 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1683 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1684 return E_DATABASE_ERROR;
1692 am_Error_e DatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
1694 assert(domainID!=0);
1695 listSourceID.clear();
1696 if (!existDomain(domainID))
1698 return E_NON_EXISTENT;
1700 sqlite3_stmt* query=NULL;
1703 std::string command= "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
1705 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1707 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1709 temp=sqlite3_column_int(query,0);
1710 listSourceID.push_back(temp);
1713 if(eCode!=SQLITE_DONE)
1715 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE error code:"),DLT_INT(eCode));
1716 return E_DATABASE_ERROR;
1719 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1721 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1722 return E_DATABASE_ERROR;
1730 am_Error_e DatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listGatewaysID) const
1732 //todo: implement crossfader
1733 (void)listGatewaysID;
1741 am_Error_e DatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
1743 assert(domainID!=0);
1744 listGatewaysID.clear();
1745 if (!existDomain(domainID))
1747 return E_NON_EXISTENT;
1749 sqlite3_stmt* query=NULL;
1751 am_gatewayID_t temp;
1753 std::string command= "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" +i2s(domainID);
1754 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1756 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1758 temp=sqlite3_column_int(query,0);
1759 listGatewaysID.push_back(temp);
1762 if(eCode!=SQLITE_DONE)
1764 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:"),DLT_INT(eCode));
1765 return E_DATABASE_ERROR;
1768 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1770 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:"),DLT_INT(eCode));
1771 return E_DATABASE_ERROR;
1779 am_Error_e DatabaseHandler::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
1781 listMainConnections.clear();
1782 sqlite3_stmt *query=NULL, *query1=NULL, *query2=NULL;
1783 int eCode=0, eCode1=0, eCode2=0;
1784 am_MainConnection_s temp;
1785 am_RoutingElement_s tempRoute;
1787 std::string command= "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
1788 std::string command1= "SELECT connectionID FROM MainConnectionRoute";
1789 std::string command2= "SELECT sourceID, sinkID, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=?";
1790 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1791 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&query2,NULL);
1793 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1795 temp.connectionID=sqlite3_column_int(query,0);
1796 temp.route.sourceID=sqlite3_column_int(query,1);
1797 temp.route.sinkID=sqlite3_column_int(query,2);
1798 temp.connectionState=(am_ConnectionState_e)sqlite3_column_int(query,3);
1799 temp.delay=sqlite3_column_int(query,4);
1800 std::string statement=command1 + i2s(temp.connectionID);
1801 sqlite3_prepare_v2(mDatabase,statement.c_str(),-1,&query1,NULL);
1802 while((eCode1=sqlite3_step(query1))==SQLITE_ROW) //todo: check results of eCode1, eCode2
1804 int k=sqlite3_column_int(query1,0);
1805 sqlite3_bind_int(query2,1,k);
1806 while((eCode2=sqlite3_step(query2))==SQLITE_ROW)
1808 tempRoute.sourceID=sqlite3_column_int(query2,0);
1809 tempRoute.sinkID=sqlite3_column_int(query2,1);
1810 tempRoute.connectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(query2,2);
1811 getDomainOfSource(tempRoute.sourceID,tempRoute.domainID);
1812 temp.route.route.push_back(tempRoute);
1814 sqlite3_reset(query2);
1816 listMainConnections.push_back(temp);
1819 if(eCode!=SQLITE_DONE)
1821 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE error code:"),DLT_INT(eCode));
1822 return E_DATABASE_ERROR;
1825 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1827 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainConnections SQLITE Finalize error code:"),DLT_INT(eCode));
1828 return E_DATABASE_ERROR;
1836 am_Error_e DatabaseHandler::getListDomains(std::vector<am_Domain_s> & listDomains) const
1838 listDomains.clear();
1839 sqlite3_stmt* query=NULL;
1842 std::string command= "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0";
1843 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1845 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1847 temp.domainID=sqlite3_column_int(query,0);
1848 temp.name=std::string((const char*)sqlite3_column_text(query,1));
1849 temp.busname=std::string((const char*)sqlite3_column_text(query,2));
1850 temp.nodename=std::string((const char*)sqlite3_column_text(query,3));
1851 temp.early=sqlite3_column_int(query,4);
1852 temp.complete=sqlite3_column_int(query,5);
1853 temp.state=(am_DomainState_e)sqlite3_column_int(query,6);
1854 listDomains.push_back(temp);
1857 if(eCode!=SQLITE_DONE)
1859 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE error code:"),DLT_INT(eCode));
1860 return E_DATABASE_ERROR;
1863 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1865 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListDomains SQLITE Finalize error code:"),DLT_INT(eCode));
1866 return E_DATABASE_ERROR;
1874 am_Error_e DatabaseHandler::getListConnections(std::vector<am_Connection_s> & listConnections) const
1876 listConnections.clear();
1877 sqlite3_stmt* query=NULL;
1879 am_Connection_s temp;
1880 std::string command= "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE)+" WHERE reserved=0";
1881 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1883 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1885 temp.connectionID=sqlite3_column_int(query,0);
1886 temp.sourceID=sqlite3_column_int(query,1);
1887 temp.sinkID=sqlite3_column_int(query,2);
1888 temp.delay=sqlite3_column_int(query,3);
1889 temp.connectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(query,4);
1890 listConnections.push_back(temp);
1893 if(eCode!=SQLITE_DONE)
1895 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE error code:"),DLT_INT(eCode));
1896 return E_DATABASE_ERROR;
1899 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1901 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListConnections SQLITE Finalize error code:"),DLT_INT(eCode));
1902 return E_DATABASE_ERROR;
1910 am_Error_e DatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const
1913 sqlite3_stmt* query=NULL, *qConnectionFormat=NULL, *qSoundProperty=NULL, *qMAinSoundProperty=NULL;
1916 am_ConnectionFormat_e tempConnectionFormat;
1917 am_SoundProperty_s tempSoundProperty;
1918 am_MainSoundProperty_s tempMainSoundProperty;
1919 std::string command= "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE)+ " WHERE reserved=0";
1920 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
1922 while((eCode=sqlite3_step(query))==SQLITE_ROW)
1924 temp.name=std::string((const char*)sqlite3_column_text(query,0));
1925 temp.domainID=sqlite3_column_int(query,1);
1926 temp.sinkClassID=sqlite3_column_int(query,2);
1927 temp.volume=sqlite3_column_int(query,3);
1928 temp.visible=sqlite3_column_int(query,4);
1929 temp.available.availability=(am_Availablility_e)sqlite3_column_int(query,5);
1930 temp.available.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,6);
1931 temp.muteState=(am_MuteState_e)sqlite3_column_int(query,7);
1932 temp.mainVolume=sqlite3_column_int(query,8);
1933 temp.sinkID=sqlite3_column_int(query,9);
1935 //read out the connectionFormats
1936 std::string commandConnectionFormat= "SELECT soundFormat FROM SinkConnectionFormat"+ i2s(temp.sinkID);
1937 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qConnectionFormat,NULL);
1938 while((eCode=sqlite3_step(qConnectionFormat))==SQLITE_ROW)
1940 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qConnectionFormat,0);
1941 temp.listConnectionFormats.push_back(tempConnectionFormat);
1944 if((eCode=sqlite3_finalize(qConnectionFormat))!=SQLITE_OK)
1946 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1947 return E_DATABASE_ERROR;
1950 //read out sound properties
1951 std::string commandSoundProperty= "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
1952 sqlite3_prepare_v2(mDatabase,commandSoundProperty.c_str(),-1,&qSoundProperty,NULL);
1953 while((eCode=sqlite3_step(qSoundProperty))==SQLITE_ROW)
1955 tempSoundProperty.type=(am_SoundPropertyType_e)sqlite3_column_int(qSoundProperty,0);
1956 tempSoundProperty.value=sqlite3_column_int(qSoundProperty,1);
1957 temp.listSoundProperties.push_back(tempSoundProperty);
1960 if((eCode=sqlite3_finalize(qSoundProperty))!=SQLITE_OK)
1962 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1963 return E_DATABASE_ERROR;
1966 //read out MainSoundProperties
1967 std::string commandMainSoundProperty= "SELECT soundPropertyType, value FROM SinkMainSoundProperty"+ i2s(temp.sinkID);
1968 sqlite3_prepare_v2(mDatabase,commandMainSoundProperty.c_str(),-1,&qMAinSoundProperty,NULL);
1969 while((eCode=sqlite3_step(qMAinSoundProperty))==SQLITE_ROW)
1971 tempMainSoundProperty.type=(am_MainSoundPropertyType_e)sqlite3_column_int(qMAinSoundProperty,0);
1972 tempMainSoundProperty.value=sqlite3_column_int(qMAinSoundProperty,1);
1973 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
1976 if((eCode=sqlite3_finalize(qMAinSoundProperty))!=SQLITE_OK)
1978 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1979 return E_DATABASE_ERROR;
1981 listSinks.push_back(temp);
1982 temp.listConnectionFormats.clear();
1983 temp.listMainSoundProperties.clear();
1984 temp.listSoundProperties.clear();
1987 if(eCode!=SQLITE_DONE)
1989 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"),DLT_INT(eCode));
1990 return E_DATABASE_ERROR;
1993 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
1995 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
1996 return E_DATABASE_ERROR;
2004 am_Error_e DatabaseHandler::getListSources(std::vector<am_Source_s> & listSources) const
2006 listSources.clear();
2007 sqlite3_stmt* query=NULL, *qConnectionFormat=NULL, *qSoundProperty=NULL, *qMAinSoundProperty=NULL;
2010 am_ConnectionFormat_e tempConnectionFormat;
2011 am_SoundProperty_s tempSoundProperty;
2012 am_MainSoundProperty_s tempMainSoundProperty;
2013 std::string command= "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) +" WHERE reserved=0";
2014 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2016 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2018 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2019 temp.domainID=sqlite3_column_int(query,1);
2020 temp.sourceClassID=sqlite3_column_int(query,2);
2021 temp.sourceState=(am_SourceState_e)sqlite3_column_int(query,3);
2022 temp.volume=sqlite3_column_int(query,4);
2023 temp.visible=sqlite3_column_int(query,5);
2024 temp.available.availability=(am_Availablility_e)sqlite3_column_int(query,6);
2025 temp.available.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,7);
2026 temp.interruptState=(am_InterruptState_e)sqlite3_column_int(query,8);
2027 temp.sourceID=sqlite3_column_int(query,9);
2029 //read out the connectionFormats
2030 std::string commandConnectionFormat= "SELECT soundFormat FROM SourceConnectionFormat"+ i2s(temp.sourceID);
2031 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qConnectionFormat,NULL);
2032 while((eCode=sqlite3_step(qConnectionFormat))==SQLITE_ROW)
2034 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qConnectionFormat,0);
2035 temp.listConnectionFormats.push_back(tempConnectionFormat);
2038 if((eCode=sqlite3_finalize(qConnectionFormat))!=SQLITE_OK)
2040 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2041 return E_DATABASE_ERROR;
2044 //read out sound properties
2045 std::string commandSoundProperty= "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
2046 sqlite3_prepare_v2(mDatabase,commandSoundProperty.c_str(),-1,&qSoundProperty,NULL);
2047 while((eCode=sqlite3_step(qSoundProperty))==SQLITE_ROW)
2049 tempSoundProperty.type=(am_SoundPropertyType_e)sqlite3_column_int(qSoundProperty,0);
2050 tempSoundProperty.value=sqlite3_column_int(qSoundProperty,1);
2051 temp.listSoundProperties.push_back(tempSoundProperty);
2054 if((eCode=sqlite3_finalize(qSoundProperty))!=SQLITE_OK)
2056 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2057 return E_DATABASE_ERROR;
2060 //read out MainSoundProperties
2061 std::string commandMainSoundProperty= "SELECT soundPropertyType, value FROM SourceMainSoundProperty"+ i2s(temp.sourceID);
2062 sqlite3_prepare_v2(mDatabase,commandMainSoundProperty.c_str(),-1,&qMAinSoundProperty,NULL);
2063 while((eCode=sqlite3_step(qMAinSoundProperty))==SQLITE_ROW)
2065 tempMainSoundProperty.type=(am_MainSoundPropertyType_e)sqlite3_column_int(qMAinSoundProperty,0);
2066 tempMainSoundProperty.value=sqlite3_column_int(qMAinSoundProperty,1);
2067 temp.listMainSoundProperties.push_back(tempMainSoundProperty);
2070 if((eCode=sqlite3_finalize(qMAinSoundProperty))!=SQLITE_OK)
2072 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2073 return E_DATABASE_ERROR;
2075 listSources.push_back(temp);
2076 temp.listConnectionFormats.clear();
2077 temp.listMainSoundProperties.clear();
2078 temp.listSoundProperties.clear();
2081 if(eCode!=SQLITE_DONE)
2083 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"),DLT_INT(eCode));
2084 return E_DATABASE_ERROR;
2087 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2089 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2090 return E_DATABASE_ERROR;
2098 am_Error_e DatabaseHandler::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
2100 listSourceClasses.clear();
2102 sqlite3_stmt* query=NULL, *subQuery=NULL;
2103 int eCode=0, eCode1;
2104 am_SourceClass_s classTemp;
2105 am_ClassProperty_s propertyTemp;
2107 std::string command= "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE);
2108 std::string command2;
2109 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2111 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2113 classTemp.sourceClassID=sqlite3_column_int(query,0);
2114 classTemp.name=std::string((const char*)sqlite3_column_text(query,1));
2116 //read out Properties
2117 command2="SELECT classProperty, value FROM SourceClassProperties"+ i2s(classTemp.sourceClassID);
2118 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&subQuery,NULL);
2120 while((eCode1=sqlite3_step(subQuery))==SQLITE_ROW)
2122 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(subQuery,0);
2123 propertyTemp.value=sqlite3_column_int(subQuery,1);
2124 classTemp.listClassProperties.push_back(propertyTemp);
2127 if(eCode1!=SQLITE_DONE)
2129 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode1));
2130 return E_DATABASE_ERROR;
2133 if((eCode1=sqlite3_finalize(subQuery))!=SQLITE_OK)
2135 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode1));
2136 return E_DATABASE_ERROR;
2138 listSourceClasses.push_back(classTemp);
2141 if(eCode!=SQLITE_DONE)
2143 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2144 return E_DATABASE_ERROR;
2147 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2149 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2150 return E_DATABASE_ERROR;
2158 am_Error_e DatabaseHandler::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
2160 //todo: implement crossfaders
2161 (void)listCrossfaders;
2167 am_Error_e DatabaseHandler::getListGateways(std::vector<am_Gateway_s> & listGateways) const
2169 listGateways.clear();
2170 sqlite3_stmt* query=NULL, *qSinkConnectionFormat=NULL, *qSourceConnectionFormat=NULL;
2173 am_ConnectionFormat_e tempConnectionFormat;
2175 std::string command= "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
2176 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2178 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2180 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2181 temp.sinkID=sqlite3_column_int(query,1);
2182 temp.sourceID=sqlite3_column_int(query,2);
2183 temp.domainSinkID=sqlite3_column_int(query,3);
2184 temp.domainSourceID=sqlite3_column_int(query,4);
2185 temp.controlDomainID=sqlite3_column_int(query,5);
2186 temp.gatewayID=sqlite3_column_int(query,6);
2189 ListConnectionFormat::const_iterator iter=mListConnectionFormat.begin();
2190 iter=mListConnectionFormat.find(temp.gatewayID);
2191 if (iter == mListConnectionFormat.end())
2193 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways database error with convertionFormat"));
2194 return E_DATABASE_ERROR;
2196 temp.convertionMatrix=iter->second;
2198 //read out the connectionFormats
2199 std::string commandConnectionFormat= "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
2200 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSourceConnectionFormat,NULL);
2201 while((eCode=sqlite3_step(qSourceConnectionFormat))==SQLITE_ROW)
2203 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSourceConnectionFormat,0);
2204 temp.listSourceFormats.push_back(tempConnectionFormat);
2207 if((eCode=sqlite3_finalize(qSourceConnectionFormat))!=SQLITE_OK)
2209 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2210 return E_DATABASE_ERROR;
2213 //read out sound properties
2214 commandConnectionFormat= "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
2215 sqlite3_prepare_v2(mDatabase,commandConnectionFormat.c_str(),-1,&qSinkConnectionFormat,NULL);
2216 while((eCode=sqlite3_step(qSinkConnectionFormat))==SQLITE_ROW)
2218 tempConnectionFormat=(am_ConnectionFormat_e)sqlite3_column_int(qSinkConnectionFormat,0);
2219 temp.listSinkFormats.push_back(tempConnectionFormat);
2222 if((eCode=sqlite3_finalize(qSinkConnectionFormat))!=SQLITE_OK)
2224 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2225 return E_DATABASE_ERROR;
2228 listGateways.push_back(temp);
2229 temp.listSinkFormats.clear();
2230 temp.listSourceFormats.clear();
2233 if(eCode!=SQLITE_DONE)
2235 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE error code:"),DLT_INT(eCode));
2236 return E_DATABASE_ERROR;
2239 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2241 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListGateways SQLITE Finalize error code:"),DLT_INT(eCode));
2242 return E_DATABASE_ERROR;
2250 am_Error_e DatabaseHandler::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
2252 listSinkClasses.clear();
2254 sqlite3_stmt* query=NULL, *subQuery=NULL;
2256 am_SinkClass_s classTemp;
2257 am_ClassProperty_s propertyTemp;
2259 std::string command= "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE);
2260 std::string command2;
2261 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2263 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2265 classTemp.sinkClassID=sqlite3_column_int(query,0);
2266 classTemp.name=std::string((const char*)sqlite3_column_text(query,1));
2268 //read out Properties
2269 command2="SELECT classProperty, value FROM SinkClassProperties"+ i2s(classTemp.sinkClassID);
2270 sqlite3_prepare_v2(mDatabase,command2.c_str(),-1,&subQuery,NULL);
2272 while((eCode=sqlite3_step(subQuery))==SQLITE_ROW)
2274 propertyTemp.classProperty=(am_ClassProperty_e)sqlite3_column_int(subQuery,0);
2275 propertyTemp.value=sqlite3_column_int(subQuery,1);
2276 classTemp.listClassProperties.push_back(propertyTemp);
2279 if(eCode!=SQLITE_DONE)
2281 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2282 return E_DATABASE_ERROR;
2285 if((eCode=sqlite3_finalize(subQuery))!=SQLITE_OK)
2287 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2288 return E_DATABASE_ERROR;
2290 listSinkClasses.push_back(classTemp);
2293 if(eCode!=SQLITE_DONE)
2295 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE error code:"),DLT_INT(eCode));
2296 return E_DATABASE_ERROR;
2299 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2301 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:"),DLT_INT(eCode));
2302 return E_DATABASE_ERROR;
2310 am_Error_e DatabaseHandler::getListVisibleMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
2312 listConnections.clear();
2313 sqlite3_stmt *query=NULL;
2315 am_MainConnectionType_s temp;
2317 std::string command= "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE);
2318 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2320 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2322 temp.mainConnectionID=sqlite3_column_int(query,0);
2323 temp.sourceID=sqlite3_column_int(query,1);
2324 temp.sinkID=sqlite3_column_int(query,2);
2325 temp.connectionState=(am_ConnectionState_e)sqlite3_column_int(query,3);
2326 temp.delay=sqlite3_column_int(query,4);
2327 listConnections.push_back(temp);
2330 if(eCode!=SQLITE_DONE)
2332 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE error code:"),DLT_INT(eCode));
2333 return E_DATABASE_ERROR;
2336 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2338 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:"),DLT_INT(eCode));
2339 return E_DATABASE_ERROR;
2347 am_Error_e DatabaseHandler::getListMainSinks(std::vector<am_SinkType_s> & listMainSinks) const
2349 listMainSinks.clear();
2350 sqlite3_stmt* query=NULL;
2354 std::string command= "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0";
2355 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2357 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2359 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2360 temp.sinkID=sqlite3_column_int(query,1);
2361 temp.availability.availability=(am_Availablility_e)sqlite3_column_int(query,2);
2362 temp.availability.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,3);
2363 temp.muteState=(am_MuteState_e)sqlite3_column_int(query,4);
2364 temp.volume=sqlite3_column_int(query,5);
2365 temp.sinkClassID=sqlite3_column_int(query,6);
2366 listMainSinks.push_back(temp);
2369 if(eCode!=SQLITE_DONE)
2371 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE error code:"),DLT_INT(eCode));
2372 return E_DATABASE_ERROR;
2375 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2377 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSinks SQLITE Finalize error code:"),DLT_INT(eCode));
2378 return E_DATABASE_ERROR;
2386 am_Error_e DatabaseHandler::getListMainSources(std::vector<am_SourceType_s> & listMainSources) const
2388 listMainSources.clear();
2389 sqlite3_stmt* query=NULL;
2391 am_SourceType_s temp;
2392 std::string command= "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1";
2393 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2395 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2397 temp.name=std::string((const char*)sqlite3_column_text(query,0));
2398 temp.sourceClassID=sqlite3_column_int(query,1);
2399 temp.availability.availability=(am_Availablility_e)sqlite3_column_int(query,2);
2400 temp.availability.availabilityReason=(am_AvailabilityReason_e)sqlite3_column_int(query,3);
2401 temp.sourceID=sqlite3_column_int(query,4);
2403 listMainSources.push_back(temp);
2406 if(eCode!=SQLITE_DONE)
2408 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE error code:"),DLT_INT(eCode));
2409 return E_DATABASE_ERROR;
2412 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2414 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSources SQLITE Finalize error code:"),DLT_INT(eCode));
2415 return E_DATABASE_ERROR;
2423 am_Error_e DatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
2426 if (!existSink(sinkID)) return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2427 listSoundProperties.clear();
2429 sqlite3_stmt* query=NULL;
2431 am_MainSoundProperty_s temp;
2432 std::string command= "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID);
2433 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2435 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2437 temp.type=(am_MainSoundPropertyType_e)sqlite3_column_int(query,0);
2438 temp.value=sqlite3_column_int(query,1);
2439 listSoundProperties.push_back(temp);
2442 if(eCode!=SQLITE_DONE)
2444 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"),DLT_INT(eCode));
2445 return E_DATABASE_ERROR;
2448 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2450 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2451 return E_DATABASE_ERROR;
2459 am_Error_e DatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
2461 assert(sourceID!=0);
2462 if (!existSource(sourceID)) return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences
2463 listSourceProperties.clear();
2465 sqlite3_stmt* query=NULL;
2467 am_MainSoundProperty_s temp;
2468 std::string command= "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID);
2469 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2471 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2473 temp.type=(am_MainSoundPropertyType_e)sqlite3_column_int(query,0);
2474 temp.value=sqlite3_column_int(query,1);
2475 listSourceProperties.push_back(temp);
2478 if(eCode!=SQLITE_DONE)
2480 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:"),DLT_INT(eCode));
2481 return E_DATABASE_ERROR;
2484 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2486 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2487 return E_DATABASE_ERROR;
2495 am_Error_e DatabaseHandler::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
2497 listSystemProperties.clear();
2499 sqlite3_stmt* query=NULL;
2501 am_SystemProperty_s temp;
2502 std::string command= "SELECT type, value FROM " + std::string(SYSTEM_TABLE);
2503 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2505 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2507 temp.type=(am_SystemPropertyType_e)sqlite3_column_int(query,0);
2508 temp.value=sqlite3_column_int(query,1);
2509 listSystemProperties.push_back(temp);
2512 if(eCode!=SQLITE_DONE)
2514 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE error code:"),DLT_INT(eCode));
2515 return E_DATABASE_ERROR;
2518 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2520 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2521 return E_DATABASE_ERROR;
2529 am_Error_e DatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
2531 assert(mainConnectionID!=0);
2533 sqlite3_stmt *query=NULL;
2536 std::string command= "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2537 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2539 while((eCode=sqlite3_step(query))==SQLITE_ROW)
2541 delay=sqlite3_column_int(query,0);
2544 if(eCode!=SQLITE_DONE)
2546 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE error code:"),DLT_INT(eCode));
2547 return E_DATABASE_ERROR;
2550 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2552 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
2553 return E_DATABASE_ERROR;
2556 if (delay==-1) return E_NOT_POSSIBLE;
2561 bool DatabaseHandler::sqQuery(const std::string& query)
2563 sqlite3_stmt* statement;
2565 if ((eCode=sqlite3_exec(mDatabase,query.c_str(),NULL,&statement,NULL))!= SQLITE_OK)
2567 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));
2573 bool DatabaseHandler::openDatabase()
2575 if (sqlite3_open_v2(mPath.c_str(),&mDatabase,SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK)
2577 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::openDatabase opened database"));
2580 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::openDatabase failed to open database"));
2584 am_Error_e DatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID)
2586 assert(connectionID!=0);
2588 sqlite3_stmt* query=NULL;
2590 std::string command="UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;";
2591 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2592 sqlite3_bind_int(query,1, delay);
2593 sqlite3_bind_int(query,2, connectionID);
2595 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2597 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:"),DLT_INT(eCode));
2598 return E_DATABASE_ERROR;
2601 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2603 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:"),DLT_INT(eCode));
2604 return E_DATABASE_ERROR;
2607 if(mDatabaseObserver) mDatabaseObserver->timingInformationChanged(connectionID,delay);
2612 am_Error_e DatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID)
2614 assert(connection.connectionID==0);
2615 assert(connection.sinkID!=0);
2616 assert(connection.sourceID!=0);
2617 //connection format is not checked, because it's project specific
2619 sqlite3_stmt* query=NULL;
2621 std::string command= "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)";
2623 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2624 sqlite3_bind_int(query,1, connection.sinkID);
2625 sqlite3_bind_int(query,2, connection.sourceID);
2626 sqlite3_bind_int(query,3, connection.delay);
2627 sqlite3_bind_int(query,4, connection.connectionFormat);
2628 sqlite3_bind_int(query,5, true);
2630 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2632 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
2633 return E_DATABASE_ERROR;
2636 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2638 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
2639 return E_DATABASE_ERROR;
2642 connectionID=sqlite3_last_insert_rowid(mDatabase);
2644 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterConnectionDB entered new connection sourceID:"), DLT_INT16(connection.sourceID),
2645 DLT_STRING("sinkID:"),DLT_INT16(connection.sinkID),
2646 DLT_STRING("sourceID:"),DLT_INT16(connection.sourceID),
2647 DLT_STRING("delay:"), DLT_INT16(connection.delay),
2648 DLT_STRING("connectionFormat:"),DLT_INT16(connection.connectionFormat),
2649 DLT_STRING("assigned ID:"),DLT_INT16(connectionID));
2653 am_Error_e DatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
2655 assert(sinkClass.sinkClassID<DYNAMIC_ID_BOUNDARY);
2656 assert(!sinkClass.listClassProperties.empty());
2657 assert(!sinkClass.name.empty());
2659 sqlite3_stmt* query=NULL;
2661 std::string command;
2663 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2664 if (sinkClass.sinkClassID==0 && !mFirstStaticSinkClass)
2666 command= "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name) VALUES (?)";
2670 //check if the ID already exists
2671 if(existSinkClass(sinkClass.sinkClassID)) return E_ALREADY_EXISTS;
2672 command= "INSERT INTO " + std::string(SINK_CLASS_TABLE) + "(name, sinkClassID) VALUES (?,?)";
2675 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2676 sqlite3_bind_text(query,1, sinkClass.name.c_str(),sinkClass.name.size(),SQLITE_STATIC);
2678 //if the ID is not created, we add it to the query
2679 if(sinkClass.sinkClassID!=0)
2681 sqlite3_bind_int(query,2, sinkClass.sinkClassID);
2684 //if the first static sink is entered, we need to set it onto the boundary
2685 else if(mFirstStaticSinkClass)
2687 sqlite3_bind_int(query,2, DYNAMIC_ID_BOUNDARY);
2688 mFirstStaticSinkClass=false;
2691 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2693 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"),DLT_INT(eCode));
2694 return E_DATABASE_ERROR;
2697 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2699 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2700 return E_DATABASE_ERROR;
2703 sinkClassID=sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2705 //now we need to create the additional tables:
2706 command="CREATE TABLE SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2707 assert(this->sqQuery(command));
2709 //fill ConnectionFormats
2710 command="INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)");
2711 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2712 std::vector<am_ClassProperty_s>::const_iterator Iterator=sinkClass.listClassProperties.begin();
2713 for(;Iterator<sinkClass.listClassProperties.end();++Iterator)
2715 sqlite3_bind_int(query,1, Iterator->classProperty);
2716 sqlite3_bind_int(query,2, Iterator->value);
2717 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2719 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Step error code:"),DLT_INT(eCode));
2720 return E_DATABASE_ERROR;
2722 sqlite3_reset(query);
2725 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2727 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2728 return E_DATABASE_ERROR;
2731 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSinkClassDB entered new sinkClass"));
2732 if (mDatabaseObserver) mDatabaseObserver->numberOfSinkClassesChanged();
2736 am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
2738 assert(sourceClass.sourceClassID<DYNAMIC_ID_BOUNDARY);
2739 assert(!sourceClass.listClassProperties.empty());
2740 assert(!sourceClass.name.empty());
2742 sqlite3_stmt* query=NULL;
2744 std::string command;
2746 //if sinkID is zero and the first Static Sink was already entered, the ID is created
2747 if (sourceClass.sourceClassID==0 && !mFirstStaticSourceClass)
2749 command= "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name) VALUES (?)";
2753 //check if the ID already exists
2754 if(existSourceClass(sourceClass.sourceClassID)) return E_ALREADY_EXISTS;
2755 command= "INSERT INTO " + std::string(SOURCE_CLASS_TABLE) + "(name, sourceClassID) VALUES (?,?)";
2758 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2759 sqlite3_bind_text(query,1, sourceClass.name.c_str(),sourceClass.name.size(),SQLITE_STATIC);
2761 //if the ID is not created, we add it to the query
2762 if(sourceClass.sourceClassID!=0)
2764 sqlite3_bind_int(query,2, sourceClass.sourceClassID);
2767 //if the first static sink is entered, we need to set it onto the boundary
2768 else if(mFirstStaticSourceClass)
2770 sqlite3_bind_int(query,2, DYNAMIC_ID_BOUNDARY);
2771 mFirstStaticSourceClass=false;
2774 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2776 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"),DLT_INT(eCode));
2777 return E_DATABASE_ERROR;
2780 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2782 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2783 return E_DATABASE_ERROR;
2786 sourceClassID=sqlite3_last_insert_rowid(mDatabase); //todo:change last_insert implementations for mulithread usage...
2788 //now we need to create the additional tables:
2789 command="CREATE TABLE SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty INTEGER, value INTEGER)");
2790 assert(sqQuery(command));
2792 //fill ConnectionFormats
2793 command="INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)");
2794 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2795 std::vector<am_ClassProperty_s>::const_iterator Iterator=sourceClass.listClassProperties.begin();
2796 for(;Iterator<sourceClass.listClassProperties.end();++Iterator)
2798 sqlite3_bind_int(query,1, Iterator->classProperty);
2799 sqlite3_bind_int(query,2, Iterator->value);
2800 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2802 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Step error code:"),DLT_INT(eCode));
2803 return E_DATABASE_ERROR;
2805 sqlite3_reset(query);
2808 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2810 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:"),DLT_INT(eCode));
2811 return E_DATABASE_ERROR;
2814 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSourceClassDB entered new sourceClass"));
2816 if (mDatabaseObserver) mDatabaseObserver->numberOfSourceClassesChanged();
2820 am_Error_e DatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
2822 sqlite3_stmt* query=NULL;
2824 std::vector<am_SystemProperty_s>::const_iterator listIterator =listSystemProperties.begin();
2825 std::string command= "DELETE * FROM " + std::string(SYSTEM_TABLE);
2828 command="INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)";
2830 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2831 for(;listIterator<listSystemProperties.end();++listIterator)
2833 sqlite3_bind_int(query,1, listIterator->type);
2834 sqlite3_bind_int(query,2, listIterator->value);
2836 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
2838 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Step error code:"),DLT_INT(eCode));
2839 return E_DATABASE_ERROR;
2842 sqlite3_reset(query);
2845 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
2847 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:"),DLT_INT(eCode));
2848 return E_DATABASE_ERROR;
2851 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::enterSystemProperties entered system properties"));
2855 bool DatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const
2857 sqlite3_stmt* query=NULL;
2858 std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID);
2860 bool returnVal=true;
2861 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2862 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2863 else if (eCode!=SQLITE_ROW)
2866 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
2868 sqlite3_finalize(query);
2872 bool DatabaseHandler::existSource(const am_sourceID_t sourceID) const
2874 sqlite3_stmt* query=NULL;
2875 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID);
2877 bool returnVal=true;
2878 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2879 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2880 else if (eCode!=SQLITE_ROW)
2883 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2885 sqlite3_finalize(query);
2889 bool DatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
2891 sqlite3_stmt* query=NULL;
2892 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)";
2894 bool returnVal=true;
2895 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2896 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2897 sqlite3_bind_int(query,2,sourceID);
2898 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2899 else if (eCode!=SQLITE_ROW)
2902 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2904 sqlite3_finalize(query);
2908 bool DatabaseHandler::existSourceName(const std::string & name) const
2910 sqlite3_stmt* query=NULL;
2911 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?";
2913 bool returnVal=true;
2914 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2915 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2916 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2917 else if (eCode!=SQLITE_ROW)
2920 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSource database error!:"), DLT_INT(eCode))
2922 sqlite3_finalize(query);
2926 bool DatabaseHandler::existSink(const am_sinkID_t sinkID) const
2928 sqlite3_stmt* query=NULL;
2929 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID);
2931 bool returnVal=true;
2932 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2933 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2934 else if (eCode!=SQLITE_ROW)
2937 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2939 sqlite3_finalize(query);
2943 bool DatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
2945 sqlite3_stmt* query=NULL;
2946 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)";
2948 bool returnVal=true;
2949 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2950 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2951 sqlite3_bind_int(query,2,sinkID);
2952 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2953 else if (eCode!=SQLITE_ROW)
2956 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2958 sqlite3_finalize(query);
2962 bool DatabaseHandler::existSinkName(const std::string & name) const
2964 sqlite3_stmt* query=NULL;
2965 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?";
2967 bool returnVal=true;
2968 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2969 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
2970 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2971 else if (eCode!=SQLITE_ROW)
2974 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSink database error!:"), DLT_INT(eCode))
2976 sqlite3_finalize(query);
2980 bool DatabaseHandler::existDomain(const am_domainID_t domainID) const
2982 sqlite3_stmt* query=NULL;
2983 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID);
2985 bool returnVal=true;
2986 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
2987 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
2988 else if (eCode!=SQLITE_ROW)
2991 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existDomain database error!:"), DLT_INT(eCode))
2993 sqlite3_finalize(query);
2997 bool DatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const
2999 sqlite3_stmt* query=NULL;
3000 std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID);
3002 bool returnVal=true;
3003 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3004 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3005 else if (eCode!=SQLITE_ROW)
3008 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existGateway database error!:"), DLT_INT(eCode))
3010 sqlite3_finalize(query);
3014 am_Error_e DatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
3016 assert(sourceID!=0);
3018 sqlite3_stmt* query=NULL;
3019 std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID);
3021 am_Error_e returnVal=E_DATABASE_ERROR;
3022 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3023 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3025 domainID=sqlite3_column_int(query,0);
3030 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainOfSource database error!:"), DLT_INT(eCode))
3032 sqlite3_finalize(query);
3037 bool DatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const
3039 sqlite3_stmt* query=NULL;
3040 std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID);
3042 bool returnVal=true;
3043 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3044 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3045 else if (eCode!=SQLITE_ROW)
3048 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3050 sqlite3_finalize(query);
3054 bool DatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const
3056 sqlite3_stmt* query=NULL;
3057 std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID);
3059 bool returnVal=true;
3060 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3061 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3062 else if (eCode!=SQLITE_ROW)
3065 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existSinkClass database error!:"), DLT_INT(eCode))
3067 sqlite3_finalize(query);
3071 am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay)
3073 assert(connectionID!=0);
3075 sqlite3_stmt *query=NULL, *queryMainConnections;
3077 std::string command= "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
3079 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3080 sqlite3_bind_int(query,1, delay);
3081 sqlite3_bind_int(query,2, connectionID);
3083 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3085 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:"),DLT_INT(eCode));
3086 return E_DATABASE_ERROR;
3089 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3091 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
3092 return E_DATABASE_ERROR;
3095 //now we need to find all mainConnections that use the changed connection and update their timing
3096 am_mainConnectionID_t mainConnectionID;
3097 am_timeSync_t tempDelay=0;
3099 command= "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE);
3100 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryMainConnections,NULL);
3102 while((eCode=sqlite3_step(queryMainConnections))==SQLITE_ROW)
3104 mainConnectionID=sqlite3_column_int(queryMainConnections,0);
3105 if(connectionPartofMainConnection(connectionID,mainConnectionID))
3107 tempDelay=calculateMainConnectionDelay(mainConnectionID);
3108 if ((error=changeDelayMainConnection(tempDelay,mainConnectionID))!= E_OK)
3115 if(eCode!=SQLITE_DONE)
3117 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"),DLT_INT(eCode));
3118 return E_DATABASE_ERROR;
3121 if((eCode=sqlite3_finalize(queryMainConnections))!=SQLITE_OK)
3123 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
3124 return E_DATABASE_ERROR;
3130 am_Error_e DatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID)
3132 assert(connectionID!=0);
3134 sqlite3_stmt *query=NULL;
3136 std::string command= "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?";
3138 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3139 sqlite3_bind_int(query,1, connectionID);
3141 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3143 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Step error code:"),DLT_INT(eCode));
3144 return E_DATABASE_ERROR;
3147 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3149 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:"),DLT_INT(eCode));
3150 return E_DATABASE_ERROR;
3155 bool DatabaseHandler::connectionPartofMainConnection(const am_connectionID_t connectionID, const am_mainConnectionID_t mainConnectionID) const
3157 sqlite3_stmt* query=NULL;
3158 std::string command = "SELECT connectionID FROM MainConnectionRoute"+ i2s(mainConnectionID)+ " WHERE connectionID=" + i2s(connectionID);
3160 bool returnVal=true;
3161 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3162 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3163 else if (eCode!=SQLITE_ROW)
3166 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::connectionPartofMainConnection database error!:"), DLT_INT(eCode))
3168 sqlite3_finalize(query);
3172 am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
3174 assert (mainConnectionID!=0);
3175 sqlite3_stmt* query=NULL;
3176 std::string command = "SELECT delay FROM MainConnectionRoute"+ i2s(mainConnectionID);
3178 am_timeSync_t delay=0;
3179 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3180 while((eCode=sqlite3_step(query))==SQLITE_ROW)
3182 int16_t temp_delay=sqlite3_column_int(query,0);
3183 if (temp_delay!=-1 && delay!=-1) delay+=temp_delay;
3186 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3188 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:"),DLT_INT(eCode));
3189 return E_DATABASE_ERROR;
3192 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3194 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:"),DLT_INT(eCode));
3195 return E_DATABASE_ERROR;
3198 if (delay==0) delay=-1;
3202 void DatabaseHandler::registerObserver(DatabaseObserver *iObserver)
3204 assert(iObserver!=NULL);
3205 mDatabaseObserver=iObserver;
3208 bool DatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const
3210 assert(sourceID!=0);
3211 sqlite3_stmt* query=NULL;
3212 std::string command = "SELECT visible FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3214 bool returnVal=false;
3215 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3216 if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3218 returnVal=sqlite3_column_int(query,0);
3220 else if (eCode!=SQLITE_ROW)
3223 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sourceVisible database error!:"), DLT_INT(eCode))
3225 sqlite3_finalize(query);
3229 bool DatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const
3231 sqlite3_stmt* query=NULL;
3232 std::string command = "SELECT visible FROM "+ std::string(SINK_TABLE) +" WHERE reserved=0 AND sinkID="+ i2s(sinkID);
3234 bool returnVal=false;
3235 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3236 if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3238 returnVal=sqlite3_column_int(query,0);
3240 else if (eCode!=SQLITE_ROW)
3243 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::sinkVisible database error!:"), DLT_INT(eCode))
3245 sqlite3_finalize(query);
3249 bool DatabaseHandler::existConnection(const am_Connection_s connection)
3251 sqlite3_stmt* query=NULL;
3252 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0";
3254 bool returnVal=true;
3255 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3256 sqlite3_bind_int(query,1, connection.sinkID);
3257 sqlite3_bind_int(query,2, connection.sourceID);
3258 sqlite3_bind_int(query,3, connection.connectionFormat);
3259 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3260 else if (eCode!=SQLITE_ROW)
3263 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3265 sqlite3_finalize(query);
3270 bool DatabaseHandler::existConnectionID(const am_connectionID_t connectionID)
3272 sqlite3_stmt* query=NULL;
3273 std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0";
3275 bool returnVal=true;
3276 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3277 sqlite3_bind_int(query,1, connectionID);
3278 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3279 else if (eCode!=SQLITE_ROW)
3282 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3284 sqlite3_finalize(query);
3288 bool DatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const
3290 sqlite3_stmt* query=NULL;
3291 std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
3293 bool returnVal=true;
3294 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3295 sqlite3_bind_int(query,1, crossfaderID);
3296 if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
3297 else if (eCode!=SQLITE_ROW)
3300 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::existMainConnection database error!:"), DLT_INT(eCode))
3302 sqlite3_finalize(query);
3306 am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const
3308 assert(sourceID!=0);
3309 sqlite3_stmt* query=NULL;
3311 std::string command = "SELECT sourceState FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3313 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3314 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3316 sourceState=(am_SourceState_e)sqlite3_column_int(query,0);
3318 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3320 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSoureState database error!:"), DLT_INT(eCode))
3323 sqlite3_finalize(query);
3327 am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState)
3329 assert(sourceID!=0);
3330 sqlite3_stmt* query=NULL;
3331 std::string command = "UPDATE " + std::string(SOURCE_TABLE) +" SET sourceState=? WHERE sourceID="+ i2s(sourceID);
3333 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3334 sqlite3_bind_int(query,1,sourceState);
3335 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3337 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Step error code:"),DLT_INT(eCode));
3338 return E_DATABASE_ERROR;
3341 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3343 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceState SQLITE Finalize error code:"),DLT_INT(eCode));
3344 return E_DATABASE_ERROR;
3349 am_Error_e DatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const
3352 sqlite3_stmt* query=NULL;
3354 std::string command = "SELECT volume FROM "+ std::string(SINK_TABLE) +" WHERE sinkID="+ i2s(sinkID);
3356 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3357 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3359 volume=sqlite3_column_int(query,0);
3361 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3363 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkVolume database error!:"), DLT_INT(eCode))
3366 sqlite3_finalize(query);
3370 am_Error_e DatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const
3372 assert(sourceID!=0);
3373 sqlite3_stmt* query=NULL;
3375 std::string command = "SELECT volume FROM "+ std::string(SOURCE_TABLE) +" WHERE sourceID="+ i2s(sourceID);
3377 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3378 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3380 volume=sqlite3_column_int(query,0);
3382 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3384 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSourceVolume database error!:"), DLT_INT(eCode))
3386 sqlite3_finalize(query);
3391 am_Error_e DatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3394 if (!existSink(sinkID)) return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3396 sqlite3_stmt* query=NULL;
3398 std::string command= "SELECT value FROM SinkSoundProperty" + i2s(sinkID) +" WHERE soundPropertyType=" +i2s(propertyType);
3399 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3401 while((eCode=sqlite3_step(query))==SQLITE_ROW)
3403 value=sqlite3_column_int(query,0);
3406 if(eCode!=SQLITE_DONE)
3408 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"),DLT_INT(eCode));
3409 return E_DATABASE_ERROR;
3412 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3414 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"),DLT_INT(eCode));
3415 return E_DATABASE_ERROR;
3421 am_Error_e DatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const
3423 assert(sourceID!=0);
3424 if (!existSource(sourceID)) return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences
3426 sqlite3_stmt* query=NULL;
3428 std::string command= "SELECT value FROM SourceSoundProperty" + i2s(sourceID) +" WHERE soundPropertyType=" +i2s(propertyType);
3429 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3431 while((eCode=sqlite3_step(query))==SQLITE_ROW)
3433 value=sqlite3_column_int(query,0);
3436 if(eCode!=SQLITE_DONE)
3438 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:"),DLT_INT(eCode));
3439 return E_DATABASE_ERROR;
3442 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3444 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:"),DLT_INT(eCode));
3445 return E_DATABASE_ERROR;
3451 am_Error_e DatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const
3453 assert(domainID!=0);
3454 sqlite3_stmt* query=NULL;
3456 std::string command = "SELECT domainState FROM "+ std::string(DOMAIN_TABLE) +" WHERE domainID="+ i2s(domainID);
3458 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3459 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3461 state=(am_DomainState_e)sqlite3_column_int(query,0);
3463 else if ((eCode=sqlite3_step(query))==SQLITE_DONE)
3465 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::getDomainState database error!:"), DLT_INT(eCode))
3468 sqlite3_finalize(query);
3473 am_Error_e DatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID)
3475 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3476 std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?";
3477 int eCode=0, eCode1=0;
3478 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3479 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3480 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3482 domainID=sqlite3_column_int(query,0);
3484 else if (eCode!=SQLITE_DONE)
3486 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain database error!:"), DLT_INT(eCode))
3487 return E_DATABASE_ERROR;
3491 command= "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)";
3492 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3493 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3494 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3495 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3497 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Step error code:"),DLT_INT(eCode1));
3498 return E_DATABASE_ERROR;
3501 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3503 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3504 return E_DATABASE_ERROR;
3506 domainID=sqlite3_last_insert_rowid(mDatabase);
3508 sqlite3_finalize(query);
3512 am_Error_e DatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID)
3514 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3515 std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?";
3516 int eCode=0, eCode1=0;
3517 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3518 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3519 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3521 sinkID=sqlite3_column_int(query,0);
3523 else if (eCode!=SQLITE_DONE)
3525 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3526 return E_DATABASE_ERROR;
3530 if (mFirstStaticSink)
3532 command= "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3533 mFirstStaticSink=false;
3537 command= "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)";
3539 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3540 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3541 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3542 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3544 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"),DLT_INT(eCode1));
3545 return E_DATABASE_ERROR;
3548 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3550 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3551 return E_DATABASE_ERROR;
3553 sinkID=sqlite3_last_insert_rowid(mDatabase);
3555 sqlite3_finalize(query);
3561 am_Error_e DatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID)
3563 sqlite3_stmt* query=NULL, *queryInsert=NULL;
3564 std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?";
3565 int eCode=0, eCode1=0;
3566 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3567 sqlite3_bind_text(query,1,name.c_str(),name.size(),SQLITE_STATIC);
3568 if ((eCode=sqlite3_step(query))==SQLITE_ROW)
3570 sourceID=sqlite3_column_int(query,0);
3572 else if (eCode!=SQLITE_DONE)
3574 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink database error!:"), DLT_INT(eCode))
3575 return E_DATABASE_ERROR;
3579 if (mFirstStaticSource)
3581 command= "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")";
3582 mFirstStaticSource=false;
3586 command= "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)";
3588 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryInsert,NULL);
3589 sqlite3_bind_text(queryInsert,1,name.c_str(),name.size(),SQLITE_STATIC);
3590 sqlite3_bind_int(queryInsert,2,1); //reservation flag
3591 if((eCode1=sqlite3_step(queryInsert))!=SQLITE_DONE)
3593 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekSink SQLITE Step error code:"),DLT_INT(eCode1));
3594 return E_DATABASE_ERROR;
3597 if((eCode1=sqlite3_finalize(queryInsert))!=SQLITE_OK)
3599 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::peekDomain SQLITE Finalize error code:"),DLT_INT(eCode1));
3600 return E_DATABASE_ERROR;
3602 sourceID=sqlite3_last_insert_rowid(mDatabase);
3604 sqlite3_finalize(query);
3608 am_Error_e DatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume)
3612 sqlite3_stmt* query=NULL;
3614 std::string command;
3616 if (!existSink(sinkID))
3618 return E_NON_EXISTENT;
3620 command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID);
3621 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3622 sqlite3_bind_int(query,1, volume);
3623 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3625 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Step error code:"),DLT_INT(eCode));
3626 return E_DATABASE_ERROR;
3628 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3630 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:"),DLT_INT(eCode));
3631 return E_DATABASE_ERROR;
3634 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSinkVolume changed volume of sink:"),DLT_INT(sinkID),DLT_STRING("to:"),DLT_INT(volume));
3639 am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume)
3641 assert(sourceID!=0);
3643 sqlite3_stmt* query=NULL;
3645 std::string command;
3647 if (!existSource(sourceID))
3649 return E_NON_EXISTENT;
3651 command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID);
3652 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3653 sqlite3_bind_int(query,1, volume);
3654 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3656 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Step error code:"),DLT_INT(eCode));
3657 return E_DATABASE_ERROR;
3659 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3661 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:"),DLT_INT(eCode));
3662 return E_DATABASE_ERROR;
3665 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeSourceVolume changed volume of source=:"),DLT_INT(sourceID),DLT_STRING("to:"),DLT_INT(volume));
3670 am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID)
3672 //todo: add checks if soundproperty exists!
3673 assert(sourceID!=0);
3675 sqlite3_stmt* query=NULL;
3677 std::string command;
3679 if (!existSource(sourceID))
3681 return E_NON_EXISTENT;
3683 command = "UPDATE SourceSoundProperty" + i2s(sourceID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3684 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3685 sqlite3_bind_int(query,1, soundProperty.value);
3686 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3688 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
3689 return E_DATABASE_ERROR;
3692 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3694 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
3695 return E_DATABASE_ERROR;
3698 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));
3703 am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID)
3705 //todo: add checks if soundproperty exists!
3708 sqlite3_stmt* query=NULL;
3710 std::string command;
3712 if (!existSink(sinkID))
3714 return E_NON_EXISTENT;
3716 command = "UPDATE SinkSoundProperty" + i2s(sinkID)+ " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type);
3717 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3718 sqlite3_bind_int(query,1, soundProperty.value);
3719 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3721 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:"),DLT_INT(eCode));
3722 return E_DATABASE_ERROR;
3723 } assert(sinkID!=0);
3725 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3727 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:"),DLT_INT(eCode));
3728 return E_DATABASE_ERROR;
3731 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));
3736 am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink)
3738 assert(crossfaderID!=0);
3740 sqlite3_stmt* query=NULL;
3742 std::string command;
3744 if (!existcrossFader(crossfaderID))
3746 return E_NON_EXISTENT;
3748 command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID);
3749 sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
3750 sqlite3_bind_int(query,1, hotsink);
3751 if((eCode=sqlite3_step(query))!=SQLITE_DONE)
3753 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:"),DLT_INT(eCode));
3754 return E_DATABASE_ERROR;
3756 if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
3758 DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:"),DLT_INT(eCode));
3759 return E_DATABASE_ERROR;
3762 DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader="),DLT_INT(crossfaderID),DLT_STRING("to:"),DLT_INT(hotsink));
3767 void DatabaseHandler::createTables()
3769 for(uint16_t i=0;i<sizeof(databaseTables)/sizeof(databaseTables[0]);i++)
3771 assert(sqQuery("CREATE TABLE " + databaseTables[i]));