1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
|
/*
* console.h: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: engine.h,v 1.1 2004/10/24 12:57:09 chelli-guest Exp $
*/
#ifndef __ENGINE_H__
#define __ENGINE_H__
#include <sys/ioctl.h>
#include <termios.h>
#include <vdr/tools.h>
#include <vdr/remote.h>
#include "ipc.h"
#define CONSOLE_DEBUG( xx )
//#define CONSOLE_DEBUG( xx ) xx;
// This program will be used to realize a console.
// Be carefull! If your VDR runs as root, then every
// user can kill your machine if you don't protect
// the cnsoles.
// So the default is "/bin/login".
#ifdef CONSOLE_USE_SHELL_INSTEAD_LOGIN
#define PROG_FOR_CONSOLE "/bin/sh"
#else
#define PROG_FOR_CONSOLE "/bin/login"
#endif
// With the small font there are many cells possible
#define CONSOLE_MAXCOLS 100
#define CONSOLE_MAXROWS 50
#define INPUT_BUFSIZE 1024
// define used keys
#define BS '\010' // Backspace
#define HT '\011' // Horizontal Tab
#define LF '\012' // Line Feed
#define VT '\013' // Vertical Tab
#define FF '\014' // Form Feed
#define CR '\015' // Carriage Return
#define SO '\016' // Shift out
#define SI '\017' // Shift in
#define CAN '\030' // Cancel
#define SUB '\032' // Substitude
#define ESC '\033' // Escape
// New keys that are not specified through keys.h
// Be carefull! It could be that these keys will
// be used some day from VDR itself.
#define kRefresh 1002
enum eConScreenState {
eCssNormal = 0,
eCssEscape,
eCssEscapeParameter,
eCssEscapeSingleCode,
eCssSelectCharSetG0,
eCssSelectCharSetG1
};
struct sConScreenChar {
sConScreenChar()
: ch (' '),
foreColor (0),
backColor (0),
Bold (false),
Underscore (false),
Blink (false),
Inverted (false),
Concealed (false),
useFore (false),
useBack (false)
{}
sConScreenChar( unsigned char Ch, const sConScreenChar& attr )
: ch (Ch),
foreColor (attr.foreColor),
backColor (attr.backColor),
Bold (attr.Bold),
Underscore (attr.Underscore),
Blink (attr.Blink),
Inverted (attr.Inverted),
Concealed (attr.Concealed),
useFore (attr.useFore),
useBack (attr.useBack)
{}
unsigned char ch;
unsigned char foreColor : 4;
unsigned char backColor : 4;
bool Bold : 1;
bool Underscore : 1;
bool Blink : 1;
bool Inverted : 1;
bool Concealed : 1;
bool useFore : 1;
bool useBack : 1;
};
struct sConScreenCursorPos {
sConScreenCursorPos( int X, int Y, const sConScreenChar& Attributes, bool ModeOrigin, sConScreenCursorPos* Prev )
: x (X),
y (Y),
attributes (Attributes),
modeOrigin (ModeOrigin),
prev (Prev)
{}
int x, y;
sConScreenChar attributes;
bool modeOrigin;
sConScreenCursorPos* prev;
};
class cTerminalEmulation
{
private:
int _w, _h;
sConScreenChar* _screen[ CONSOLE_MAXROWS ];
int _curX, _curY;
sConScreenCursorPos* _curPosSaved;
int _scrollRegionTop, _scrollRegionBottom;
bool _modeCurVisible;
bool _modeOrigin;
bool _modeWrapAround;
bool _modeInsert;
bool _modeNewLine;
eConScreenState _state;
int* _escapeParams;
int _escapeParamsCount;
bool _changed, _bell;
sConScreenChar _defaultChar;
int _tabs[ CONSOLE_MAXCOLS ];
cMutex _mutex;
bool _wantRefreshEvent;
unsigned char _charSet[ 256 ];
int _fd;
private:
void Changed();
void Clear( int fromX = 0, int fromY = 0, int toX = -1, int toY = -1 );
void ScrollUp( int Count = 1 ) { ScrollUp( Count, _scrollRegionTop ); }
void ScrollUp( int Count, int FromLine );
void ScrollDown( int Count = 1 ) { ScrollDown( Count, _scrollRegionTop ); }
void ScrollDown( int Count, int FromLine );
void decodeEscapeSequence( char code );
void decodeEscapeCode( char code );
void decodeEscapeSingleCode( char code );
void tabStopClear();
void tabStopAdd( int tabstop );
void tabStopRemove( int tabstop );
void keyCarriageReturn();
void keyLineFeed( bool NewLine );
void keyBackspace();
void keyDelete();
void keyTab();
void keyInsert( unsigned char ch = ' ' );
void keyBell();
void setAttributes( int* attributes, int count );
void setModes( int* attributes, int count );
void resetModes( int* attributes, int count );
void setModeCurVisible( bool visible );
void setModeOrigin( bool origin );
void ClearToEnd();
void ClearFromBegin();
void ClearLine();
void InsertChar( int count );
void DeleteChar( int count );
void InsertLine( int count );
void DeleteLine( int count );
void reportDeviceStatus( int request );
void reportDeviceAttributes( int request );
void MoveTo( int col, int row );
void MoveRelative( int d_col, int d_row );
void setScrollRegion( int top, int bottom );
void CursorPosSave();
void CursorPosRestore();
void Write( unsigned char ch );
void SelectCharSet( int g, char set );
public:
cTerminalEmulation();
virtual ~cTerminalEmulation();
void setOutputFileDescriptor( int fd ) { _fd = fd; }
void Write( const unsigned char* stream );
const sConScreenChar** getScreen() { return (const sConScreenChar**)_screen; }
int getW() { return _w; }
int getH() { return _h; }
bool setSize( int w, int h );
int getCursorX() { return _curX; }
int getCursorY() { return _modeOrigin ? _curY - _scrollRegionTop : _curY; }
bool getCursorVisible() { return _modeCurVisible; }
bool ToRefresh() { return _changed; }
void Refreshed();
bool ToRing() { return _bell; }
void BellSeen();
cMutex* getMutex() { return &_mutex; }
void WantRefreshEvent( bool WantIt ) { _wantRefreshEvent = WantIt; }
};
class cConsoles;
class cVirtualConsole
: public cListObject,
public IWaitable
{
friend class cConsoles;
private:
unsigned char _buf[ INPUT_BUFSIZE + 1 ];
volatile int _childPid;
int _master;
bool _isOpen;
char* _title;
cTerminalEmulation _screen;
private:
bool Open(const char* command, char* const argv[]);
bool ConsoleWaitPid(volatile int& pid, int timeoutMs);
bool HandleOutput();
public:
cVirtualConsole(const char* title, const char* command, char* const argv[]);
virtual ~cVirtualConsole();
bool IsOpen();
bool Close();
void HasClosed( bool force = false );
void setTerminalSize( int charW, int charH, int pixelW, int pixelH );
void Write( const unsigned char* data, int len );
const char* getTitle() { return _title; }
cTerminalEmulation& getScreen() { return _screen; }
pid_t getChildPid() { return _childPid; }
// IWaitable
virtual int SignalToWaitFor() const { return _master; }
};
// ----- cConsoles --------------------------------------------------------------------------
class cConsoles
: public cThread
{
private:
cList<cVirtualConsole> _consoles;
int _inputActive;
struct termios _oldTerminalSettings;
cSignal _consolesChanged;
cWaitableList _wait;
volatile bool _terminate;
private:
virtual void Action();
public:
cConsoles();
~cConsoles();
virtual bool Start();
void activateInputForTerminal();
void deactivateInputForTerminal();
void Flush(int WaitMs);
void WantAllRefreshEvents( bool WantIt );
int getCount() { LOCK_THREAD; return _consoles.Count(); }
cVirtualConsole& getItem( int index0 ) { LOCK_THREAD; return *_consoles.Get(index0); }
int CreateConsole();
int CreateCommand(const char* title, const char* command);
void Remove(cVirtualConsole* pConsole);
static bool Active();
};
extern cConsoles* gl_pConsoles;
#endif // __ENGINE_H__
|