00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#ifndef WT_COFFEE_BASE_H
00023
#define WT_COFFEE_BASE_H
00024
00025
#include <wefts_cleanup.h>
00026
#include <string>
00027
00043
namespace Wefts {
00044
00050
#if defined(_MSC_VER) || defined(__BORLANDC__)
00051
typedef unsigned __int64
file_size_t;
00052
#else
00053 typedef long long file_size_t;
00054
#endif
00055
00057 typedef enum {
00058
00059 LM_SHARED,
00060
00061 LM_SHARED_RO,
00062
00063 LM_EXCLUSIVE,
00064 } LockMode;
00065
00066
00068 typedef enum {
00070 OM_RO,
00072 OM_WO,
00074 OM_RW,
00079 OM_TRUNC_WO,
00084 OM_TRUNC_RW,
00086 OM_APPEND_WO,
00088 OM_APPEND_RW
00089 } OpenMode;
00090
00109 typedef enum {
00111 CM_ARCHIVE,
00113 CM_SYSTEM,
00120 CM_EXECUTABLE,
00122 CM_PRIVATE,
00124 CM_PRIVATE_EX
00125 } CreateMode;
00126
00127
00143 typedef enum {
00145 CFF_DONE,
00148 CFF_WAITING,
00158 CFF_TIMEDOUT,
00159
00165 CFF_SOFTERROR,
00166
00170 CFF_HARDERROR,
00171
00188 CFF_PROGERROR
00189 }CffStatus;
00190
00192 typedef enum {
00194 SW_FROM_BEGIN=0,
00196 SW_FROM_CUR=1,
00198 SW_FROM_CURENT=1,
00200 SW_FROM_END=2
00201 } SeekWhence;
00202
00225 class OSFileFuncBase {
00226
protected:
00237 OSFileFuncBase() {
00238
m_timeout = -1.0;
00239
m_osError = 0;
00240
m_status =
CFF_DONE;
00241 }
00242
00243 double m_timeout;
00244 CffStatus m_status;
00245 int m_osError;
00246
00247
public:
00280
virtual inline CffStatus open(
00281 std::string filespec,
00282 OpenMode openMode = OM_RO,
00283 LockMode lockMode = LM_SHARED
00284 ) = 0;
00285
00315
virtual inline CffStatus create(
00316 std::string filespec,
00317 CreateMode cMode = CM_ARCHIVE,
00318 LockMode lockMode = LM_EXCLUSIVE
00319 ) = 0;
00320
00333
inline virtual void getDescriptor(
void *data )
const = 0;
00334
00347
inline virtual void setDescriptor(
void *data ) = 0;
00348
00349
00351 inline CffStatus status()
const {
return m_status; }
00352
00357 inline void status(
const CffStatus st ) {
m_status = st ; }
00358
00367 inline int osError()
const {
return m_osError; }
00368
00372 inline void osError(
const int osError ) {
m_osError = osError; }
00373
00374
00376 inline double timeout()
const {
return m_timeout; }
00377
00388 inline void timeout(
const double to ) {
m_timeout = to; }
00389
00390
00391
00392
00393 inline void clearTimeout() {
timeout( -1.0 ); }
00394
00395
00396
00397
00398
00399 inline void dontBlock() {
timeout( 0.0 ); }
00400
00414
virtual file_size_t read(
void *buffer,
const file_size_t len ) = 0;
00415
00430
virtual file_size_t write(
void *buffer,
const file_size_t len ) = 0;
00431
00439
virtual file_size_t seek(
00440
const file_size_t position,
00441
const SeekWhence swFrom= SW_FROM_BEGIN
00442 ) = 0;
00443
00445
virtual CffStatus close()=0;
00446
00451
inline virtual void setStdIn() = 0;
00452
00457
inline virtual void setStdOut() = 0;
00458
00463
inline virtual void setStdErr() = 0;
00464
00465 };
00466
00488 class OSProcessBase:
public CleanupHandler
00489 {
00490
private:
00491 void internal_init()
00492 {
00493
m_started =
false;
00494
m_ended =
false;
00495
m_mergeStdErr =
false;
00496
m_retval = -1;
00497
m_osError = 0;
00498
m_detached =
false;
00499 }
00500
00501
protected:
00503 int m_osError;
00504 bool m_started;
00505 bool m_ended;
00506 bool m_mergeStdErr;
00507 int m_retval;
00508 bool m_detached;
00510 OSProcessBase()
00511 :
CleanupHandler()
00512 {
00513
internal_init();
00514 }
00515
00516
public:
00517
00521
virtual bool running()=0;
00522
00545
virtual bool wait(
const double seconds=-1.0 )=0;
00546
00558
virtual bool start(
const std::string process,
bool useShell=
false,
bool usePath=
true )=0;
00559
00565
virtual bool stop()=0;
00566
00571
virtual bool getProcessValue(
int &retvalue )
const=0;
00572
00574 int osError()
const {
return m_osError; }
00575
00593
virtual file_size_t getProcessId() const =0;
00594
00604 virtual
int write( const
void *data, const
int size, const
double seconds=-1.0 )=0;
00605
00620 virtual
int read(
void *data, const
int size, const
double seconds=-1.0 )=0;
00621
00639 virtual
int readStdErr(
void *data, const
int size, const
double seconds=-1.0 )=0;
00640
00648 virtual
void mergeStdErr()=0;
00649
00658 virtual
void detach()=0;
00659
00663 virtual
void sinkInput() = 0;
00667 virtual
void sinkOutput() = 0;
00671 virtual
void sinkError() = 0;
00672
00673 virtual
bool closeRead()=0;
00674 virtual
bool closeWrite()=0;
00675 virtual
bool closeStdErr()=0;
00676
00677 virtual
void handleCleanup(
int code,
void *caller=0 ) = 0;
00678 };
00679
00681 }
00682
00683 #endif
00684
00685