systemCall.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::functionObjects::systemCall
28 
29 Group
30  grpUtilitiesFunctionObjects
31 
32 Description
33  Executes system calls, entered in the form of string lists.
34 
35  Calls can be made at the following points in the calculation:
36  - every time step
37  - every output time
38  - end of the calculation
39 
40 Usage
41  Example of the function object specification:
42  \verbatim
43  systemCall1
44  {
45  type systemCall;
46  libs ("libutilityFunctionObjects.so");
47  ...
48  executeCalls
49  (
50  "echo execute"
51  );
52  writeCalls
53  (
54  "echo === writing data ==="
55  );
56  endCalls
57  (
58  "echo === echoing .bashrc ==="
59  "cat ~/.bashrc"
60  "echo \*\*\* done \*\*\*"
61  );
62  }
63  \endverbatim
64 
65  Where the entries comprise:
66  \table
67  Property | Description | Required | Default value
68  type | type name: systemCall | yes |
69  executeCalls | list of calls on execute | yes |
70  writeCalls | list of calls on write | yes |
71  endCalls | list of calls on end | yes |
72  master | execute on master only | no | false
73  \endtable
74 
75 Note
76  Since this function object executes system calls, there is a potential
77  security risk. In order to use the \c systemCall function object, the
78  \c allowSystemOperations must be set to '1'; otherwise, system calls will
79  not be allowed.
80 
81  Additionally, since the system commands are normally sent via the shell,
82  special shell character may require backslash escaping.
83 
84 See also
85  Foam::functionObject
86  Foam::functionObjects::timeControl
87 
88 SourceFiles
89  systemCall.C
90 
91 \*---------------------------------------------------------------------------*/
92 
93 #ifndef functionObjects_systemCall_H
94 #define functionObjects_systemCall_H
95 
96 #include "functionObject.H"
97 #include "stringList.H"
98 
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
100 
101 namespace Foam
102 {
103 namespace functionObjects
104 {
105 
106 /*---------------------------------------------------------------------------*\
107  Class systemCall Declaration
108 \*---------------------------------------------------------------------------*/
109 
110 class systemCall
111 :
112  public functionObject
113 {
114 protected:
115 
116  // Private data
117 
118  //- List of calls to execute - every step
120 
121  //- List of calls to execute - write steps
123 
124  //- List of calls to execute when exiting the time-loop
126 
127  //- Perform system calls on the master only
128  bool masterOnly_;
129 
130 
131  // Protected Member Functions
132 
133  //- Dispatch specified calls
134  label dispatch(const stringList& calls);
135 
136  //- No copy construct
137  systemCall(const systemCall&) = delete;
138 
139  //- No copy assignment
140  void operator=(const systemCall&) = delete;
141 
142 
143 public:
144 
145  //- Runtime type information
146  TypeName("systemCall");
147 
148 
149  // Constructors
150 
151  //- Construct from Time and dictionary
152  systemCall
153  (
154  const word& name,
155  const Time& runTime,
156  const dictionary& dict
157  );
158 
159 
160  //- Destructor
161  virtual ~systemCall() = default;
162 
163 
164  // Member Functions
165 
166  //- Read the system calls
167  virtual bool read(const dictionary& dict);
168 
169  //- Execute the "executeCalls" at each time-step
170  virtual bool execute();
171 
172  //- Write, execute the "writeCalls"
173  virtual bool write();
174 
175  //- Execute the "endCalls" at the final time-loop
176  virtual bool end();
177 };
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace functionObjects
183 } // End namespace Foam
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::systemCall::end
virtual bool end()
Execute the "endCalls" at the final time-loop.
Definition: systemCall.C:166
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::systemCall::TypeName
TypeName("systemCall")
Runtime type information.
Foam::functionObjects::systemCall::operator=
void operator=(const systemCall &)=delete
No copy assignment.
Foam::functionObjects::systemCall
Executes system calls, entered in the form of string lists.
Definition: systemCall.H:139
Foam::functionObjects::systemCall::writeCalls_
stringList writeCalls_
List of calls to execute - write steps.
Definition: systemCall.H:151
Foam::stringList
List< string > stringList
A List of strings.
Definition: stringList.H:58
Foam::functionObjects::systemCall::executeCalls_
stringList executeCalls_
List of calls to execute - every step.
Definition: systemCall.H:148
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:229
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::functionObjects::systemCall::dispatch
label dispatch(const stringList &calls)
Dispatch specified calls.
Definition: systemCall.C:55
Foam::functionObjects::systemCall::~systemCall
virtual ~systemCall()=default
Destructor.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::systemCall::systemCall
systemCall(const systemCall &)=delete
No copy construct.
Foam::functionObjects::systemCall::read
virtual bool read(const dictionary &dict)
Read the system calls.
Definition: systemCall.C:104
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::systemCall::write
virtual bool write()
Write, execute the "writeCalls".
Definition: systemCall.C:159
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::List< string >
Foam::functionObjects::systemCall::endCalls_
stringList endCalls_
List of calls to execute when exiting the time-loop.
Definition: systemCall.H:154
Foam::functionObjects::systemCall::execute
virtual bool execute()
Execute the "executeCalls" at each time-step.
Definition: systemCall.C:152
functionObject.H
Foam::functionObjects::systemCall::masterOnly_
bool masterOnly_
Perform system calls on the master only.
Definition: systemCall.H:157
stringList.H