/[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 1781 by iliev, Mon Sep 29 18:21:21 2008 UTC revision 1850 by persson, Sun Mar 1 16:33:22 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 507  int LSCPServer::Main() { Line 528  int LSCPServer::Main() {
528    
529          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);
530    
531          if (retval == 0)          if (retval == 0 || (retval == -1 && errno == EINTR))
532                  continue; //Nothing try again                  continue; //Nothing try again
533          if (retval == -1) {          if (retval == -1) {
534                  std::cerr << "LSCPServer: Socket select error." << std::endl;                  std::cerr << "LSCPServer: Socket select error." << std::endl;
# Line 605  void LSCPServer::CloseConnection( std::v Line 626  void LSCPServer::CloseConnection( std::v
626          NotifyMutex.Unlock();          NotifyMutex.Unlock();
627  }  }
628    
629    void LSCPServer::CloseAllConnections() {
630        std::vector<yyparse_param_t>::iterator iter = Sessions.begin();
631        while(iter != Sessions.end()) {
632            CloseConnection(iter);
633            iter = Sessions.begin();
634        }
635    }
636    
637  void LSCPServer::LockRTNotify() {  void LSCPServer::LockRTNotify() {
638      RTNotifyMutex.Lock();      RTNotifyMutex.Lock();
639  }  }
# Line 1259  String LSCPServer::GetMidiInputDriverInf Line 1288  String LSCPServer::GetMidiInputDriverInf
1288              for (;iter != parameters.end(); iter++) {              for (;iter != parameters.end(); iter++) {
1289                  if (s != "") s += ",";                  if (s != "") s += ",";
1290                  s += iter->first;                  s += iter->first;
1291                    delete iter->second;
1292              }              }
1293              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1294          }          }
# Line 1283  String LSCPServer::GetAudioOutputDriverI Line 1313  String LSCPServer::GetAudioOutputDriverI
1313              for (;iter != parameters.end(); iter++) {              for (;iter != parameters.end(); iter++) {
1314                  if (s != "") s += ",";                  if (s != "") s += ",";
1315                  s += iter->first;                  s += iter->first;
1316                    delete iter->second;
1317              }              }
1318              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1319          }          }
# Line 1313  String LSCPServer::GetMidiInputDriverPar Line 1344  String LSCPServer::GetMidiInputDriverPar
1344          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
1345          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1346          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1347            delete pParameter;
1348      }      }
1349      catch (Exception e) {      catch (Exception e) {
1350          result.Error(e);          result.Error(e);
# Line 1340  String LSCPServer::GetAudioOutputDriverP Line 1372  String LSCPServer::GetAudioOutputDriverP
1372          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
1373          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1374          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1375            delete pParameter;
1376      }      }
1377      catch (Exception e) {      catch (Exception e) {
1378          result.Error(e);          result.Error(e);
# Line 2540  String LSCPServer::GetTotalVoiceCount() Line 2573  String LSCPServer::GetTotalVoiceCount()
2573  String LSCPServer::GetTotalVoiceCountMax() {  String LSCPServer::GetTotalVoiceCountMax() {
2574      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
2575      LSCPResultSet result;      LSCPResultSet result;
2576      result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES);      result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES);
2577        return result.Produce();
2578    }
2579    
2580    /**
2581     * Will be called by the parser to return the sampler global maximum
2582     * allowed number of voices.
2583     */
2584    String LSCPServer::GetGlobalMaxVoices() {
2585        dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));
2586        LSCPResultSet result;
2587        result.Add(GLOBAL_MAX_VOICES);
2588        return result.Produce();
2589    }
2590    
2591    /**
2592     * Will be called by the parser to set the sampler global maximum number of
2593     * voices.
2594     */
2595    String LSCPServer::SetGlobalMaxVoices(int iVoices) {
2596        dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));
2597        LSCPResultSet result;
2598        try {
2599            if (iVoices < 1) throw Exception("Maximum voices may not be less than 1");
2600            GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp
2601            const std::set<Engine*>& engines = EngineFactory::EngineInstances();
2602            if (engines.size() > 0) {
2603                std::set<Engine*>::iterator iter = engines.begin();
2604                std::set<Engine*>::iterator end  = engines.end();
2605                for (; iter != end; ++iter) {
2606                    (*iter)->SetMaxVoices(iVoices);
2607                }
2608            }
2609            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES));
2610        } catch (Exception e) {
2611            result.Error(e);
2612        }
2613        return result.Produce();
2614    }
2615    
2616    /**
2617     * Will be called by the parser to return the sampler global maximum
2618     * allowed number of disk streams.
2619     */
2620    String LSCPServer::GetGlobalMaxStreams() {
2621        dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));
2622        LSCPResultSet result;
2623        result.Add(GLOBAL_MAX_STREAMS);
2624        return result.Produce();
2625    }
2626    
2627    /**
2628     * Will be called by the parser to set the sampler global maximum number of
2629     * disk streams.
2630     */
2631    String LSCPServer::SetGlobalMaxStreams(int iStreams) {
2632        dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));
2633        LSCPResultSet result;
2634        try {
2635            if (iStreams < 0) throw Exception("Maximum disk streams may not be negative");
2636            GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp
2637            const std::set<Engine*>& engines = EngineFactory::EngineInstances();
2638            if (engines.size() > 0) {
2639                std::set<Engine*>::iterator iter = engines.begin();
2640                std::set<Engine*>::iterator end  = engines.end();
2641                for (; iter != end; ++iter) {
2642                    (*iter)->SetMaxDiskStreams(iStreams);
2643                }
2644            }
2645            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS));
2646        } catch (Exception e) {
2647            result.Error(e);
2648        }
2649      return result.Produce();      return result.Produce();
2650  }  }
2651    
# Line 2728  void LSCPServer::VerifyFile(String Filen Line 2833  void LSCPServer::VerifyFile(String Filen
2833          throw Exception("Directory is specified");          throw Exception("Directory is specified");
2834      }      }
2835      #else      #else
2836      struct stat statBuf;      File f(Filename);
2837      int res = stat(Filename.c_str(), &statBuf);      if(!f.Exist()) throw Exception(f.GetErrorMsg());
2838      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");  
     }  
2839      #endif      #endif
2840  }  }
2841    

Legend:
Removed from v.1781  
changed lines
  Added in v.1850

  ViewVC Help
Powered by ViewVC