1 module aurorafw.core.appcontext;
2 
3 /****************************************************************************
4 ** ┌─┐┬ ┬┬─┐┌─┐┬─┐┌─┐  ┌─┐┬─┐┌─┐┌┬┐┌─┐┬ ┬┌─┐┬─┐┬┌─
5 ** ├─┤│ │├┬┘│ │├┬┘├─┤  ├┤ ├┬┘├─┤│││├┤ ││││ │├┬┘├┴┐
6 ** ┴ ┴└─┘┴└─└─┘┴└─┴ ┴  └  ┴└─┴ ┴┴ ┴└─┘└┴┘└─┘┴└─┴ ┴
7 ** A Powerful General Purpose Framework
8 ** More information in: https://aurora-fw.github.io/
9 **
10 ** Copyright (C) 2018 Aurora Framework, All rights reserved.
11 **
12 ** This file is part of the Aurora Framework. This framework is free
13 ** software; you can redistribute it and/or modify it under the terms of
14 ** the GNU Lesser General Public License version 3 as published by the
15 ** Free Software Foundation and appearing in the file LICENSE included in
16 ** the packaging of this file. Please review the following information to
17 ** ensure the GNU Lesser General Public License version 3 requirements
18 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
19 ****************************************************************************/
20 
21 import aurorafw.core.opt;
22 import aurorafw.core.debugmanager;
23 
24 abstract class ApplicationContext {
25 public:
26 	final this(string name = "AuroraFW Application", string[] args = null)
27 	{
28 		_name = name;
29 		_opts = OptionHandler(args);
30 		_opts.add("afw-debug", "Enable the aurora built-in debug logger");
31 		if(_opts.option("afw-debug").active)
32 		{
33 			afwDebugFlag = true;
34 			debug trace(afwDebugFlag, "Debug is now enabled");
35 		}
36 
37 		debug trace(afwDebugFlag, "creating new application");
38 		debug trace(afwDebugFlag, "application is created.");
39 	}
40 
41 	pure ~this() @safe
42 	{
43 		debug trace(afwDebugFlag, "application is destroyed.");
44 	}
45 
46 	void onStart() @safe;
47 	void onClose() @safe;
48 
49 	final void start() @safe
50 	{
51 		debug trace(afwDebugFlag, "application is starting");
52 		_internalStart();
53 		onStart();
54 		debug trace(afwDebugFlag, "application started");
55 	}
56 
57 	final void close() @safe
58 	{
59 		debug trace(afwDebugFlag, "application is closing");
60 		_internalClose();
61 		onClose();
62 		debug trace(afwDebugFlag, "application closed");
63 	}
64 
65 	pure @property string name() @safe { return _name; }
66 	pure @property string name(string name) @safe { return _name = name; }
67 
68 protected:
69 	void _internalSetName(string ) @safe;
70 	void _internalStart() @safe;
71 	void _internalClose() @safe;
72 
73 private:
74 	string _name;
75 	OptionHandler _opts;
76 }