i6engine  1.0
EngineCoreController.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_CORE_ENGINECORECONTROLLER_H__
26 #define __I6ENGINE_CORE_ENGINECORECONTROLLER_H__
27 
28 #include <condition_variable>
29 #include <mutex>
30 #include <vector>
31 
33 
35 
36 #include "boost/function.hpp"
37 
49 namespace i6e {
50 namespace core {
51 
52  class SubSystemController;
53 
62  public:
67 
69 
73  void SetOnAfterInitializedCallback(const boost::function<void(void)> & ptrOnAfterInitialize) {
74  _vptrOnAfterInitialize.push_back(ptrOnAfterInitialize);
75  }
76 
80  void RunEngine();
81 
85  void ShutDown() {
86  _bolLoop = false;
87  std::unique_lock<std::mutex> ul(_lock);
88  _condVar.notify_all();
89  }
90 
94  inline void SetInitialized() {
95  _bolIsInitialized = true;
96  }
97 
101  void WaitForShutDown() const;
102 
106  inline void SetShutdownComplete() {
107  _bolShutdownComplete = true;
108  }
109 
116  uint64_t registerTimer(uint64_t time, const boost::function<bool(void)> & func, bool looping, JobPriorities priority);
117 
121  void removeTimer(JobPriorities priority);
122 
126  bool removeTimerID(uint64_t id);
127 
131  uint64_t getTimeLeft(uint64_t id) const;
132 
136  uint64_t getCurrentTime() const {
137  return _rClock.getCurrentTime(0);
138  }
139 
143  void setCurrentTime(uint64_t time) {
144  _rClock.setCurrentTime(time);
145  }
146 
147  private:
148  SubSystemController * _subsystemController;
149  bool _bolIsInitialized;
150  bool _bolLoop;
151  bool _bolShutdownComplete;
152  std::vector<boost::function<void(void)>> _vptrOnAfterInitialize;
153  mutable std::mutex _lock;
154  mutable std::condition_variable _condVar;
155  std::mutex _runningLock;
156  std::condition_variable _runningConditionVariable;
157 
160 
164  void MainLoop();
165 
169  void Run();
170 
174  void Initialize() const;
175 
179  EngineCoreController(const EngineCoreController &) = delete;
180 
184  EngineCoreController & operator=(const EngineCoreController &) = delete;
185  };
186 
187 } /* namespace core */
188 } /* namespace i6e */
189 
190 #endif /* __I6ENGINE_CORE_ENGINECORECONTROLLER_H__ */
191 
void SetInitialized()
This method will tell the EngineController that the subsystems have been initialized.
void setCurrentTime(uint64_t time)
sets the current time (only at clients, time will be synchronized by server)
void SetShutdownComplete()
This method initializes the final shutdown of the main loop.
this class is used as an abstraction layer
void SetOnAfterInitializedCallback(const boost::function< void(void)> &ptrOnAfterInitialize)
This method will set the callback which will be called after initialization.
void ShutDown()
This method will stop the main loop and will start the shut down sequence.
#define ISIXE_CORE_API
uint64_t getCurrentTime() const
returns current application time in microseconds
This class is used as an abstraction layer.