mirror of
				https://github.com/pocoproject/poco.git
				synced 2025-11-03 19:40:37 +01:00 
			
		
		
		
	Add getter for an Application's list of Subsystems
This commit is contained in:
		@@ -70,7 +70,7 @@ class Util_API Application: public Subsystem
 | 
				
			|||||||
	///   - a SystemConfiguration (priority 100)
 | 
						///   - a SystemConfiguration (priority 100)
 | 
				
			||||||
	///   - the configurations loaded with loadConfiguration().
 | 
						///   - the configurations loaded with loadConfiguration().
 | 
				
			||||||
	///
 | 
						///
 | 
				
			||||||
	/// The Application class sets a few default properties in 
 | 
						/// The Application class sets a few default properties in
 | 
				
			||||||
	/// its configuration. These are:
 | 
						/// its configuration. These are:
 | 
				
			||||||
	///   - application.path: the absolute path to application executable
 | 
						///   - application.path: the absolute path to application executable
 | 
				
			||||||
	///   - application.name: the file name of the application executable
 | 
						///   - application.name: the file name of the application executable
 | 
				
			||||||
@@ -86,6 +86,8 @@ class Util_API Application: public Subsystem
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	typedef std::vector<std::string> ArgVec;
 | 
						typedef std::vector<std::string> ArgVec;
 | 
				
			||||||
 | 
						typedef Poco::AutoPtr<Subsystem> SubsystemPtr;
 | 
				
			||||||
 | 
						typedef std::vector<SubsystemPtr> SubsystemVec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	enum ExitCode
 | 
						enum ExitCode
 | 
				
			||||||
		/// Commonly used exit status codes.
 | 
							/// Commonly used exit status codes.
 | 
				
			||||||
@@ -108,14 +110,14 @@ public:
 | 
				
			|||||||
		EXIT_NOPERM      = 77, /// permission denied
 | 
							EXIT_NOPERM      = 77, /// permission denied
 | 
				
			||||||
		EXIT_CONFIG      = 78  /// configuration error
 | 
							EXIT_CONFIG      = 78  /// configuration error
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	enum ConfigPriority
 | 
						enum ConfigPriority
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		PRIO_APPLICATION = -100,
 | 
							PRIO_APPLICATION = -100,
 | 
				
			||||||
		PRIO_DEFAULT     = 0,
 | 
							PRIO_DEFAULT     = 0,
 | 
				
			||||||
		PRIO_SYSTEM      = 100
 | 
							PRIO_SYSTEM      = 100
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	Application();
 | 
						Application();
 | 
				
			||||||
		/// Creates the Application.
 | 
							/// Creates the Application.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -131,7 +133,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	void init(int argc, char* argv[]);
 | 
						void init(int argc, char* argv[]);
 | 
				
			||||||
		/// Processes the application's command line arguments
 | 
							/// Processes the application's command line arguments
 | 
				
			||||||
		/// and sets the application's properties (e.g., 
 | 
							/// and sets the application's properties (e.g.,
 | 
				
			||||||
		/// "application.path", "application.name", etc.).
 | 
							/// "application.path", "application.name", etc.).
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// Note that as of release 1.3.7, init() no longer
 | 
							/// Note that as of release 1.3.7, init() no longer
 | 
				
			||||||
@@ -140,7 +142,7 @@ public:
 | 
				
			|||||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
 | 
					#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
 | 
				
			||||||
	void init(int argc, wchar_t* argv[]);
 | 
						void init(int argc, wchar_t* argv[]);
 | 
				
			||||||
		/// Processes the application's command line arguments
 | 
							/// Processes the application's command line arguments
 | 
				
			||||||
		/// and sets the application's properties (e.g., 
 | 
							/// and sets the application's properties (e.g.,
 | 
				
			||||||
		/// "application.path", "application.name", etc.).
 | 
							/// "application.path", "application.name", etc.).
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// Note that as of release 1.3.7, init() no longer
 | 
							/// Note that as of release 1.3.7, init() no longer
 | 
				
			||||||
@@ -152,7 +154,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	void init(const ArgVec& args);
 | 
						void init(const ArgVec& args);
 | 
				
			||||||
		/// Processes the application's command line arguments
 | 
							/// Processes the application's command line arguments
 | 
				
			||||||
		/// and sets the application's properties (e.g., 
 | 
							/// and sets the application's properties (e.g.,
 | 
				
			||||||
		/// "application.path", "application.name", etc.).
 | 
							/// "application.path", "application.name", etc.).
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// Note that as of release 1.3.7, init() no longer
 | 
							/// Note that as of release 1.3.7, init() no longer
 | 
				
			||||||
