/[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 2515 - (show annotations) (download) (as text)
Wed Feb 5 20:45:18 2014 UTC (10 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 1848 byte(s)
* WIP: Introducing the LSCP shell: for now, providing color
  highlighting while typing (indicating correct part bold white,
  incorrect part red, and turning green when the command is
  complete. The shell application is implemented as thin client,
  that is the parser work is performed on sampler side and the
  shell application is just providing output formatting.
* Bumped version (1.0.0.svn28).

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 protected:
66 int Main() OVERRIDE;
67 optional<String> receiveLine();
68 private:
69 int hSocket;
70 String m_lineBuffer;
71 std::list<String> m_lines;
72 Mutex m_linesMutex;
73 Callback_t m_callback;
74 Condition m_sync;
75 bool m_multiLineExpected;
76 bool m_multiLineComplete;
77 };
78
79 #endif // LSCPCLIENT_H

  ViewVC Help
Powered by ViewVC