WSF
WsfApplication.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFAPPLICATION_HPP
13#define WSFAPPLICATION_HPP
14
15#include "wsf_export.h"
16
17#include <list>
18#include <memory>
19#include <mutex>
20#include <string>
21#include <vector>
22
23#include "UtException.hpp"
24class UtScriptTypes;
28class WsfScenario;
29class WsfSimulation;
30class WsfSystemLog;
31
45{
46 friend class WsfScenario;
47
48public:
50 class Exception : public UtException
51 {
52 public:
53 Exception(const std::string& aWhat)
54 : UtException(aWhat)
55 , mReturnCode(0)
56 {
57 }
58
59 int GetReturnCode() const { return mReturnCode; }
60
61 protected:
63 };
64
68 {
69 public:
70 FeatureNotPresent(bool aTestingEnabled);
71 ~FeatureNotPresent() override = default;
72 };
73
74 using PluginPaths = std::list<std::string>;
75
76 WsfApplication(const std::string& aApplicationName,
77 int aArgc,
78 char* aArgv[],
79 const PluginPaths& aPluginPaths = PluginPaths());
80 virtual ~WsfApplication();
81
83 const std::string& GetApplicationName() const { return mApplicationName; }
84
86
87 void GetCommandLineArguments(int& aArgc, char**& aArgv);
88
89 void RemoveCommandLineOptions(int aArgc, int aArgCount);
91
94
95 void RegisterExtension(const std::string& aName, std::unique_ptr<WsfApplicationExtension> aExtensionPtr);
96
97 void ExtensionDepends(const std::string& aExtensionName, const std::string& aDependsOnExtensionName, bool aRequired);
98
99 bool ExtensionIsRegistered(const std::string& aName) const;
100 WsfApplicationExtension* FindExtension(const std::string& aName) const;
101 WsfApplicationExtension& GetExtension(const std::string& aName) const;
102
104 const WsfExtensionList& GetExtensions() const { return *mExtensionListPtr; }
106
119
120
121 struct Feature
122 {
124 std::string mName;
126 std::string mProject;
127 };
128
129 void RegisterFeature(const std::string& aFeature, const std::string& aProjectName = std::string());
130
132 const std::vector<Feature>& GetRegisteredFeatures() { return mRegisteredFeatures; }
134
136
137
138 UtScriptTypes* GetScriptTypes() const { return mScriptTypesPtr; }
139
141 WsfSystemLog& GetSystemLog() { return *mSystemLogPtr; }
143
145
146
147 bool IsTestingEnabled() const { return mIsTestingEnabled; }
149
150private:
152 WsfApplication(const WsfApplication& aSrc);
153
154 void RegisterDefaultFeatures();
155
156 void ScenarioCreated(WsfScenario& aScenario);
157 void SimulationCreated(WsfSimulation& aSimulation);
158
159 bool InitializeTestEnvironment();
160
162 static WsfApplication* mInstancePtr;
163
165 std::string mApplicationName;
166
168 std::vector<char*> mArgv;
169
171 WsfExtensionList* mExtensionListPtr;
172
174 std::vector<Feature> mRegisteredFeatures;
175
177 WsfSystemLog* mSystemLogPtr;
178
180 UtScriptTypes* mScriptTypesPtr;
181
183 WsfPluginManager* mPluginManagerPtr;
184
186 std::recursive_mutex mMutex;
187
189 bool mIsTestingEnabled;
190};
191
192// Define a macro that, if used in a standard way, provides a way to register an extension without
193// the need to bring a header file for the extension. This can potentially eliminate a the need
194// to define a lot of include paths to build the application. The extension should define a static
195// method of the form:
196//
197// void Register_<ExtensionName>(WsfApplication& aApplication);
198//
199// 'WSF_REGISTER_APPLICATION(app, <ExtensionName>)' generates the code:
200//
201// void Register_<ExtensionName>(WsfApplication& aApplication);
202// Register_<ExtensionName>(app);
203//
204// For instance:
205//
206// WsfApplication app;
207// WSF_REGISTER_EXTENSION(app, WsfEventOutput);
208// WSF_REGISTER_EXTENSION(app, WsfDisInterface);
209//
210// will register the standard event output and DIS interface extensions...
211
212#define WSF_REGISTER_EXTENSION(APP, NAME) \
213 extern void Register_##NAME(WsfApplication& aApplication); \
214 Register_##NAME(APP);
215
216#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfApplicationExtension.hpp:86
int mReturnCode
Definition WsfApplication.hpp:62
int GetReturnCode() const
Definition WsfApplication.hpp:59
Exception(const std::string &aWhat)
Definition WsfApplication.hpp:53
FeatureNotPresent(bool aTestingEnabled)
Definition WsfApplication.cpp:348
~FeatureNotPresent() override=default
Definition WsfApplication.hpp:45
UtScriptTypes * GetScriptTypes() const
Return a pointer to the script types/classes.
Definition WsfApplication.hpp:138
std::list< std::string > PluginPaths
Definition WsfApplication.hpp:74
const WsfExtensionList & GetExtensions() const
Returns all extension dependencies, added by ExtensionDepends().
Definition WsfApplication.hpp:104
WsfSystemLog & GetSystemLog()
Return a reference to the system log.
Definition WsfApplication.hpp:141
const std::string & GetApplicationName() const
Return the name of the application.
Definition WsfApplication.hpp:83
WsfApplication(const std::string &aApplicationName, int aArgc, char *aArgv[], const PluginPaths &aPluginPaths=PluginPaths())
Definition WsfApplication.cpp:47
bool IsTestingEnabled() const
Returns 'true' if application is executing under the control of an automated test executive.
Definition WsfApplication.hpp:147
const std::vector< Feature > & GetRegisteredFeatures()
Returns a list of registered features.
Definition WsfApplication.hpp:132
friend class WsfScenario
Definition WsfApplication.hpp:46
void RegisterFeature(const std::string &aFeature, const std::string &aProjectName=std::string())
Definition WsfApplication.cpp:224
Definition WsfExtensionList.hpp:46
Definition WsfPluginManager.hpp:40
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfSystemLog.hpp:28
An application feature, used for test if features exist.
Definition WsfApplication.hpp:122
std::string mName
Name of the feature.
Definition WsfApplication.hpp:124
std::string mProject
Name of the project which implements the feature.
Definition WsfApplication.hpp:126
Copyrights Multiple, All Rights Reserved