add command to manually close input pipe (send CTRL-D / EOF)
[vuplus_dvbapp] / lib / base / console.h
1 #ifndef __LIB_BASE_CONSOLE_H__
2 #define __LIB_BASE_CONSOLE_H__
3
4 #include "Python.h"
5 #include <string>
6 #include <lib/base/ebase.h>
7 #include <lib/python/connections.h>
8 #include <queue>
9
10 #ifndef SWIG
11 struct queue_data
12 {
13         queue_data( char *data, int len )
14                 :data(data), len(len), dataSent(0)
15         {
16         }
17         char *data;
18         int len;
19         int dataSent;
20 };
21 #endif
22
23 class eConsoleAppContainer: public Object
24 {
25 #ifndef SWIG
26         int fd[3];
27         int filefd[3];
28         int pid;
29         int killstate;
30         std::string m_cwd;
31         std::queue<struct queue_data> outbuf;
32         eSocketNotifier *in, *out, *err;
33         void readyRead(int what);
34         void readyErrRead(int what);
35         void readyWrite(int what);
36         void closePipes();
37 #endif
38 public:
39         eConsoleAppContainer();
40         int setCWD( const char *path );
41         int execute( const char *str );
42         int execute( const char *cmdline, const char *const argv[] );
43         int execute( PyObject *cmdline, PyObject *args );
44         ~eConsoleAppContainer();
45         int getPID() { return pid; }
46         void kill();
47         void sendCtrlC();
48         void sendEOF();
49         void write( const char *data, int len );
50         void write( PyObject *data );
51         void readFromFile( PyObject *py_filename );
52         void dumpToFile( PyObject *py_filename );
53         bool running() { return (fd[0]!=-1) && (fd[1]!=-1) && (fd[2]!=-1); }
54         PSignal1<void, const char*> dataAvail;
55         PSignal1<void, const char*> stdoutAvail;
56         PSignal1<void, const char*> stderrAvail;
57         PSignal1<void,int> dataSent;
58         PSignal1<void,int> appClosed;
59 };
60
61 #endif // __LIB_BASE_CONSOLE_H__