OpendTect  6.3
batchprog.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. Bril
8  Date: 14-9-1998
9 ________________________________________________________________________
10 
11  Batch programs should include this header, and define a BatchProgram::go().
12  If program args are needed outside this method, BP() can be accessed.
13 
14 */
15 
16 #include "batchmod.h"
17 #include "prog.h"
18 #include "namedobj.h"
19 #include "bufstringset.h"
20 #include "genc.h"
21 #include "od_iostream.h"
22 #include "oscommand.h"
23 
24 class CommandLineParser;
25 class IOObj;
26 class IOObjContext;
27 class MMSockCommunic;
28 class JobCommunic;
29 class StreamData;
30 
50  mGlobal(Batch) friend BatchProgram& BP();
51 
52 public:
53 
54  const IOPar& pars() const { return *iopar_; }
55  IOPar& pars() { return *iopar_; }
56 
57  const CommandLineParser& clParser() { return *clparser_; }
58 
60  bool go(od_ostream& log_stream);
61 
62  mExp(Batch) IOObj* getIOObjFromPars(const char* keybase,bool mknew,
63  const IOObjContext& ctxt,
64  bool msgiffail=true) const;
65 
67  mExp(Batch) bool pauseRequested() const;
68 
69  mExp(Batch) bool errorMsg( const uiString& msg, bool cc_stderr=false);
70  mExp(Batch) bool infoMsg( const char* msg, bool cc_stdout=false);
71 
72  mExp(Batch) static void deleteInstance();
73 
74 
75  static const char* sKeyDataDir() { return "datadir"; }
76  static const char* sKeyFinishMsg() { return "Finished batch processing."; }
77  static bool doImport( od_ostream& strm, IOPar& iop, bool is2d );
78  static bool doExport( od_ostream& strm, IOPar& iop, bool is2d );
79 
80 protected:
81 
82  friend int Execute_batch(int*,char**);
83 
84  //friend class JobCommunic;
85 
86  BatchProgram();
87  ~BatchProgram();
88 
89  mExp(Batch) void init();
91 
92 
93  bool stillok_;
94  bool inbg_;
98 
100 
101  mExp(Batch) bool initOutput();
102  mExp(Batch) void progKilled(CallBacker*);
103  mExp(Batch) void killNotify( bool yn );
104 
105  JobCommunic* mmComm() { return comm_; }
106  int jobId() { return jobid_; }
107 
108 private:
109 
111  int jobid_;
112 
113 };
114 
115 
116 int Execute_batch(int*,char**);
118 
119 #define mRetJobErr(s) \
120 { \
121  if ( comm_ ) comm_->setState( JobCommunic::JobError ); \
122  mRetError(s) \
123 }
124 
125 
126 #define mRetError(s) \
127 { errorMsg(toUiString(s)); mDestroyWorkers; return false; }
128 
129 #define mRetHostErr(s) \
130 { \
131  if ( comm_ ) comm_->setState( JobCommunic::HostError ); \
132  mRetError(toUiString(s)) \
133 }
134 
135 #define mStrmWithProcID(s) \
136 strm << "\n[" << process_id << "]: " << s << "." << od_newline
137 
138 #define mMessage(s) \
139 strm << s << '.' << od_newline
140 
141 #define mSetCommState(State) \
142 if ( comm_ ) \
143 { \
144  comm_->setState( JobCommunic::State ); \
145  if ( !comm_->updateState() ) \
146  mRetHostErr( comm_->errMsg() ) \
147 }
148 
149 #ifdef __prog__
150 # ifdef __win__
151 # include "_execbatch.h"
152 # endif
153 #define mMainIsDefined
154  int main( int argc, char** argv )
155  {
156  SetProgramArgs( argc, argv );
157  int ret = Execute_batch(&argc,argv);
158  ExitProgram( ret );
159  return ret;
160  }
161 
162 #endif // __prog__
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:182
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
Definition: ioobj.h:57
StreamData & sdout_
Definition: batchprog.h:95
int jobid_
Definition: batchprog.h:111
#define mODTextTranslationClass(clss)
Definition: uistring.h:37
#define mGlobal(module)
Definition: commondefs.h:160
const CommandLineParser & clParser()
Definition: batchprog.h:57
void SetProgramArgs(int argc, char **argv, bool require_valid_dataroot=true)
bool init()
bool inbg_
Definition: batchprog.h:94
Definition: uistring.h:88
IOPar * iopar_
Definition: batchprog.h:96
#define mExp(module)
Definition: commondefs.h:156
Set of BufferString objects.
Definition: bufstringset.h:25
static const char * sKeyFinishMsg()
Definition: batchprog.h:76
const IOPar & pars() const
Definition: batchprog.h:54
BatchProgram & BP()
Definition: commandlineparser.h:49
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:53
static BatchProgram * inst_
Definition: batchprog.h:90
Holds data to use and close an iostream.
Definition: strmdata.h:29
Main object for &#39;standard&#39; batch programs.
Definition: batchprog.h:48
JobCommunic * comm_
Definition: batchprog.h:110
Definition: batchjobdispatch.h:19
int main(int argc, char **argv)
Definition: testprog.h:34
int Execute_batch(int *, char **)
Definition: _execbatch.h:97
int ExitProgram(int ret)
BufferStringSet requests_
Definition: batchprog.h:99
IOPar & pars()
Definition: batchprog.h:55
bool stillok_
Definition: batchprog.h:93
#define mClass(module)
Definition: commondefs.h:161
CommandLineParser * clparser_
Definition: batchprog.h:97
Multi-machine socket communicator Handles the communication between a client and the master...
Definition: jobcommunic.h:49
CallBacker object with a name. Use if you want your object to be able to send and receive CallBack&#39;s...
Definition: namedobj.h:50
int jobId()
Definition: batchprog.h:106
Holds the context for selecting and/or creating IOObjs.
Definition: ioobjctxt.h:59

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