@@ -172,11 +174,11 @@ public:
 | 
				
			|||||||
	int loadConfiguration(int priority = PRIO_DEFAULT);
 | 
						int loadConfiguration(int priority = PRIO_DEFAULT);
 | 
				
			||||||
		/// Loads configuration information from a default location.
 | 
							/// Loads configuration information from a default location.
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// The configuration(s) will be added to the application's 
 | 
							/// The configuration(s) will be added to the application's
 | 
				
			||||||
		/// LayeredConfiguration with the given priority.
 | 
							/// LayeredConfiguration with the given priority.
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// The configuration file(s) must be located in the same directory
 | 
							/// The configuration file(s) must be located in the same directory
 | 
				
			||||||
		/// as the executable or a parent directory of it, and must have the 
 | 
							/// as the executable or a parent directory of it, and must have the
 | 
				
			||||||
		/// same base name as the executable, with one of the following extensions:
 | 
							/// same base name as the executable, with one of the following extensions:
 | 
				
			||||||
		/// .properties, .ini or .xml.
 | 
							/// .properties, .ini or .xml.
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
@@ -185,9 +187,9 @@ public:
 | 
				
			|||||||
		///
 | 
							///
 | 
				
			||||||
		/// If the application is built in debug mode (the _DEBUG preprocessor
 | 
							/// If the application is built in debug mode (the _DEBUG preprocessor
 | 
				
			||||||
		/// macro is defined) and the base name of the appication executable
 | 
							/// macro is defined) and the base name of the appication executable
 | 
				
			||||||
		/// ends with a 'd', a config file without the 'd' ending its base name is 
 | 
							/// ends with a 'd', a config file without the 'd' ending its base name is
 | 
				
			||||||
		/// also found.
 | 
							/// also found.
 | 
				
			||||||
		/// 
 | 
							///
 | 
				
			||||||
		/// Example: Given the application "SampleAppd.exe", built in debug mode.
 | 
							/// Example: Given the application "SampleAppd.exe", built in debug mode.
 | 
				
			||||||
		/// Then loadConfiguration() will automatically find a configuration file
 | 
							/// Then loadConfiguration() will automatically find a configuration file
 | 
				
			||||||
		/// named "SampleApp.properties" if it exists and if "SampleAppd.properties"
 | 
							/// named "SampleApp.properties" if it exists and if "SampleAppd.properties"
 | 
				
			||||||
@@ -208,7 +210,7 @@ public:
 | 
				
			|||||||
		///
 | 
							///
 | 
				
			||||||
		/// Extensions are not case sensitive.
 | 
							/// Extensions are not case sensitive.
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// The configuration will be added to the application's 
 | 
							/// The configuration will be added to the application's
 | 
				
			||||||
		/// LayeredConfiguration with the given priority.
 | 
							/// LayeredConfiguration with the given priority.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	template <class C> C& getSubsystem() const;
 | 
						template <class C> C& getSubsystem() const;
 | 
				
			||||||
@@ -218,6 +220,9 @@ public:
 | 
				
			|||||||
		/// Throws a NotFoundException if such a subsystem has
 | 
							/// Throws a NotFoundException if such a subsystem has
 | 
				
			||||||
		/// not been registered.
 | 
							/// not been registered.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SubsystemVec& subsystems();
 | 
				
			||||||
 | 
							/// Returns a reference to the subsystem list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	virtual int run();
 | 
						virtual int run();
 | 
				
			||||||
		/// Runs the application by performing additional (un)initializations
 | 
							/// Runs the application by performing additional (un)initializations
 | 
				
			||||||
		/// and calling the main() method.
 | 
							/// and calling the main() method.
 | 
				
			||||||
