--- linuxsampler/trunk/src/network/lscpserver.h 2004/06/29 21:11:50 159 +++ linuxsampler/trunk/src/network/lscpserver.h 2004/07/03 20:08:07 170 @@ -26,24 +26,28 @@ #include #include #include +#include +#include #include #include #include #include +#include + #include "lscp.h" #include "lscpparser.h" +#include "lscp.h" +#include "lscpevent.h" #include "../Sampler.h" #include "../common/Thread.h" +#include "../common/Mutex.h" /// TCP Port on which the server should listen for connection requests. #define LSCP_PORT 8888 using namespace LinuxSampler; -/// Handle for a client connection (FIXME: doesn't work for more than one network connections of course, thus has to be included to the yyparse() parameters instead). -extern int hSession; - // External references to the main scanner and parser functions extern int yyparse(void* YYPARSE_PARAM); extern int yylex_init(yyscan_t* scanner); @@ -109,15 +113,21 @@ String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); String SetVolume(double Volume, uint uiSamplerChannel); String ResetChannel(uint uiSamplerChannel); - String SubscribeNotification(event_t Event); - String UnsubscribeNotification(event_t Event); + String SubscribeNotification(LSCPEvent::event_t); + String UnsubscribeNotification(LSCPEvent::event_t); void AnswerClient(String ReturnMessage); + + static int currentSocket; + static std::map bufferedCommands; protected: int hSocket; sockaddr_in SocketAddress; Sampler* pSampler; int Main(); ///< Implementation of virtual method from class Thread + + static void SendLSCPNotify( LSCPEvent Event ); + private: /** @@ -130,35 +140,17 @@ */ int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); - /** - * Converts a result_t structure into a valid LSCP answer message. - */ - inline String ConvertResult(result_t result) { - switch (result.type) { - case result_type_success: { - return "OK\r\n"; - } - case result_type_warning: { - std::stringstream ss; - ss << "WRN:" << result.code << ":" << result.message << "\r\n"; - return ss.str(); - } - case result_type_error: { - std::stringstream ss; - ss << "ERR:" << result.code << ":" << result.message << "\r\n"; - return ss.str(); - } - } - } - - template inline String ToString(T o) { - std::stringstream ss; - ss << o; - return ss.str(); - } + static std::map bufferedNotifies; + static Mutex NotifyMutex; + static Mutex NotifyBufferMutex; + static bool GetLSCPCommand( std::vector::iterator iter ); + static void CloseConnection( std::vector::iterator iter ); + static std::vector hSessions; + static Mutex SubscriptionMutex; + static std::map< LSCPEvent::event_t, std::list > eventSubscriptions; + static fd_set fdSet; }; - /** * Instrument loader thread for the LinuxSampler Control Protocol (LSCP). */