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

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