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
33namespace 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 */
44ExitSimulationInterface::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 */
58ExitSimulationInterface::~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 */
67bool
68ExitSimulationInterface::is_shutdown_initiated() const
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 */
77size_t
78ExitSimulationInterface::maxlenof_shutdown_initiated() const
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 */
87void
88ExitSimulationInterface::set_shutdown_initiated(const bool new_shutdown_initiated)
89{
90 set_field(data->shutdown_initiated, new_shutdown_initiated);
91}
92
93/* =========== message create =========== */
94Message *
95ExitSimulationInterface::create_message(const char *type) const
96{
97 if ( strncmp("ExitSimulationMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
98 return new ExitSimulationMessage();
99 } else {
100 throw UnknownTypeException("The given type '%s' does not match any known "
101 "message type for this interface type.", type);
102 }
103}
104
105
106/** Copy values from other interface.
107 * @param other other interface to copy values from
108 */
109void
110ExitSimulationInterface::copy_values(const Interface *other)
111{
112 const ExitSimulationInterface *oi = dynamic_cast<const ExitSimulationInterface *>(other);
113 if (oi == NULL) {
114 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
115 type(), other->type());
116 }
117 memcpy(data, oi->data, sizeof(ExitSimulationInterface_data_t));
118}
119
120const char *
121ExitSimulationInterface::enum_tostring(const char *enumtype, int val) const
122{
123 throw UnknownTypeException("Unknown enum type %s", enumtype);
124}
125
126/* =========== messages =========== */
127/** @class ExitSimulationInterface::ExitSimulationMessage <interfaces/ExitSimulationInterface.h>
128 * ExitSimulationMessage Fawkes BlackBoard Interface Message.
129 *
130
131 */
132
133
134/** Constructor */
135ExitSimulationInterface::ExitSimulationMessage::ExitSimulationMessage() : Message("ExitSimulationMessage")
136{
137 data_size = sizeof(ExitSimulationMessage_data_t);
138 data_ptr = malloc(data_size);
139 memset(data_ptr, 0, data_size);
140 data = (ExitSimulationMessage_data_t *)data_ptr;
142}
143
144/** Destructor */
146{
147 free(data_ptr);
148}
149
150/** Copy constructor.
151 * @param m message to copy from
152 */
154{
155 data_size = m->data_size;
156 data_ptr = malloc(data_size);
157 memcpy(data_ptr, m->data_ptr, data_size);
158 data = (ExitSimulationMessage_data_t *)data_ptr;
160}
161
162/* Methods */
163/** Clone this message.
164 * Produces a message of the same type as this message and copies the
165 * data to the new message.
166 * @return clone of this message
167 */
168Message *
170{
172}
173/** Check if message is valid and can be enqueued.
174 * @param message Message to check
175 * @return true if the message is valid, false otherwise.
176 */
177bool
179{
180 const ExitSimulationMessage *m0 = dynamic_cast<const ExitSimulationMessage *>(message);
181 if ( m0 != NULL ) {
182 return true;
183 }
184 return false;
185}
186
187/// @cond INTERNALS
188EXPORT_INTERFACE(ExitSimulationInterface)
189/// @endcond
190
191
192} // end namespace fawkes
ExitSimulationMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
ExitSimulationInterface Fawkes BlackBoard Interface.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:244
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:146
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:156
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:147
Fawkes library namespace.
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:152