FreeRDP-WebConnect WebSockets gateway  1.0.0.167
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
common.hpp
1 /* vim: set et ts=4 sw=4 cindent:
2  *
3  * FreeRDP-WebConnect,
4  * A gateway for seamless access to your RDP-Sessions in any HTML5-compliant browser.
5  *
6  * Copyright 2012 Fritz Elfert <wsgate@fritz-elfert.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef _COMMON_H_
21 #define _COMMON_H_
22 
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26 
27 #ifdef HAVE_CONIO_H
28 # include <conio.h>
29 #endif
30 #ifdef HAVE_TERMIOS_H
31 # include <termios.h>
32 #endif
33 #ifdef HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
36 #include <string>
37 
38 #ifdef _WIN32
39 inline void sleep(int seconds) { Sleep(seconds * 1000); }
40 #endif
41 
45 namespace wsgate {
46 
50 class kbdio {
51  public:
54 #ifndef _WIN32
55  : st(termios()), stsave(termios())
56 #endif
57  {
58 #ifndef _WIN32
59  tcgetattr(0, &stsave);
60  memcpy(&st, &stsave, sizeof(st));
61  st.c_lflag &= ~ICANON;
62  st.c_cc[VMIN] = st.c_cc[VTIME] = 0;
63  tcsetattr(0, TCSANOW, &st);
64 #endif
65  }
66 #ifdef _WIN32
67  bool qpressed() {
68  char c;
69  bool ret = false;
70  while (0 != _kbhit()) {
71  c = _getch();
72  ret |= ('q' == c);
73  }
74  return ret;
75  }
76 #else
77 
78  ~kbdio() {
79  tcsetattr(0, TCSANOW, &stsave);
80  }
81 
86  bool qpressed() {
87  char c;
88  bool ret = false;
89  while (1 == read(0, &c, 1)) {
90  ret |= ('q' == c);
91  }
92  return ret;
93  }
94  private:
95  struct termios st;
96  struct termios stsave;
97 #endif
98 };
99 
100 }
101 
102 #endif