Fawkes API  Fawkes Development Version
robot_memory_inifin.cpp
1 /***************************************************************************
2  * robot_memory_inifin.cpp - RobotMemoryAspect initializer/finalizer
3  *
4  *
5  * Created: Aug 23, 2016 1:28:04 PM 2016
6  * Copyright 2016 Frederik Zwilling
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.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 #include "robot_memory_inifin.h"
22 
23 namespace fawkes {
24 
25 /** @class RobotMemoryIniFin robot_memory_inifin.cpp
26  * RobotMemoryAspect initializer/finalizer.
27  * This initializer/finalizer will provide the RobotMemory to
28  * threads with the RobotMemoryAspect.
29  * @author Frederik Zwilling
30  */
31 
32 RobotMemoryIniFin::RobotMemoryIniFin() : AspectIniFin("RobotMemoryAspect")
33 {
34 }
35 
36 /** Initialize
37  * @param thread thread
38  */
39 void
41 {
42  RobotMemoryAspect *robot_memory_thread;
43  robot_memory_thread = dynamic_cast<RobotMemoryAspect *>(thread);
44  if (robot_memory_thread == NULL) {
45  throw CannotInitializeThreadException("Thread '%s' claims to have the "
46  "RobotMemoryAspect, but RTTI says it "
47  "has not. ",
48  thread->name());
49  }
50  if (!robot_memory_) {
51  throw CannotInitializeThreadException("robot_memory object has not been set.");
52  }
53 
54  robot_memory_thread->init_RobotMemoryAspect(robot_memory_);
55 }
56 
57 /** Finilize
58  * @param thread thread
59  */
60 void
62 {
63  RobotMemoryAspect *robot_memory_thread;
64  robot_memory_thread = dynamic_cast<RobotMemoryAspect *>(thread);
65  if (robot_memory_thread == NULL) {
66  throw CannotInitializeThreadException("Thread '%s' claims to have the "
67  "RobotMemoryAspect, but RTTI says it "
68  "has not. ",
69  thread->name());
70  }
71  robot_memory_thread->finalize_RobotMemoryAspect();
72 }
73 
74 /**
75  * Set the reference to the robot memory for the aspect
76  * @param robot_memory Robot Memory
77  */
78 void
80 {
81  robot_memory_ = robot_memory;
82 }
83 
84 } /* namespace fawkes */
fawkes::RobotMemoryIniFin::finalize
virtual void finalize(Thread *thread)
Finilize.
Definition: robot_memory_inifin.cpp:61
RobotMemory
Access to the robot memory based on mongodb.
Definition: robot_memory.h:47
fawkes::CannotInitializeThreadException
Thread cannot be initialized.
Definition: thread_initializer.h:34
fawkes::Thread::name
const char * name() const
Get name of thread.
Definition: thread.h:100
fawkes::RobotMemoryIniFin::set_robot_memory
void set_robot_memory(RobotMemory *robot_memory)
Set the reference to the robot memory for the aspect.
Definition: robot_memory_inifin.cpp:79
fawkes
Fawkes library namespace.
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
fawkes::RobotMemoryAspect
Thread aspect to get access to a the RobotMemory.
Definition: robot_memory_aspect.h:34
fawkes::RobotMemoryIniFin::init
virtual void init(Thread *thread)
Initialize.
Definition: robot_memory_inifin.cpp:40