interface_info.cpp

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 #ifdef __FreeBSD__
00030 #  include <strfunc.h>
00031 #endif
00032 
00033 namespace fawkes {
00034 
00035 /** @class InterfaceInfo <interface/interface_info.h>
00036  * Interface info.
00037  * This class holds information about a specific interface.
00038  * @author Tim Niemueller
00039  */
00040 
00041 /** Constructor.
00042  * @param type type of the interface
00043  * @param id id of the interface
00044  * @param hash version hash
00045  * @param has_writer true if there is a writer, false otherwise
00046  * @param num_readers number of readers
00047  * @param serial instance serial
00048  */
00049 InterfaceInfo::InterfaceInfo(const char *type, const char *id, const unsigned char *hash,
00050                              unsigned int serial, bool has_writer, unsigned int num_readers)
00051 {
00052   __type = strndup(type, __INTERFACE_TYPE_SIZE);
00053   __id   = strndup(id, __INTERFACE_ID_SIZE);
00054   __hash = (unsigned char *)malloc(__INTERFACE_HASH_SIZE);
00055   memcpy(__hash, hash, __INTERFACE_HASH_SIZE);
00056   __has_writer = has_writer;
00057   __num_readers = num_readers;
00058   __serial = serial;
00059 }
00060
00061 
00062 /** Copy constructor.
00063  * @param i info to copy
00064  */
00065 InterfaceInfo::InterfaceInfo(const InterfaceInfo &i)
00066 {
00067   __type = strndup(i.__type, __INTERFACE_TYPE_SIZE);
00068   __id   = strndup(i.__id, __INTERFACE_ID_SIZE);
00069   __hash = (unsigned char *)malloc(__INTERFACE_HASH_SIZE);
00070   memcpy(__hash, i.__hash, __INTERFACE_HASH_SIZE);
00071   __has_writer = i.__has_writer;
00072   __num_readers = i.__num_readers;
00073   __serial = i.__serial;
00074 }
00075
00076 
00077 /** Destructor. */
00078 InterfaceInfo::~InterfaceInfo()
00079 {
00080   free(__type);
00081   free(__id);
00082   free(__hash);
00083 }
00084
00085 
00086 /** Get interface type.
00087  * @return type string
00088  */
00089 const char *
00090 InterfaceInfo::type() const
00091 {
00092   return __type;
00093 }
00094
00095 
00096 /** Get interface ID.
00097  * @return ID string
00098  */
00099 const char *
00100 InterfaceInfo::id() const
00101 {
00102   return __id;
00103 }
00104
00105 
00106 /** Get interface version hash.
00107  * @return interface version hash
00108  */
00109 const unsigned char *
00110 InterfaceInfo::hash() const
00111 {
00112   return __hash;
00113 }
00114
00115 
00116 /** Check if there is a writer.
00117  * @return true if there is a writer, false otherwise
00118  */
00119 bool
00120 InterfaceInfo::has_writer() const
00121 {
00122   return __has_writer;
00123 }
00124
00125 
00126 /** Get number of readers.
00127  * @return number of readers
00128  */
00129 unsigned int
00130 InterfaceInfo::num_readers() const
00131 {
00132   return __num_readers;
00133 }
00134
00135 
00136 /** Get interface instance serial.
00137  * @return type string
00138  */
00139 unsigned int
00140 InterfaceInfo::serial() const
00141 {
00142   return __serial;
00143 }
00144
00145 
00146 /** @class InterfaceInfoList <interface/interface_info.h>
00147  * Interface information list.
00148  * List with InterfaceInfo instances.
00149  * @author Tim Niemueller
00150  */
00151 
00152 /** Append an interface info.
00153  * @param type type of the interface
00154  * @param id id of the interface
00155  * @param hash version hash
00156  * @param has_writer true if there is a writer, false otherwise
00157  * @param num_readers number of readers
00158  * @param serial instance serial
00159  */
00160 void
00161 InterfaceInfoList::append(const char *type, const char *id, const unsigned char *hash,
00162                           unsigned int serial, bool has_writer, unsigned int num_readers)
00163 {
00164   push_back(InterfaceInfo(type, id, hash, serial, has_writer, num_readers));
00165 }
00166
00167 } // end namespace fawkes