OpendTect-6_4  6.4
jobcommunic.h
Go to the documentation of this file.
1 #ifndef JobCommunic_h
2 #define JobCommunic_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H. Lammertink
9  Date: 9-5-2005
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 */
14 
15 #include "networkmod.h"
16 #include "bufstring.h"
17 #include "genc.h"
18 #include "callback.h"
19 #include "uistring.h"
20 #include "od_ostream.h"
21 
22 class BatchProgram;
23 class StreamData;
24 namespace Network { class Socket; }
25 
26 #define mReturn( ret ) { \
27  if ( ret ) { nrattempts_ = 0; return true; } \
28  if ( nrattempts_++ < maxtries_ ) return true; \
29  stillok_ = false; \
30  directMsg("Lost connection with master[1]. Exiting."); \
31  ExitProgram( -1 ); return false; \
32 }
33 
34 #define mTryMaxtries( fn ) { \
35  for ( int i=0; i<maxtries_; i++ ) \
36  { \
37  bool ret = fn; \
38  if ( ret ) return true; \
39  sleepSeconds(1); \
40  } \
41  stillok_ = false; \
42  directMsg("Lost connection with master[2]. Exiting."); \
43  ExitProgram( -1 ); return false; \
44 }
45 
46 
53 public:
54  enum State { Undef, Working, WrapUp, Finished, AllDone, Paused,
55  JobError, HostError, Killed, Timeout };
56 
57  JobCommunic( const char* host, int port,
58  int jobid, StreamData& );
59  ~JobCommunic();
60 
61  bool ok() { return stillok_; }
62  uiString errMsg() { return errmsg_; }
63 
64  State state() const { return stat_; }
65  void setState( State s ) { stat_ = s; }
66 
67  bool updateState()
68  {
69  bool ret = sendState_(stat_,false,false);
70  mReturn(ret)
71  }
72  bool updateProgress( int p )
73  { bool ret = sendProgress_(p,false); mReturn(ret) }
74 
75  void setTimeBetweenMsgUpdates(int);
76 
77  bool sendState( bool isexit=false )
78  { mTryMaxtries( sendState_(stat_,isexit,true) ) }
79  bool sendProgress( int p )
80  { mTryMaxtries( sendProgress_(p,true) ) }
81 
83  bool sendErrMsg( const char* msg )
84  { mTryMaxtries( sendErrMsg_(msg) ) }
85  bool sendPID( int pid )
86  { mTryMaxtries( sendPID_(pid) ) }
87 
88  bool pauseRequested() const
89  { return pausereq_; }
90  void disConnect();
91 
92 protected:
93 
96  bool stillok_;
99  int jobid_;
100  bool pausereq_;
102 
103  Network::Socket* socket_;
104 
105  bool sendState_( State, bool isexit, bool immediate );
106  bool sendProgress_( int, bool immediate );
107  bool sendPID_( int );
108  bool sendErrMsg_( const char* msg );
109 
110  void alarmHndl( CallBacker* );
111 private:
112 
113  bool updateMsg( char tag, int, const char* msg=0 );
114  bool sendMsg( char tag, int, const char* msg=0 );
115  BufferString buildString(char tag, int, const char* msg=0 );
116 
118  void directMsg( const char* msg );
119 
120  void setErrMsg(const char*);
121 
122  void checkMasterTimeout();
123 
133 
134  void logMsg(bool stat,const char* msg, const char* details);
136  od_ostream* createLogStream();
137  void dumpSystemInfo();
138 
139 };
140 
141 #undef mReturn
142 #undef mTryMaxtries
143 
144 #endif
#define mExpClass(module)
Definition: commondefs.h:160
#define mReturn(ret)
Definition: jobcommunic.h:26
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
int socktimeout_
Definition: jobcommunic.h:127
bool sendState(bool isexit=false)
Definition: jobcommunic.h:77
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
bool stillok_
Definition: jobcommunic.h:96
FixedString Undef()
Definition: keystrs.h:142
Definition: jobcommunic.h:24
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
State stat_
Definition: jobcommunic.h:97
int failtimeout_
Definition: jobcommunic.h:128
void setState(State s)
Definition: jobcommunic.h:65
bool sendPID(int pid)
Definition: jobcommunic.h:85
int timestamp_
Definition: jobcommunic.h:124
Definition: uistring.h:89
int nrattempts_
Definition: jobcommunic.h:125
od_ostream * logstream_
Definition: jobcommunic.h:135
int min_time_between_update_
Definition: jobcommunic.h:129
int maxtries_
Definition: jobcommunic.h:126
bool updateProgress(int p)
Definition: jobcommunic.h:72
int lastsucces_
Definition: jobcommunic.h:130
uiString errmsg_
Definition: jobcommunic.h:98
Holds data to use and close an iostream.
Definition: strmdata.h:28
#define mTryMaxtries(fn)
Definition: jobcommunic.h:34
int lastupdate_
Definition: jobcommunic.h:132
int min_time_between_msgupdates_
Definition: jobcommunic.h:131
Main object for &#39;standard&#39; batch programs.
Definition: batchprog.h:49
bool ok()
Definition: jobcommunic.h:61
State
Definition: jobcommunic.h:54
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
BufferString errmsg_
Definition: horizontracker.h:119
int masterport_
Definition: jobcommunic.h:95
bool updateState()
Definition: jobcommunic.h:67
BufferString masterhost_
Definition: jobcommunic.h:94
int jobid_
Definition: jobcommunic.h:99
uiString errMsg()
Definition: jobcommunic.h:62
State state() const
Definition: jobcommunic.h:64
bool sendProgress(int p)
Definition: jobcommunic.h:79
Multi-machine socket communicator Handles the communication between a client and the master...
Definition: jobcommunic.h:51
bool sendErrMsg(const char *msg)
hostrelated error messages are more serious.
Definition: jobcommunic.h:83
Definition: jobcommunic.h:54
Network::Socket * socket_
Definition: jobcommunic.h:103
bool pausereq_
Definition: jobcommunic.h:100
StreamData & sdout_
Definition: jobcommunic.h:101
bool pauseRequested() const
Definition: jobcommunic.h:88

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019