/[svn]/linuxsampler/trunk/src/shell/LSCPClient.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/shell/LSCPClient.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2532 - (show annotations) (download) (as text)
Wed Mar 5 17:29:15 2014 UTC (10 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 1922 byte(s)
* LSCP server: fixed crash caused by endless recursion in
  LSCP shell grammar evaluation algorithm.
* LSCP shell: quit shell app when TCP connection aborted.
* Bumped version (1.0.0.svn36).

1 /*
2 * LSCP Shell
3 *
4 * Copyright (c) 2014 Christian Schoenebeck
5 *
6 * This program is part of LinuxSampler and released under the same terms.
7 */
8
9 #ifndef LSCPCLIENT_H
10 #define LSCPCLIENT_H
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string>
15 #include <list>
16
17 #if defined(WIN32)
18 #include <windows.h>
19 typedef int socklen_t;
20 #else
21 #include <unistd.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <sys/select.h>
25 #include <sys/time.h>
26 #include <netinet/in.h>
27 #include <netinet/tcp.h>
28 #include <arpa/inet.h>
29 #include <netdb.h>
30 #endif
31
32 #include "../common/global.h"
33 #include "../common/Thread.h"
34 #include "../common/Mutex.h"
35 #include "../common/Condition.h"
36 #include "../common/optional.h"
37 #include "../network/lscp.h"
38
39 using namespace LinuxSampler;
40
41 /**
42 * Implements network communication with LinuxSampler's LSCP server. A separate
43 * thread is spawned which will constantly read on new incoming data coming from
44 * the LSCP server, it can call a callback function whenever new response data
45 * arrived.
46 */
47 class LSCPClient : protected Thread {
48 public:
49 typedef void(*Callback_t)(LSCPClient*);
50
51 LSCPClient();
52 virtual ~LSCPClient();
53 bool connect(String host, int port);
54 void disconnect();
55 bool isConnected() const;
56 bool send(char c);
57 bool send(String s);
58 String sendCommandSync(String s);
59 bool lineAvailable() const;
60 bool messageComplete();
61 bool multiLine();
62 optional<String> lookAheadLine(int index);
63 optional<String> popLine();
64 void setCallback(Callback_t fn);
65 void setErrorCallback(Callback_t fn);
66 protected:
67 int Main() OVERRIDE;
68 optional<String> receiveLine();
69 private:
70 int hSocket;
71 String m_lineBuffer;
72 std::list<String> m_lines;
73 Mutex m_linesMutex;
74 Callback_t m_callback;
75 Callback_t m_errorCallback;
76 Condition m_sync;
77 bool m_multiLineExpected;
78 bool m_multiLineComplete;
79 };
80
81 #endif // LSCPCLIENT_H

  ViewVC Help
Powered by ViewVC