/[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 1808 by persson, Sun Dec 14 15:43:18 2008 UTC revision 1897 by persson, Sun May 10 09:31:51 2009 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 - 2008 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2009 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 24  Line 24 
24  #include <algorithm>  #include <algorithm>
25  #include <string>  #include <string>
26    
27    #include "../common/File.h"
28  #include "lscpserver.h"  #include "lscpserver.h"
29  #include "lscpresultset.h"  #include "lscpresultset.h"
30  #include "lscpevent.h"  #include "lscpevent.h"
# Line 140  LSCPServer::LSCPServer(Sampler* pSampler Line 141  LSCPServer::LSCPServer(Sampler* pSampler
141  }  }
142    
143  LSCPServer::~LSCPServer() {  LSCPServer::~LSCPServer() {
144        CloseAllConnections();
145        InstrumentManager::StopBackgroundThread();
146  #if defined(WIN32)  #if defined(WIN32)
147      if (hSocket >= 0) closesocket(hSocket);      if (hSocket >= 0) closesocket(hSocket);
148  #else  #else
# Line 334  void LSCPServer::DbInstrumentsEventHandl Line 337  void LSCPServer::DbInstrumentsEventHandl
337  }  }
338  #endif // HAVE_SQLITE3  #endif // HAVE_SQLITE3
339    
340    void LSCPServer::RemoveListeners() {
341        pSampler->RemoveChannelCountListener(&eventHandler);
342        pSampler->RemoveAudioDeviceCountListener(&eventHandler);
343        pSampler->RemoveMidiDeviceCountListener(&eventHandler);
344        pSampler->RemoveVoiceCountListener(&eventHandler);
345        pSampler->RemoveStreamCountListener(&eventHandler);
346        pSampler->RemoveBufferFillListener(&eventHandler);
347        pSampler->RemoveTotalStreamCountListener(&eventHandler);
348        pSampler->RemoveTotalVoiceCountListener(&eventHandler);
349        pSampler->RemoveFxSendCountListener(&eventHandler);
350        MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler);
351        MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler);
352        MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler);
353        MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler);
354    #if HAVE_SQLITE3
355        InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler);
356    #endif
357    }
358    
359  /**  /**
360   * Blocks the calling thread until the LSCP Server is initialized and   * Blocks the calling thread until the LSCP Server is initialized and
# Line 534  int LSCPServer::Main() { Line 555  int LSCPServer::Main() {
555                    exit(EXIT_FAILURE);                    exit(EXIT_FAILURE);
556                  }                  }
557          #else          #else
558                    struct linger linger;
559                    linger.l_onoff = 1;
560                    linger.l_linger = 0;
561                    if(setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger))) {
562                        std::cerr << "LSCPServer: Failed to set SO_LINGER\n";
563                    }
564    
565                  if (fcntl(socket, F_SETFL, O_NONBLOCK)) {                  if (fcntl(socket, F_SETFL, O_NONBLOCK)) {
566                          std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl;                          std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl;
567                          exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
# Line 605  void LSCPServer::CloseConnection( std::v Line 633  void LSCPServer::CloseConnection( std::v
633          NotifyMutex.Unlock();          NotifyMutex.Unlock();
634  }  }
635    
636    void LSCPServer::CloseAllConnections() {
637        std::vector<yyparse_param_t>::iterator iter = Sessions.begin();
638        while(iter != Sessions.end()) {
639            CloseConnection(iter);
640            iter = Sessions.begin();
641        }
642    }
643    
644  void LSCPServer::LockRTNotify() {  void LSCPServer::LockRTNotify() {
645      RTNotifyMutex.Lock();      RTNotifyMutex.Lock();
646  }  }
# Line 1259  String LSCPServer::GetMidiInputDriverInf Line 1295  String LSCPServer::GetMidiInputDriverInf
1295              for (;iter != parameters.end(); iter++) {              for (;iter != parameters.end(); iter++) {
1296                  if (s != "") s += ",";                  if (s != "") s += ",";
1297                  s += iter->first;                  s += iter->first;
1298                    delete iter->second;
1299              }              }
1300              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1301          }          }
# Line 1283  String LSCPServer::GetAudioOutputDriverI Line 1320  String LSCPServer::GetAudioOutputDriverI
1320              for (;iter != parameters.end(); iter++) {              for (;iter != parameters.end(); iter++) {
1321                  if (s != "") s += ",";                  if (s != "") s += ",";
1322                  s += iter->first;                  s += iter->first;
1323                    delete iter->second;
1324              }              }
1325              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1326          }          }
# Line 1313  String LSCPServer::GetMidiInputDriverPar Line 1351  String LSCPServer::GetMidiInputDriverPar
1351          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
1352          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1353          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1354            delete pParameter;
1355      }      }
1356      catch (Exception e) {      catch (Exception e) {
1357          result.Error(e);          result.Error(e);
# Line 1340  String LSCPServer::GetAudioOutputDriverP Line 1379  String LSCPServer::GetAudioOutputDriverP
1379          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
1380          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1381          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1382            delete pParameter;
1383      }      }
1384      catch (Exception e) {      catch (Exception e) {
1385          result.Error(e);          result.Error(e);
# Line 1806  String LSCPServer::SetMIDIInputType(Stri Line 1846  String LSCPServer::SetMIDIInputType(Stri
1846              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1847              // Make it with at least one initial port.              // Make it with at least one initial port.
1848              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
             parameters["PORTS"]->SetValue("1");  
1849          }          }
1850          // Must have a device...          // Must have a device...
1851          if (pDevice == NULL)          if (pDevice == NULL)
# Line 2800  void LSCPServer::VerifyFile(String Filen Line 2839  void LSCPServer::VerifyFile(String Filen
2839          throw Exception("Directory is specified");          throw Exception("Directory is specified");
2840      }      }
2841      #else      #else
2842      struct stat statBuf;      File f(Filename);
2843      int res = stat(Filename.c_str(), &statBuf);      if(!f.Exist()) throw Exception(f.GetErrorMsg());
2844      if (res) {      if (f.IsDirectory()) throw Exception("Directory is specified");
         std::stringstream ss;  
         ss << "Fail to stat `" << Filename << "`: " << strerror(errno);  
         throw Exception(ss.str());  
     }  
   
     if (S_ISDIR(statBuf.st_mode)) {  
         throw Exception("Directory is specified");  
     }  
2845      #endif      #endif
2846  }  }
2847    

Legend:
Removed from v.1808  
changed lines
  Added in v.1897

  ViewVC Help
Powered by ViewVC