@@ -237,7 +242,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	LayeredConfiguration& config() const;
 | 
						LayeredConfiguration& config() const;
 | 
				
			||||||
		/// Returns the application's configuration.
 | 
							/// Returns the application's configuration.
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	Poco::Logger& logger() const;
 | 
						Poco::Logger& logger() const;
 | 
				
			||||||
		/// Returns the application's logger.
 | 
							/// Returns the application's logger.
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
@@ -245,21 +250,21 @@ public:
 | 
				
			|||||||
		/// application's logger is "ApplicationStartup", which is
 | 
							/// application's logger is "ApplicationStartup", which is
 | 
				
			||||||
		/// connected to a ConsoleChannel.
 | 
							/// connected to a ConsoleChannel.
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// After the logging subsystem has been initialized, which 
 | 
							/// After the logging subsystem has been initialized, which
 | 
				
			||||||
		/// usually happens as the first action in Application::initialize(),
 | 
							/// usually happens as the first action in Application::initialize(),
 | 
				
			||||||
		/// the application's logger is the one specified by the
 | 
							/// the application's logger is the one specified by the
 | 
				
			||||||
		/// "application.logger" configuration property. If that property
 | 
							/// "application.logger" configuration property. If that property
 | 
				
			||||||
		/// is not specified, the logger is "Application".
 | 
							/// is not specified, the logger is "Application".
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	const ArgVec& argv() const;
 | 
						const ArgVec& argv() const;
 | 
				
			||||||
		/// Returns reference to vector of the application's arguments as 
 | 
							/// Returns reference to vector of the application's arguments as
 | 
				
			||||||
		/// specified on the command line. If user overrides the 
 | 
							/// specified on the command line. If user overrides the
 | 
				
			||||||
		/// Application::main(const ArgVec&) function, it will receive
 | 
							/// Application::main(const ArgVec&) function, it will receive
 | 
				
			||||||
		/// only the command line parameters that were not processed in
 | 
							/// only the command line parameters that were not processed in
 | 
				
			||||||
		/// Application::processOptons(). This function returns the 
 | 
							/// Application::processOptons(). This function returns the
 | 
				
			||||||
		/// full set of command line parameters as received in
 | 
							/// full set of command line parameters as received in
 | 
				
			||||||
		/// main(argc, argv*).
 | 
							/// main(argc, argv*).
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	const OptionSet& options() const;
 | 
						const OptionSet& options() const;
 | 
				
			||||||
		/// Returns the application's option set.
 | 
							/// Returns the application's option set.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -273,7 +278,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	Poco::Timespan uptime() const;
 | 
						Poco::Timespan uptime() const;
 | 
				
			||||||
		/// Returns the application uptime.
 | 
							/// Returns the application uptime.
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	void stopOptionsProcessing();
 | 
						void stopOptionsProcessing();
 | 
				
			||||||
		/// If called from an option callback, stops all further
 | 
							/// If called from an option callback, stops all further
 | 
				
			||||||
		/// options processing.
 | 
							/// options processing.
 | 
				
			||||||
@@ -295,11 +300,11 @@ protected:
 | 
				
			|||||||
		/// in which they have been registered.
 | 
							/// in which they have been registered.
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// Overriding implementations must call the base class implementation.
 | 
							/// Overriding implementations must call the base class implementation.
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	void uninitialize();
 | 
						void uninitialize();
 | 
				
			||||||
		/// Uninitializes the application and all registered subsystems.
 | 
							/// Uninitializes the application and all registered subsystems.
 | 
				
			||||||
		/// Subsystems are always uninitialized in reverse order in which
 | 
							/// Subsystems are always uninitialized in reverse order in which
 | 
				
			||||||
		/// they have been initialized. 
 | 
							/// they have been initialized.
 | 
				
			||||||
		///
 | 
							///
 | 
				
			||||||
		/// Overriding implementations must call the base class implementation.
 | 
							/// Overriding implementations must call the base class implementation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -367,10 +372,8 @@ private:
 | 
				
			|||||||
	void processOptions();
 | 
						void processOptions();
 | 
				
			||||||
	bool findAppConfigFile(const std::string& appName, const std::string& extension, Poco::Path& path) const;
 | 
						bool findAppConfigFile(const std::string& appName, const std::string& extension, Poco::Path& path) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	typedef Poco::AutoPtr<Subsystem> SubsystemPtr;
 | 
					 | 
				
			||||||
	typedef std::vector<SubsystemPtr> SubsystemVec;
 | 
					 | 
				
			||||||
	typedef Poco::AutoPtr<LayeredConfiguration> ConfigPtr;
 | 
						typedef Poco::AutoPtr<LayeredConfiguration> ConfigPtr;
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	ConfigPtr       _pConfig;
 | 
						ConfigPtr       _pConfig;
 | 
				
			||||||
	SubsystemVec    _subsystems;
 | 
						SubsystemVec    _subsystems;
 | 
				
			||||||
	bool            _initialized;
 | 
						bool            _initialized;
 | 
				
			||||||
