Fawkes API  Fawkes Development Version
ExitSimulationInterface.cpp
1 
2 /***************************************************************************
3  * ExitSimulationInterface.cpp - Fawkes BlackBoard Interface - ExitSimulationInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2016 Gesche Gierse
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <interfaces/ExitSimulationInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <map>
29 #include <string>
30 #include <cstring>
31 #include <cstdlib>
32 
33 namespace fawkes {
34 
35 /** @class ExitSimulationInterface <interfaces/ExitSimulationInterface.h>
36  * ExitSimulationInterface Fawkes BlackBoard Interface.
37  * Exit simulation interface. Use this to exit fawkes and the simulation.
38  * @ingroup FawkesInterfaces
39  */
40 
41 
42 
43 /** Constructor */
44 ExitSimulationInterface::ExitSimulationInterface() : Interface()
45 {
46  data_size = sizeof(ExitSimulationInterface_data_t);
47  data_ptr = malloc(data_size);
48  data = (ExitSimulationInterface_data_t *)data_ptr;
49  data_ts = (interface_data_ts_t *)data_ptr;
50  memset(data_ptr, 0, data_size);
51  add_fieldinfo(IFT_BOOL, "shutdown_initiated", 1, &data->shutdown_initiated);
52  add_messageinfo("ExitSimulationMessage");
53  unsigned char tmp_hash[] = {0xbf, 0xa, 0x70, 0x60, 0x7f, 0xe8, 0xb2, 0xaf, 0x54, 0xce, 0x2d, 0xf7, 0xff, 0x79, 0x84, 0x40};
54  set_hash(tmp_hash);
55 }
56 
57 /** Destructor */
58 ExitSimulationInterface::~ExitSimulationInterface()
59 {
60  free(data_ptr);
61 }
62 /* Methods */
63 /** Get shutdown_initiated value.
64  * Whether a shutdown was initiated
65  * @return shutdown_initiated value
66  */
67 bool
69 {
70  return data->shutdown_initiated;
71 }
72 
73 /** Get maximum length of shutdown_initiated value.
74  * @return length of shutdown_initiated value, can be length of the array or number of
75  * maximum number of characters for a string
76  */
77 size_t
79 {
80  return 1;
81 }
82 
83 /** Set shutdown_initiated value.
84  * Whether a shutdown was initiated
85  * @param new_shutdown_initiated new shutdown_initiated value
86  */
87 void
88 ExitSimulationInterface::set_shutdown_initiated(const bool new_shutdown_initiated)
89 {
90  data->shutdown_initiated = new_shutdown_initiated;
91  data_changed = true;
92 }
93 
94 /* =========== message create =========== */
95 Message *
97 {
98  if ( strncmp("ExitSimulationMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
99  return new ExitSimulationMessage();
100  } else {
101  throw UnknownTypeException("The given type '%s' does not match any known "
102  "message type for this interface type.", type);
103  }
104 }
105 
106 
107 /** Copy values from other interface.
108  * @param other other interface to copy values from
109  */
110 void
112 {
113  const ExitSimulationInterface *oi = dynamic_cast<const ExitSimulationInterface *>(other);
114  if (oi == NULL) {
115  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
116  type(), other->type());
117  }
118  memcpy(data, oi->data, sizeof(ExitSimulationInterface_data_t));
119 }
120 
121 const char *
122 ExitSimulationInterface::enum_tostring(const char *enumtype, int val) const
123 {
124  throw UnknownTypeException("Unknown enum type %s", enumtype);
125 }
126 
127 /* =========== messages =========== */
128 /** @class ExitSimulationInterface::ExitSimulationMessage <interfaces/ExitSimulationInterface.h>
129  * ExitSimulationMessage Fawkes BlackBoard Interface Message.
130  *
131 
132  */
133 
134 
135 /** Constructor */
137 {
138  data_size = sizeof(ExitSimulationMessage_data_t);
139  data_ptr = malloc(data_size);
140  memset(data_ptr, 0, data_size);
141  data = (ExitSimulationMessage_data_t *)data_ptr;
143 }
144 
145 /** Destructor */
147 {
148  free(data_ptr);
149 }
150 
151 /** Copy constructor.
152  * @param m message to copy from
153  */
155 {
156  data_size = m->data_size;
157  data_ptr = malloc(data_size);
159  data = (ExitSimulationMessage_data_t *)data_ptr;
161 }
162 
163 /* Methods */
164 /** Clone this message.
165  * Produces a message of the same type as this message and copies the
166  * data to the new message.
167  * @return clone of this message
168  */
169 Message *
171 {
173 }
174 /** Check if message is valid and can be enqueued.
175  * @param message Message to check
176  * @return true if the message is valid, false otherwise.
177  */
178 bool
180 {
181  const ExitSimulationMessage *m0 = dynamic_cast<const ExitSimulationMessage *>(message);
182  if ( m0 != NULL ) {
183  return true;
184  }
185  return false;
186 }
187 
188 /// @cond INTERNALS
189 EXPORT_INTERFACE(ExitSimulationInterface)
190 /// @endcond
191 
192 
193 } // end namespace fawkes
fawkes::Interface::data_ptr
void * data_ptr
Definition: interface.h:223
fawkes::Message
Definition: message.h:40
fawkes::ExitSimulationInterface::is_shutdown_initiated
bool is_shutdown_initiated() const
Get shutdown_initiated value.
Definition: ExitSimulationInterface.cpp:72
fawkes::Message::data_ptr
void * data_ptr
Definition: message.h:124
fawkes::IFT_BOOL
boolean field
Definition: types.h:48
fawkes::ExitSimulationInterface::copy_values
virtual void copy_values(const Interface *other)
Copy values from other interface.
Definition: ExitSimulationInterface.cpp:115
fawkes::Message::data_ts
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:134
fawkes::ExitSimulationInterface::ExitSimulationMessage::~ExitSimulationMessage
~ExitSimulationMessage()
Destructor.
Definition: ExitSimulationInterface.cpp:150
fawkes::ExitSimulationInterface::ExitSimulationMessage::clone
virtual Message * clone() const
Clone this message.
Definition: ExitSimulationInterface.cpp:174
fawkes::Interface::type
const char * type() const
Get type of interface.
Definition: interface.cpp:643
fawkes::Interface::data_ts
interface_data_ts_t * data_ts
Definition: interface.h:227
fawkes::Message::message_data_ts_t
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:129
fawkes::ExitSimulationInterface::enum_tostring
virtual const char * enum_tostring(const char *enumtype, int val) const
Definition: ExitSimulationInterface.cpp:126
fawkes::TypeMismatchException
Definition: software.h:47
fawkes::Interface::data_changed
bool data_changed
Definition: interface.h:225
fawkes::UnknownTypeException
Definition: software.h:53
fawkes::Interface::Interface
Interface()
Constructor.
Definition: interface.cpp:236
fawkes
fawkes::Interface::set_hash
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:319
fawkes::Message::data_size
unsigned int data_size
Definition: message.h:125
fawkes::ExitSimulationInterface::create_message
virtual Message * create_message(const char *type) const
Definition: ExitSimulationInterface.cpp:100
fawkes::Message::add_fieldinfo
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition: message.cpp:404
fawkes::Interface::data_size
unsigned int data_size
Definition: interface.h:224
fawkes::ExitSimulationInterface::message_valid
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Definition: ExitSimulationInterface.cpp:183
fawkes::ExitSimulationInterface::ExitSimulationMessage::ExitSimulationMessage
ExitSimulationMessage()
Constructor.
Definition: ExitSimulationInterface.cpp:140
fawkes::ExitSimulationInterface::maxlenof_shutdown_initiated
size_t maxlenof_shutdown_initiated() const
Get maximum length of shutdown_initiated value.
Definition: ExitSimulationInterface.cpp:82
fawkes::Interface::add_messageinfo
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:378
fawkes::ExitSimulationInterface::ExitSimulationMessage
Definition: ExitSimulationInterface.h:62
fawkes::ExitSimulationInterface::set_shutdown_initiated
void set_shutdown_initiated(const bool new_shutdown_initiated)
Set shutdown_initiated value.
Definition: ExitSimulationInterface.cpp:92