Fawkes API  Fawkes Development Version
EclipseDebuggerInterface.cpp
1 
2 /***************************************************************************
3  * EclipseDebuggerInterface.cpp - Fawkes BlackBoard Interface - EclipseDebuggerInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2012 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/EclipseDebuggerInterface.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 EclipseDebuggerInterface <interfaces/EclipseDebuggerInterface.h>
36  * EclipseDebuggerInterface Fawkes BlackBoard Interface.
37  * Interface to enable connection between tktools and readylog agent.
38  * @ingroup FawkesInterfaces
39  */
40 
41 
42 
43 /** Constructor */
44 EclipseDebuggerInterface::EclipseDebuggerInterface() : Interface()
45 {
46  data_size = sizeof(EclipseDebuggerInterface_data_t);
47  data_ptr = malloc(data_size);
48  data = (EclipseDebuggerInterface_data_t *)data_ptr;
49  data_ts = (interface_data_ts_t *)data_ptr;
50  memset(data_ptr, 0, data_size);
51  add_fieldinfo(IFT_UINT16, "port", 1, &data->port);
52  add_fieldinfo(IFT_STRING, "host", 100, data->host);
53  add_messageinfo("ConnectionMessage");
54  unsigned char tmp_hash[] = {0xc0, 0x8f, 0x5b, 0xb4, 0xcd, 0xf, 0xe0, 0x88, 0xfd, 0x5d, 0xe4, 0xfe, 0x1, 0xb, 0xa2, 0x83};
55  set_hash(tmp_hash);
56 }
57 
58 /** Destructor */
59 EclipseDebuggerInterface::~EclipseDebuggerInterface()
60 {
61  free(data_ptr);
62 }
63 /* Methods */
64 /** Get port value.
65  * Port where to connect to
66  * @return port value
67  */
68 uint16_t
70 {
71  return data->port;
72 }
73 
74 /** Get maximum length of port value.
75  * @return length of port value, can be length of the array or number of
76  * maximum number of characters for a string
77  */
78 size_t
80 {
81  return 1;
82 }
83 
84 /** Set port value.
85  * Port where to connect to
86  * @param new_port new port value
87  */
88 void
89 EclipseDebuggerInterface::set_port(const uint16_t new_port)
90 {
91  data_changed |= change_field(data->port, new_port);
92 }
93 
94 /** Get host value.
95  * Host where to connect to
96  * @return host value
97  */
98 char *
100 {
101  return data->host;
102 }
103 
104 /** Get maximum length of host value.
105  * @return length of host value, can be length of the array or number of
106  * maximum number of characters for a string
107  */
108 size_t
110 {
111  return 100;
112 }
113 
114 /** Set host value.
115  * Host where to connect to
116  * @param new_host new host value
117  */
118 void
120 {
121  data_changed |= change_field(data->host, new_host);
122 }
123 
124 /* =========== message create =========== */
125 Message *
127 {
128  if ( strncmp("ConnectionMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
129  return new ConnectionMessage();
130  } else {
131  throw UnknownTypeException("The given type '%s' does not match any known "
132  "message type for this interface type.", type);
133  }
134 }
135 
136 
137 /** Copy values from other interface.
138  * @param other other interface to copy values from
139  */
140 void
142 {
143  const EclipseDebuggerInterface *oi = dynamic_cast<const EclipseDebuggerInterface *>(other);
144  if (oi == NULL) {
145  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
146  type(), other->type());
147  }
148  memcpy(data, oi->data, sizeof(EclipseDebuggerInterface_data_t));
149 }
150 
151 const char *
152 EclipseDebuggerInterface::enum_tostring(const char *enumtype, int val) const
153 {
154  throw UnknownTypeException("Unknown enum type %s", enumtype);
155 }
156 
157 /* =========== messages =========== */
158 /** @class EclipseDebuggerInterface::ConnectionMessage <interfaces/EclipseDebuggerInterface.h>
159  * ConnectionMessage Fawkes BlackBoard Interface Message.
160  *
161 
162  */
163 
164 
165 /** Constructor */
167 {
168  data_size = sizeof(ConnectionMessage_data_t);
169  data_ptr = malloc(data_size);
170  memset(data_ptr, 0, data_size);
171  data = (ConnectionMessage_data_t *)data_ptr;
173 }
174 
175 /** Destructor */
177 {
178  free(data_ptr);
179 }
180 
181 /** Copy constructor.
182  * @param m message to copy from
183  */
185 {
186  data_size = m->data_size;
187  data_ptr = malloc(data_size);
188  memcpy(data_ptr, m->data_ptr, data_size);
189  data = (ConnectionMessage_data_t *)data_ptr;
191 }
192 
193 /* Methods */
194 /** Clone this message.
195  * Produces a message of the same type as this message and copies the
196  * data to the new message.
197  * @return clone of this message
198  */
199 Message *
201 {
203 }
204 /** Check if message is valid and can be enqueued.
205  * @param message Message to check
206  * @return true if the message is valid, false otherwise.
207  */
208 bool
210 {
211  const ConnectionMessage *m0 = dynamic_cast<const ConnectionMessage *>(message);
212  if ( m0 != NULL ) {
213  return true;
214  }
215  return false;
216 }
217 
218 /// @cond INTERNALS
219 EXPORT_INTERFACE(EclipseDebuggerInterface)
220 /// @endcond
221 
222 
223 } // end namespace fawkes
fawkes::Interface::data_ptr
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:224
fawkes::EclipseDebuggerInterface::copy_values
virtual void copy_values(const Interface *other)
Copy values from other interface.
Definition: EclipseDebuggerInterface.cpp:141
fawkes::EclipseDebuggerInterface::maxlenof_host
size_t maxlenof_host() const
Get maximum length of host value.
Definition: EclipseDebuggerInterface.cpp:109
fawkes::Message
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:45
fawkes::Message::data_ptr
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:128
fawkes::Message::data_ts
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:138
fawkes::IFT_UINT16
@ IFT_UINT16
16 bit unsigned integer field
Definition: types.h:41
fawkes::Interface::type
const char * type() const
Get type of interface.
Definition: interface.cpp:643
fawkes::EclipseDebuggerInterface::ConnectionMessage::ConnectionMessage
ConnectionMessage()
Constructor.
Definition: EclipseDebuggerInterface.cpp:166
fawkes::EclipseDebuggerInterface::maxlenof_port
size_t maxlenof_port() const
Get maximum length of port value.
Definition: EclipseDebuggerInterface.cpp:79
fawkes::EclipseDebuggerInterface::ConnectionMessage::~ConnectionMessage
~ConnectionMessage()
Destructor.
Definition: EclipseDebuggerInterface.cpp:176
fawkes::EclipseDebuggerInterface::port
uint16_t port() const
Get port value.
Definition: EclipseDebuggerInterface.cpp:69
fawkes::EclipseDebuggerInterface::set_host
void set_host(const char *new_host)
Set host value.
Definition: EclipseDebuggerInterface.cpp:119
fawkes::Message::message_data_ts_t
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:134
fawkes::TypeMismatchException
Type mismatch.
Definition: software.h:44
fawkes::Interface::data_changed
bool data_changed
Indicator if data has changed.
Definition: interface.h:226
fawkes::UnknownTypeException
Unknown type.
Definition: software.h:50
fawkes
Fawkes library namespace.
fawkes::Interface::set_hash
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:316
fawkes::Message::data_size
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:129
fawkes::EclipseDebuggerInterface
EclipseDebuggerInterface Fawkes BlackBoard Interface.
Definition: EclipseDebuggerInterface.h:34
fawkes::Interface
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
fawkes::EclipseDebuggerInterface::host
char * host() const
Get host value.
Definition: EclipseDebuggerInterface.cpp:99
fawkes::EclipseDebuggerInterface::set_port
void set_port(const uint16_t new_port)
Set port value.
Definition: EclipseDebuggerInterface.cpp:89
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:400
fawkes::EclipseDebuggerInterface::create_message
virtual Message * create_message(const char *type) const
Create message based on type name.
Definition: EclipseDebuggerInterface.cpp:126
fawkes::EclipseDebuggerInterface::message_valid
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Definition: EclipseDebuggerInterface.cpp:209
fawkes::IFT_STRING
@ IFT_STRING
string field
Definition: types.h:48
fawkes::EclipseDebuggerInterface::ConnectionMessage
ConnectionMessage Fawkes BlackBoard Interface Message.
Definition: EclipseDebuggerInterface.h:55
fawkes::Interface::add_messageinfo
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:375
fawkes::EclipseDebuggerInterface::ConnectionMessage::clone
virtual Message * clone() const
Clone this message.
Definition: EclipseDebuggerInterface.cpp:200
fawkes::EclipseDebuggerInterface::enum_tostring
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
Definition: EclipseDebuggerInterface.cpp:152
fawkes::change_field
bool change_field(FieldT &field, const DataT &value)
Set a field and return whether it changed.
Definition: message.h:167