/[svn]/linuxsampler/trunk/src/network/lscpserver.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscpserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2324 by persson, Sun Mar 4 09:01:32 2012 UTC revision 2535 by schoenebeck, Tue Apr 15 19:35:35 2014 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2012 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2014 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 47  Line 47 
47    
48  namespace LinuxSampler {  namespace LinuxSampler {
49    
50    String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param, bool possibilities);
51    
52  /**  /**
53   * Returns a copy of the given string where all special characters are   * Returns a copy of the given string where all special characters are
54   * replaced by LSCP escape sequences ("\xHH"). This function shall be used   * replaced by LSCP escape sequences ("\xHH"). This function shall be used
# Line 97  static String _escapeLscpResponse(String Line 99  static String _escapeLscpResponse(String
99   */   */
100  fd_set LSCPServer::fdSet;  fd_set LSCPServer::fdSet;
101  int LSCPServer::currentSocket = -1;  int LSCPServer::currentSocket = -1;
102  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();  std::vector<yyparse_param_t> LSCPServer::Sessions;
103  std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator();  std::vector<yyparse_param_t>::iterator itCurrentSession;
104  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedNotifies;
105  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedCommands;
106  std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >();  std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions;
107  Mutex LSCPServer::NotifyMutex = Mutex();  Mutex LSCPServer::NotifyMutex;
108  Mutex LSCPServer::NotifyBufferMutex = Mutex();  Mutex LSCPServer::NotifyBufferMutex;
109  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex;
110  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex;
111    
112  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) {  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) {
113      SocketAddress.sin_family      = AF_INET;      SocketAddress.sin_family      = AF_INET;
# Line 447  int LSCPServer::Main() { Line 449  int LSCPServer::Main() {
449          #endif          #endif
450          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
451          {          {
452              EngineChannelFactory::EngineChannelsMutex.Lock();              LockGuard lock(EngineChannelFactory::EngineChannelsMutex);
453              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
454              std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();              std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
455              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
# Line 465  int LSCPServer::Main() { Line 467  int LSCPServer::Main() {
467                      }                      }
468                  }                  }
469              }              }
             EngineChannelFactory::EngineChannelsMutex.Unlock();  
470          }          }
471    
472          // check if MIDI data arrived on some engine channel          // check if MIDI data arrived on some engine channel
# Line 517  int LSCPServer::Main() { Line 518  int LSCPServer::Main() {
518              }              }
519          }          }
520    
521          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
522          NotifyBufferMutex.Lock();          {
523          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {              LockGuard lock(NotifyBufferMutex);
524                for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
525  #ifdef MSG_NOSIGNAL  #ifdef MSG_NOSIGNAL
526                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
527  #else  #else
528                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
529  #endif  #endif
530          }              }
531          bufferedNotifies.clear();              bufferedNotifies.clear();
532          NotifyBufferMutex.Unlock();          }
533    
534          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
535          timeout.tv_sec  = 0;          timeout.tv_sec  = 0;
# Line 592  int LSCPServer::Main() { Line 594  int LSCPServer::Main() {
594          //Something was selected and it was not the hSocket, so it must be some command(s) coming.          //Something was selected and it was not the hSocket, so it must be some command(s) coming.
595          for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) {          for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) {
596                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
597                            currentSocket = (*iter).hSession;  //a hack
598                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
599                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
600                                  int dummy; // just a temporary hack to fulfill the restart() function prototype                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
601                                  restart(NULL, dummy); // restart the 'scanner'                                  restart(NULL, dummy); // restart the 'scanner'
                                 currentSocket = (*iter).hSession;  //a hack  
602                                  itCurrentSession = iter; // another hack                                  itCurrentSession = iter; // another hack
603                                  dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));                                  dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
604                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
# Line 610  int LSCPServer::Main() { Line 612  int LSCPServer::Main() {
612                                          CloseConnection(iter);                                          CloseConnection(iter);
613                                  }                                  }
614                          }                          }
615                            currentSocket = -1;     //continuation of a hack
616                          //socket may have been closed, iter may be invalid, get out of the loop for now.                          //socket may have been closed, iter may be invalid, get out of the loop for now.
617                          //we'll be back if there is data.                          //we'll be back if there is data.
618                          break;                          break;
# Line 624  void LSCPServer::CloseConnection( std::v Line 627  void LSCPServer::CloseConnection( std::v
627          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));
628          Sessions.erase(iter);          Sessions.erase(iter);
629          FD_CLR(socket,  &fdSet);          FD_CLR(socket,  &fdSet);
630          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)          {
631          for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {              LockGuard lock(SubscriptionMutex);
632                  iter->second.remove(socket);              // Must unsubscribe this socket from all events (if any)
633          }              for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {
634          SubscriptionMutex.Unlock();                  iter->second.remove(socket);
635          NotifyMutex.Lock();              }
636            }
637            LockGuard lock(NotifyMutex);
638          bufferedCommands.erase(socket);          bufferedCommands.erase(socket);
639          bufferedNotifies.erase(socket);          bufferedNotifies.erase(socket);
640          #if defined(WIN32)          #if defined(WIN32)
# Line 637  void LSCPServer::CloseConnection( std::v Line 642  void LSCPServer::CloseConnection( std::v
642          #else          #else
643          close(socket);          close(socket);
644          #endif          #endif
         NotifyMutex.Unlock();  