@@ -388,7 +391,7 @@ private:
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static Application* _pInstance;
 | 
						static Application* _pInstance;
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	friend class LoggingSubsystem;
 | 
						friend class LoggingSubsystem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Application(const Application&);
 | 
						Application(const Application&);
 | 
				
			||||||
@@ -410,6 +413,11 @@ template <class C> C& Application::getSubsystem() const
 | 
				
			|||||||
	throw Poco::NotFoundException("The subsystem has not been registered", typeid(C).name());
 | 
						throw Poco::NotFoundException("The subsystem has not been registered", typeid(C).name());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					inline Application::SubsystemVec& Application::subsystems()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return _subsystems;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline bool Application::initialized() const
 | 
					inline bool Application::initialized() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -459,7 +467,7 @@ inline Poco::Timespan Application::uptime() const
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	Poco::Timestamp now;
 | 
						Poco::Timestamp now;
 | 
				
			||||||
	Poco::Timespan uptime = now - _startTime;
 | 
						Poco::Timespan uptime = now - _startTime;
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	return uptime;
 | 
						return uptime;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,7 +44,7 @@ class Util_API Subsystem: public Poco::RefCountedObject
 | 
				
			|||||||
	/// life of a running application.
 | 
						/// life of a running application.
 | 
				
			||||||
	///
 | 
						///
 | 
				
			||||||
	/// The degree to which dynamic reconfiguration is supported
 | 
						/// The degree to which dynamic reconfiguration is supported
 | 
				
			||||||
	/// is up to the actual subsystem implementation. It can 
 | 
						/// is up to the actual subsystem implementation. It can
 | 
				
			||||||
	/// range from ignoring the reconfiguration request (not
 | 
						/// range from ignoring the reconfiguration request (not
 | 
				
			||||||
	/// recommended), to changing certain settings that affect
 | 
						/// recommended), to changing certain settings that affect
 | 
				
			||||||
	/// the performance, to a complete reinitialization.
 | 
						/// the performance, to a complete reinitialization.
 | 
				
			||||||
@@ -52,15 +52,15 @@ class Util_API Subsystem: public Poco::RefCountedObject
 | 
				
			|||||||
public:
 | 
					public:
 | 
				
			||||||
	Subsystem();
 | 
						Subsystem();
 | 
				
			||||||
		/// Creates the Subsystem.
 | 
							/// Creates the Subsystem.
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
protected:
 | 
					 | 
				
			||||||
	virtual const char* name() const = 0;
 | 
						virtual const char* name() const = 0;
 | 
				
			||||||
		/// Returns the name of the subsystem.
 | 
							/// Returns the name of the subsystem.
 | 
				
			||||||
		/// Must be implemented by subclasses.
 | 
							/// Must be implemented by subclasses.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
	virtual void initialize(Application& app) = 0;
 | 
						virtual void initialize(Application& app) = 0;
 | 
				
			||||||
		/// Initializes the subsystem.
 | 
							/// Initializes the subsystem.
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	virtual void uninitialize() = 0;
 | 
						virtual void uninitialize() = 0;
 | 
				
			||||||
		/// Uninitializes the subsystem.
 | 
							/// Uninitializes the subsystem.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -70,7 +70,7 @@ protected:
 | 
				
			|||||||
		/// The default implementation just calls
 | 
							/// The default implementation just calls
 | 
				
			||||||
		/// uninitialize() followed by initialize().
 | 
							/// uninitialize() followed by initialize().
 | 
				
			||||||
		/// Actual implementations might want to use a
 | 
							/// Actual implementations might want to use a
 | 
				
			||||||
		/// less radical and possibly more performant 
 | 
							/// less radical and possibly more performant
 | 
				
			||||||
		/// approach.
 | 
							/// approach.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	virtual void defineOptions(OptionSet& options);
 | 
						virtual void defineOptions(OptionSet& options);
 | 
				
			||||||
@@ -85,9 +85,9 @@ protected:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	virtual ~Subsystem();
 | 
						virtual ~Subsystem();
 | 
				
			||||||
		/// Destroys the Subsystem.
 | 
							/// Destroys the Subsystem.
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	friend class Application;
 | 
						friend class Application;
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	Subsystem(const Subsystem&);
 | 
						Subsystem(const Subsystem&);
 | 
				
			||||||
	Subsystem& operator = (const Subsystem&);
 | 
						Subsystem& operator = (const Subsystem&);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user