systemCall.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "systemCall.H"
27 #include "Time.H"
28 #include "dynamicCode.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 defineTypeNameAndDebug(systemCall, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 (
42  const word& name,
43  const objectRegistry&,
44  const dictionary& dict,
45  const bool
46 )
47 :
48  name_(name),
49  executeCalls_(),
50  endCalls_(),
51  writeCalls_()
52 {
53  read(dict);
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
58 
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
66 {
67  dict.readIfPresent("executeCalls", executeCalls_);
68  dict.readIfPresent("endCalls", endCalls_);
69  dict.readIfPresent("writeCalls", writeCalls_);
70 
71  if (executeCalls_.empty() && endCalls_.empty() && writeCalls_.empty())
72  {
73  WarningIn("Foam::system::read(const dictionary&)")
74  << "no executeCalls, endCalls or writeCalls defined."
75  << endl;
76  }
78  {
79  FatalErrorIn("systemCall::read(const dictionary&)")
80  << "Executing user-supplied system calls is not enabled by "
81  << "default because of " << nl
82  << "security issues. If you trust the case you can enable this "
83  << "facility by " << nl
84  << "adding to the InfoSwitches setting in the system controlDict:"
85  << nl << nl
86  << " allowSystemOperations 1" << nl << nl
87  << "The system controlDict is either" << nl << nl
88  << " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << nl << nl
89  << "or" << nl << nl
90  << " $WM_PROJECT_DIR/etc/controlDict" << nl << nl
91  << exit(FatalError);
92  }
93 }
94 
95 
97 {
98  forAll(executeCalls_, callI)
99  {
100  Foam::system(executeCalls_[callI]);
101  }
102 }
103 
104 
106 {
107  forAll(endCalls_, callI)
108  {
109  Foam::system(endCalls_[callI]);
110  }
111 }
112 
113 
115 {
116  // Do nothing
117 }
118 
119 
121 {
122  forAll(writeCalls_, callI)
123  {
124  Foam::system(writeCalls_[callI]);
125  }
126 }
127 
128 
129 // ************************************************************************* //
A class for handling words, derived from string.
Definition: word.H:59
virtual ~systemCall()
Destructor.
Definition: systemCall.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
static int allowSystemOperations
Flag if system operations are allowed.
Definition: dynamicCode.H:161
systemCall(const systemCall &)
Disallow default bitwise copy construct.
virtual void write()
Write, execute the "writeCalls".
Definition: systemCall.C:120
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
virtual void end()
Execute the "endCalls" at the final time-loop.
Definition: systemCall.C:105
#define forAll(list, i)
Definition: UList.H:421
virtual void execute()
Execute the "executeCalls" at each time-step.
Definition: systemCall.C:96
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1162
error FatalError
Registry of regIOobjects.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: systemCall.C:114
defineTypeNameAndDebug(combustionModel, 0)
virtual void read(const dictionary &)
Read the system calls.
Definition: systemCall.C:65