645  }  }
646    
647  void LSCPServer::CloseAllConnections() {  void LSCPServer::CloseAllConnections() {
# Line 648  void LSCPServer::CloseAllConnections() { Line 652  void LSCPServer::CloseAllConnections() {
652      }      }
653  }  }
654    
 void LSCPServer::LockRTNotify() {  
     RTNotifyMutex.Lock();  
 }  
   
 void LSCPServer::UnlockRTNotify() {  
     RTNotifyMutex.Unlock();  
 }  
   
655  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
656          int subs = 0;          int subs = 0;
657          SubscriptionMutex.Lock();          LockGuard lock(SubscriptionMutex);
658          for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();          for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
659                          iter != events.end(); iter++)                          iter != events.end(); iter++)
660          {          {
661                  subs += eventSubscriptions.count(*iter);                  subs += eventSubscriptions.count(*iter);
662          }          }
         SubscriptionMutex.Unlock();  
663          return subs;          return subs;
664  }  }
665    
666  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
667          SubscriptionMutex.Lock();          LockGuard lock(SubscriptionMutex);
668          if (eventSubscriptions.count(event.GetType()) == 0) {          if (eventSubscriptions.count(event.GetType()) == 0) {
669                  SubscriptionMutex.Unlock();     //Nobody is subscribed to this event                  // Nobody is subscribed to this event
670                  return;                  return;
671          }          }
672          std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin();          std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin();
# Line 697  void LSCPServer::SendLSCPNotify( LSCPEve Line 692  void LSCPServer::SendLSCPNotify( LSCPEve
692                          }                          }
693                  }                  }
694          }          }
         SubscriptionMutex.Unlock();  
