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