ExecutableCommPort.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_ExecutableCommPort_h_
00003 #define INCLUDED_ExecutableCommPort_h_
00004
00005 #include "local/CommPort.h"
00006 #include "Wireless/netstream.h"
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 class ExecutableCommPort : public CommPort, public virtual plist::PrimitiveListener {
00019 public:
00020 explicit ExecutableCommPort(const std::string& name)
00021 : CommPort(autoRegisterExecutableCommPort,name),
00022 command(), shell("sh"), child(0), rbuf(), wbuf(), openedCnt(0)
00023 {
00024 addEntry("Command",command,"Specifies the shell command to run, stdio from this process will be piped through the comm port");
00025 addEntry("Shell",shell,"The shell executable to use for executing the command, can be found via PATH, or explicit path\n"
00026 "The shell will be passed '-c' and then your command");
00027 }
00028
00029
00030 virtual ~ExecutableCommPort();
00031
00032 virtual std::string getClassName() const { return autoRegisterExecutableCommPort; }
00033
00034 virtual streambuf& getReadStreambuf() { return rbuf; }
00035 virtual streambuf& getWriteStreambuf() { return wbuf; }
00036 virtual bool isWriteable() { wbuf.update_status(); return wbuf.is_open(); }
00037 virtual bool isReadable() { rbuf.update_status(); return rbuf.is_open(); }
00038
00039
00040 virtual bool open();
00041
00042
00043 virtual bool close();
00044
00045
00046 virtual void plistValueChanged(const plist::PrimitiveBase& pl);
00047
00048 plist::Primitive<std::string> command;
00049 plist::Primitive<std::string> shell;
00050
00051 protected:
00052 pid_t child;
00053
00054 basic_netbuf<std::ios::char_type> rbuf;
00055 basic_netbuf<std::ios::char_type> wbuf;
00056
00057 unsigned int openedCnt;
00058
00059 enum {
00060 READPIPE=0,
00061 WRITEPIPE=1
00062 };
00063
00064
00065 bool waitChild(unsigned int t, unsigned int p);
00066
00067
00068 bool isChildRunning() const;
00069
00070
00071 static const std::string autoRegisterExecutableCommPort;
00072 };
00073
00074
00075
00076
00077
00078
00079 #endif