695  }  }
696    
697  extern int GetLSCPCommand( void *buf, int max_size ) {  extern int GetLSCPCommand( void *buf, int max_size ) {
# Line 722  extern yyparse_param_t* GetCurrentYaccSe Line 716  extern yyparse_param_t* GetCurrentYaccSe
716  }  }
717    
718  /**  /**
719     * Generate the relevant LSCP documentation reference section if necessary.
720     * The documentation section for the currently active command on the LSCP
721     * shell's command line will be encoded in a special format, specifically for
722     * the LSCP shell application.
723     *
724     * @param line - current LSCP command line
725     * @param param - reentrant Bison parser parameters
726     *
727     * @return encoded reference string or empty string if nothing shall be sent
728     *         to LSCP shell (client) at this point
729     */
730    String LSCPServer::generateLSCPDocReply(const String& line, yyparse_param_t* param) {
731        String result;
732        lscp_ref_entry_t* ref = lscp_reference_for_command(line.c_str());
733        // Pointer comparison works here, since the function above always
734        // returns the same constant pointer for the respective LSCP
735        // command ... Only send the LSCP reference section to the client if
736        // another LSCP reference section became relevant now:
737        if (ref != param->pLSCPDocRef) {
738            param->pLSCPDocRef = ref;
739            if (ref) { // send a new LSCP doc section to client ...
740                result += "SHD:" + ToString(LSCP_SHD_MATCH) + ":" + String(ref->name) + "\n";
741                result += String(ref->section) + "\n";
742                result += "."; // dot line marks the end of the text for client
743            } else { // inform client that no LSCP doc section matches right now ...
744                result = "SHD:" + ToString(LSCP_SHD_NO_MATCH);
745            }
746        }
747        dmsg(4,("LSCP doc reply -> '%s'\n", result.c_str()));
748        return result;
749    }
750    
751    /**
752   * Will be called to try to read the command from the socket   * Will be called to try to read the command from the socket
753   * If command is read, it will return true. Otherwise false is returned.   * If command is read, it will return true. Otherwise false is returned.
754   * In any case the received portion (complete or incomplete) is saved into bufferedCommand map.   * In any case the received portion (complete or incomplete) is saved into bufferedCommand map.
755   */   */
756  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {
757          int socket = (*iter).hSession;          int socket = (*iter).hSession;
758            int result;
759          char c;          char c;
760          int i = 0;          std::vector<char> input;
761    
762            // first get as many character as possible and add it to the 'input' buffer
763          while (true) {          while (true) {
764                  #if defined(WIN32)                  #if defined(WIN32)
765                  int result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now                  result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now
766                  #else                  #else
767                  int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now                  result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now
768                  #endif                  #endif
769                  if (result == 0) { //socket was selected, so 0 here means client has closed the connection                  if (result == 1) input.push_back(c);
770                          CloseConnection(iter);                  else break; // end of input or some error
771                          break;                  if (c == '\n') break; // process line by line
772            }
773    
774            // process input buffer
775            for (int i = 0; i < input.size(); ++i) {
776                    c = input[i];
777                    if (c == '\r') continue; //Ignore CR
778                    if (c == '\n') {
779                            // only if the other side is the LSCP shell application:
780                            // check the current (incomplete) command line for syntax errors,
781                            // possible completions and report everything back to the shell
782                            if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) {
783                                    String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), false);
784                                    if (!s.empty() && (*iter).bShellInteract) AnswerClient(s + "\n");
785                            }
786                            // if other side is LSCP shell application, send the relevant LSCP
787                            // documentation section of the current command line (if necessary)
788                            if ((*iter).bShellSendLSCPDoc && (*iter).bShellInteract) {
789                                    String s = generateLSCPDocReply(bufferedCommands[socket], &(*iter));
790                                    if (!s.empty()) AnswerClient(s + "\n");
791                            }
792                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
793                            bufferedCommands[socket] += "\r\n";
794                            return true; //Complete command was read
795                    } else if (c == 2) { // custom ASCII code usage for moving cursor left (LSCP shell)
796                            if (iter->iCursorOffset + bufferedCommands[socket].size() > 0)
797                                    iter->iCursorOffset--;
798                    } else if (c == 3) { // custom ASCII code usage for moving cursor right (LSCP shell)
799                            if (iter->iCursorOffset < 0) iter->iCursorOffset++;
800                    } else {
801                            size_t cursorPos = bufferedCommands[socket].size() + iter->iCursorOffset;
802                            // backspace character - should only happen with shell
803                            if (c == '\b') {
804                                    if (!bufferedCommands[socket].empty() && cursorPos > 0)
805                                            bufferedCommands[socket].erase(cursorPos - 1, 1);
806                            } else { // append (or insert) new character (at current cursor position) ...
807                                    if (cursorPos >= 0)
808                                            bufferedCommands[socket].insert(cursorPos, String(1,c)); // insert
809                                    else
810                                            bufferedCommands[socket] += c; // append
811                            }
812                  }                  }
813                  if (result == 1) {                  // Only if the other side (client) is the LSCP shell application:
814                          if (c == '\r')                  // The following block takes care about automatic correction, auto
815                                  continue; //Ignore CR                  // completion (and suggestions), LSCP reference documentation, etc.
816                          if (c == '\n') {                  // The "if" statement here is for optimization reasons, so that the
817                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                  // heavy LSCP grammar evaluation algorithm is only executed once for an
818                                  bufferedCommands[socket] += "\r\n";                  // entire command line received.
819                                  return true; //Complete command was read                  if (i == input.size() - 1) {
820                            // check the current (incomplete) command line for syntax errors,
821                            // possible completions and report everything back to the shell
822                            if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) {
823                                    String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), true);
824                                    if (!s.empty() && (*iter).bShellInteract && i == input.size() - 1)
825                                            AnswerClient(s + "\n");
826                            }
827                            // if other side is LSCP shell application, send the relevant LSCP
828                            // documentation section of the current command line (if necessary)
829                            if ((*iter).bShellSendLSCPDoc && (*iter).bShellInteract) {
830                                    String s = generateLSCPDocReply(bufferedCommands[socket], &(*iter));
831                                    if (!s.empty()) AnswerClient(s + "\n");
832                          }                          }
                         bufferedCommands[socket] += c;  
