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->port = new_port;
92  data_changed = true;
93 }
94 
95 /** Get host value.
96  * Host where to connect to
97  * @return host value
98  */
99 char *
101 {
102  return data->host;
103 }
104 
105 /** Get maximum length of host value.
106  * @return length of host value, can be length of the array or number of
107  * maximum number of characters for a string
108  */
109 size_t
111 {
112  return 100;
113 }
114 
115 /** Set host value.
116  * Host where to connect to
117  * @param new_host new host value
118  */
119 void
121 {
122  strncpy(data->host, new_host, sizeof(data->host)-1);
123  data->host[sizeof(data->host)-1] = 0;
124  data_changed = true;
125 }
126 
127 /* =========== message create =========== */
128 Message *
130 {
131  if ( strncmp("ConnectionMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_) == 0 ) {
132  return new ConnectionMessage();
133  } else {
134  throw UnknownTypeException("The given type '%s' does not match any known "
135  "message type for this interface type.", type);
136  }
137 }
138 
139 
140 /** Copy values from other interface.
141  * @param other other interface to copy values from
142  */
143 void
145 {
146  const EclipseDebuggerInterface *oi = dynamic_cast<const EclipseDebuggerInterface *>(other);
147  if (oi == NULL) {
148  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
149  type(), other->type());
150  }
151  memcpy(data, oi->data, sizeof(EclipseDebuggerInterface_data_t));
152 }
153 
154 const char *
155 EclipseDebuggerInterface::enum_tostring(const char *enumtype, int val) const
156 {
157  throw UnknownTypeException("Unknown enum type %s", enumtype);
158 }
159 
160 /* =========== messages =========== */
161 /** @class EclipseDebuggerInterface::ConnectionMessage <interfaces/EclipseDebuggerInterface.h>
162  * ConnectionMessage Fawkes BlackBoard Interface Message.
163  *
164 
165  */
166 
167 
168 /** Constructor */
170 {
171  data_size = sizeof(ConnectionMessage_data_t);
172  data_ptr = malloc(data_size);
173  memset(data_ptr, 0, data_size);
174  data = (ConnectionMessage_data_t *)data_ptr;
176 }
177 
178 /** Destructor */
180 {
181  free(data_ptr);
182 }
183 
184 /** Copy constructor.
185  * @param m message to copy from
186  */
188 {
189  data_size = m->data_size;
190  data_ptr = malloc(data_size);
191  memcpy(data_ptr, m->data_ptr, data_size);
192  data = (ConnectionMessage_data_t *)data_ptr;
194 }
195 
196 /* Methods */
197 /** Clone this message.
198  * Produces a message of the same type as this message and copies the
199  * data to the new message.
200  * @return clone of this message
201  */
202 Message *
204 {
206 }
207 /** Check if message is valid and can be enqueued.
208  * @param message Message to check
209  * @return true if the message is valid, false otherwise.
210  */
211 bool
213 {
214  const ConnectionMessage *m0 = dynamic_cast<const ConnectionMessage *>(message);
215  if ( m0 != NULL ) {
216  return true;
217  }
218  return false;
219 }
220 
221 /// @cond INTERNALS
222 EXPORT_INTERFACE(EclipseDebuggerInterface)
223 /// @endcond
224 
225 
226 } // end namespace fawkes
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:125
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:41
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:316
Fawkes library namespace.
size_t maxlenof_host() const
Get maximum length of host value.
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:130
16 bit unsigned integer field
Definition: types.h:41
string field
Definition: types.h:48
virtual void copy_values(const Interface *other)
Copy values from other interface.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:78
void set_host(const char *new_host)
Set host value.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:135
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:126
size_t maxlenof_port() const
Get maximum length of port value.
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:375
bool data_changed
Indicator if data has changed.
Definition: interface.h:226
virtual Message * clone() const
Clone this message.
const char * type() const
Get type of interface.
Definition: interface.cpp:640
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:224
EclipseDebuggerInterface Fawkes BlackBoard Interface.
uint16_t port() const
Get port value.
virtual Message * create_message(const char *type) const
Create message based on type name.
ConnectionMessage Fawkes BlackBoard Interface Message.
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:410
void set_port(const uint16_t new_port)
Set port value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.