* remove some warnings
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / src / CAmTelnetMenuHelper.cpp
1 /**
2  * Copyright (C) 2012, BMW AG
3  *
4  * This file is part of GENIVI Project AudioManager.
5  *
6  * Contributions are licensed to the GENIVI Alliance under one or more
7  * Contribution License Agreements.
8  *
9  * \copyright
10  * This Source Code Form is subject to the terms of the
11  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
12  * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  *
15  * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
16  * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012
17  *
18  * \file CAmTelnetMenuHelper.cpp
19  * For further information see http://www.genivi.org/.
20  *
21  */
22
23 #include "CAmTelnetMenuHelper.h"
24 #include <cassert>
25 #include "config.h"
26 #include "CAmRouter.h"
27 #include "CAmTelnetServer.h"
28 #include "CAmDatabaseHandler.h"
29 #include "CAmControlSender.h"
30 #include "CAmCommandSender.h"
31 #include "CAmRoutingSender.h"
32 #include "CAmRoutingReceiver.h"
33 #include "CAmCommandReceiver.h"
34 #include "CAmControlReceiver.h"
35 #include "shared/CAmDltWrapper.h"
36
37 static const std::string COLOR_WELCOME("\033[1;33m\033[44m");
38 static const std::string COLOR_HEAD("\033[1m\033[42m");
39 static const std::string COLOR_DEFAULT("\033[0m");
40
41
42 namespace am {
43
44 CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL;
45
46 /****************************************************************************/
47 CAmTelnetMenuHelper::CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, CAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer)
48 /****************************************************************************/
49 :mpTelenetServer(iTelnetServer), mpSocketHandler(iSocketHandler), mpCommandSender(iCommandSender), mpCommandReceiver(iCommandReceiver), mpRoutingSender(iRoutingSender), mpRoutingReceiver(iRoutingReceiver), mpControlSender(iControlSender), mpControlReceiver(iControlReceiver), mpDatabasehandler(iDatabasehandler), mpRouter(iRouter)
50 {
51     instance = this;
52     createCommandMaps();
53 }
54
55 /****************************************************************************/
56 CAmTelnetMenuHelper::~CAmTelnetMenuHelper()
57 /****************************************************************************/
58 {
59 }
60
61 /****************************************************************************/
62 void CAmTelnetMenuHelper::createCommandMaps()
63 /****************************************************************************/
64 {
65     // ROOT commands
66     mRootCommands.clear();
67     mRootCommands.insert(std::make_pair("help", sCommandPrototypeInfo("show all possible commands", &CAmTelnetMenuHelper::helpCommand)));
68     mRootCommands.insert(std::make_pair("list", sCommandPrototypeInfo("Go into 'list'-submenu", &CAmTelnetMenuHelper::rootListCommand)));
69     mRootCommands.insert(std::make_pair("info", sCommandPrototypeInfo("Go into 'info'-submenu", &CAmTelnetMenuHelper::rootInfoCommand)));
70     mRootCommands.insert(std::make_pair("set", sCommandPrototypeInfo("Go into 'set'-submenu", &CAmTelnetMenuHelper::rootSetCommand)));
71     mRootCommands.insert(std::make_pair("get", sCommandPrototypeInfo("Go into 'get'-submenu", &CAmTelnetMenuHelper::rootGetCommand)));
72     mRootCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("quit telnet session", &CAmTelnetMenuHelper::exitCommand)));
73     // List commands
74     mListCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
75     mListCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("list all connections", &CAmTelnetMenuHelper::listConnectionsCommand)));
76     mListCommands.insert(std::make_pair("sources", sCommandPrototypeInfo("list all available sources", &CAmTelnetMenuHelper::listSourcesCommand)));
77     mListCommands.insert(std::make_pair("sinks", sCommandPrototypeInfo("list all available sinks", &CAmTelnetMenuHelper::listSinksCommands)));
78     mListCommands.insert(std::make_pair("crfader", sCommandPrototypeInfo("list all crossfaders", &CAmTelnetMenuHelper::listCrossfaders)));
79     mListCommands.insert(std::make_pair("domains", sCommandPrototypeInfo("list all domains", &CAmTelnetMenuHelper::listDomainsCommand)));
80     mListCommands.insert(std::make_pair("gws", sCommandPrototypeInfo("list all gateways", &CAmTelnetMenuHelper::listGatewaysCommand)));
81     mListCommands.insert(std::make_pair("mainconn", sCommandPrototypeInfo("list all main connections", &CAmTelnetMenuHelper::listMainConnectionsCommand)));
82     mListCommands.insert(std::make_pair("mainsinks", sCommandPrototypeInfo("list all main sinks", &CAmTelnetMenuHelper::listMainSinksCommand)));
83     mListCommands.insert(std::make_pair("mainsources", sCommandPrototypeInfo("list all main sources", &CAmTelnetMenuHelper::listMainSourcesCommand)));
84     mListCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
85     mListCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
86     // Set commands
87     mSetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
88     mSetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
89     mSetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
90     mSetCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink", &CAmTelnetMenuHelper::setConnection)));
91     mSetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("use 'routing sourceId sinkId' to get all\n\t  possible routes between a sourceID and a sinkID", &CAmTelnetMenuHelper::setRoutingCommand)));
92     mSetCommands.insert(std::make_pair("disc", sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t  this connection", &CAmTelnetMenuHelper::setDisconnectConnId)));
93     mSetCommands.insert(std::make_pair("sinkvolume", sCommandPrototypeInfo("use 'sinkvolume sinkID volume' to set \n\t  absorption in db of sink", &CAmTelnetMenuHelper::setSinkVolume)));
94     mSetCommands.insert(std::make_pair("sinkvolstep", sCommandPrototypeInfo("use 'sinkvolstep sinkID volumestep' to increment \n\t or decrement  volume", &CAmTelnetMenuHelper::setVolumeStep)));
95     mSetCommands.insert(std::make_pair("sinkprop", sCommandPrototypeInfo("use 'sinkprop type value' to set \n\t  a specific sinksoundproperty", &CAmTelnetMenuHelper::setSinkSoundProperty)));
96     mSetCommands.insert(std::make_pair("sinkmute", sCommandPrototypeInfo("use 'sinkmute sinkid mutestate' to mute \n\t or unmute", &CAmTelnetMenuHelper::setSinkMuteState)));
97     mSetCommands.insert(std::make_pair("sourceprop", sCommandPrototypeInfo("use 'sourceprop type value' to set \n\t  a specific sinksoundproperty", &CAmTelnetMenuHelper::setSourceSoundProperty)));
98     // Get commands
99     mGetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
100     mGetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("show current routing", &CAmTelnetMenuHelper::getRoutingCommand)));
101     mGetCommands.insert(std::make_pair("sendv", sCommandPrototypeInfo("show senderversion", &CAmTelnetMenuHelper::getSenderversionCommand)));
102     mGetCommands.insert(std::make_pair("recv", sCommandPrototypeInfo("show receiverversion ", &CAmTelnetMenuHelper::getReceiverversionCommand)));
103     mGetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
104     mGetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
105     // Info comands
106     mInfoCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
107     mInfoCommands.insert(std::make_pair("sysprop", sCommandPrototypeInfo("show all systemproperties", &CAmTelnetMenuHelper::infoSystempropertiesCommand)));
108     mInfoCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
109     mInfoCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
110 }
111
112 /****************************************************************************/
113 void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor)
114 /****************************************************************************/
115 {
116     EMainState state = eRootState;
117     std::map<int, EMainState>::iterator it;
118     std::stringstream welcome;
119     it = mCurrentMainStateMap.find(filedescriptor);
120     if (it != mCurrentMainStateMap.end())
121     {
122         // socket connection already exists, delete entry and go back to root state
123         mCurrentMainStateMap.erase(it);
124     }
125     it = mCurrentMainStateMap.begin();
126     // insert new socket connection
127     mCurrentMainStateMap.insert(it, std::make_pair(filedescriptor, state));
128     // Send welcome message
129     welcome << COLOR_WELCOME << "Welcome to GENIVI AudioManager " << DAEMONVERSION << COLOR_DEFAULT << "\n>";
130     assert(send(filedescriptor, welcome.str().c_str(), welcome.str().size(), 0)>=0);
131     logInfo("[TN] New connection: ", filedescriptor);
132 }
133
134 /****************************************************************************/
135 void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor)
136 /****************************************************************************/
137 {
138     std::map<int, EMainState>::iterator it;
139     it = mCurrentMainStateMap.find(filedescriptor);
140     if (it != mCurrentMainStateMap.end())
141     {
142         mCurrentMainStateMap.erase(it);
143     }
144     else
145     {
146         logError("[TN] socketConnectionsClosed, fd not found, ", filedescriptor);
147     }
148 }
149
150 /****************************************************************************/
151 void CAmTelnetMenuHelper::enterCmdQueue(std::queue<std::string>& CmdQueue, int& filedescriptor)
152 /****************************************************************************/
153 {
154     std::map<int, EMainState>::iterator it;
155     std::string cmd;
156     tCommandMap::iterator cmditer;
157     // find current filedescriptor to get the current state of the telnet session
158     it = mCurrentMainStateMap.find(filedescriptor);
159     while (!CmdQueue.empty())
160     {
161         cmd = CmdQueue.front();
162         // Now remove the first command, it's stored in 'cmd'
163         CmdQueue.pop();
164         // telnet session found. depending on the current state, different commands are available
165         switch (it->second)
166         {
167         case eRootState:
168             cmditer = mRootCommands.find(cmd);
169             if (mRootCommands.end() != cmditer)
170                 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
171             else
172                 sendError(filedescriptor, "Command not found\n");
173
174             break;
175         case eListState:
176             cmditer = mListCommands.find(cmd);
177             if (mListCommands.end() != cmditer)
178                 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
179             else
180                 sendError(filedescriptor, "Command not found\n");
181
182             break;
183         case eInfoState:
184             cmditer = mInfoCommands.find(cmd);
185             if (mInfoCommands.end() != cmditer)
186                 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
187             else
188                 sendError(filedescriptor, "Command not found\n");
189
190             break;
191         case eGetState:
192             cmditer = mGetCommands.find(cmd);
193             if (mGetCommands.end() != cmditer)
194                 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
195             else
196                 sendError(filedescriptor, "Command not found\n");
197
198             break;
199         case eSetState:
200             cmditer = mSetCommands.find(cmd);
201             if (mSetCommands.end() != cmditer)
202                 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
203             else
204                 sendError(filedescriptor, "Command not found\n");
205
206             break;
207         default:
208             break;
209         }
210     }
211
212     sendCurrentCmdPrompt(filedescriptor);
213 }
214
215 /****************************************************************************/
216 void CAmTelnetMenuHelper::sendError(int& filedescriptor, std::string error_string)
217 /****************************************************************************/
218 {
219     assert(send(filedescriptor, error_string.c_str(), error_string.size(), 0)>=0);
220 }
221
222 /****************************************************************************/
223 void CAmTelnetMenuHelper::sendTelnetLine(int& filedescriptor, std::stringstream& line)
224 /****************************************************************************/
225 {
226     assert(send(filedescriptor, line.str().c_str(), line.str().size(), 0)>=0);
227 }
228
229 /****************************************************************************/
230 void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int& filedescriptor)
231 /****************************************************************************/
232 {
233     std::map<int, EMainState>::iterator it;
234     std::stringstream outputstream;
235     outputstream << std::endl;
236     it = mCurrentMainStateMap.find(filedescriptor);
237     if (it != mCurrentMainStateMap.end())
238     {
239         switch (it->second)
240         {
241         case eRootState:
242             outputstream << "\\>";
243             break;
244         case eListState:
245             outputstream << "\\List>";
246             break;
247         case eGetState:
248             outputstream << "\\Get>";
249             break;
250         case eSetState:
251             outputstream << "\\Set>";
252             break;
253         case eInfoState:
254             outputstream << "\\Info>";
255             break;
256         default:
257             break;
258         }
259         assert(send(filedescriptor, outputstream.str().c_str(), outputstream.str().size(), 0)>=0);
260     }
261     else
262     {
263         logInfo("[TN] sendCurrentCmdPrompt, fd not found: ", filedescriptor);
264     }
265 }
266
267 /****************************************************************************/
268 void CAmTelnetMenuHelper::exitCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
269 /****************************************************************************/
270 {
271     instance->exitCommandExec(CmdQueue, filedescriptor);
272 }
273
274 /****************************************************************************/
275 void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
276 /****************************************************************************/
277 {
278     (void) (CmdQueue);
279     std::map<int, EMainState>::iterator it;
280     it = mCurrentMainStateMap.find(filedescriptor);
281     if (it != mCurrentMainStateMap.end())
282     {
283         switch (it->second)
284         {
285         case eRootState:
286             it->second = eRootState;
287             break;
288         case eListState:
289             it->second = eRootState;
290             ;
291             break;
292         case eGetState:
293             it->second = eRootState;
294             ;
295             break;
296         case eSetState:
297             it->second = eRootState;
298             ;
299             break;
300         case eInfoState:
301             it->second = eRootState;
302             ;
303             break;
304         default:
305             it->second = eRootState;
306             break;
307         }
308         logInfo("[TN] oneStepBackCommandExec, state: ", it->second);
309     }
310
311 }
312
313 /****************************************************************************/
314 void CAmTelnetMenuHelper::oneStepBackCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
315 /****************************************************************************/
316 {
317     instance->oneStepBackCommandExec(CmdQueue, filedescriptor);
318 }
319
320 /****************************************************************************/
321 void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
322 /****************************************************************************/
323 {
324     (void) (CmdQueue);
325     std::map<int, EMainState>::iterator it;
326     std::stringstream line;
327     std::stringstream output;
328     // Sending a last message to the client
329     output << "bye!" << COLOR_DEFAULT << std::endl;
330     sendTelnetLine(filedescriptor, output);
331     tCommandMap::iterator iter;
332     it = mCurrentMainStateMap.find(filedescriptor);
333     if (it != mCurrentMainStateMap.end())
334     {
335         if (NULL != mpTelenetServer)
336         {
337             logInfo("[TN] exitCommandExec, removing fd ", filedescriptor);
338             mpTelenetServer->disconnectClient(filedescriptor);
339             mCurrentMainStateMap.erase(it);
340         }
341         else
342         {
343             logError("[TN] exitCommandExec, mpTelenetServer == NULL, fd ", filedescriptor);
344         }
345     }
346 }
347
348 /****************************************************************************/
349 void CAmTelnetMenuHelper::helpCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
350 /****************************************************************************/
351 {
352     instance->helpCommandExec(CmdQueue, filedescriptor);
353 }
354
355 /****************************************************************************/
356 void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
357 /****************************************************************************/
358 {
359     (void) (CmdQueue);
360     std::map<int, EMainState>::iterator it;
361     std::stringstream line;
362     tCommandMap::iterator cmdIter;
363     it = mCurrentMainStateMap.find(filedescriptor);
364     if (it != mCurrentMainStateMap.end())
365     {
366         line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl;
367         line << COLOR_HEAD << "###### The following commands are supported: ######" << COLOR_DEFAULT << std::endl;
368         line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl << std::endl;
369         switch (it->second)
370         {
371         case eRootState:
372             cmdIter = mRootCommands.begin();
373             while (cmdIter != mRootCommands.end())
374             {
375                 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
376                 cmdIter++;
377             }
378             break;
379         case eListState:
380             cmdIter = mListCommands.begin();
381             while (cmdIter != mListCommands.end())
382             {
383                 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
384                 cmdIter++;
385             }
386             break;
387         case eGetState:
388             cmdIter = mGetCommands.begin();
389             while (cmdIter != mGetCommands.end())
390             {
391                 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
392                 cmdIter++;
393             }
394             break;
395         case eSetState:
396             cmdIter = mSetCommands.begin();
397             while (cmdIter != mSetCommands.end())
398             {
399                 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
400                 cmdIter++;
401             }
402             break;
403         case eInfoState:
404             cmdIter = mInfoCommands.begin();
405             while (cmdIter != mInfoCommands.end())
406             {
407                 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
408                 cmdIter++;
409             }
410             break;
411         default:
412             break;
413         }
414
415         sendTelnetLine(filedescriptor, line);
416     }
417
418 }
419
420 /****************************************************************************/
421 void CAmTelnetMenuHelper::rootGetCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
422 /****************************************************************************/
423 {
424     instance->rootGetCommandExec(CmdQueue, filedescriptor);
425 }
426
427 /****************************************************************************/
428 void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
429 /****************************************************************************/
430 {
431     (void) (CmdQueue);
432     std::map<int, EMainState>::iterator it;
433     it = mCurrentMainStateMap.find(filedescriptor);
434     if (it != mCurrentMainStateMap.end())
435     {
436         it->second = eGetState;
437     }
438 }
439
440 /****************************************************************************/
441 void CAmTelnetMenuHelper::rootSetCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
442 /****************************************************************************/
443 {
444     instance->rootSetCommandExec(CmdQueue, filedescriptor);
445 }
446
447 /****************************************************************************/
448 void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
449 /****************************************************************************/
450 {
451     (void) (CmdQueue);
452     std::map<int, EMainState>::iterator it;
453     it = mCurrentMainStateMap.find(filedescriptor);
454     if (it != mCurrentMainStateMap.end())
455     {
456         it->second = eSetState;
457     }
458 }
459
460 /****************************************************************************/
461 void CAmTelnetMenuHelper::rootListCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
462 /****************************************************************************/
463 {
464     instance->rootListCommandExec(CmdQueue, filedescriptor);
465 }
466
467 /****************************************************************************/
468 void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
469 /****************************************************************************/
470 {
471     (void) (CmdQueue);
472     std::map<int, EMainState>::iterator it;
473     it = mCurrentMainStateMap.find(filedescriptor);
474     if (it != mCurrentMainStateMap.end())
475     {
476         it->second = eListState;
477     }
478 }
479
480 /****************************************************************************/
481 void CAmTelnetMenuHelper::rootInfoCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
482 /****************************************************************************/
483 {
484     instance->rootInfoCommandExec(CmdQueue, filedescriptor);
485 }
486
487 /****************************************************************************/
488 void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
489 /****************************************************************************/
490 {
491     (void) (CmdQueue);
492     std::map<int, EMainState>::iterator it;
493     it = mCurrentMainStateMap.find(filedescriptor);
494     if (it != mCurrentMainStateMap.end())
495     {
496         it->second = eInfoState;
497     }
498 }
499
500 /****************************************************************************/
501 void CAmTelnetMenuHelper::listConnectionsCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
502 /****************************************************************************/
503 {
504     instance->listConnectionsCommandExec(CmdQueue, filedescriptor);
505 }
506
507 /****************************************************************************/
508 void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
509 /****************************************************************************/
510 {
511     (void) (CmdQueue);
512     std::vector < am_Connection_s > listConnections;
513     if (E_OK == mpDatabasehandler->getListConnections(listConnections))
514     {
515         std::stringstream output;
516         output << "\tConnections: " << listConnections.size() << std::endl;
517         for (std::vector<am_Connection_s>::iterator iter(listConnections.begin()); iter < listConnections.end(); iter++)
518         {
519             output << "\tID: " << iter->connectionID << "\tSrcID: " << iter->sourceID << "\tSinkID: " << iter->sinkID << "\tFormat: " << iter->connectionFormat << "\tdelay: " << iter->delay << std::endl;
520         }
521         sendTelnetLine(filedescriptor, output);
522     }
523     else
524     {
525         sendError(filedescriptor, "ERROR: mDatabasehandler->getListConnections");
526     }
527 }
528
529 /****************************************************************************/
530 void CAmTelnetMenuHelper::listSourcesCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
531 /****************************************************************************/
532 {
533     instance->listSourcesCommandExec(CmdQueue, filedescriptor);
534 }
535
536 /****************************************************************************/
537 void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
538 /****************************************************************************/
539 {
540     (void) (CmdQueue);
541     std::vector < am_Source_s > listSources;
542     if (E_OK == mpDatabasehandler->getListSources(listSources))
543     {
544         std::stringstream output;
545         output << "\tSources: " << listSources.size() << std::endl;
546         for (std::vector<am_Source_s>::iterator iter(listSources.begin()); iter < listSources.end(); iter++)
547         {
548             output << "\tID: " << iter->sourceID << "\tName: " << iter->name << "\tDomainID: " << iter->domainID << "\tState: " << iter->sourceState << "\tVolume: " << iter->volume << std::endl;
549         }
550         sendTelnetLine(filedescriptor, output);
551     }
552     else
553     {
554         sendError(filedescriptor, "ERROR: mDatabasehandler->getListSources");
555     }
556 }
557
558 /****************************************************************************/
559 void CAmTelnetMenuHelper::listSinksCommands(std::queue<std::string>& CmdQueue, int& filedescriptor)
560 /****************************************************************************/
561 {
562     instance->listSinksCommandsExec(CmdQueue, filedescriptor);
563 }
564
565 /****************************************************************************/
566 void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
567 /****************************************************************************/
568 {
569     (void) (CmdQueue);
570     std::vector < am_Sink_s > listSinks;
571     if (E_OK == mpDatabasehandler->getListSinks(listSinks))
572     {
573         std::stringstream output;
574         output << "\tSinks: " << listSinks.size() << std::endl;
575         for (std::vector<am_Sink_s>::iterator iter(listSinks.begin()); iter < listSinks.end(); iter++)
576         {
577             output << "\tID: " << iter->sinkID << "\tDomainID: " << iter->domainID << "\tName: " << iter->name << "\tAvailable: " << iter->available.availability << "\tVolume: " << iter->volume << std::endl;
578         }
579         sendTelnetLine(filedescriptor, output);
580     }
581     else
582     {
583         sendError(filedescriptor, "ERROR: mDatabasehandler->getListSinks");
584     }
585 }
586
587 /****************************************************************************/
588 void CAmTelnetMenuHelper::listCrossfaders(std::queue<std::string>& CmdQueue, int& filedescriptor)
589 /****************************************************************************/
590 {
591     instance->listCrossfadersExec(CmdQueue, filedescriptor);
592 }
593
594 /****************************************************************************/
595 void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
596 /****************************************************************************/
597 {
598     (void) (CmdQueue);
599     std::vector < am_Crossfader_s > listCrossfaders;
600     if (E_OK == mpDatabasehandler->getListCrossfaders(listCrossfaders))
601     {
602         std::stringstream output;
603         output << "\tCrossfader: " << listCrossfaders.size() << std::endl;
604         for (std::vector<am_Crossfader_s>::iterator iter(listCrossfaders.begin()); iter < listCrossfaders.end(); iter++)
605         {
606             output << "\tID: " << iter->crossfaderID << "\tName: " << iter->name << "\tSinkA: " << iter->sinkID_A << "\tSinkB: " << iter->sinkID_B << "\tSourceID: " << iter->sourceID << std::endl;
607         }
608         sendTelnetLine(filedescriptor, output);
609     }
610     else
611     {
612         sendError(filedescriptor, "ERROR: mDatabasehandler->getListCrossfaders");
613     }
614 }
615
616 /****************************************************************************/
617 void CAmTelnetMenuHelper::listDomainsCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
618 /****************************************************************************/
619 {
620     instance->listDomainsCommandExec(CmdQueue, filedescriptor);
621 }
622
623 /****************************************************************************/
624 void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
625 /****************************************************************************/
626 {
627     (void) (CmdQueue);
628     std::vector < am_Domain_s > listDomains;
629     if (E_OK == mpDatabasehandler->getListDomains(listDomains))
630     {
631         std::stringstream output;
632         output << "\tDomains: " << listDomains.size() << std::endl;
633         for (std::vector<am_Domain_s>::iterator iter(listDomains.begin()); iter < listDomains.end(); iter++)
634         {
635             output << "\tID: " << iter->domainID << "\tName: " << iter->name << "\tBusname: " << iter->busname << "\tNodename: " << iter->nodename << "\tState: " << static_cast<int>(iter->state) << std::endl;
636         }
637         sendTelnetLine(filedescriptor, output);
638     }
639     else
640     {
641         sendError(filedescriptor, "ERROR: mDatabasehandler->getListDomains");
642     }
643 }
644
645 /****************************************************************************/
646 void CAmTelnetMenuHelper::listGatewaysCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
647 /****************************************************************************/
648 {
649     instance->listGatewaysCommandExec(CmdQueue, filedescriptor);
650 }
651
652 /****************************************************************************/
653 void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
654 /****************************************************************************/
655 {
656     (void) (CmdQueue);
657     std::vector < am_Gateway_s > listGateways;
658     if (E_OK == mpDatabasehandler->getListGateways(listGateways))
659     {
660         std::stringstream output;
661         output << "\tGateways: " << listGateways.size();
662         for (std::vector<am_Gateway_s>::iterator iter(listGateways.begin()); iter < listGateways.end(); iter++)
663         {
664             output << "\tID: " << iter->gatewayID << "\tName: " << iter->name << "\tSourceID: " << iter->sourceID << "\tSinkID: " << iter->sinkID << std::endl;
665         }
666         sendTelnetLine(filedescriptor, output);
667     }
668     else
669     {
670         sendError(filedescriptor, "ERROR: mDatabasehandler->getListGateways");
671     }
672 }
673
674 /****************************************************************************/
675 void CAmTelnetMenuHelper::getRoutingCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
676 /****************************************************************************/
677 {
678     instance->getRoutingCommandExec(CmdQueue, filedescriptor);
679 }
680
681 /****************************************************************************/
682 void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
683 /****************************************************************************/
684 {
685     (void) (CmdQueue);
686     (void) (filedescriptor);
687 //TODO: fill with function
688 }
689
690 /****************************************************************************/
691 void CAmTelnetMenuHelper::getSenderversionCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
692 /****************************************************************************/
693 {
694     instance->getSenderversionCommandExec(CmdQueue, filedescriptor);
695 }
696
697 /****************************************************************************/
698 void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
699 /****************************************************************************/
700 {
701     (void) (CmdQueue);
702     std::stringstream output;
703     std::string versionCommand;
704     std::string versionRouting;
705     std::string versionControl;
706     mpControlSender->getInterfaceVersion(versionControl);
707     mpRoutingSender->getInterfaceVersion(versionRouting);
708     mpCommandSender->getInterfaceVersion(versionCommand);
709     output << "\tSender versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl;
710     sendTelnetLine(filedescriptor, output);
711 }
712
713 /****************************************************************************/
714 void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
715 /****************************************************************************/
716 {
717     instance->getReceiverversionCommandExec(CmdQueue, filedescriptor);
718 }
719
720 /****************************************************************************/
721 void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
722 /****************************************************************************/
723 {
724     (void) (CmdQueue);
725     std::stringstream output;
726     std::string versionCommand;
727     std::string versionRouting;
728     std::string versionControl;
729     mpControlReceiver->getInterfaceVersion(versionControl);
730     mpRoutingReceiver->getInterfaceVersion(versionRouting);
731     mpCommandReceiver->getInterfaceVersion(versionCommand);
732     output << "\tReceiver versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl;
733     sendTelnetLine(filedescriptor, output);
734 }
735
736 /****************************************************************************/
737 void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
738 /****************************************************************************/
739 {
740     instance->infoSystempropertiesCommandExec(CmdQueue, filedescriptor);
741 }
742
743 /****************************************************************************/
744 void CAmTelnetMenuHelper::setVolumeStep(std::queue<std::string>& CmdQueue, int& filedescriptor)
745 /****************************************************************************/
746 {
747     instance->setSinkVolumeExec(CmdQueue,filedescriptor);
748 }
749
750 /****************************************************************************/
751 void CAmTelnetMenuHelper::setVolumeStepExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
752 /****************************************************************************/
753 {
754     if (CmdQueue.size() >= 2)
755     {
756         int16_t volumestep = 0;
757         am_sinkID_t sinkID = 0;
758         bool error = false;
759         std::istringstream istream_sinkID(CmdQueue.front());
760         CmdQueue.pop();
761         std::istringstream istream_volumestep(CmdQueue.front());
762         CmdQueue.pop();
763         if (!(istream_volumestep >> volumestep))
764             error = true;
765
766         if (!(istream_sinkID >> sinkID))
767             error = true;
768
769         if (error)
770         {
771             sendError(filedescriptor, "Error parsing setVolumeStep 'sinkID' or 'volumestep'");
772             return;
773         }
774         if (E_OK == mpCommandReceiver->volumeStep(sinkID,volumestep))
775         {
776             std::stringstream output;
777             output << "SetSinkVolumeStep set: " << sinkID << "->" << volumestep << std::endl;
778             sendTelnetLine(filedescriptor, output);
779         }
780         else
781         {
782             sendError(filedescriptor, "Error SetSinkVolumeStep");
783         }
784     }
785     else
786     {
787         sendError(filedescriptor, "Not enough arguments to set SetSinkVolumeStep, please enter 'sinkID' and 'volumestep' after command");
788         return;
789     }
790 }
791
792 /****************************************************************************/
793 void CAmTelnetMenuHelper::setSinkMuteState(std::queue<std::string>& CmdQueue, int& filedescriptor)
794 /****************************************************************************/
795 {
796     instance->setSinkMuteStateExec(CmdQueue,filedescriptor);
797 }
798
799 /****************************************************************************/
800 void CAmTelnetMenuHelper::setSinkMuteStateExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
801 /****************************************************************************/
802 {
803     if (CmdQueue.size() >= 2)
804     {
805         u_int16_t tmp = 0;
806         am_MuteState_e MuteState = MS_UNKNOWN;
807         am_sinkID_t sinkID = 0;
808         bool error = false;
809         std::istringstream istream_sinkID(CmdQueue.front());
810         CmdQueue.pop();
811         std::istringstream istream_mutestate(CmdQueue.front());
812         CmdQueue.pop();
813         if (!(istream_mutestate >> tmp))
814             error = true;
815
816         if (!(istream_sinkID >> sinkID))
817             error = true;
818
819         if(tmp < MS_MAX)
820         {
821             MuteState = static_cast<am_MuteState_e>(tmp);
822         }
823         else
824         {
825             sendError(filedescriptor, "You tried to set an invalid am_MuteState_e");
826             error = true;
827         }
828
829         if (error)
830         {
831             sendError(filedescriptor, "Error parsing setSinkMuteState 'sinkID' or 'mutestate'");
832             return;
833         }
834         if (E_OK == mpCommandReceiver->setSinkMuteState(sinkID,MuteState))
835         {
836             std::stringstream output;
837             output << "setSinkMuteState set: " << sinkID << "->" << MuteState << std::endl;
838             sendTelnetLine(filedescriptor, output);
839         }
840         else
841         {
842             sendError(filedescriptor, "Error setSinkMuteState");
843         }
844     }
845     else
846     {
847         sendError(filedescriptor, "Not enough arguments to set setSinkMuteState, please enter 'sinkID' and 'mutestate' after command");
848         return;
849     }
850 }
851
852 /****************************************************************************/
853 void CAmTelnetMenuHelper::setSourceSoundProperty(std::queue<std::string>& CmdQueue, int& filedescriptor)
854 /****************************************************************************/
855 {
856     instance->setSourceSoundPropertiesExec(CmdQueue,filedescriptor);
857 }
858
859 /****************************************************************************/
860 void CAmTelnetMenuHelper::setSourceSoundPropertyExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
861 /****************************************************************************/
862 {
863     unsigned int tmpType = 0;
864     bool error = false;
865     if (CmdQueue.size() >= 3)
866     {
867         std::istringstream istream_sourceID(CmdQueue.front());
868         CmdQueue.pop();
869         std::istringstream istream_type(CmdQueue.front());
870         CmdQueue.pop();
871         std::istringstream istream_value(CmdQueue.front());
872         CmdQueue.pop();
873         if (!(istream_type >> tmpType))
874             error = true;
875
876         am_MainSoundProperty_s soundProperty;
877         if (tmpType < MSP_MAX)
878             soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
879         else
880             error = true;
881
882         if (!(istream_value >> soundProperty.value))
883             error = true;
884
885         am_sourceID_t sourceID = 0;
886         if (!(istream_sourceID >> sourceID))
887             error = true;
888
889         if (error)
890         {
891             sendError(filedescriptor, "Error parsing setMainSourceSoundProperty 'type', 'value' or 'sourceID'");
892             return;
893         }
894         if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID))
895         {
896             std::stringstream output;
897             output << "setMainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
898             sendTelnetLine(filedescriptor, output);
899         }
900         else
901         {
902             sendError(filedescriptor, "Error setMainSourceSoundProperty");
903         }
904     }
905     else
906     {
907         sendError(filedescriptor, "Not enough arguments to set setMainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command");
908         return;
909     }
910 }
911
912 /****************************************************************************/
913 void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
914 /****************************************************************************/
915 {
916     (void) (CmdQueue);
917     std::vector < am_SystemProperty_s > listSystemProperties;
918     if (E_OK == mpDatabasehandler->getListSystemProperties(listSystemProperties))
919     {
920         std::stringstream output;
921         output << "\tSystemproperties: " << listSystemProperties.size() << std::endl;
922         std::vector<am_SystemProperty_s>::iterator it;
923         for (it = listSystemProperties.begin(); it < listSystemProperties.end(); it++)
924         {
925             output << "\tType: " << it->type << " Value: " << it->value << std::endl;
926         }
927         sendTelnetLine(filedescriptor, output);
928     }
929     else
930     {
931         sendError(filedescriptor, "ERROR: mDatabasehandler->getListSystemProperties");
932     }
933 }
934
935 /****************************************************************************/
936 void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
937 /****************************************************************************/
938 {
939     instance->setRoutingCommandExec(CmdQueue, filedescriptor);
940 }
941
942 /****************************************************************************/
943 void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
944 /****************************************************************************/
945 {
946     if (CmdQueue.size() >= 2)
947     {
948         bool error = false;
949         std::istringstream istream_sourceID(CmdQueue.front());
950         CmdQueue.pop();
951         std::istringstream istream_sinkID(CmdQueue.front());
952         CmdQueue.pop();
953         am_sourceID_t sourceID = 0;
954         if (!(istream_sourceID >> sourceID))
955             error = true;
956
957         am_sinkID_t sinkID = 0;
958         if (!(istream_sinkID >> sinkID))
959             error = true;
960
961         if (error)
962         {
963             sendError(filedescriptor, "Error parsing sourcID and sinkID");
964             return;
965         }
966         std::vector < am_Route_s > routingList;
967         if (E_OK == mpRouter->getRoute(true, sourceID, sinkID, routingList))
968         {
969             std::stringstream output;
970             std::vector<am_Route_s>::iterator rlIter = routingList.begin();
971             for (int rlCnt = 1; rlIter < routingList.end(); rlIter++)
972             {
973                 output << "#" << rlCnt << " ";
974                 std::vector<am_RoutingElement_s>::iterator reIter = rlIter->route.begin();
975                 for (; reIter < rlIter->route.end(); reIter++)
976                 {
977                     output << ">(" << reIter->sourceID << ")->--[D:" << reIter->domainID << "][F:" << reIter->connectionFormat << "]-->-(" << reIter->sinkID << ")" << std::endl;
978                 }
979                 rlCnt++;
980             }
981
982             sendTelnetLine(filedescriptor, output);
983         }
984         else
985         {
986             sendError(filedescriptor, "Error getting route");
987         }
988     }
989     else
990     {
991         if (!CmdQueue.empty())
992             CmdQueue.pop();
993
994         sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command");
995     }
996 }
997
998 /****************************************************************************/
999 void CAmTelnetMenuHelper::setConnection(std::queue<std::string>& CmdQueue, int& filedescriptor)
1000 /****************************************************************************/
1001 {
1002     instance->setConnectionExec(CmdQueue, filedescriptor);
1003 }
1004
1005 /****************************************************************************/
1006 void CAmTelnetMenuHelper::setConnectionExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1007 /****************************************************************************/
1008 {
1009     bool error = false;
1010     am_Error_e rError = E_OK;
1011     if (CmdQueue.size() >= 2)
1012     {
1013         std::istringstream istream_sourceID(CmdQueue.front());
1014         CmdQueue.pop();
1015         std::istringstream istream_sinkID(CmdQueue.front());
1016         CmdQueue.pop();
1017         am_sourceID_t sourceID = 0;
1018         if (!(istream_sourceID >> sourceID))
1019             error = true;
1020
1021         am_sinkID_t sinkID = 0;
1022         if (!(istream_sinkID >> sinkID))
1023             error = true;
1024
1025         if (error)
1026         {
1027             sendError(filedescriptor, "Error parsing sinkID and/or sourceID");
1028             return;
1029         }
1030 // Try to set up connection
1031         am_mainConnectionID_t connID = 0;
1032         rError = mpCommandReceiver->connect(sourceID, sinkID, connID);
1033         if (E_OK == rError)
1034         {
1035             std::stringstream output;
1036             output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl;
1037             sendTelnetLine(filedescriptor, output);
1038         }
1039         else
1040         {
1041             sendError(filedescriptor, "Error connecting sourceID and sinkID");
1042         }
1043     }
1044     else
1045     {
1046 // remove 1 element if list is not empty
1047         if (!CmdQueue.empty())
1048             CmdQueue.pop();
1049
1050         sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command");
1051         return;
1052     }
1053 }
1054
1055 /****************************************************************************/
1056 void CAmTelnetMenuHelper::setDisconnectConnId(std::queue<std::string>& CmdQueue, int& filedescriptor)
1057 /****************************************************************************/
1058 {
1059     instance->setDisconnectConnIdExec(CmdQueue, filedescriptor);
1060 }
1061
1062 /****************************************************************************/
1063 void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1064 /****************************************************************************/
1065 {
1066     am_mainConnectionID_t connID = 0;
1067     bool error = false;
1068     am_Error_e rError = E_OK;
1069     if (CmdQueue.size() >= 1)
1070     {
1071         std::istringstream istream_connID(CmdQueue.front());
1072         CmdQueue.pop();
1073         if (!(istream_connID >> connID))
1074             error = true;
1075
1076         if (error)
1077         {
1078             sendError(filedescriptor, "Error parsing connID");
1079             return;
1080         }
1081 // Try to disconnect connection id
1082         rError = mpCommandReceiver->disconnect(connID);
1083         if (E_OK == rError)
1084         {
1085             std::stringstream output;
1086             output << "ConnID " << connID << " closed successfully! " << std::endl;
1087             sendTelnetLine(filedescriptor, output);
1088         }
1089         else
1090         {
1091             sendError(filedescriptor, "Error disconnecting connectionID");
1092         }
1093     }
1094     else
1095     {
1096         sendError(filedescriptor, "Not enough arguments to disconnect a Main Connection, please enter 'connectionID' after command");
1097         return;
1098     }
1099 }
1100
1101 /****************************************************************************/
1102 void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue<std::string>& CmdQueue, int& filedescriptor)
1103 /****************************************************************************/
1104 {
1105     instance->setConnectionExec(CmdQueue, filedescriptor);
1106 }
1107
1108 /****************************************************************************/
1109 void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1110 /****************************************************************************/
1111 {
1112     if (CmdQueue.size() >= 3)
1113     {
1114         bool error = false;
1115         std::istringstream istream_sourceID(CmdQueue.front());
1116         CmdQueue.pop();
1117         std::istringstream istream_type(CmdQueue.front());
1118         CmdQueue.pop();
1119         std::istringstream istream_value(CmdQueue.front());
1120         CmdQueue.pop();
1121         unsigned int tmpType = 0;
1122         if (!(istream_type >> tmpType))
1123             error = true;
1124
1125         am_MainSoundProperty_s soundProperty;
1126         if (tmpType < MSP_MAX)
1127             soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1128         else
1129             error = true;
1130
1131         if (!(istream_value >> soundProperty.value))
1132             error = true;
1133
1134         am_sinkID_t sourceID = 0;
1135         if (!(istream_sourceID >> sourceID))
1136             error = true;
1137
1138         if (error)
1139         {
1140             sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'");
1141             return;
1142         }
1143         if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID))
1144         {
1145             std::stringstream output;
1146             output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1147             sendTelnetLine(filedescriptor, output);
1148         }
1149         else
1150         {
1151             sendError(filedescriptor, "Error setMainSourceSoundProperty");
1152         }
1153     }
1154     else
1155     {
1156         sendError(filedescriptor, "Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command");
1157         return;
1158     }
1159 }
1160
1161 /****************************************************************************/
1162 void CAmTelnetMenuHelper::setSinkSoundProperty(std::queue<std::string>& CmdQueue, int& filedescriptor)
1163 /****************************************************************************/
1164 {
1165     instance->setSinkSoundPropertyExec(CmdQueue, filedescriptor);
1166 }
1167
1168 /****************************************************************************/
1169 void CAmTelnetMenuHelper::setSinkSoundPropertyExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1170 /****************************************************************************/
1171 {
1172     unsigned int tmpType = 0;
1173     bool error = false;
1174     if (CmdQueue.size() >= 3)
1175     {
1176         std::istringstream istream_sinkID(CmdQueue.front());
1177         CmdQueue.pop();
1178         std::istringstream istream_type(CmdQueue.front());
1179         CmdQueue.pop();
1180         std::istringstream istream_value(CmdQueue.front());
1181         CmdQueue.pop();
1182         if (!(istream_type >> tmpType))
1183             error = true;
1184
1185         am_MainSoundProperty_s soundProperty;
1186         if (tmpType < MSP_MAX)
1187             soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1188         else
1189             error = true;
1190
1191         if (!(istream_value >> soundProperty.value))
1192             error = true;
1193
1194         am_sinkID_t sinkID = 0;
1195         if (!(istream_sinkID >> sinkID))
1196             error = true;
1197
1198         if (error)
1199         {
1200             sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'");
1201             return;
1202         }
1203         if (E_OK == mpCommandReceiver->setMainSinkSoundProperty(soundProperty, sinkID))
1204         {
1205             std::stringstream output;
1206             output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1207             sendTelnetLine(filedescriptor, output);
1208         }
1209         else
1210         {
1211             sendError(filedescriptor, "Error setMainSinkSoundProperty");
1212         }
1213     }
1214     else
1215     {
1216         sendError(filedescriptor, "Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command");
1217         return;
1218     }
1219 }
1220
1221 /****************************************************************************/
1222 void CAmTelnetMenuHelper::setSinkVolume(std::queue<std::string>& CmdQueue, int& filedescriptor)
1223 /****************************************************************************/
1224 {
1225     instance->setSinkVolumeExec(CmdQueue, filedescriptor);
1226 }
1227
1228 /****************************************************************************/
1229 void CAmTelnetMenuHelper::setSinkVolumeExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1230 /****************************************************************************/
1231 {
1232     if (CmdQueue.size() >= 2)
1233     {
1234         am_volume_t volume = 0;
1235         am_sinkID_t sinkID = 0;
1236         bool error = false;
1237         std::istringstream istream_sinkID(CmdQueue.front());
1238         CmdQueue.pop();
1239         std::istringstream istream_volume(CmdQueue.front());
1240         CmdQueue.pop();
1241         if (!(istream_volume >> volume))
1242             error = true;
1243
1244         if (!(istream_sinkID >> sinkID))
1245             error = true;
1246
1247         if (error)
1248         {
1249             sendError(filedescriptor, "Error parsing SetSinkVolume 'sinkID' or 'volume'");
1250             return;
1251         }
1252         if (E_OK == mpCommandReceiver->setVolume(sinkID,volume))
1253         {
1254             std::stringstream output;
1255             output << "setVolume set: " << sinkID << "->" << volume << std::endl;
1256             sendTelnetLine(filedescriptor, output);
1257         }
1258         else
1259         {
1260             sendError(filedescriptor, "Error setVolume");
1261         }
1262     }
1263     else
1264     {
1265         sendError(filedescriptor, "Not enough arguments to set setVolume, please enter 'sinkID' and 'volume' after command");
1266         return;
1267     }
1268 }
1269
1270 /****************************************************************************/
1271 void CAmTelnetMenuHelper::listPluginsCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
1272 /****************************************************************************/
1273 {
1274     instance->listPluginsCommandExec(CmdQueue, filedescriptor);
1275 }
1276
1277 /****************************************************************************/
1278 void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1279 /****************************************************************************/
1280 {
1281     (void) (CmdQueue);
1282     std::vector < std::string > PlugInNames;
1283     std::vector<std::string>::iterator iter;
1284     std::stringstream output;
1285     if (E_OK == mpCommandSender->getListPlugins(PlugInNames))
1286     {
1287         output << "\tCommandSender Plugins loaded: " << PlugInNames.size() << std::endl;
1288         for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++)
1289         {
1290             output << iter->c_str() << std::endl;
1291         }
1292     }
1293     else
1294     {
1295         sendError(filedescriptor, "ERROR: mCommandSender->getListPlugins");
1296     }
1297     if (E_OK == mpRoutingSender->getListPlugins(PlugInNames))
1298     {
1299         output << std::endl << "\tRoutingSender Plugins loaded: " << PlugInNames.size() << std::endl;
1300         for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++)
1301         {
1302             output << iter->c_str() << std::endl;
1303         }
1304     }
1305     else
1306     {
1307         sendError(filedescriptor, "ERROR: mRoutingSender->getListPlugins");
1308     }
1309     sendTelnetLine(filedescriptor, output);
1310 }
1311
1312 /****************************************************************************/
1313 void CAmTelnetMenuHelper::listMainSourcesCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
1314 /****************************************************************************/
1315 {
1316     instance->listMainSourcesCommandExec(CmdQueue, filedescriptor);
1317 }
1318
1319 /****************************************************************************/
1320 void CAmTelnetMenuHelper::listMainSourcesCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1321 /****************************************************************************/
1322 {
1323     (void) (CmdQueue);
1324     std::vector < am_SourceType_s > listMainSources;
1325     if (E_OK == mpDatabasehandler->getListMainSources(listMainSources))
1326     {
1327         std::stringstream output;
1328         output << std::endl << "\tMainSources:  " << listMainSources.size() << std::endl;
1329         std::vector<am_SourceType_s>::iterator iter;
1330         for (iter = listMainSources.begin(); iter < listMainSources.end(); iter++)
1331         {
1332             output << "\tID: " << iter->sourceID << "\tName: " << iter->name << "\tsourceClassID: " << iter->sourceClassID << "\tavailability: " << iter->availability.availability << std::endl;
1333         }
1334         sendTelnetLine(filedescriptor, output);
1335     }
1336     else
1337     {
1338         sendError(filedescriptor, "ERROR: mDatabasehandler->getListMainSources");
1339     }
1340 }
1341
1342 /****************************************************************************/
1343 void CAmTelnetMenuHelper::listMainSinksCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
1344 /****************************************************************************/
1345 {
1346     instance->listMainSinksCommandExec(CmdQueue, filedescriptor);
1347 }
1348
1349 /****************************************************************************/
1350 void CAmTelnetMenuHelper::listMainSinksCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1351 /****************************************************************************/
1352 {
1353     (void) (CmdQueue);
1354     std::vector < am_SinkType_s > listMainSinks;
1355     if (E_OK == mpDatabasehandler->getListMainSinks(listMainSinks))
1356     {
1357         std::stringstream output;
1358         output << std::endl << "\tMainSinks: " << listMainSinks.size() << std::endl;
1359         std::vector<am_SinkType_s>::iterator iter;
1360         for (iter = listMainSinks.begin(); iter < listMainSinks.end(); iter++)
1361         {
1362             output << "\tID: " << iter->sinkID << "\tsinkClassID: " << iter->sinkClassID << "\tName: " << iter->name << "\tAvailable: " << iter->availability.availability << "\tVolume: " << iter->volume << std::endl;
1363         }
1364         sendTelnetLine(filedescriptor, output);
1365     }
1366     else
1367     {
1368         sendError(filedescriptor, "ERROR: mDatabasehandler->getListMainSinks");
1369     }
1370 }
1371
1372 /****************************************************************************/
1373 void CAmTelnetMenuHelper::listMainConnectionsCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
1374 /****************************************************************************/
1375 {
1376     instance->listMainConnectionsCommandExec(CmdQueue, filedescriptor);
1377 }
1378
1379 /****************************************************************************/
1380 void CAmTelnetMenuHelper::listMainConnectionsCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
1381 /****************************************************************************/
1382 {
1383     (void) (CmdQueue);
1384     std::vector<am_MainConnection_s> listMainConnections;
1385
1386     if(E_OK == mpDatabasehandler->getListMainConnections(listMainConnections))
1387     {
1388         std::stringstream output;
1389         output << std::endl << "\tMainConnections: " << listMainConnections.size() << std::endl;
1390
1391         std::vector<am_MainConnection_s>::iterator iter;
1392         for (iter = listMainConnections.begin(); iter < listMainConnections.end(); iter++)
1393         {
1394             output << "\tID: " << iter->mainConnectionID
1395                    << "\tState: " << iter->connectionState
1396                    << "\tDelay: " << iter->delay
1397                    << "\tsourceID: " << iter->sourceID
1398                    << "\tsinkID: " << iter->sinkID << std::endl;
1399
1400             output << "ConnectionIDs: ";
1401             std::vector<am_connectionID_t>::iterator list_connIDs_iter = iter->listConnectionID.begin();
1402             for(;list_connIDs_iter < iter->listConnectionID.end();list_connIDs_iter++)
1403             {
1404                 output << *list_connIDs_iter << " ";
1405             }
1406
1407             output << std::endl;
1408         }
1409         sendTelnetLine(filedescriptor,output);
1410     }
1411     else
1412     {
1413         sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks");
1414     }
1415 }
1416 }
1417
1418
1419
1420
1421