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));
123  data_changed = true;
124 }
125 
126 /* =========== message create =========== */
127 Message *
129 {
130  if ( strncmp("ConnectionMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
131  return new ConnectionMessage();
132  } else {
133  throw UnknownTypeException("The given type '%s' does not match any known "
134  "message type for this interface type.", type);
135  }
136 }
137 
138 
139 /** Copy values from other interface.
140  * @param other other interface to copy values from
141  */
142 void
144 {
145  const EclipseDebuggerInterface *oi = dynamic_cast<const EclipseDebuggerInterface *>(other);
146  if (oi == NULL) {
147  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
148  type(), other->type());
149  }
150  memcpy(data, oi->data, sizeof(EclipseDebuggerInterface_data_t));
151 }
152 
153 const char *
154 EclipseDebuggerInterface::enum_tostring(const char *enumtype, int val) const
155 {
156  throw UnknownTypeException("Unknown enum type %s", enumtype);
157 }
158 
159 /* =========== messages =========== */
160 /** @class EclipseDebuggerInterface::ConnectionMessage <interfaces/EclipseDebuggerInterface.h>
161  * ConnectionMessage Fawkes BlackBoard Interface Message.
162  *
163 
164  */
165 
166 
167 /** Constructor */
169 {
170  data_size = sizeof(ConnectionMessage_data_t);
171  data_ptr = malloc(data_size);
172  memset(data_ptr, 0, data_size);
173  data = (ConnectionMessage_data_t *)data_ptr;
175 }
176 
177 /** Destructor */
179 {
180  free(data_ptr);
181 }
182 
183 /** Copy constructor.
184  * @param m message to copy from
185  */
187 {
188  data_size = m->data_size;
189  data_ptr = malloc(data_size);
190  memcpy(data_ptr, m->data_ptr, data_size);
191  data = (ConnectionMessage_data_t *)data_ptr;
193 }
194 
195 /* Methods */
196 /** Clone this message.
197  * Produces a message of the same type as this message and copies the
198  * data to the new message.
199  * @return clone of this message
200  */
201 Message *
203 {
205 }
206 /** Check if message is valid and can be enqueued.
207  * @param message Message to check
208  * @return true if the message is valid, false otherwise.
209  */
210 bool
212 {
213  const ConnectionMessage *m0 = dynamic_cast<const ConnectionMessage *>(message);
214  if ( m0 != NULL ) {
215  return true;
216  }
217  return false;
218 }
219 
220 /// @cond INTERNALS
221 EXPORT_INTERFACE(EclipseDebuggerInterface)
222 /// @endcond
223 
224 
225 } // end namespace fawkes
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:124
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:314
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! This leans on time...
Definition: message.h:129
16 bit unsigned integer field
Definition: types.h:40
string field
Definition: types.h:47
virtual void copy_values(const Interface *other)
Copy values from other interface.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
void set_host(const char *new_host)
Set host value.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:133
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:125
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:373
bool data_changed
Indicator if data has changed.
Definition: interface.h:222
virtual Message * clone() const
Clone this message.
const char * type() const
Get type of interface.
Definition: interface.cpp:651
EclipseDebuggerInterface Fawkes BlackBoard Interface.
uint16_t port() const
Get port value.
char * host() const
Get host 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:436
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.
const char * type() const
Get message type.
Definition: message.cpp:378
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.