~wintermute-devel/wintermute/master

« back to all changes in this revision

Viewing changes to src/Wintermute/application.cpp

  • Committer: Jacky Alciné
  • Date: 2013-05-08 11:22:08 UTC
  • mfrom: (299.1.31)
  • Revision ID: git-v1:736770b4615b8c7cfec6437d8a7d0c8cd95b7d25
Merge branch 'feature/extensibility' into develop

* feature/extensibility:
  Added winfo to updates.
  Updates to Wintermute::Factory.
  Licenses to Wintermute::Version.
  Updates to Wintermute::Application.
  Docs + licensing for header.
  Updated ctags git hook.
  Moved private data into source code.
  Added documentation in application.hpp
  Added changes due to logging infrastructure.
  Added shortcuts for logging to console.
  Added new temporary plugin definition data.
  Improved plugin code.
  Improved logging capability.
  Improved definitions of factory.*pp.
  Improved definitions of arguments.*pp.
  Improved definitions of arguments.*pp.
  Improved definitions in 'application.cpp'
  Added two more non-existing source files to build.
  Updated changes for CMake for extensibility.
  Define default path for extension loading.
  Update generate-ctags.
  Add post-commit hook to VCS.
  Adding logging function to Wintermute::Arguments.
  Updated Wintermute::Application with functionality.
  Added Wintermute::Factory to build.
  Updated Wintermute's global header.
  Add semantic versioning + Git to CMake.
  Updated CMake configuration and add 'Version'.
  Updated 'src/CMakeLists.txt' to reflect source.
  Add 'Wintermute::Plugin' to codebase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *
18
18
 * You should have received a copy of the GNU General Public License
19
19
 * along with Wintermute.  If not, see <http://www.gnu.org/licenses/>.
20
 
**/
 
20
 **/
21
21
 
22
22
#include "application.hpp"
23
23
#include "arguments.hpp"
24
24
#include "logging.hpp"
25
 
#include "Wintermute/globals.hpp"
 
25
#include "factory.hpp"
 
26
#include "version.hpp"
26
27
#include <QtCore/QCoreApplication>
27
28
#include <QtCore/QDebug>
 
29
#include <QtCore/QSharedPointer>
28
30
 
29
31
using Wintermute::Arguments;
30
32
using Wintermute::Logging;
 
33
using Wintermute::Version;
 
34
using Wintermute::Factory;
31
35
using Wintermute::Application;
32
36
using Wintermute::ApplicationPrivate;
33
37
 
34
 
class ApplicationPrivate {
35
 
  public:
36
 
    QSharedPointer<QCoreApplication> app;
37
 
 
38
 
    ApplicationPrivate(int &argc, char **argv) {
39
 
      app = QSharedPointer<QCoreApplication>(new QCoreApplication(argc,argv));
40
 
    }
41
 
 
42
 
    void
43
 
    initialize(){
44
 
      // Allocate necessary variables for logging and arguments.
45
 
      Logging* logging     = Logging::self   = new Logging;
46
 
      Arguments* arguments = Arguments::self = new Arguments;
47
 
    }
48
 
 
49
 
    int
50
 
    exec(){
51
 
      return app->exec();
52
 
    }
53
 
};
 
38
namespace Wintermute {
 
39
  class ApplicationPrivate {
 
40
    public:
 
41
      QSharedPointer<QCoreApplication> app;
 
42
 
 
43
      ApplicationPrivate(int &argc, char **argv) {
 
44
        app = QSharedPointer<QCoreApplication>(new QCoreApplication(argc,argv));
 
45
      }
 
46
 
 
47
      void
 
48
      initialize(){
 
49
          // Allocate necessary variables for logging and arguments.
 
50
          Logging::instance();
 
51
          Arguments::instance();
 
52
          Factory::instance();
 
53
 
 
54
          // Add library paths for plug-ins.
 
55
          app->addLibraryPath(WINTERMUTE_LIBRARY_DIR);
 
56
      }
 
57
 
 
58
      int
 
59
      exec(){
 
60
          return app->exec();
 
61
      }
 
62
  };
 
63
 
 
64
}
54
65
 
55
66
Application* Application::self = 0;
56
67
 
62
73
 
63
74
  // Define the application in Qt.
64
75
  d->app->setApplicationName("Wintermute");
65
 
  d->app->setApplicationVersion(WINTERMUTE_VERSION_EXACT);
 
76
  d->app->setApplicationVersion(this->version().toString());
66
77
  d->app->setOrganizationName("Synthetic Intellect Institute");
67
78
  d->app->setOrganizationDomain("thesii.org");
68
79
}
69
80
 
70
81
int
71
82
Application::run(int &argc, char **argv){
 
83
  int returnCode = -1;
 
84
 
72
85
  if (Application::instance() == 0){
73
86
    // Define the application.
74
87
    Application::self = new Application(argc,argv);
 
88
    Logger* log = wlog(Application::self);
75
89
 
76
90
    // Invoke the initialization code.
77
91
    self->d_ptr->initialize();
78
 
    Logging::obtainLogger(Application::self)->debug("Completed initialization phase.");
 
92
    log->debug("Completed initialization phase.");
79
93
 
80
94
    // Start thyself.
81
95
    self->start(); 
82
 
    Logging::obtainLogger(Application::self)->debug("Started.");
83
96
 
84
97
    // Begin the event loop.
85
 
    Logging::obtainLogger(Application::self)->debug("Beginning event loop.");
86
 
    int returnCode = self->d_ptr->exec();
87
 
    Logging::obtainLogger(Application::self)->info("Event loop ended. Ended with exit code " + QString::number(returnCode));
88
 
 
89
 
    return returnCode;
 
98
    log->debug("Beginning event loop.");
 
99
    returnCode = self->d_ptr->exec();
 
100
    log->info(QString("Event loop ended; ended with exit code %1").arg(returnCode));
90
101
  }
91
102
 
92
 
  return -1;
 
103
  return returnCode;
93
104
}
94
105
 
95
106
void
96
107
Application::start(){
97
 
  Logger* log = Logging::obtainLogger(this);
 
108
  //Q_D(Application);
 
109
  Logger* log = wlog(this);
 
110
  log->info("Starting.");
 
111
 
 
112
  // Privately start the Factory.
 
113
  Factory::instance()->start();
 
114
 
 
115
 
 
116
  log->info("Started.");
98
117
}
99
118
 
100
 
 
101
119
void
102
120
Application::stop(){
 
121
  //Q_D(Application);
 
122
 
 
123
  // Privately clean up the Factory.
 
124
  Factory::instance()->stop();
 
125
}
 
126
 
 
127
Version
 
128
Application::version() const {
 
129
  Version ver;
 
130
  ver.major = WINTERMUTE_VERSION_MAJOR;
 
131
  ver.minor = WINTERMUTE_VERSION_MINOR;
 
132
  ver.patch = WINTERMUTE_VERSION_PATCH;
 
133
  ver.state = (Wintermute::Version::DevelopmentStage) WINTERMUTE_VERSION_STAGE;
 
134
  ver.stage = WINTERMUTE_VERSION_STAGE_REVISION;
 
135
 
 
136
  return ver;
103
137
}
104
138
 
105
139
Application::~Application(){