00001 #ifndef CliCommandThread_h
00002 #define CliCommandThread_h
00003
00004 #include <string>
00005 #include <cc++/thread.h>
00006 #include <mpi.h>
00007 #include <sstream>
00008
00009 #include "CliOutputReceiveThread.h"
00010
00011 #ifdef CCXX_NAMESPACES
00012 using namespace std;
00013 using namespace ost;
00014 #endif
00015
00016 namespace BIE {
00017
00018
00020 class CliCommandThread: public Thread {
00021 public:
00022
00024 CliCommandThread(string hostname, int port);
00025
00027 ~CliCommandThread();
00028
00030 void run();
00032 void sampleNext();
00034 void finish();
00036 void sendCommand(string& cmd);
00038 void sendScript(const string& filename);
00040 istream *getReply();
00042 istream *getCommandReply();
00044 Semaphore *getSemaphore() { return _qsem;};
00046 void setControllerSemaphore (Semaphore *controller) { _controller = controller; };
00047
00049 CliOutputReceiveThread *getConsoleLogger();
00050
00051 private:
00052 int writeCommand();
00053 int writeCommand(const string& msg);
00054 int writeCommand(istream *strm);
00055 int readPrompt();
00056 int readReply();
00057 int readReply(int socketid);
00058 void notifyController() { _controller->post(); };
00059
00060 char *_hname;
00061 int _port;
00062 int _socketid, _console_socketid;
00063 char *_sendBuffer;
00064 char *_receiveBuffer;
00065 int _receiveBufferSize, _sendBufferSize, _cmdBufferSize;
00066 Semaphore *_qsem;
00067 Semaphore *_controller;
00068 char *_clicmd;
00069 CliOutputReceiveThread *_consoleLogger;
00070 bool _loop;
00071 };
00072 }
00073 #endif