* change includes in CAmTelnetMenuHelper
[profile/ivi/audiomanager.git] / AudioManagerDaemon / src / CAmTelnetMenuHelper.cpp
1 /**
2 * Copyright (C) 2012, BMW AG
3 *
4 * GeniviAudioMananger AudioManagerDaemon
5 *
6 * \file CAmTelnetMenuHelper.cpp
7 *
8 * \date 24-Jan-2012
9 * \author Frank Herchet (frank.fh.herchet@bmw.de)
10 *
11 * \section License
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2012, BMW AG Frank Herchet  frank.fh.herchet@bmw.de
14 *
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.
22 *
23 */
24
25 #include "CAmTelnetMenuHelper.h"
26 #include "TelnetServer.h"
27 #include "DatabaseHandler.h"
28 #include "ControlSender.h"
29 #include "CommandSender.h"
30 #include "RoutingSender.h"
31 #include "RoutingReceiver.h"
32 #include "CommandReceiver.h"
33 #include "ControlReceiver.h"
34 #include "Router.h"
35 #include "config.h"
36 #include <cassert>
37
38 #define DEBUG_ON false
39
40 using namespace am;
41
42 CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL;
43
44 /****************************************************************************/
45 CAmTelnetMenuHelper::CAmTelnetMenuHelper(SocketHandler *iSocketHandler,
46                                          CommandSender *iCommandSender,
47                                          CommandReceiver *iCommandReceiver,
48                                          RoutingSender *iRoutingSender,
49                                          RoutingReceiver *iRoutingReceiver,
50                                          ControlSender *iControlSender,
51                                          ControlReceiver *iControlReceiver,
52                                          DatabaseHandler *iDatabasehandler,
53                                          Router *iRouter)
54 /****************************************************************************/
55 : mTelenetServer(NULL)
56 , mSocketHandler(iSocketHandler)
57 , mCommandSender(iCommandSender)
58 , mCommandReceiver(iCommandReceiver)
59 , mRoutingSender(iRoutingSender)
60 , mRoutingReceiver(iRoutingReceiver)
61 , mControlSender(iControlSender)
62 , mControlReceiver(iControlReceiver)
63 , mDatabasehandler(iDatabasehandler)
64 , mRouter(iRouter)
65 {
66    instance = this;
67    createCommandMaps();
68 }
69
70 /****************************************************************************/
71 CAmTelnetMenuHelper::~CAmTelnetMenuHelper()
72 /****************************************************************************/
73 {
74 }
75
76 /****************************************************************************/
77 void CAmTelnetMenuHelper::createCommandMaps()
78 /****************************************************************************/
79 {
80    // ROOT commands
81
82    mRootCommands.clear();
83
84    mRootCommands.insert(std::make_pair("help",sCommandPrototypeInfo("show all possible commands",&CAmTelnetMenuHelper::helpCommand)));
85    mRootCommands.insert(std::make_pair("list",sCommandPrototypeInfo("Go into 'list'-submenu",&CAmTelnetMenuHelper::rootListCommand)));
86    mRootCommands.insert(std::make_pair("info",sCommandPrototypeInfo("Go into 'info'-submenu",&CAmTelnetMenuHelper::rootInfoCommand)));
87    mRootCommands.insert(std::make_pair("set",sCommandPrototypeInfo("Go into 'set'-submenu",&CAmTelnetMenuHelper::rootSetCommand)));
88    mRootCommands.insert(std::make_pair("get",sCommandPrototypeInfo("Go into 'get'-submenu",&CAmTelnetMenuHelper::rootGetCommand)));
89    mRootCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("quit telnet session",&CAmTelnetMenuHelper::exitCommand)));
90
91    // List commands
92    mListCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
93    mListCommands.insert(std::make_pair("conn",sCommandPrototypeInfo("list all connections",&CAmTelnetMenuHelper::listConnectionsCommand)));
94    mListCommands.insert(std::make_pair("sources",sCommandPrototypeInfo("list all available sources",&CAmTelnetMenuHelper::listSourcesCommand)));
95    mListCommands.insert(std::make_pair("sinks",sCommandPrototypeInfo("list all available sinks",&CAmTelnetMenuHelper::listSinksCommands)));
96    mListCommands.insert(std::make_pair("crfaders",sCommandPrototypeInfo("list all crossfaders",&CAmTelnetMenuHelper::listCrossfaders)));
97    mListCommands.insert(std::make_pair("domains",sCommandPrototypeInfo("list all domains",&CAmTelnetMenuHelper::listDomainsCommand)));
98    mListCommands.insert(std::make_pair("gws",sCommandPrototypeInfo("list all gateways",&CAmTelnetMenuHelper::listGatewaysCommand)));
99    mListCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
100    mListCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
101
102    // Set commands
103    mSetCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
104    mSetCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
105    mSetCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
106    mSetCommands.insert(std::make_pair("conn",sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink",&CAmTelnetMenuHelper::setConnection)));
107    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)));
108    mSetCommands.insert(std::make_pair("disc",sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t  this connection",&CAmTelnetMenuHelper::setDisconnectConnId)));
109
110    // Get commands
111    mGetCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
112    mGetCommands.insert(std::make_pair("routing",sCommandPrototypeInfo("show current routing",&CAmTelnetMenuHelper::getRoutingCommand)));
113    mGetCommands.insert(std::make_pair("sendv",sCommandPrototypeInfo("show senderversion",&CAmTelnetMenuHelper::getSenderversionCommand)));
114    mGetCommands.insert(std::make_pair("recv",sCommandPrototypeInfo("show receiverversion ",&CAmTelnetMenuHelper::getReceiverversionCommand)));
115    mGetCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
116    mGetCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
117
118    // Info comands
119    mInfoCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
120    mInfoCommands.insert(std::make_pair("sysprop",sCommandPrototypeInfo("show all systemproperties",&CAmTelnetMenuHelper::infoSystempropertiesCommand)));
121    mInfoCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
122    mInfoCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
123 }
124
125 /****************************************************************************/
126 void CAmTelnetMenuHelper::setTelnetServer(TelnetServer* iTelnetServer)
127 /****************************************************************************/
128 {
129    mTelenetServer = iTelnetServer;
130 }
131
132 /****************************************************************************/
133 void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor)
134 /****************************************************************************/
135 {
136    EMainState state = eRootState;
137    std::map<int,EMainState>::iterator it;
138    std::stringstream welcome;
139
140    it = mCurrentMainStateMap.find(filedescriptor);
141    if( it != mCurrentMainStateMap.end())
142    {
143       // socket connection already exists, delete entry and go back to root state
144       mCurrentMainStateMap.erase(it);
145    }
146
147    it = mCurrentMainStateMap.begin();
148
149    // insert new socket connection
150    mCurrentMainStateMap.insert(it,std::make_pair<int,EMainState>(filedescriptor,state));
151
152    // Send welcome message
153    welcome << "Welcome to GENIVI AudioManager " << DAEMONVERSION << "\n>";
154    send(filedescriptor,welcome.str().c_str(),welcome.str().size(),0);
155 }
156
157 /****************************************************************************/
158 void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor)
159 /****************************************************************************/
160 {
161    std::map<int,EMainState>::iterator it;
162
163    it = mCurrentMainStateMap.find(filedescriptor);
164    if( it != mCurrentMainStateMap.end())
165    {
166       mCurrentMainStateMap.erase(it);
167    }
168    else
169    {
170       // connection not found
171    }
172 }
173
174 /****************************************************************************/
175 void CAmTelnetMenuHelper::enterCmdQueue(std::queue<std::string> & CmdQueue, int & filedescriptor)
176 /****************************************************************************/
177 {
178    std::map<int,EMainState>::iterator it;
179    std::string cmd;
180    tCommandMap::iterator cmditer;
181
182    // find current filedescriptor to get the current state of the telnet session
183    it = mCurrentMainStateMap.find(filedescriptor);
184    while(!CmdQueue.empty())
185    {
186       cmd = CmdQueue.front();
187
188       // Now remove the first command, it's stored in 'cmd'
189       CmdQueue.pop();
190       // telnet session found. depending on the current state, different commands are available
191       switch(it->second)
192       {
193          case eRootState:
194             cmditer = mRootCommands.find(cmd);
195             if(mRootCommands.end() != cmditer)
196                cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
197             else
198                sendError(filedescriptor,"Command not found\n");
199             break;
200          case eListState:
201             cmditer = mListCommands.find(cmd);
202             if(mListCommands.end() != cmditer)
203                cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
204             else
205                sendError(filedescriptor,"Command not found\n");
206             break;
207          case eInfoState:
208             cmditer = mInfoCommands.find(cmd);
209             if(mInfoCommands.end() != cmditer)
210                cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
211             else
212                sendError(filedescriptor,"Command not found\n");
213             break;
214          case eGetState:
215             cmditer = mGetCommands.find(cmd);
216             if(mGetCommands.end() != cmditer)
217                cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
218             else
219                sendError(filedescriptor,"Command not found\n");
220             break;
221          case eSetState:
222             cmditer = mSetCommands.find(cmd);
223             if(mSetCommands.end() != cmditer)
224                cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
225             else
226                sendError(filedescriptor,"Command not found\n");
227             break;
228          default:
229             break;
230       }
231    }
232
233    sendCurrentCmdPrompt(filedescriptor);
234 }
235
236 /****************************************************************************/
237 void CAmTelnetMenuHelper::sendError(int & filedescriptor, std::string error_string)
238 /****************************************************************************/
239 {
240    send(filedescriptor,error_string.c_str(),error_string.size(),0);
241 }
242
243 /****************************************************************************/
244 void CAmTelnetMenuHelper::sendTelnetLine(int & filedescriptor, std::stringstream &line)
245 /****************************************************************************/
246 {
247    send(filedescriptor,line.str().c_str(),line.str().size(),0);
248 }
249
250 /****************************************************************************/
251 void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int & filedescriptor)
252 /****************************************************************************/
253 {
254    std::map<int,EMainState>::iterator it;
255    std::stringstream outputstream;
256    outputstream << std::endl;
257
258    it = mCurrentMainStateMap.find(filedescriptor);
259    if( it != mCurrentMainStateMap.end())
260    {
261       switch(it->second)
262       {
263          case eRootState:
264             outputstream  << "\\>";
265             break;
266          case eListState:
267             outputstream  << "\\List>";
268             break;
269          case eGetState:
270             outputstream  << "\\Get>";
271             break;
272          case eSetState:
273             outputstream  << "\\Set>";
274             break;
275          case eInfoState:
276             outputstream  << "\\Info>";
277             break;
278          default:
279             break;
280       }
281
282       send(filedescriptor,outputstream.str().c_str(),outputstream.str().size(),0);
283
284    }
285    else
286    {
287       // connection not found
288    }
289 }
290
291 /****************************************************************************/
292 void CAmTelnetMenuHelper::exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
293 /****************************************************************************/
294 {
295    instance->exitCommandExec(CmdQueue,filedescriptor);
296 }
297
298 /****************************************************************************/
299 void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
300 /****************************************************************************/
301 {
302    std::map<int,EMainState>::iterator it;
303    it = mCurrentMainStateMap.find(filedescriptor);
304    if( it != mCurrentMainStateMap.end())
305    {
306       if(DEBUG_ON)std::cout << "old state: " << it->second;
307       switch(it->second)
308       {
309          case eRootState:
310             it->second = eRootState;
311             break;
312          case eListState:
313             it->second = eRootState;;
314             break;
315          case eGetState:
316             it->second = eRootState;;
317             break;
318          case eSetState:
319             it->second = eRootState;;
320             break;
321          case eInfoState:
322             it->second = eRootState;;
323             break;
324          default:
325             it->second = eRootState;
326             break;
327       }
328       if(DEBUG_ON)std::cout << "new state: " << it->second << std::endl;
329    }
330 }
331
332 /****************************************************************************/
333 void CAmTelnetMenuHelper::oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
334 /****************************************************************************/
335 {
336    instance->oneStepBackCommandExec(CmdQueue,filedescriptor);
337 }
338
339 /****************************************************************************/
340 void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
341 /****************************************************************************/
342 {
343    std::map<int,EMainState>::iterator it;
344    std::stringstream line;
345    std::stringstream output;
346
347    // Sending a last message to the client
348    output << "Your wish is my command ... bye!" << std::endl;
349    sendTelnetLine(filedescriptor,output);
350
351
352    tCommandMap::iterator iter;
353    it = mCurrentMainStateMap.find(filedescriptor);
354    if( it != mCurrentMainStateMap.end())
355    {
356       if(DEBUG_ON)std::cout << "removing client connection " << filedescriptor << std::endl;
357
358       if(NULL != mTelenetServer)
359       {
360          mTelenetServer->disconnectClient(filedescriptor);
361          mCurrentMainStateMap.erase(it);
362       }
363       else
364       {
365          // ASSERT mTelenetServer == NULL
366          if(DEBUG_ON)std::cout << "mTelenetServer";
367       }
368    }
369 }
370
371 /****************************************************************************/
372 void CAmTelnetMenuHelper::helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
373 /****************************************************************************/
374 {
375    instance->helpCommandExec(CmdQueue,filedescriptor);
376 }
377
378 /****************************************************************************/
379 void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
380 /****************************************************************************/
381 {
382    std::map<int,EMainState>::iterator it;
383    std::stringstream line;
384    tCommandMap::iterator cmdIter;
385    it = mCurrentMainStateMap.find(filedescriptor);
386    if( it != mCurrentMainStateMap.end())
387    {
388       line << "###################################################" << std::endl;
389       line << "###### The following commands are supported: ######"<< std::endl;
390       line << "###################################################" << std::endl << std::endl;
391       switch(it->second)
392       {
393          case eRootState:
394
395             cmdIter = mRootCommands.begin();
396             while(cmdIter != mRootCommands.end())
397             {
398                line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
399                cmdIter++;
400             }
401             break;
402          case eListState:
403             cmdIter = mListCommands.begin();
404             while(cmdIter != mListCommands.end())
405             {
406                line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
407                cmdIter++;
408             }
409             break;
410          case eGetState:
411             cmdIter = mGetCommands.begin();
412             while(cmdIter != mGetCommands.end())
413             {
414                line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
415                cmdIter++;
416             }
417             break;
418          case eSetState:
419             cmdIter = mSetCommands.begin();
420             while(cmdIter != mSetCommands.end())
421             {
422                line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
423                cmdIter++;
424             }
425             break;
426          case eInfoState:
427             cmdIter = mInfoCommands.begin();
428             while(cmdIter != mInfoCommands.end())
429             {
430                line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
431                cmdIter++;
432             }
433             break;
434          default:
435             break;
436       }
437       sendTelnetLine(filedescriptor,line);
438    }
439 }
440
441 /****************************************************************************/
442 void CAmTelnetMenuHelper::rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
443 /****************************************************************************/
444 {
445    instance->rootGetCommandExec(CmdQueue,filedescriptor);
446 }
447
448 /****************************************************************************/
449 void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
450 /****************************************************************************/
451 {
452    std::map<int,EMainState>::iterator it;
453    it = mCurrentMainStateMap.find(filedescriptor);
454    if( it != mCurrentMainStateMap.end())
455    {
456       it->second = eGetState;
457    }
458 }
459
460 /****************************************************************************/
461 void CAmTelnetMenuHelper::rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
462 /****************************************************************************/
463 {
464    instance->rootSetCommandExec(CmdQueue,filedescriptor);
465 }
466
467 /****************************************************************************/
468 void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
469 /****************************************************************************/
470 {
471    std::map<int,EMainState>::iterator it;
472    it = mCurrentMainStateMap.find(filedescriptor);
473    if( it != mCurrentMainStateMap.end())
474    {
475       it->second = eSetState;
476    }
477 }
478
479 /****************************************************************************/
480 void CAmTelnetMenuHelper::rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
481 /****************************************************************************/
482 {
483    instance->rootListCommandExec(CmdQueue,filedescriptor);
484 }
485
486 /****************************************************************************/
487 void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
488 /****************************************************************************/
489 {
490    std::map<int,EMainState>::iterator it;
491    it = mCurrentMainStateMap.find(filedescriptor);
492    if( it != mCurrentMainStateMap.end())
493    {
494       it->second = eListState;
495    }
496 }
497
498 /****************************************************************************/
499 void CAmTelnetMenuHelper::rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
500 /****************************************************************************/
501 {
502    instance->rootInfoCommandExec(CmdQueue,filedescriptor);
503 }
504
505 /****************************************************************************/
506 void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
507 /****************************************************************************/
508 {
509    std::map<int,EMainState>::iterator it;
510    it = mCurrentMainStateMap.find(filedescriptor);
511    if( it != mCurrentMainStateMap.end())
512    {
513       it->second = eInfoState;
514    }
515 }
516
517 /****************************************************************************/
518 void CAmTelnetMenuHelper::listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
519 /****************************************************************************/
520 {
521    instance->listConnectionsCommandExec(CmdQueue,filedescriptor);
522 }
523
524 /****************************************************************************/
525 void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
526 /****************************************************************************/
527 {
528    std::vector<am_Connection_s> listConnections;
529    std::stringstream line;
530
531    mDatabasehandler->getListConnections(listConnections);
532
533    line << "\tCurrent connections: " << listConnections.size() << std::endl;
534
535    sendTelnetLine(filedescriptor,line);
536
537    std::vector<am_Connection_s>::iterator it(listConnections.begin());
538    while(it != listConnections.end())
539    {
540       line.str("");
541       line << "\tID: "  << it->connectionID
542            << "\tSrcID: "  << it->sourceID
543            << "\tSinkID: " << it->sinkID
544            << "\tFormat: " << it->connectionFormat
545            << "\tdelay: "  << it->delay
546            << std::endl;
547
548       sendTelnetLine(filedescriptor,line);
549       it++;
550    }
551 }
552
553 /****************************************************************************/
554 void CAmTelnetMenuHelper::listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
555 /****************************************************************************/
556 {
557    instance->listSourcesCommandExec(CmdQueue,filedescriptor);
558 }
559
560 /****************************************************************************/
561 void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
562 /****************************************************************************/
563 {
564    std::vector<am_Source_s> listSources;
565    std::stringstream line;
566
567    mDatabasehandler->getListSources(listSources);
568
569    line << "\tCurrent sources: " << listSources.size();
570    sendTelnetLine(filedescriptor,line);
571
572    std::vector<am_Source_s>::iterator it(listSources.begin());
573    while(it != listSources.end())
574    {
575       line.str("");
576       line << "\tID: "  << it->sourceID
577            << "\tDomainID: "  << it->domainID
578            << "\tName: " << it->name
579            << "\tState: " << it->sourceState
580            << "\tVolume: "  << it->volume
581            << std::endl;
582
583       sendTelnetLine(filedescriptor,line);
584       it++;
585    }
586 }
587
588 /****************************************************************************/
589 void CAmTelnetMenuHelper::listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor)
590 /****************************************************************************/
591 {
592    instance->listSinksCommandsExec(CmdQueue,filedescriptor);
593 }
594
595 /****************************************************************************/
596 void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
597 /****************************************************************************/
598 {
599    std::vector<am_Sink_s> listSinks;
600    std::stringstream line;
601
602    mDatabasehandler->getListSinks(listSinks);
603
604    line << "\tCurrent sinks: " << listSinks.size() << std::endl;
605    sendTelnetLine(filedescriptor,line);
606
607    std::vector<am_Sink_s>::iterator it(listSinks.begin());
608    while(it != listSinks.end())
609    {
610       line.str("");
611       line << "\tID: "  << it->sinkID
612            << "\tDomainID: "  << it->domainID
613            << "\tName: " << it->name
614            << "\tAvailable: " << it->available.availability
615            << "\tVolume: "  << it->volume
616            << std::endl;
617
618       sendTelnetLine(filedescriptor,line);
619       it++;
620    }
621 }
622
623 /****************************************************************************/
624 void CAmTelnetMenuHelper::listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor)
625 /****************************************************************************/
626 {
627    instance->listCrossfadersExec(CmdQueue,filedescriptor);
628 }
629
630 /****************************************************************************/
631 void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
632 /****************************************************************************/
633 {
634    std::vector<am_Crossfader_s> listCrossfaders;
635    std::stringstream line;
636
637    mDatabasehandler->getListCrossfaders(listCrossfaders);
638
639    line << "\tCurrent crossfaders: " << listCrossfaders.size();
640    sendTelnetLine(filedescriptor,line);
641
642    std::vector<am_Crossfader_s>::iterator it(listCrossfaders.begin());
643    while(it != listCrossfaders.end())
644    {
645       line.str("");
646       line << "\tID: "  << it->crossfaderID
647            << "\tName: "  << it->name
648            << "\tSourceID: " << it->sourceID
649            << std::endl;
650
651       sendTelnetLine(filedescriptor,line);
652       it++;
653    }
654 }
655
656 /****************************************************************************/
657 void CAmTelnetMenuHelper::listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
658 /****************************************************************************/
659 {
660    instance->listDomainsCommandExec(CmdQueue,filedescriptor);
661 }
662
663 /****************************************************************************/
664 void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
665 /****************************************************************************/
666 {
667    std::vector<am_Domain_s> listDomains;
668    std::stringstream line;
669
670    mDatabasehandler->getListDomains(listDomains);
671
672    line << "\tCurrent domains: " << listDomains.size()<<std::endl;
673    sendTelnetLine(filedescriptor,line);
674
675    std::vector<am_Domain_s>::iterator it(listDomains.begin());
676    while(it != listDomains.end())
677    {
678       line.str("");
679       line << "\tID: "  << it->domainID
680            << "\tName: "  << it->name
681            << "\tBusname: " << it->busname
682            << "\tNodename: " << it->nodename
683            << "\tState: " << static_cast<int>(it->state)
684            << std::endl;
685
686       sendTelnetLine(filedescriptor,line);
687       it++;
688    }
689 }
690
691 /****************************************************************************/
692 void CAmTelnetMenuHelper::listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
693 /****************************************************************************/
694 {
695    instance->listGatewaysCommandExec(CmdQueue,filedescriptor);
696 }
697
698 /****************************************************************************/
699 void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
700 /****************************************************************************/
701 {
702    std::vector<am_Gateway_s> listGateways;
703    std::stringstream line;
704
705    mDatabasehandler->getListGateways(listGateways);
706
707    line << "\tCurrent gateways: " << listGateways.size();
708    sendTelnetLine(filedescriptor,line);
709
710    std::vector<am_Gateway_s>::iterator it(listGateways.begin());
711    while(it != listGateways.end())
712    {
713       line.str("");
714       line << "\tID: "  << it->gatewayID
715            << "\tName: "  << it->name
716            << "\tSourceID: " << it->sourceID
717            << "\tSinkID: " << it->sinkID
718            << std::endl;
719
720       sendTelnetLine(filedescriptor,line);
721       it++;
722    }
723 }
724
725 /****************************************************************************/
726 void CAmTelnetMenuHelper::getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
727 /****************************************************************************/
728 {
729    instance->getRoutingCommandExec(CmdQueue,filedescriptor);
730 }
731
732 /****************************************************************************/
733 void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
734 /****************************************************************************/
735 {
736    //TODO: fill with function
737 }
738
739 /****************************************************************************/
740 void CAmTelnetMenuHelper::getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
741 /****************************************************************************/
742 {
743    instance->getSenderversionCommandExec(CmdQueue,filedescriptor);
744 }
745
746 /****************************************************************************/
747 void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
748 /****************************************************************************/
749 {
750    std::stringstream line;
751
752    line << "\tSender versions:" << std::endl
753         << "\tCtrl: "     << mControlSender->getInterfaceVersion() << " | "
754         << "Cmd: "      << mCommandSender->getInterfaceVersion() << " | "
755         << "Routing: "  << mRoutingSender->getInterfaceVersion() << std::endl;
756
757    sendTelnetLine(filedescriptor,line);
758 }
759
760 /****************************************************************************/
761 void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
762 /****************************************************************************/
763 {
764    instance->getReceiverversionCommandExec(CmdQueue,filedescriptor);
765 }
766
767 /****************************************************************************/
768 void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
769 /****************************************************************************/
770 {
771    std::stringstream line;
772
773    line << "\tReceiver versions:" << std::endl
774         << "\tCtrl: "     << mControlReceiver->getInterfaceVersion() << " | "
775         << "Cmd: "      << mCommandReceiver->getInterfaceVersion() << " | "
776         << "Routing: "  << mRoutingReceiver->getInterfaceVersion() << std::endl;
777
778    sendTelnetLine(filedescriptor,line);
779
780 }
781
782 /****************************************************************************/
783 void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
784 /****************************************************************************/
785 {
786    instance->infoSystempropertiesCommandExec(CmdQueue,filedescriptor);
787 }
788
789 /****************************************************************************/
790 void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
791 /****************************************************************************/
792 {
793    std::vector<am_SystemProperty_s> listSystemProperties;
794    std::vector<am_SystemProperty_s>::iterator it;
795    std::stringstream line;
796
797    mDatabasehandler->getListSystemProperties(listSystemProperties);
798
799    line << "\tSystemproperties: ";
800    sendTelnetLine(filedescriptor,line);
801
802    for(it = listSystemProperties.begin(); it < listSystemProperties.end(); it++ )
803    {
804       line.str("");
805       line << "\tType: " <<  it->type << " Value: " << it->value << std::endl;
806       sendTelnetLine(filedescriptor,line);
807    }
808 }
809
810 /****************************************************************************/
811 void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
812 /****************************************************************************/
813 {
814    instance->setRoutingCommandExec(CmdQueue,filedescriptor);
815 }
816
817 /****************************************************************************/
818 void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
819 /****************************************************************************/
820 {
821    std::stringstream                   output;
822    std::vector<am_Route_s>             routingList;
823
824    am_sourceID_t                       sourceID = 0;
825    am_sinkID_t                         sinkID   = 0;
826
827    bool                                error = false;
828    am_Error_e                          rError = E_OK;
829
830
831    if(CmdQueue.size() >= 2)
832    {
833       std::istringstream istream_sourceID(CmdQueue.front());
834       CmdQueue.pop();
835       std::istringstream istream_sinkID(CmdQueue.front());
836       CmdQueue.pop();
837
838       if(!(istream_sourceID >> sourceID))
839          error = true;
840       if(!(istream_sinkID >> sinkID))
841          error = true;
842
843       if(error)
844       {
845          sendError(filedescriptor,"Error parsing sourcID and sinkID");
846          return;
847       }
848
849       if(DEBUG_ON)std::cout << "setRoutingCommandExec(sourceID: " << sourceID << ",sinkID: " << sinkID << ")" << std::endl;
850
851       rError = mRouter->getRoute(true,sourceID,sinkID,routingList);
852
853       if(E_OK == rError)
854       {
855          std::vector<am_Route_s>::iterator rlIter = routingList.begin();
856          for(int rlCnt = 1;rlIter < routingList.end();rlIter++)
857          {
858             output << "#" << rlCnt << " ";
859
860             std::vector<am_RoutingElement_s>::iterator reIter = rlIter->route.begin();
861             for(;reIter < rlIter->route.end();reIter++)
862             {
863                reIter->connectionFormat;
864                reIter->domainID;
865                output << ">(" << reIter->sourceID << ")->--[D:"<< reIter->domainID <<"][F:"<< reIter->connectionFormat <<"]-->-(" << reIter->sinkID<< ")" << std::endl;
866             }
867
868             rlCnt++;
869          }
870
871          sendTelnetLine(filedescriptor,output);
872       }
873       else
874       {
875          sendError(filedescriptor,"Error getting route");
876       }
877
878    }
879    else
880    {
881       CmdQueue.pop();
882       output << "Not enough arguments to set routing. Please enter sourceID and sinkID after command" << std::endl;
883       return;
884    }
885
886
887 }
888
889 /****************************************************************************/
890 void CAmTelnetMenuHelper::setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor)
891 /****************************************************************************/
892 {
893    instance->setConnectionExec(CmdQueue,filedescriptor);
894 }
895
896 /****************************************************************************/
897 void CAmTelnetMenuHelper::setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
898 /****************************************************************************/
899 {
900    std::stringstream                   output;
901
902    am_sourceID_t                       sourceID = 0;
903    am_sinkID_t                         sinkID   = 0;
904    am_mainConnectionID_t               connID   = 0;
905
906    bool                                error = false;
907    am_Error_e                          rError = E_OK;
908
909    if(CmdQueue.size() >= 2)
910    {
911       std::istringstream istream_sourceID(CmdQueue.front());
912       CmdQueue.pop();
913
914       std::istringstream istream_sinkID(CmdQueue.front());
915             CmdQueue.pop();
916
917       if(!(istream_sourceID >> sourceID))
918          error = true;
919
920       if(!(istream_sinkID >> sinkID))
921          error = true;
922
923       if(error)
924       {
925          sendError(filedescriptor,"Error parsing sinkID and/or sourceID");
926          return;
927       }
928
929       // Try to set up connection
930       rError = mCommandReceiver->connect(sourceID,sinkID,connID);
931
932       if(E_OK == rError)
933       {
934          output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl;
935          sendTelnetLine(filedescriptor,output);
936       }
937       else
938       {
939          sendError(filedescriptor,"Error connecting sourceID and sinkID");
940       }
941
942    }
943    else
944    {
945       CmdQueue.pop();
946       sendError(filedescriptor,"Not enough arguments to set routing. Please enter sourceID and sinkID after command");
947       return;
948    }
949 }
950
951 /****************************************************************************/
952 void CAmTelnetMenuHelper::setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor)
953 /****************************************************************************/
954 {
955    instance->setDisconnectConnIdExec(CmdQueue,filedescriptor);
956 }
957
958 /****************************************************************************/
959 void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
960 /****************************************************************************/
961 {
962    std::stringstream                   output;
963
964    am_mainConnectionID_t               connID   = 0;
965
966    bool                                error = false;
967    am_Error_e                          rError = E_OK;
968
969    if(CmdQueue.size() >= 1)
970    {
971       std::istringstream istream_connID(CmdQueue.front());
972       CmdQueue.pop();
973
974       if(!(istream_connID >> connID))
975          error = true;
976
977       if(error)
978       {
979          sendError(filedescriptor,"Error parsing connID");
980          return;
981       }
982
983       // Try to disconnect connection id
984       rError = mCommandReceiver->disconnect(connID);
985
986       if(E_OK == rError)
987       {
988          output << "ConnID " << connID << " closed successfully! " << std::endl;
989          sendTelnetLine(filedescriptor,output);
990       }
991       else
992       {
993          sendError(filedescriptor,"Error disconnecting connectionID");
994       }
995    }
996    else
997    {
998       sendError(filedescriptor,"Not enough arguments to disconnect a Main Connection, please enter 'connectionID' after command");
999       return;
1000    }
1001 }
1002
1003 /****************************************************************************/
1004 void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1005 /****************************************************************************/
1006 {
1007    instance->setConnectionExec(CmdQueue,filedescriptor);
1008 }
1009
1010 /****************************************************************************/
1011 void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1012 /****************************************************************************/
1013 {
1014    std::stringstream    output;
1015    am_sinkID_t          sourceID;
1016    am_MainSoundProperty_s soundProperty;
1017    unsigned int tmpType = 0;
1018    bool error = false;
1019
1020    if(CmdQueue.size() >= 3)
1021    {
1022       std::istringstream istream_sourceID(CmdQueue.front());
1023       CmdQueue.pop();
1024
1025       std::istringstream istream_type(CmdQueue.front());
1026       CmdQueue.pop();
1027
1028       std::istringstream istream_value(CmdQueue.front());
1029       CmdQueue.pop();
1030
1031       if(!(istream_type >> tmpType))
1032          error = true;
1033
1034       if(tmpType < MSP_MAX)
1035          soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1036       else
1037          error = true;
1038
1039       if(!(istream_value >> soundProperty.value))
1040          error = true;
1041
1042       if(!(istream_sourceID >> sourceID))
1043          error = true;
1044
1045       if(error)
1046       {
1047          sendError(filedescriptor,"Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'");
1048          return;
1049       }
1050
1051       if(E_OK == mCommandReceiver->setMainSourceSoundProperty(soundProperty,sourceID))
1052       {
1053          output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1054          sendTelnetLine(filedescriptor,output);
1055       }
1056       else
1057       {
1058          sendError(filedescriptor,"Error setMainSourceSoundProperty");
1059       }
1060    }
1061    else
1062    {
1063       sendError(filedescriptor,"Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command");
1064       return;
1065    }
1066 }
1067
1068 /****************************************************************************/
1069 void CAmTelnetMenuHelper::setSinkSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1070 /****************************************************************************/
1071 {
1072    instance->setConnectionExec(CmdQueue,filedescriptor);
1073 }
1074
1075 /****************************************************************************/
1076 void CAmTelnetMenuHelper::setSinkSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1077 /****************************************************************************/
1078 {
1079    std::stringstream    output;
1080    am_sinkID_t          sinkID;
1081    am_MainSoundProperty_s soundProperty;
1082    unsigned int tmpType = 0;
1083    bool error = false;
1084
1085    if(CmdQueue.size() >= 3)
1086    {
1087       std::istringstream istream_sinkID(CmdQueue.front());
1088       CmdQueue.pop();
1089
1090       std::istringstream istream_type(CmdQueue.front());
1091       CmdQueue.pop();
1092
1093       std::istringstream istream_value(CmdQueue.front());
1094       CmdQueue.pop();
1095
1096       if(!(istream_type >> tmpType))
1097          error = true;
1098
1099       if(tmpType < MSP_MAX)
1100          soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1101       else
1102          error = true;
1103
1104       if(!(istream_value >> soundProperty.value))
1105          error = true;
1106
1107       if(!(istream_sinkID >> sinkID))
1108          error = true;
1109
1110       if(error)
1111       {
1112          sendError(filedescriptor,"Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'");
1113          return;
1114       }
1115
1116       if(E_OK == mCommandReceiver->setMainSinkSoundProperty(soundProperty,sinkID))
1117       {
1118          output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1119          sendTelnetLine(filedescriptor,output);
1120       }
1121       else
1122       {
1123          sendError(filedescriptor,"Error setMainSinkSoundProperty");
1124       }
1125    }
1126    else
1127    {
1128       sendError(filedescriptor,"Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command");
1129       return;
1130    }
1131 }
1132
1133
1134 /****************************************************************************/
1135 void CAmTelnetMenuHelper::listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1136 /****************************************************************************/
1137 {
1138    instance->listPluginsCommandExec(CmdQueue,filedescriptor);
1139 }
1140
1141 /****************************************************************************/
1142 void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1143 /****************************************************************************/
1144 {
1145    std::vector<std::string> PlugInNames;
1146    std::vector<std::string>::iterator iter;
1147    std::stringstream output;
1148    am_Error_e rError = E_OK;
1149
1150
1151    rError = mCommandSender->getListPlugins(PlugInNames);
1152
1153    output << "CommandSender Plugins loaded: " << PlugInNames.size() << std::endl;
1154
1155    for(iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++ )
1156    {
1157       output << iter->c_str() << std::endl;
1158    }
1159
1160    rError = mRoutingSender->getListPlugins(PlugInNames);
1161
1162    output << std::endl << "RoutingSender Plugins loaded: " << PlugInNames.size() << std::endl;
1163
1164    for(iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++ )
1165    {
1166       output << iter->c_str() << std::endl;
1167    }
1168
1169    sendTelnetLine(filedescriptor,output);
1170 }
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181