833                  }                  }
834                  #if defined(WIN32)          }
835                  if (result == SOCKET_ERROR) {  
836                      int wsa_lasterror = WSAGetLastError();          // handle network errors ...
837                          if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later.          if (result == 0) { //socket was selected, so 0 here means client has closed the connection
838                    CloseConnection(iter);
839                    return false;
840            }
841            #if defined(WIN32)
842            if (result == SOCKET_ERROR) {
843                    int wsa_lasterror = WSAGetLastError();
844                    if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later.
845                            return false;
846                    dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror));
847                    CloseConnection(iter);
848                    return false;
849            }
850            #else
851            if (result == -1) {
852                    if (errno == EAGAIN) //Would block, try again later.
853                            return false;
854                    switch(errno) {
855                            case EBADF:
856                                    dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n"));
857                                  return false;                                  return false;
858                          dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror));                          case ECONNREFUSED:
859                          CloseConnection(iter);                                  dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n"));
860                          break;                                  return false;
861                  }                          case ENOTCONN:
862                  #else                                  dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n"));
863                  if (result == -1) {                                  return false;
864                          if (errno == EAGAIN) //Would block, try again later.                          case ENOTSOCK:
865                                    dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n"));
866                                    return false;
867                            case EAGAIN:
868                                    dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));
869                                    return false;
870                            case EINTR:
871                                    dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));
872                                    return false;
873                            case EFAULT:
874                                    dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));
875                                    return false;
876                            case EINVAL:
877                                    dmsg(2,("LSCPScanner: Invalid argument passed.\n"));
878                                    return false;
879                            case ENOMEM:
880                                    dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));
881                                    return false;
882                            default:
883                                    dmsg(2,("LSCPScanner: Unknown recv() error.\n"));
884                                  return false;                                  return false;
                         switch(errno) {  
                                 case EBADF:  
                                         dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n"));  
                                         break;  
                                 case ECONNREFUSED:  
                                         dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n"));  
                                         break;  
                                 case ENOTCONN:  
                                         dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n"));  
                                         break;  
                                 case ENOTSOCK:  
                                         dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n"));  
                                         break;  
                                 case EAGAIN:  
                                         dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));  
                                         break;  
                                 case EINTR:  
                                         dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));  
                                         break;  
                                 case EFAULT:  
                                         dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));  
                                         break;  
                                 case EINVAL:  
                                         dmsg(2,("LSCPScanner: Invalid argument passed.\n"));  
                                         break;  
                                 case ENOMEM:  
                                         dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));  
                                         break;  
                                 default:  
                                         dmsg(2,("LSCPScanner: Unknown recv() error.\n"));  
                                         break;  
                         }  
                         CloseConnection(iter);  
                         break;  
