Fawkes API
Fawkes Development Version
list_message.cpp
1
2
/***************************************************************************
3
* plugin_list_messages.cpp - Fawkes Plugin List Message
4
*
5
* Created: Sat Jun 02 01:25:48 2007
6
* Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
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 <plugin/net/list_message.h>
25
26
#include <netcomm/utils/dynamic_buffer.h>
27
#include <netcomm/fawkes/component_ids.h>
28
#include <core/exceptions/software.h>
29
#include <utils/misc/strndup.h>
30
#include <cstdlib>
31
#include <cstring>
32
33
namespace
fawkes
{
34
35
/** @class PluginListMessage <plugin/net/list_message.h>
36
* Plugin list message.
37
* A complex dynamic message with an arbitrary number of plugins. Uses
38
* DynamicBuffer for the internal list of plugins and thus the buffer is
39
* limited to 64 KB.
40
*
41
* @author Tim Niemueller
42
*/
43
44
/** Constructor. */
45
PluginListMessage::PluginListMessage
()
46
{
47
plugin_list =
new
DynamicBuffer
(&(msg.
plugin_list
));
48
}
49
50
51
/** Message content constructor.
52
* This constructor is meant to be used with FawkesNetworkMessage::msgc().
53
* @param component_id component ID
54
* @param msg_id message ID
55
* @param payload message payload
56
* @param payload_size total payload size
57
*/
58
PluginListMessage::PluginListMessage
(
unsigned
int
component_id,
59
unsigned
int
msg_id,
60
void
*
payload
,
size_t
payload_size
)
61
{
62
if
( component_id != FAWKES_CID_PLUGINMANAGER ) {
63
throw
TypeMismatchException
(
"PluginListMessage: invalid component ID"
);
64
}
65
plugin_list_msg_t
*tmsg = (
plugin_list_msg_t
*)payload;
66
void
*plugin_list_payload = (
void
*)((
size_t
)payload +
sizeof
(msg));
67
plugin_list =
new
DynamicBuffer
(&(tmsg->
plugin_list
), plugin_list_payload,
68
payload_size -
sizeof
(msg));
69
}
70
71
72
/** Destructor. */
73
PluginListMessage::~PluginListMessage
()
74
{
75
delete
plugin_list;
76
if
(
_payload
!= NULL) {
77
free(
_payload
);
78
_payload
= NULL;
79
_payload_size
= 0;
80
}
81
}
82
83
84
/** Append plugin name.
85
* @param plugin_name plugin name
86
* @param len length in bytes to append (can be used for example to avoid
87
* adding a file extension.
88
*/
89
void
90
PluginListMessage::append
(
const
char
*plugin_name,
size_t
len)
91
{
92
plugin_list->
append
(plugin_name, len);
93
}
94
95
96
void
97
PluginListMessage::serialize
()
98
{
99
_payload_size
=
sizeof
(msg) + plugin_list->
buffer_size
();
100
_payload
= malloc(
_payload_size
);
101
copy_payload
(0, &msg,
sizeof
(msg));
102
copy_payload
(
sizeof
(msg), plugin_list->
buffer
(), plugin_list->
buffer_size
());
103
}
104
105
106
/** Reset iterator.
107
* For incoming messages only.
108
*/
109
void
110
PluginListMessage::reset_iterator
()
111
{
112
plugin_list->
reset_iterator
();
113
}
114
115
116
/** Check if more list elements are available.
117
* For incoming messages only.
118
* @return true if there are more elements available, false otherwise.
119
*/
120
bool
121
PluginListMessage::has_next
()
122
{
123
return
plugin_list->
has_next
();
124
}
125
126
127
/** Get next plugin from list.
128
* @return next plugin from list. This string has been allocated via strndup, so
129
* you have to free it yourself!
130
*/
131
char
*
132
PluginListMessage::next
()
133
{
134
size_t
size;
135
void
*tmp = plugin_list->
next
(&size);
136
return
strndup((
const
char
*)tmp, size);
137
}
138
139
}
// end namespace fawkes
fawkes::FawkesNetworkMessageContent::_payload
void * _payload
Pointer to payload.
Definition:
message_content.h:47
fawkes::TypeMismatchException
Type mismatch.
Definition:
software.h:46
fawkes::PluginListMessage::next
char * next()
Get next plugin from list.
Definition:
list_message.cpp:132
fawkes::FawkesNetworkMessageContent::_payload_size
size_t _payload_size
Payloda size.
Definition:
message_content.h:49
fawkes
Fawkes library namespace.
fawkes::DynamicBuffer::buffer
void * buffer()
Get pointer to buffer.
Definition:
dynamic_buffer.cpp:159
fawkes::PluginListMessage::~PluginListMessage
virtual ~PluginListMessage()
Destructor.
Definition:
list_message.cpp:73
fawkes::plugin_list_msg_t::plugin_list
dynamic_list_t plugin_list
dynamically growing list of plugin names.
Definition:
messages.h:95
fawkes::plugin_list_msg_t
Plugin list message.
Definition:
messages.h:94
fawkes::DynamicBuffer::has_next
bool has_next()
Check if another element is available.
Definition:
dynamic_buffer.cpp:245
fawkes::DynamicBuffer::buffer_size
size_t buffer_size()
Get buffer size.
Definition:
dynamic_buffer.cpp:201
fawkes::PluginListMessage::reset_iterator
void reset_iterator()
Reset iterator.
Definition:
list_message.cpp:110
fawkes::PluginListMessage::PluginListMessage
PluginListMessage()
Constructor.
Definition:
list_message.cpp:45
fawkes::PluginListMessage::serialize
virtual void serialize()
Serialize message content.
Definition:
list_message.cpp:97
fawkes::FawkesNetworkMessageContent::payload
virtual void * payload()
Return pointer to payload.
Definition:
message_content.cpp:72
fawkes::PluginListMessage::has_next
bool has_next()
Check if more list elements are available.
Definition:
list_message.cpp:121
fawkes::FawkesNetworkMessageContent::copy_payload
void copy_payload(size_t offset, const void *buf, size_t len)
Copy payload into payload buffer to a specified offset.
Definition:
message_content.cpp:104
fawkes::DynamicBuffer
Dynamically growing buffer.
Definition:
dynamic_buffer.h:46
fawkes::PluginListMessage::append
void append(const char *plugin_name, size_t len)
Append plugin name.
Definition:
list_message.cpp:90
fawkes::FawkesNetworkMessageContent::payload_size
virtual size_t payload_size()
Return payload size.
Definition:
message_content.cpp:88
fawkes::DynamicBuffer::reset_iterator
void reset_iterator()
Reset iterator.
Definition:
dynamic_buffer.cpp:232
fawkes::DynamicBuffer::append
void append(const void *data, size_t data_size)
Append data.
Definition:
dynamic_buffer.cpp:123
fawkes::DynamicBuffer::next
void * next(size_t *size)
Get next buffer.
Definition:
dynamic_buffer.cpp:258
src
libs
plugin
net
list_message.cpp
Generated by
1.8.13