Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * interface_info.h - BlackBoard Interface Info 00004 * 00005 * Created: Mon Mar 03 15:44:46 2008 00006 * Copyright 2006-2008 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 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 /** @class InterfaceInfo <interface/interface_info.h> 00033 * Interface info. 00034 * This class holds information about a specific interface. 00035 * @author Tim Niemueller 00036 */ 00037 00038 /** Constructor. 00039 * @param type type of the interface 00040 * @param id id of the interface 00041 * @param hash version hash 00042 * @param has_writer true if there is a writer, false otherwise 00043 * @param num_readers number of readers 00044 * @param serial instance serial 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 /** Copy constructor. 00060 * @param i info to copy 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 /** Destructor. */ 00075 InterfaceInfo::~InterfaceInfo() 00076 { 00077 free(__type); 00078 free(__id); 00079 free(__hash); 00080 } 00081 00082 00083 /** Get interface type. 00084 * @return type string 00085 */ 00086 const char * 00087 InterfaceInfo::type() const 00088 { 00089 return __type; 00090 } 00091 00092 00093 /** Get interface ID. 00094 * @return ID string 00095 */ 00096 const char * 00097 InterfaceInfo::id() const 00098 { 00099 return __id; 00100 } 00101 00102 00103 /** Get interface version hash. 00104 * @return interface version hash 00105 */ 00106 const unsigned char * 00107 InterfaceInfo::hash() const 00108 { 00109 return __hash; 00110 } 00111 00112 00113 /** Check if there is a writer. 00114 * @return true if there is a writer, false otherwise 00115 */ 00116 bool 00117 InterfaceInfo::has_writer() const 00118 { 00119 return __has_writer; 00120 } 00121 00122 00123 /** Get number of readers. 00124 * @return number of readers 00125 */ 00126 unsigned int 00127 InterfaceInfo::num_readers() const 00128 { 00129 return __num_readers; 00130 } 00131 00132 00133 /** Get interface instance serial. 00134 * @return type string 00135 */ 00136 unsigned int 00137 InterfaceInfo::serial() const 00138 { 00139 return __serial; 00140 } 00141 00142 00143 /** < operator 00144 * This compares two interface infos with respect to the less than (<) relation 00145 * considering the type and id of an interface. 00146 * An interface info A is less than an interface info B (A < B) iff 00147 * (A.type < B.type) or ((A.type == B.type) && A.id < B.id). 00148 * @param ii interface info to compare this to 00149 * @return true if this instance is considered less than @p ii, false otherwise 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 /** @class InterfaceInfoList <interface/interface_info.h> 00166 * Interface information list. 00167 * List with InterfaceInfo instances. 00168 * @author Tim Niemueller 00169 */ 00170 00171 /** Append an interface info. 00172 * @param type type of the interface 00173 * @param id id of the interface 00174 * @param hash version hash 00175 * @param has_writer true if there is a writer, false otherwise 00176 * @param num_readers number of readers 00177 * @param serial instance serial 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 } // end namespace fawkes