Fawkes API  Fawkes Development Version
clingo_manager_inifin.cpp
1 /***************************************************************************
2  * clingo_manager_inifin.cpp - Fawkes ClingoManagerAspect initializer/finalizer
3  *
4  * Created: Sat Oct 29 11:30:07 2016
5  * Copyright 2016 Björn Schäpers
6  * 2018 Tim Niemueller [www.niemueller.org]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version. A runtime exception applies to
13  * this software (see LICENSE.GPL_WRE file mentioned below for details).
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21  */
22 
23 #include <plugins/asp/aspect/clingo_manager.h>
24 #include <plugins/asp/aspect/clingo_manager_inifin.h>
25 
26 namespace fawkes {
27 
28 /**
29  * @class ClingoManagerAspectIniFin <plugins/asp/aspect/clingo_manager_inifin.h>
30  * ClingoManagerAspect initializer/finalizer.
31  * @author Björn Schäpers
32  *
33  * @property ClingoManagerAspectIniFin::clingo_ctrl_mgr_
34  * @brief The Clingo control manager.
35  */
36 
37 /** Constructor. */
38 ClingoManagerAspectIniFin::ClingoManagerAspectIniFin(void) : AspectIniFin("ClingoManagerAspect")
39 {
40 }
41 
42 /** Destructor. */
44 {
45 }
46 
47 void
49 {
50  auto clingo_thread = dynamic_cast<ClingoManagerAspect *>(thread);
51  if (clingo_thread == nullptr) {
52  throw CannotInitializeThreadException("Thread '%s' claims to have the ClingoManagerAspect, "
53  "but RTTI says it has not. ",
54  thread->name());
55  }
56 
57  clingo_thread->init_ClingoManagerAspect(clingo_ctrl_mgr_);
58 }
59 
60 void
62 {
63  auto clingo_thread = dynamic_cast<ClingoManagerAspect *>(thread);
64  if (clingo_thread == nullptr) {
65  throw CannotFinalizeThreadException("Thread '%s' claims to have the ClingoManagerAspect, "
66  "but RTTI says it has not. ",
67  thread->name());
68  }
69 
70  clingo_thread->finalize_ClingoManagerAspect();
71 }
72 
73 /** Set Clingo control manger.
74  * @param[in] clingo_ctrl_mgr Clingo control manager
75  */
76 void
77 ClingoManagerAspectIniFin::set_control_manager(LockPtr<ClingoControlManager> &clingo_ctrl_mgr)
78 {
79  clingo_ctrl_mgr_ = clingo_ctrl_mgr;
80 }
81 
82 } // end namespace fawkes
fawkes::CannotInitializeThreadException
Definition: thread_initializer.h:39
fawkes::Thread::name
const char * name() const
Definition: thread.h:100
fawkes::ClingoManagerAspectIniFin::ClingoManagerAspectIniFin
ClingoManagerAspectIniFin(void)
Constructor.
Definition: clingo_manager_inifin.cpp:44
fawkes::ClingoManagerAspectIniFin::~ClingoManagerAspectIniFin
~ClingoManagerAspectIniFin(void)
Destructor.
Definition: clingo_manager_inifin.cpp:49
fawkes::ClingoManagerAspectIniFin::set_control_manager
void set_control_manager(LockPtr< ClingoControlManager > &clingo_ctrl_mgr)
Set Clingo control manger.
Definition: clingo_manager_inifin.cpp:83
fawkes::ClingoManagerAspect
Definition: clingo_manager.h:38
fawkes
fawkes::ClingoManagerAspectIniFin::init
void init(Thread *thread) override
Definition: clingo_manager_inifin.cpp:54
fawkes::Thread
Definition: thread.h:45
fawkes::ClingoManagerAspectIniFin::finalize
void finalize(Thread *thread) override
Definition: clingo_manager_inifin.cpp:67