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