ilist_content.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <blackboard/net/ilist_content.h>
00025
00026 #include <netcomm/utils/dynamic_buffer.h>
00027 #include <netcomm/fawkes/component_ids.h>
00028 #include <core/exceptions/software.h>
00029 #include <cstdlib>
00030 #include <cstring>
00031
00032 namespace fawkes {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 BlackBoardInterfaceListContent::BlackBoardInterfaceListContent()
00045 {
00046 interface_list = new DynamicBuffer(&(msg.interface_list));
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 BlackBoardInterfaceListContent::BlackBoardInterfaceListContent(unsigned int component_id,
00058 unsigned int msg_id,
00059 void *payload,
00060 size_t payload_size)
00061 {
00062 if ( component_id != FAWKES_CID_BLACKBOARD ) {
00063 throw TypeMismatchException("BlackBoardInterfaceListContent: invalid component ID");
00064 }
00065 bb_ilist_msg_t *tmsg = (bb_ilist_msg_t *)payload;
00066 void *ilist_payload = (void *)((size_t)payload + sizeof(msg));
00067 interface_list = new DynamicBuffer(&(tmsg->interface_list), ilist_payload,
00068 payload_size - sizeof(msg));
00069 }
00070
00071
00072
00073 BlackBoardInterfaceListContent::~BlackBoardInterfaceListContent()
00074 {
00075 delete interface_list;
00076 if (_payload != NULL) {
00077 free(_payload);
00078 _payload = NULL;
00079 _payload_size = 0;
00080 }
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 void
00094 BlackBoardInterfaceListContent::append_interface(const char *type, const char *id,
00095 const unsigned char *hash,
00096 unsigned int serial,
00097 bool has_writer, unsigned int num_readers)
00098 {
00099 bb_iinfo_msg_t info;
00100 memset(&info, 0, sizeof(info));
00101 strncpy(info.type, type, __INTERFACE_TYPE_SIZE);
00102 strncpy(info.id, id, __INTERFACE_ID_SIZE);
00103 memcpy(info.hash, hash, __INTERFACE_HASH_SIZE);
00104 interface_list->append(&info, sizeof(info));
00105 info.serial = serial;
00106 info.has_writer = has_writer ? 1 : 0;
00107 info.num_readers = num_readers;
00108 }
00109
00110
00111
00112
00113
00114 void
00115 BlackBoardInterfaceListContent::append_interface(InterfaceInfo &iinfo)
00116 {
00117 bb_iinfo_msg_t info;
00118 memset(&info, 0, sizeof(info));
00119 strncpy(info.type, iinfo.type(), __INTERFACE_TYPE_SIZE);
00120 strncpy(info.id, iinfo.id(), __INTERFACE_ID_SIZE);
00121 memcpy(info.hash, iinfo.hash(), __INTERFACE_HASH_SIZE);
00122 info.serial = iinfo.serial();
00123 info.has_writer = iinfo.has_writer() ? 1 : 0;
00124 info.num_readers = iinfo.num_readers();
00125 interface_list->append(&info, sizeof(info));
00126 }
00127
00128
00129 void
00130 BlackBoardInterfaceListContent::serialize()
00131 {
00132 _payload_size = sizeof(msg) + interface_list->buffer_size();
00133 _payload = malloc(_payload_size);
00134 copy_payload(0, &msg, sizeof(msg));
00135 copy_payload(sizeof(msg), interface_list->buffer(), interface_list->buffer_size());
00136 }
00137
00138
00139
00140
00141
00142 void
00143 BlackBoardInterfaceListContent::reset_iterator()
00144 {
00145 interface_list->reset_iterator();
00146 }
00147
00148
00149
00150
00151
00152
00153 bool
00154 BlackBoardInterfaceListContent::has_next()
00155 {
00156 return interface_list->has_next();
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166 bb_iinfo_msg_t *
00167 BlackBoardInterfaceListContent::next(size_t *size)
00168 {
00169 void *tmp = interface_list->next(size);
00170 return (bb_iinfo_msg_t *)tmp;
00171 }
00172
00173 }