/[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 209 by schoenebeck, Sun Jul 18 00:29:39 2004 UTC revision 210 by schoenebeck, Sat Jul 24 12:33:49 2004 UTC
# Line 43  Line 43 
43   */   */
44  fd_set LSCPServer::fdSet;  fd_set LSCPServer::fdSet;
45  int LSCPServer::currentSocket = -1;  int LSCPServer::currentSocket = -1;
46  std::vector<int> LSCPServer::hSessions = std::vector<int>();  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();
47  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();
48  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();
49  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 = std::map< LSCPEvent::event_t, std::list<int> >();
# Line 90  int LSCPServer::Main() { Line 90  int LSCPServer::Main() {
90      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
91      int maxSessions = hSocket;      int maxSessions = hSocket;
92    
     // Parser initialization  
     yyparse_param_t yyparse_param;  
     yyparse_param.pServer = this;  
   
93      while (true) {      while (true) {
94          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
95          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);
# Line 118  int LSCPServer::Main() { Line 114  int LSCPServer::Main() {
114                          exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
115                  }                  }
116    
117                  hSessions.push_back(socket);                  // Parser initialization
118                    yyparse_param_t yyparse_param;
119                    yyparse_param.pServer  = this;
120                    yyparse_param.hSession = socket;
121    
122                    Sessions.push_back(yyparse_param);
123                  FD_SET(socket, &fdSet);                  FD_SET(socket, &fdSet);
124                  if (socket > maxSessions)                  if (socket > maxSessions)
125                          maxSessions = socket;                          maxSessions = socket;
# Line 128  int LSCPServer::Main() { Line 129  int LSCPServer::Main() {
129          }          }
130    
131          //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.
132          for (std::vector<int>::iterator iter = hSessions.begin(); iter !=  hSessions.end(); iter++) {          for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) {
133                  if (FD_ISSET(*iter, &selectSet)) {      //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
134                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
135                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
136                                  yylex_init(&yyparse_param.pScanner);                                  yylex_init(&((*iter).pScanner)); //FIXME: should me moved out of this loop and initialized only when a new session is created
137                                  currentSocket = *iter;  //a hack                                  currentSocket = (*iter).hSession;  //a hack
138                                  int result = yyparse(&yyparse_param);                                  if ((*iter).bVerbose) { // if echo mode enabled
139                                        AnswerClient(bufferedCommands[currentSocket]);
140                                    }
141                                    int result = yyparse(&(*iter));
142                                  currentSocket = -1;     //continuation of a hack                                  currentSocket = -1;     //continuation of a hack
143                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));
144                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?
# Line 159  int LSCPServer::Main() { Line 163  int LSCPServer::Main() {
163      //yylex_destroy(yyparse_param.pScanner);      //yylex_destroy(yyparse_param.pScanner);
164  }  }
165    
166  void LSCPServer::CloseConnection( std::vector<int>::iterator iter ) {  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {
167          int socket = *iter;          int socket = (*iter).hSession;
168          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));
169          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));
170          hSessions.erase(iter);          Sessions.erase(iter);
171          FD_CLR(socket,  &fdSet);          FD_CLR(socket,  &fdSet);
172          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)
173          for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {          for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {
# Line 175  void LSCPServer::CloseConnection( std::v Line 179  void LSCPServer::CloseConnection( std::v
179          bufferedNotifies.erase(socket);          bufferedNotifies.erase(socket);
180          close(socket);          close(socket);
181          NotifyMutex.Unlock();          NotifyMutex.Unlock();
182            //yylex_destroy((*iter).pScanner);
183  }  }
184    
185  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
# Line 227  extern int GetLSCPCommand( void *buf, in Line 232  extern int GetLSCPCommand( void *buf, in
232   * If command is read, it will return true. Otherwise false is returned.   * If command is read, it will return true. Otherwise false is returned.
233   * 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.
234   */   */
235  bool LSCPServer::GetLSCPCommand( std::vector<int>::iterator iter ) {  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {
236          int socket = *iter;          int socket = (*iter).hSession;
237          char c;          char c;
238          int i = 0;          int i = 0;
239          while (true) {          while (true) {
# Line 1290  String LSCPServer::UnsubscribeNotificati Line 1295  String LSCPServer::UnsubscribeNotificati
1295      return result.Produce();      return result.Produce();
1296  }  }
1297    
1298    /**
1299     * Will be called by the parser to enable or disable echo mode; if echo
1300     * mode is enabled, all commands from the client will (immediately) be
1301     * echoed back to the client.
1302     */
1303    String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) {
1304        dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value));
1305        LSCPResultSet result;
1306        try {
1307            if      (boolean_value == 0) pSession->bVerbose = false;
1308            else if (boolean_value == 1) pSession->bVerbose = true;
1309            else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1");
1310        }
1311        catch (LinuxSamplerException e) {
1312             result.Error(e);
1313        }
1314        return result.Produce();
1315    }
1316    
1317  // Instrument loader constructor.  // Instrument loader constructor.
1318  LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)  LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)

Legend:
Removed from v.209  
changed lines
  Added in v.210

  ViewVC Help
Powered by ViewVC