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" |
141 |
} |
} |
142 |
|
|
143 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
144 |
|
CloseAllConnections(); |
145 |
#if defined(WIN32) |
#if defined(WIN32) |
146 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
147 |
#else |
#else |
336 |
} |
} |
337 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
338 |
|
|
339 |
|
void LSCPServer::RemoveListeners() { |
340 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
341 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
342 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
343 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
344 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
345 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
346 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
347 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
348 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
349 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
350 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
351 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
352 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
353 |
|
#if HAVE_SQLITE3 |
354 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
355 |
|
#endif |
356 |
|
} |
357 |
|
|
358 |
/** |
/** |
359 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
527 |
|
|
528 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
529 |
|
|
530 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
531 |
continue; //Nothing try again |
continue; //Nothing try again |
532 |
if (retval == -1) { |
if (retval == -1) { |
533 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
625 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
626 |
} |
} |
627 |
|
|
628 |
|
void LSCPServer::CloseAllConnections() { |
629 |
|
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
630 |
|
while(iter != Sessions.end()) { |
631 |
|
CloseConnection(iter); |
632 |
|
iter = Sessions.begin(); |
633 |
|
} |
634 |
|
} |
635 |
|
|
636 |
void LSCPServer::LockRTNotify() { |
void LSCPServer::LockRTNotify() { |
637 |
RTNotifyMutex.Lock(); |
RTNotifyMutex.Lock(); |
638 |
} |
} |
1287 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1288 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1289 |
s += iter->first; |
s += iter->first; |
1290 |
|
delete iter->second; |
1291 |
} |
} |
1292 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1293 |
} |
} |
1312 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1313 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1314 |
s += iter->first; |
s += iter->first; |
1315 |
|
delete iter->second; |
1316 |
} |
} |
1317 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1318 |
} |
} |
1343 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1344 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1345 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1346 |
|
delete pParameter; |
1347 |
} |
} |
1348 |
catch (Exception e) { |
catch (Exception e) { |
1349 |
result.Error(e); |
result.Error(e); |
1371 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1372 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1373 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1374 |
|
delete pParameter; |
1375 |
} |
} |
1376 |
catch (Exception e) { |
catch (Exception e) { |
1377 |
result.Error(e); |
result.Error(e); |
2572 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
2573 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
2574 |
LSCPResultSet result; |
LSCPResultSet result; |
2575 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES); |
2576 |
|
return result.Produce(); |
2577 |
|
} |
2578 |
|
|
2579 |
|
/** |
2580 |
|
* Will be called by the parser to return the sampler global maximum |
2581 |
|
* allowed number of voices. |
2582 |
|
*/ |
2583 |
|
String LSCPServer::GetGlobalMaxVoices() { |
2584 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
2585 |
|
LSCPResultSet result; |
2586 |
|
result.Add(GLOBAL_MAX_VOICES); |
2587 |
|
return result.Produce(); |
2588 |
|
} |
2589 |
|
|
2590 |
|
/** |
2591 |
|
* Will be called by the parser to set the sampler global maximum number of |
2592 |
|
* voices. |
2593 |
|
*/ |
2594 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
2595 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
2596 |
|
LSCPResultSet result; |
2597 |
|
try { |
2598 |
|
if (iVoices < 1) throw Exception("Maximum voices may not be less than 1"); |
2599 |
|
GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp |
2600 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2601 |
|
if (engines.size() > 0) { |
2602 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2603 |
|
std::set<Engine*>::iterator end = engines.end(); |
2604 |
|
for (; iter != end; ++iter) { |
2605 |
|
(*iter)->SetMaxVoices(iVoices); |
2606 |
|
} |
2607 |
|
} |
2608 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES)); |
2609 |
|
} catch (Exception e) { |
2610 |
|
result.Error(e); |
2611 |
|
} |
2612 |
|
return result.Produce(); |
2613 |
|
} |
2614 |
|
|
2615 |
|
/** |
2616 |
|
* Will be called by the parser to return the sampler global maximum |
2617 |
|
* allowed number of disk streams. |
2618 |
|
*/ |
2619 |
|
String LSCPServer::GetGlobalMaxStreams() { |
2620 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
2621 |
|
LSCPResultSet result; |
2622 |
|
result.Add(GLOBAL_MAX_STREAMS); |
2623 |
|
return result.Produce(); |
2624 |
|
} |
2625 |
|
|
2626 |
|
/** |
2627 |
|
* Will be called by the parser to set the sampler global maximum number of |
2628 |
|
* disk streams. |
2629 |
|
*/ |
2630 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
2631 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
2632 |
|
LSCPResultSet result; |
2633 |
|
try { |
2634 |
|
if (iStreams < 0) throw Exception("Maximum disk streams may not be negative"); |
2635 |
|
GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp |
2636 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2637 |
|
if (engines.size() > 0) { |
2638 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2639 |
|
std::set<Engine*>::iterator end = engines.end(); |
2640 |
|
for (; iter != end; ++iter) { |
2641 |
|
(*iter)->SetMaxDiskStreams(iStreams); |
2642 |
|
} |
2643 |
|
} |
2644 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS)); |
2645 |
|
} catch (Exception e) { |
2646 |
|
result.Error(e); |
2647 |
|
} |
2648 |
return result.Produce(); |
return result.Produce(); |
2649 |
} |
} |
2650 |
|
|
2832 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
2833 |
} |
} |
2834 |
#else |
#else |
2835 |
struct stat statBuf; |
File f(Filename); |
2836 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
2837 |
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"); |
|
|
} |
|
2838 |
#endif |
#endif |
2839 |
} |
} |
2840 |
|
|