885                  }                  }
886                  #endif                  CloseConnection(iter);
887                    return false;
888          }          }
889            #endif
890    
891          return false;          return false;
892  }  }
893    
# Line 810  bool LSCPServer::GetLSCPCommand( std::ve Line 898  bool LSCPServer::GetLSCPCommand( std::ve
898   * @param ReturnMessage - message that will be send to the client   * @param ReturnMessage - message that will be send to the client
899   */   */
900  void LSCPServer::AnswerClient(String ReturnMessage) {  void LSCPServer::AnswerClient(String ReturnMessage) {
901      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage='%s')", ReturnMessage.c_str()));
902      if (currentSocket != -1) {      if (currentSocket != -1) {
903              NotifyMutex.Lock();              LockGuard lock(NotifyMutex);
904    
905            // just if other side is LSCP shell: in case respose is a multi-line
906            // one, then inform client about it before sending the actual mult-line
907            // response
908            if (GetCurrentYaccSession()->bShellInteract) {
909                // check if this is a multi-line response
910                int n = 0;
911                for (int i = 0; i < ReturnMessage.size(); ++i)
912                    if (ReturnMessage[i] == '\n') ++n;
913                if (n >= 2) {
914                    dmsg(2,("LSCP Shell <- expect mult-line response\n"));
915                    String s = LSCP_SHK_EXPECT_MULTI_LINE "\r\n";
916    #ifdef MSG_NOSIGNAL
917                    send(currentSocket, s.c_str(), s.size(), MSG_NOSIGNAL);
918    #else
919                    send(currentSocket, s.c_str(), s.size(), 0);
920    #endif                
921                }
922            }
923    
924  #ifdef MSG_NOSIGNAL  #ifdef MSG_NOSIGNAL
925              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
926  #else  #else
927              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
928  #endif  #endif
             NotifyMutex.Unlock();  
929      }      }
930  }  }
931    
# Line 968  String LSCPServer::SetEngineType(String Line 1075  String LSCPServer::SetEngineType(String
1075      try {      try {
1076          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1077          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1078          LockRTNotify();          LockGuard lock(RTNotifyMutex);
1079          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
1080          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
         UnlockRTNotify();  
1081      }      }
1082      catch (Exception e) {      catch (Exception e) {
1083           result.Error(e);           result.Error(e);
# Line 1011  String LSCPServer::ListChannels() { Line 1117  String LSCPServer::ListChannels() {
1117   */   */
1118  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
1119      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
1120      LockRTNotify();      SamplerChannel* pSamplerChannel;
1121      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      {
1122      UnlockRTNotify();          LockGuard lock(RTNotifyMutex);
1123            pSamplerChannel = pSampler->AddSamplerChannel();
1124        }
1125      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
1126      return result.Produce();      return result.Produce();
1127  }  }
# Line 1024  String LSCPServer::AddChannel() { Line 1132  String LSCPServer::AddChannel() {
1132  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
1133      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
1134      LSCPResultSet result;      LSCPResultSet result;
1135      LockRTNotify();      {
1136      pSampler->RemoveSamplerChannel(uiSamplerChannel);          LockGuard lock(RTNotifyMutex);
1137      UnlockRTNotify();          pSampler->RemoveSamplerChannel(uiSamplerChannel);
1138        }
1139      return result.Produce();      return result.Produce();
1140  }  }
1141    
# Line 1069  String LSCPServer::ListAvailableEngines( Line 1178  String LSCPServer::ListAvailableEngines(
1178  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
1179      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
1180      LSCPResultSet result;      LSCPResultSet result;
1181      LockRTNotify();      {
1182      try {          LockGuard lock(RTNotifyMutex);
1183          Engine* pEngine = EngineFactory::Create(EngineName);          try {
1184          result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));              Engine* pEngine = EngineFactory::Create(EngineName);
1185          result.Add("VERSION",     pEngine->Version());              result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));
1186          EngineFactory::Destroy(pEngine);              result.Add("VERSION",     pEngine->Version());
1187      }              EngineFactory::Destroy(pEngine);
1188      catch (Exception e) {          }
1189           result.Error(e);          catch (Exception e) {
1190                result.Error(e);
1191            }
1192      }      }
     UnlockRTNotify();  
