Leosac  0.7.0
OpenSourceAccessControl
CoreUtils.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "CoreUtils.hpp"
21 #include "kernel.hpp"
22 #include "tools/db/db_fwd.hpp"
23 #include "tools/log.hpp"
24 
26  Leosac::ConfigCheckerPtr cfgcheck, bool strict_mode)
27  : kptr_(kptr)
28  , scheduler_(sched)
29  , config_checker_(cfgcheck)
30  , strict_mode_(strict_mode)
31 {
32 }
33 
35  : kptr_(nullptr)
36  , strict_mode_(false)
37 {
38 }
39 
41 {
42  ASSERT_LOG(scheduler_, "No scheduler object in CoreUtils.");
43  return *scheduler_;
44 }
45 
47 {
48  ASSERT_LOG(config_checker_, "No ConfigChecker object in CoreUtils.");
49  return *config_checker_;
50 }
51 
53 {
54  return kernel().database();
55 }
56 
58 {
59  return strict_mode_;
60 }
61 
63 {
64  ASSERT_LOG(kptr_, "Kernel pointer is NULL in CoreUtils");
65  return *kptr_;
66 }
67 
69 {
70  return Leosac::CoreAPI(kernel());
71 }
72 
74 {
75  return kernel().zmqpp_context();
76 }
77 
79 {
80  return kernel().service_registry();
81 }
A class that manages services.
Scheduler & scheduler()
Definition: CoreUtils.cpp:40
CoreAPI is a class for interact with Leosac&#39;s core.
Definition: CoreAPI.hpp:47
DBPtr database()
Retrieve a pointer to the database, if any.
Definition: kernel.cpp:518
SchedulerPtr scheduler_
Definition: CoreUtils.hpp:77
ServiceRegistry & service_registry()
Retrieve a reference to the service registry.
Definition: kernel.cpp:617
Core of Leosac.
Definition: kernel.hpp:73
This class is here to help check the validity of the configuration.
bool is_strict() const
Are we running in strict mode ?
Definition: CoreUtils.cpp:57
ConfigCheckerPtr config_checker_
Definition: CoreUtils.hpp:78
zmqpp::context & zmqpp_context()
Definition: CoreUtils.cpp:73
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:221
std::shared_ptr< Scheduler > SchedulerPtr
Definition: LeosacFwd.hpp:31
CoreAPI core_api()
Instantiate a new, ready to use, CoreAPI object.
Definition: CoreUtils.cpp:68
Kernel & kernel()
Definition: CoreUtils.cpp:62
std::shared_ptr< ConfigChecker > ConfigCheckerPtr
Definition: LeosacFwd.hpp:32
This is a scheduler that is used internally to schedule asynchronous / long running tasks...
Definition: Scheduler.hpp:47
ConfigChecker & config_checker()
Definition: CoreUtils.cpp:46
ServiceRegistry & service_registry()
Definition: CoreUtils.cpp:78
std::shared_ptr< odb::database > DBPtr
Definition: db_fwd.hpp:31
zmqpp::context & zmqpp_context()
Returns a reference to the zmqpp context created for the application.
Definition: kernel.cpp:431