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-2015 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  {
74  << "no executeCalls, endCalls or writeCalls defined."
75  << endl;
76  }
78  {
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 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
systemCall.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dynamicCode::allowSystemOperations
static int allowSystemOperations
Flag if system operations are allowed.
Definition: dynamicCode.H:161
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::systemCall::~systemCall
virtual ~systemCall()
Destructor.
Definition: systemCall.C:59
Foam::systemCall::systemCall
systemCall(const systemCall &)
Disallow default bitwise copy construct.
Foam::nl
static const char nl
Definition: Ostream.H:260
dynamicCode.H
Foam::systemCall::read
virtual void read(const dictionary &)
Read the system calls.
Definition: systemCall.C:65
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::systemCall::write
virtual void write()
Write, execute the "writeCalls".
Definition: systemCall.C:120
Foam::systemCall::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: systemCall.C:114
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::systemCall::end
virtual void end()
Execute the "endCalls" at the final time-loop.
Definition: systemCall.C:105
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::system
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1155
Foam::systemCall::execute
virtual void execute()
Execute the "executeCalls" at each time-step.
Definition: systemCall.C:96
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47