1193      return result.Produce();      return result.Produce();
1194  }  }
1195    
# Line 1728  String LSCPServer::SetAudioOutputChannel Line 1838  String LSCPServer::SetAudioOutputChannel
1838  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1839      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1840      LSCPResultSet result;      LSCPResultSet result;
1841      LockRTNotify();      {
1842            LockGuard lock(RTNotifyMutex);
1843            try {
1844                SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1845                if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1846                std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1847                if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));
1848                AudioOutputDevice* pDevice = devices[AudioDeviceId];
1849                pSamplerChannel->SetAudioOutputDevice(pDevice);
1850            }
1851            catch (Exception e) {
1852                result.Error(e);
1853            }
1854        }
1855        return result.Produce();
1856    }
1857    
1858    String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1859        dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
1860        LSCPResultSet result;
1861        {
1862            LockGuard lock(RTNotifyMutex);
1863            try {
1864                SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1865                if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1866                // Driver type name aliasing...
1867                if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1868                if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1869                // Check if there's one audio output device already created
1870                // for the intended audio driver type (AudioOutputDriver)...
1871                AudioOutputDevice *pDevice = NULL;
1872                std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1873                std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
1874                for (; iter != devices.end(); iter++) {
1875                    if ((iter->second)->Driver() == AudioOutputDriver) {
1876                        pDevice = iter->second;
1877                        break;
1878                    }
1879                }
1880                // If it doesn't exist, create a new one with default parameters...
1881                if (pDevice == NULL) {
1882                    std::map<String,String> params;
1883                    pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);
1884                }
1885                // Must have a device...
1886                if (pDevice == NULL)
1887                    throw Exception("Internal error: could not create audio output device.");
1888                // Set it as the current channel device...
1889                pSamplerChannel->SetAudioOutputDevice(pDevice);
1890            }
1891            catch (Exception e) {
1892                result.Error(e);
1893            }
1894        }
1895        return result.Produce();
1896    }
1897    
1898    String LSCPServer::AddChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) {
1899        dmsg(2,("LSCPServer: AddChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort));
1900        LSCPResultSet result;
1901      try {      try {
1902          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1903          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1904          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();  
1905          if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1906          AudioOutputDevice* pDevice = devices[AudioDeviceId];          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1907          pSamplerChannel->SetAudioOutputDevice(pDevice);          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1908    
1909            MidiInputPort* pPort = pDevice->GetPort(MIDIPort);
1910            if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId));
1911    
1912            pSamplerChannel->Connect(pPort);
1913        } catch (Exception e) {
1914            result.Error(e);
1915      }      }
1916      catch (Exception e) {      return result.Produce();
1917           result.Error(e);  }
1918    
1919    String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel) {
1920        dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d)\n",uiSamplerChannel));
1921        LSCPResultSet result;
1922        try {
1923            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1924            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1925            pSamplerChannel->DisconnectAllMidiInputPorts();
1926        } catch (Exception e) {
1927            result.Error(e);
1928      }      }
     UnlockRTNotify();  
1929      return result.Produce();      return result.Produce();
1930  }  }
1931    
1932  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId) {
1933      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d)\n",uiSamplerChannel,MIDIDeviceId));
1934      LSCPResultSet result;      LSCPResultSet result;
     LockRTNotify();  
1935      try {      try {
1936          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1937          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1938          // Driver type name aliasing...  
1939          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1940          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1941          // Check if there's one audio output device already created          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1942          // for the intended audio driver type (AudioOutputDriver)...          
1943          AudioOutputDevice *pDevice = NULL;          std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts();
1944          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          for (int i = 0; i < vPorts.size(); ++i)
1945          std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();              if (vPorts[i]->GetDevice() == pDevice)
1946          for (; iter != devices.end(); iter++) {                  pSamplerChannel->Disconnect(vPorts[i]);
1947              if ((iter->second)->Driver() == AudioOutputDriver) {  
1948                  pDevice = iter->second;      } catch (Exception e) {
1949                  break;          result.Error(e);
             }  
         }  
         // If it doesn't exist, create a new one with default parameters...  
         if (pDevice == NULL) {  
             std::map<String,String> params;  
             pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);  
         }  
         // Must have a device...  
         if (pDevice == NULL)  
             throw Exception("Internal error: could not create audio output device.");  
         // Set it as the current channel device...  
         pSamplerChannel->SetAudioOutputDevice(pDevice);  
1950      }      }
1951      catch (Exception e) {      return result.Produce();
1952           result.Error(e);  }
1953    
1954    String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) {
1955        dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort));
1956        LSCPResultSet result;
1957        try {
1958            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1959            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1960    
1961            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1962            if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1963            MidiInputDevice* pDevice = devices[MIDIDeviceId];
1964    
1965            MidiInputPort* pPort = pDevice->GetPort(MIDIPort);
1966            if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId));
1967    
1968            pSamplerChannel->Disconnect(pPort);
1969        } catch (Exception e) {
1970            result.Error(e);
1971        }
1972        return result.Produce();
1973    }
1974    
1975    String LSCPServer::ListChannelMidiInputs(uint uiSamplerChannel) {
1976        dmsg(2,("LSCPServer: ListChannelMidiInputs(uiSamplerChannel=%d)\n",uiSamplerChannel));
1977        LSCPResultSet result;
1978        try {
1979            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1980            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1981            std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts();
1982    
1983            String s;
1984            for (int i = 0; i < vPorts.size(); ++i) {
1985                const int iDeviceID = vPorts[i]->GetDevice()->MidiInputDeviceID();
1986                const int iPortNr   = vPorts[i]->GetPortNumber();
1987                if (s.size()) s += ",";
1988                s += "{" + ToString(iDeviceID) + ","
1989                         + ToString(iPortNr) + "}";
1990            }
1991            result.Add(s);
1992        } catch (Exception e) {
1993            result.Error(e);
1994      }      }
     UnlockRTNotify();  
