/* * LSCP Shell * * Copyright (c) 2014 Christian Schoenebeck * * This program is part of LinuxSampler and released under the same terms. */ #ifndef LSCPCLIENT_H #define LSCPCLIENT_H #include #include #include #include #if defined(WIN32) #include typedef int socklen_t; #else #include #include #include #include #include #include #include #include #include #endif #include "../common/global.h" #include "../common/Thread.h" #include "../common/Mutex.h" #include "../common/Condition.h" #include "../common/optional.h" #include "../network/lscp.h" using namespace LinuxSampler; /** * Implements network communication with LinuxSampler's LSCP server. A separate * thread is spawned which will constantly read on new incoming data coming from * the LSCP server, it can call a callback function whenever new response data * arrived. */ class LSCPClient : protected Thread { public: typedef void(*Callback_t)(LSCPClient*); LSCPClient(); virtual ~LSCPClient(); bool connect(String host, int port); void disconnect(); bool isConnected() const; bool send(char c); bool send(String s); String sendCommandSync(String s); bool lineAvailable() const; bool messageComplete(); bool multiLine(); optional lookAheadLine(int index); optional popLine(); void setCallback(Callback_t fn); protected: int Main() OVERRIDE; optional receiveLine(); private: int hSocket; String m_lineBuffer; std::list m_lines; Mutex m_linesMutex; Callback_t m_callback; Condition m_sync; bool m_multiLineExpected; bool m_multiLineComplete; }; #endif // LSCPCLIENT_H