OpendTect  6.6
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  RCS: $Id$
10 ________________________________________________________________________
11 
12 */
13 
14 #include "networkcommon.h"
15 
16 #include "applicationdata.h"
17 #include "genc.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 primary host[1]. Exiting."); \
29  ApplicationData::exit( -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 primary host[2]. Exiting."); \
41  ApplicationData::exit( -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,PortNr_Type,
56  int jobid);
58  int jobid,StreamData&);
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  void setStream( od_ostream& strm ) { strm_ = &strm; }
68 
69  bool updateState()
70  {
71  bool ret = sendState_(stat_,false,false);
72  mReturn(ret)
73  }
74  bool updateProgress( int p )
75  { bool ret = sendProgress_(p,false); mReturn(ret) }
76 
78 
79  bool sendState( bool isexit=false )
80  { mTryMaxtries( sendState_(stat_,isexit,true) ) }
81  bool sendProgress( int p )
82  { mTryMaxtries( sendProgress_(p,true) ) }
83 
85  bool sendErrMsg( const char* msg )
86  { mTryMaxtries( sendErrMsg_(msg) ) }
87  bool sendPID( int pid )
88  { mTryMaxtries( sendPID_(pid) ) }
89 
90  bool pauseRequested() const
91  { return pausereq_; }
92  void disConnect();
93 
94 protected:
95 
96 // TODO: Rename to primaryauth_;
98  bool stillok_;
101  int jobid_;
102  bool pausereq_;
103  od_ostream* strm_ = nullptr;
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 
113 
114 private:
115 
116  void sendMsgCB(CallBacker* cb=nullptr);
117  bool updateMsg( char tag, int, const char* msg=0 );
118  bool sendMsg( char tag, int, const char* msg=0 );
119  BufferString buildString(char tag, int, const char* msg=0 );
120 
122  void directMsg( const char* msg );
123 
124  void setErrMsg(const char*);
125 
128 
138 
139  void logMsg(bool stat,const char* msg, const char* details);
143 
144  mDeprecated("Use checkPrimaryHostTimeout()")
145  void checkMasterTimeout();
146 };
147 
148 #undef mReturn
149 #undef mTryMaxtries
150 
JobCommunic::state
State state() const
Definition: jobcommunic.h:64
JobCommunic::updateState
bool updateState()
Definition: jobcommunic.h:69
JobCommunic::setState
void setState(State s)
Definition: jobcommunic.h:65
JobCommunic::nrattempts_
int nrattempts_
Definition: jobcommunic.h:130
JobCommunic::jobid_
int jobid_
Definition: jobcommunic.h:101
JobCommunic::stat_
State stat_
Definition: jobcommunic.h:99
JobCommunic::sendState_
bool sendState_(State, bool isexit, bool immediate)
JobCommunic::sendState
bool sendState(bool isexit=false)
Definition: jobcommunic.h:79
JobCommunic::stillok_
bool stillok_
Definition: jobcommunic.h:98
StreamData
Holds data to use and close an iostream. Usually created by StreamProvider.
Definition: strmdata.h:27
JobCommunic
Multi-machine socket communicator Handles the communication between a client and the primary host,...
Definition: jobcommunic.h:50
JobCommunic::sendProgress
bool sendProgress(int p)
Definition: jobcommunic.h:81
JobCommunic::mDeprecated
mDeprecated("Use checkPrimaryHostTimeout()") void checkMasterTimeout()
od_ostream.h
JobCommunic::socktimeout_
int socktimeout_
Definition: jobcommunic.h:132
JobCommunic::errMsg
uiString errMsg()
Definition: jobcommunic.h:62
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
BatchProgram
Main object for 'standard' batch programs.
Definition: batchprog.h:64
Network
Definition: jobcommunic.h:22
Network::Authority
Definition: networkcommon.h:56
JobCommunic::sendMsg
bool sendMsg(char tag, int, const char *msg=0)
genc.h
CallBacker
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:185
JobCommunic::updateProgress
bool updateProgress(int p)
Definition: jobcommunic.h:74
JobCommunic::~JobCommunic
~JobCommunic()
JobCommunic::State
State
Definition: jobcommunic.h:52
JobCommunic::alarmHndl
void alarmHndl(CallBacker *)
time-out
JobCommunic::sendProgress_
bool sendProgress_(int, bool immediate)
JobCommunic::primaryAuthority
Network::Authority & primaryAuthority()
mTryMaxtries
#define mTryMaxtries(fn)
Definition: jobcommunic.h:32
sKey::Undef
FixedString Undef()
Definition: keystrs.h:176
JobCommunic::errmsg_
uiString errmsg_
Definition: jobcommunic.h:100
JobCommunic::sendPID
bool sendPID(int pid)
Definition: jobcommunic.h:87
JobCommunic::logstream_
od_ostream * logstream_
Definition: jobcommunic.h:140
JobCommunic::buildString
BufferString buildString(char tag, int, const char *msg=0)
JobCommunic::lastsucces_
int lastsucces_
Definition: jobcommunic.h:135
JobCommunic::min_time_between_msgupdates_
int min_time_between_msgupdates_
Definition: jobcommunic.h:136
JobCommunic::JobCommunic
mDeprecatedDef JobCommunic(const char *host, PortNr_Type, int jobid, StreamData &)
JobCommunic::createLogStream
od_ostream * createLogStream()
JobCommunic::disConnect
void disConnect()
JobCommunic::maxtries_
int maxtries_
Definition: jobcommunic.h:131
JobCommunic::min_time_between_update_
int min_time_between_update_
Definition: jobcommunic.h:134
JobCommunic::directMsg
void directMsg(const char *msg)
directly to bp.stdout.ostrem or std::cerr.
JobCommunic::pauseRequested
bool pauseRequested() const
Definition: jobcommunic.h:90
JobCommunic::mODTextTranslationClass
mODTextTranslationClass(JobCommunic)
JobCommunic::timestamp_
int timestamp_
Definition: jobcommunic.h:129
JobCommunic::logMsg
void logMsg(bool stat, const char *msg, const char *details)
JobCommunic::checkPrimaryHostTimeout
void checkPrimaryHostTimeout()
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
mReturn
#define mReturn(ret)
Definition: jobcommunic.h:24
networkcommon.h
JobCommunic::WrapUp
@ WrapUp
Definition: jobcommunic.h:52
JobCommunic::masterauth_
Network::Authority masterauth_
Definition: jobcommunic.h:97
JobCommunic::setTimeBetweenMsgUpdates
void setTimeBetweenMsgUpdates(int)
uiString
String that is able to hold international (UTF-8) strings for the user interface.
Definition: uistring.h:121
JobCommunic::sendPID_
bool sendPID_(int)
MPE::errmsg_
BufferString errmsg_
Definition: horizontracker.h:118
applicationdata.h
JobCommunic::socket_
Network::Socket * socket_
Definition: jobcommunic.h:105
JobCommunic::lastupdate_
int lastupdate_
Definition: jobcommunic.h:137
JobCommunic::ok
bool ok()
Definition: jobcommunic.h:61
JobCommunic::failtimeout_
int failtimeout_
Definition: jobcommunic.h:133
JobCommunic::JobCommunic
JobCommunic(const char *host, PortNr_Type, int jobid)
mDeprecatedDef
#define mDeprecatedDef
Definition: plfdefs.h:216
JobCommunic::pausereq_
bool pausereq_
Definition: jobcommunic.h:102
JobCommunic::sendErrMsg_
bool sendErrMsg_(const char *msg)
JobCommunic::dumpSystemInfo
void dumpSystemInfo()
od_ostream
OD class for stream write common access to the user log file, or std::cout in other than od_main.
Definition: od_ostream.h:26
JobCommunic::setStream
void setStream(od_ostream &strm)
Definition: jobcommunic.h:67
JobCommunic::sendMsgCB
void sendMsgCB(CallBacker *cb=nullptr)
PortNr_Type
unsigned short PortNr_Type
Definition: commontypes.h:37
JobCommunic::setErrMsg
void setErrMsg(const char *)
JobCommunic::sendErrMsg
bool sendErrMsg(const char *msg)
hostrelated error messages are more serious.
Definition: jobcommunic.h:85
JobCommunic::updateMsg
bool updateMsg(char tag, int, const char *msg=0)

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