NAP
service.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "numeric.h"
9 
10 // External Includes
11 #include <utility/dllexport.h>
12 #include <utility/errorstate.h>
13 #include <rtti/object.h>
14 #include <rtti/factory.h>
15 #include <set>
16 
17 namespace nap
18 {
19 
20  // Forward Declares
21  class Core;
22  class Module;
23  class ServiceObjectGraphItem;
24 
28  class NAPAPI ServiceConfiguration : public rtti::Object
29  {
30  RTTI_ENABLE(rtti::Object)
31  public:
35  virtual rtti::TypeInfo getServiceType() const = 0;
36  };
37 
38 
52  class NAPAPI Service
53  {
54  RTTI_ENABLE()
55  friend class Core;
56  friend class ServiceObjectGraphItem;
57  public:
58  Service(ServiceConfiguration* configuration);
59 
60  // Virtual destructor because of virtual methods!
61  virtual ~Service();
62 
66  Core& getCore();
67 
71  const Core& getCore() const;
72 
76  std::string getTypeName() const;
77 
81  const Module& getModule() const;
82 
86  Service(Service&) = delete;
87 
91  Service& operator=(const Service&) = delete;
92 
96  Service(Service&&) = delete;
97 
101  Service& operator=(Service&&) = delete;
102 
103  protected:
108  virtual void registerObjectCreators(rtti::Factory& factory) { }
109 
116  virtual void getDependentServices(std::vector<rtti::TypeInfo>& dependencies) { }
117 
122  virtual void created() {}
123 
130  virtual bool init(utility::ErrorState& error) { return true; }
131 
138  virtual void preUpdate(double deltaTime) { }
139 
146  virtual void update(double deltaTime) { }
147 
153  virtual void postUpdate(double deltaTime) { }
154 
162  virtual void preShutdown() { }
163 
169  virtual void shutdown() { }
170 
174  virtual void preResourcesLoaded() { }
175 
179  virtual void postResourcesLoaded() { }
180 
185  template<typename SERVICE_CONFIG>
186  SERVICE_CONFIG* getConfiguration()
187  {
188  return rtti_cast<SERVICE_CONFIG>(mConfiguration);
189  }
190 
195  template<typename SERVICE_CONFIG>
196  const SERVICE_CONFIG* getConfiguration() const
197  {
198  return rtti_cast<SERVICE_CONFIG>(mConfiguration);
199  }
200 
207  std::string getIniFilePath() const;
208 
216  std::string getIniFilePath(const std::string& appendix) const;
217 
218  private:
219  // this variable will be set by the core when the service is added
220  Core* mCore = nullptr;
221  ServiceConfiguration* mConfiguration;
222  };
223 }
nap::Service::getConfiguration
const SERVICE_CONFIG * getConfiguration() const
Definition: service.h:196
nap::Service::getDependentServices
virtual void getDependentServices(std::vector< rtti::TypeInfo > &dependencies)
Definition: service.h:116
nap::Service::shutdown
virtual void shutdown()
Definition: service.h:169
nap::ServiceObjectGraphItem
Definition: serviceobjectgraphitem.h:15
nap::rtti::Object
Definition: object.h:30
nap::Service::preResourcesLoaded
virtual void preResourcesLoaded()
Definition: service.h:174
nap::utility::ErrorState
Definition: errorstate.h:19
nap::Service::postResourcesLoaded
virtual void postResourcesLoaded()
Definition: service.h:179
nap::ServiceConfiguration
Definition: service.h:28
nap::Service::created
virtual void created()
Definition: service.h:122
nap::Core
Definition: core.h:82
nap::Service::postUpdate
virtual void postUpdate(double deltaTime)
Definition: service.h:153
nap::Service::update
virtual void update(double deltaTime)
Definition: service.h:146
nap::Service
Definition: templateservice.h:8
nap::Service::preShutdown
virtual void preShutdown()
Definition: service.h:162
nap::Service::getConfiguration
SERVICE_CONFIG * getConfiguration()
Definition: service.h:186
nap::rtti::Factory
Definition: factory.h:78
nap
Definition: templateapp.h:17
nap::Service::init
virtual bool init(utility::ErrorState &error)
Definition: service.h:130
nap::Service::preUpdate
virtual void preUpdate(double deltaTime)
Definition: service.h:138
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140
nap::Module
Definition: modulemanager.h:28