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

Contents of /linuxsampler/trunk/src/shell/KeyboardReader.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: 1456 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 KEYBOARDREADER_H
10 #define KEYBOARDREADER_H
11
12 #include <list>
13 #include <string>
14
15 #include "../common/global.h"
16 #include "../common/Thread.h"
17 #include "../common/Condition.h"
18 #include "TerminalCtrl.h"
19
20 #define KBD_BACKSPACE 127
21
22 using namespace LinuxSampler;
23
24 /**
25 * Implements a FIFO object that is constantly reading from stdin on a separate
26 * thread. The reader thread can call a callback function as soon as new data
27 * arrived from stdin. The reader thread will react on every single key stroke,
28 * that is it will already fire before line end (RETURN / ENTER) was received.
29 */
30 class KeyboardReader : protected Thread {
31 public:
32 typedef void(*Callback_t)(KeyboardReader*);
33
34 KeyboardReader();
35 virtual ~KeyboardReader();
36 void setCallback(Callback_t fn);
37 void callback(bool b);
38 bool charAvailable() const;
39 char popChar();
40 void startReading();
41 void stopReading();
42 std::string popStringToDelimiterSync(char delimiter, bool includeDelimiter = false);
43
44 static KeyboardReader* singleton();
45 protected:
46 int Main() OVERRIDE;
47 private:
48 TerminalSetting m_originalTerminalSetting;
49 Callback_t m_callback;
50 std::list<char> m_fifo;
51 Mutex m_fifoMutex;
52 bool m_doCallback;
53 Condition m_sync;
54 char m_syncDelimiter;
55 };
56
57 #endif // KEYBOARDREADER_H

  ViewVC Help
Powered by ViewVC