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 <interface/interface_info.h>
00025 #include <interface/interface.h>
00026
00027 #include <cstdlib>
00028 #include <cstring>
00029
00030 namespace fawkes {
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 InterfaceInfo::InterfaceInfo(const char *type, const char *id, const unsigned char *hash,
00047 unsigned int serial, bool has_writer, unsigned int num_readers)
00048 {
00049 __type = strndup(type, __INTERFACE_TYPE_SIZE);
00050 __id = strndup(id, __INTERFACE_ID_SIZE);
00051 __hash = (unsigned char *)malloc(__INTERFACE_HASH_SIZE);
00052 memcpy(__hash, hash, __INTERFACE_HASH_SIZE);
00053 __has_writer = has_writer;
00054 __num_readers = num_readers;
00055 __serial = serial;
00056 }
00057
00058
00059
00060
00061
00062 InterfaceInfo::InterfaceInfo(const InterfaceInfo &i)
00063 {
00064 __type = strndup(i.__type, __INTERFACE_TYPE_SIZE);
00065 __id = strndup(i.__id, __INTERFACE_ID_SIZE);
00066 __hash = (unsigned char *)malloc(__INTERFACE_HASH_SIZE);
00067 memcpy(__hash, i.__hash, __INTERFACE_HASH_SIZE);
00068 __has_writer = i.__has_writer;
00069 __num_readers = i.__num_readers;
00070 __serial = i.__serial;
00071 }
00072
00073
00074
00075 InterfaceInfo::~InterfaceInfo()
00076 {
00077 free(__type);
00078 free(__id);
00079 free(__hash);
00080 }
00081
00082
00083
00084
00085
00086 const char *
00087 InterfaceInfo::type() const
00088 {
00089 return __type;
00090 }
00091
00092
00093
00094
00095
00096 const char *
00097 InterfaceInfo::id() const
00098 {
00099 return __id;
00100 }
00101
00102
00103
00104
00105
00106 const unsigned char *
00107 InterfaceInfo::hash() const
00108 {
00109 return __hash;
00110 }
00111
00112
00113
00114
00115
00116 bool
00117 InterfaceInfo::has_writer() const
00118 {
00119 return __has_writer;
00120 }
00121
00122
00123
00124
00125
00126 unsigned int
00127 InterfaceInfo::num_readers() const
00128 {
00129 return __num_readers;
00130 }
00131
00132
00133
00134
00135
00136 unsigned int
00137 InterfaceInfo::serial() const
00138 {
00139 return __serial;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 bool
00152 InterfaceInfo::operator<(const InterfaceInfo &ii) const
00153 {
00154 int td = strncmp(__type, ii.__type, __INTERFACE_TYPE_SIZE);
00155 if ( td < 0 ) {
00156 return true;
00157 } else if (td > 0) {
00158 return false;
00159 } else {
00160 return (strncmp(__id, ii.__id, __INTERFACE_ID_SIZE) < 0);
00161 }
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 void
00180 InterfaceInfoList::append(const char *type, const char *id, const unsigned char *hash,
00181 unsigned int serial, bool has_writer, unsigned int num_readers)
00182 {
00183 push_back(InterfaceInfo(type, id, hash, serial, has_writer, num_readers));
00184 }
00185
00186 }