add support for writing python strings directly
[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)
15         {
16         }
17         char *data;
18         int len;
19 };
20 #endif
21
22 class eConsoleAppContainer: public Object
23 {
24 #ifndef SWIG
25         int fd[3];
26         int pid;
27         int killstate;
28         std::queue<struct queue_data> outbuf;
29         eSocketNotifier *in, *out, *err;
30         void readyRead(int what);
31         void readyErrRead(int what);
32         void readyWrite(int what);
33         void closePipes();
34 #endif
35 public:
36         eConsoleAppContainer();
37         int execute( const char *str );
38         int execute( const char *cmdline, const char *const argv[] );
39         int execute( PyObject *cmdline, PyObject *args );
40         ~eConsoleAppContainer();
41         int getPID() { return pid; }
42         void kill();
43         void sendCtrlC();
44         void write( const char *data, int len );
45         void write( PyObject *data );
46         bool running() { return (fd[0]!=-1) && (fd[1]!=-1) && (fd[2]!=-1); }
47         PSignal1<void, const char*> dataAvail;
48         PSignal1<void,int> dataSent;
49         PSignal1<void,int> appClosed;
50 };
51
52 #endif // __LIB_BASE_CONSOLE_H__