WvStreams
|
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2004 Net Integration Technologies, Inc. 00004 * 00005 * WvStreams implementation of ptys under Linux. 00006 * 00007 * For more information on programming ptys, see chapter 19 of 00008 * Stevens' "Advanced Programming in the UNIX Environment" 00009 */ 00010 #ifndef __WVPTY_H 00011 #define __WVPTY_H 00012 00013 #include "wvfdstream.h" 00014 #include "wvtr1.h" 00015 00016 class WvPty: public WvFDStream 00017 { 00018 private: 00019 WvString _master, _slave; 00020 pid_t _pid; 00021 int _exit_status; 00022 00023 static bool open_pty(WvString &master, int &master_fd, 00024 WvString &slave, int &slave_fd); 00025 00026 void monitor_child(bool wait); 00027 00028 public: 00029 typedef wv::function<bool(WvPty&)> Callback; 00030 00031 Callback pre_exec_cb; 00032 Callback post_exec_cb; // This can only be called if exec() fails 00033 00034 WvPty(const char *program, const char * const *argv, 00035 Callback _pre_exec_cb = Callback(), 00036 Callback _post_exec_cb = Callback()); 00037 00038 void kill(int signum); 00039 bool child_exited(); 00040 bool child_killed(); 00041 int finish(); 00042 int exit_status(); 00043 00044 const char *master() const 00045 { return _master; } 00046 const char *slave() const 00047 { return _slave; } 00048 pid_t pid() const 00049 { return _pid; } 00050 00051 const char *wstype() const { return "WvPty"; } 00052 }; 00053 00054 #endif // __WVPTY_H