1995      return result.Produce();      return result.Produce();
1996  }  }
1997    
# Line 3063  String LSCPServer::GetTotalVoiceCount() Line 3275  String LSCPServer::GetTotalVoiceCount()
3275  String LSCPServer::GetTotalVoiceCountMax() {  String LSCPServer::GetTotalVoiceCountMax() {
3276      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
3277      LSCPResultSet result;      LSCPResultSet result;
3278      result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES);      result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices());
3279      return result.Produce();      return result.Produce();
3280  }  }
3281    
# Line 3074  String LSCPServer::GetTotalVoiceCountMax Line 3286  String LSCPServer::GetTotalVoiceCountMax
3286  String LSCPServer::GetGlobalMaxVoices() {  String LSCPServer::GetGlobalMaxVoices() {
3287      dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));      dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));
3288      LSCPResultSet result;      LSCPResultSet result;
3289      result.Add(GLOBAL_MAX_VOICES);      result.Add(pSampler->GetGlobalMaxVoices());
3290      return result.Produce();      return result.Produce();
3291  }  }
3292    
# Line 3086  String LSCPServer::SetGlobalMaxVoices(in Line 3298  String LSCPServer::SetGlobalMaxVoices(in
3298      dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));      dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));
3299      LSCPResultSet result;      LSCPResultSet result;
3300      try {      try {
3301          if (iVoices < 1) throw Exception("Maximum voices may not be less than 1");          pSampler->SetGlobalMaxVoices(iVoices);
3302          GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp          LSCPServer::SendLSCPNotify(
3303          const std::set<Engine*>& engines = EngineFactory::EngineInstances();              LSCPEvent(LSCPEvent::event_global_info, "VOICES", pSampler->GetGlobalMaxVoices())
3304          if (engines.size() > 0) {          );
             std::set<Engine*>::iterator iter = engines.begin();  
             std::set<Engine*>::iterator end  = engines.end();  
             for (; iter != end; ++iter) {  
                 (*iter)->SetMaxVoices(iVoices);  
             }  
         }  
         LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES));  
3305      } catch (Exception e) {      } catch (Exception e) {
3306          result.Error(e);          result.Error(e);
3307      }      }
# Line 3110  String LSCPServer::SetGlobalMaxVoices(in Line 3315  String LSCPServer::SetGlobalMaxVoices(in
3315  String LSCPServer::GetGlobalMaxStreams() {  String LSCPServer::GetGlobalMaxStreams() {
3316      dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));      dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));
3317      LSCPResultSet result;      LSCPResultSet result;
3318      result.Add(GLOBAL_MAX_STREAMS);      result.Add(pSampler->GetGlobalMaxStreams());
3319      return result.Produce();      return result.Produce();
3320  }  }
3321    
# Line 3122  String LSCPServer::SetGlobalMaxStreams(i Line 3327  String LSCPServer::SetGlobalMaxStreams(i
3327      dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));      dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));
3328      LSCPResultSet result;      LSCPResultSet result;
3329      try {      try {
3330          if (iStreams < 0) throw Exception("Maximum disk streams may not be negative");          pSampler->SetGlobalMaxStreams(iStreams);
3331          GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp          LSCPServer::SendLSCPNotify(
3332          const std::set<Engine*>& engines = EngineFactory::EngineInstances();              LSCPEvent(LSCPEvent::event_global_info, "STREAMS", pSampler->GetGlobalMaxStreams())
3333          if (engines.size() > 0) {          );
             std::set<Engine*>::iterator iter = engines.begin();  
             std::set<Engine*>::iterator end  = engines.end();  
             for (; iter != end; ++iter) {  
                 (*iter)->SetMaxDiskStreams(iStreams);  
             }  
         }  
         LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS));  
