OpendTect-6_4  6.4
batchprog.h
Go to the documentation of this file.
1 #ifndef batchprog_h
2 #define batchprog_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H. Bril
9  Date: 14-9-1998
10  RCS: $Id$
11 ________________________________________________________________________
12 
13  Batch programs should include this header, and define a BatchProgram::go().
14  If program args are needed outside this method, BP() can be accessed.
15 
16 */
17 
18 #include "batchmod.h"
19 #include "prog.h"
20 #include "namedobj.h"
21 #include "bufstringset.h"
22 #include "genc.h"
23 #include "od_iostream.h"
24 
25 class CommandLineParser;
26 class IOObj;
27 class IOObjContext;
28 class MMSockCommunic;
29 class JobCommunic;
30 class StreamData;
31 
51  mGlobal(Batch) friend BatchProgram& BP();
52 
53 public:
54 
55  const IOPar& pars() const { return *iopar_; }
56  IOPar& pars() { return *iopar_; }
57 
58  const CommandLineParser& clParser() { return *clparser_; }
59 
61  bool go(od_ostream& log_stream);
62 
63  mExp(Batch) IOObj* getIOObjFromPars(const char* keybase,bool mknew,
64  const IOObjContext& ctxt,
65  bool msgiffail=true) const;
66 
68  mExp(Batch) bool pauseRequested() const;
69 
70  mExp(Batch) bool errorMsg( const uiString& msg, bool cc_stderr=false);
71  mExp(Batch) bool infoMsg( const char* msg, bool cc_stdout=false);
72 
73  mExp(Batch) static void deleteInstance();
74 
75 
76  static const char* sKeyMasterHost();
77  static const char* sKeyMasterPort();
78  static const char* sKeyBG();
79  static const char* sKeyJobID();
80  static const char* sKeyDataDir() { return "datadir"; }
81  static const char* sKeyFinishMsg() { return "Finished batch processing."; }
82 
83 protected:
84 
85  friend int Execute_batch(int*,char**);
86 
87  //friend class JobCommunic;
88 
89  BatchProgram();
90  ~BatchProgram();
91 
92  mExp(Batch) void init();
94 
95 
96  bool stillok_;
97  bool inbg_;
101 
103  BufferString finishmsg_; //Dot NOT use, will be removed after 6.2
104 
105  mExp(Batch) bool initOutput();
106  mExp(Batch) void progKilled(CallBacker*);
107  mExp(Batch) void killNotify( bool yn );
108 
109  JobCommunic* mmComm() { return comm_; }
110  int jobId() { return jobid_; }
111 
112 private:
113 
115  int jobid_;
116 
117 };
118 
119 
120 int Execute_batch(int*,char**);
122 
123 #define mRetJobErr(s) \
124 { \
125  if ( comm_ ) comm_->setState( JobCommunic::JobError ); \
126  mRetError(s) \
127 }
128 
129 
130 #define mRetError(s) \
131 { errorMsg(toUiString(s)); mDestroyWorkers; return false; }
132 
133 #define mRetHostErr(s) \
134 { \
135  if ( comm_ ) comm_->setState( JobCommunic::HostError ); \
136  mRetError(s) \
137 }
138 
139 #define mStrmWithProcID(s) \
140 strm << "\n[" << process_id << "]: " << s << "." << od_newline
141 
142 #define mMessage(s) \
143 strm << s << '.' << od_newline
144 
145 #define mSetCommState(State) \
146 if ( comm_ ) \
147 { \
148  comm_->setState( JobCommunic::State ); \
149  if ( !comm_->updateState() ) \
150  mRetHostErr( comm_->errMsg() ) \
151 }
152 
153 #ifdef __prog__
154 # ifdef __win__
155 # include "_execbatch.h"
156 # endif
157  int main( int argc, char** argv )
158  {
159  SetProgramArgs( argc, argv );
160  int ret = Execute_batch(&argc,argv);
161  ExitProgram( ret );
162  return ret;
163  }
164 
165 #endif // __prog__
166 
167 #endif
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
void SetProgramArgs(int argc, char **argv)
BufferString finishmsg_
Definition: batchprog.h:103
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
Definition: ioobj.h:58
StreamData & sdout_
Definition: batchprog.h:98
int jobid_
Definition: batchprog.h:115
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
#define mGlobal(module)
Definition: commondefs.h:163
const CommandLineParser & clParser()
Definition: batchprog.h:58
bool init()
bool inbg_
Definition: batchprog.h:97
Definition: uistring.h:89
IOPar * iopar_
Definition: batchprog.h:99
#define mExp(module)
Definition: commondefs.h:159
Set of BufferString objects.
Definition: bufstringset.h:28
static const char * sKeyFinishMsg()
Definition: batchprog.h:81
const IOPar & pars() const
Definition: batchprog.h:55
BatchProgram & BP()
Definition: commandlineparser.h:51
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
static BatchProgram * inst_
Definition: batchprog.h:93
Holds data to use and close an iostream.
Definition: strmdata.h:28
Main object for &#39;standard&#39; batch programs.
Definition: batchprog.h:49
JobCommunic * comm_
Definition: batchprog.h:114
Definition: batchjobdispatch.h:21
int Execute_batch(int *, char **)
Definition: _execbatch.h:99
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
Object with a name.
Definition: namedobj.h:35
int ExitProgram(int ret)
int main(int argc, char **argv)
BufferStringSet requests_
Definition: batchprog.h:102
IOPar & pars()
Definition: batchprog.h:56
bool stillok_
Definition: batchprog.h:96
#define mClass(module)
Definition: commondefs.h:164
CommandLineParser * clparser_
Definition: batchprog.h:100
Multi-machine socket communicator Handles the communication between a client and the master...
Definition: jobcommunic.h:51
int jobId()
Definition: batchprog.h:110
Holds the context for selecting and/or creating IOObjs.
Definition: ctxtioobj.h:62

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