3334      } catch (Exception e) {      } catch (Exception e) {
3335          result.Error(e);          result.Error(e);
3336      }      }
# Line 3336  void LSCPServer::VerifyFile(String Filen Line 3534  void LSCPServer::VerifyFile(String Filen
3534  String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) {  String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) {
3535      dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));      dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));
3536      LSCPResultSet result;      LSCPResultSet result;
3537      SubscriptionMutex.Lock();      {
3538      eventSubscriptions[type].push_back(currentSocket);          LockGuard lock(SubscriptionMutex);
3539      SubscriptionMutex.Unlock();          eventSubscriptions[type].push_back(currentSocket);
3540        }
3541      return result.Produce();      return result.Produce();
3542  }  }
3543    
# Line 3349  String LSCPServer::SubscribeNotification Line 3548  String LSCPServer::SubscribeNotification
3548  String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) {  String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) {
3549      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));
3550      LSCPResultSet result;      LSCPResultSet result;
3551      SubscriptionMutex.Lock();      {
3552      eventSubscriptions[type].remove(currentSocket);          LockGuard lock(SubscriptionMutex);
3553      SubscriptionMutex.Unlock();          eventSubscriptions[type].remove(currentSocket);
3554        }
3555      return result.Produce();      return result.Produce();
3556  }  }
3557    
# Line 3876  String LSCPServer::SetEcho(yyparse_param Line 4076  String LSCPServer::SetEcho(yyparse_param
4076      }      }
4077      return result.Produce();      return result.Produce();
4078  }  }
4079    
4080    String LSCPServer::SetShellInteract(yyparse_param_t* pSession, double boolean_value) {
4081        dmsg(2,("LSCPServer: SetShellInteract(val=%f)\n", boolean_value));
4082        LSCPResultSet result;
4083        try {
4084            if      (boolean_value == 0) pSession->bShellInteract = false;
4085            else if (boolean_value == 1) pSession->bShellInteract = true;
4086            else throw Exception("Not a boolean value, must either be 0 or 1");
4087        } catch (Exception e) {
4088            result.Error(e);
4089        }
4090        return result.Produce();
4091    }
4092    
4093    String LSCPServer::SetShellAutoCorrect(yyparse_param_t* pSession, double boolean_value) {
4094        dmsg(2,("LSCPServer: SetShellAutoCorrect(val=%f)\n", boolean_value));
4095        LSCPResultSet result;
4096        try {
4097            if      (boolean_value == 0) pSession->bShellAutoCorrect = false;
4098            else if (boolean_value == 1) pSession->bShellAutoCorrect = true;
4099            else throw Exception("Not a boolean value, must either be 0 or 1");
4100        } catch (Exception e) {
4101            result.Error(e);
4102        }
4103        return result.Produce();
4104    }
4105    
4106    String LSCPServer::SetShellDoc(yyparse_param_t* pSession, double boolean_value) {
4107        dmsg(2,("LSCPServer: SetShellDoc(val=%f)\n", boolean_value));
4108        LSCPResultSet result;
4109        try {
4110            if      (boolean_value == 0) pSession->bShellSendLSCPDoc = false;
4111            else if (boolean_value == 1) pSession->bShellSendLSCPDoc = true;
4112            else throw Exception("Not a boolean value, must either be 0 or 1");
4113        } catch (Exception e) {
4114            result.Error(e);
4115        }
4116        return result.Produce();
4117    }
4118    
4119  }  }

Legend:
Removed from v.2324  
changed lines
  Added in v.2535

  ViewVC Help
Powered by ViewVC