00001 /*************************************************************************** 00002 LOW_network.h - description 00003 ------------------- 00004 begin : Tue Jul 23 2002 00005 copyright : (C) 2002 by Harald Roelle, Helmut Reiser 00006 email : roelle@informatik.uni-muenchen.de, reiser@informatik.uni-muenchen.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef LOW_NETWORK_H 00019 #define LOW_NETWORK_H 00020 00021 00022 #include "LOW_link.h" 00023 #include "LOW_netSegment.h" 00024 00025 00026 00027 /** Class to represent a whole 1-Wire network. 00028 00029 A network consists of multiple links (LOW_link). 00030 On a link there is at least one segment (LOW_netSegment). 00031 00032 @todo Add multi-segment support. 00033 00034 @author Harald Roelle, Helmut Reiser 00035 */ 00036 class LOW_network 00037 { 00038 00039 //======================================================================================= 00040 public: 00041 00042 //===================================================================================== 00043 // 00044 // exceptions 00045 // 00046 00047 /** Exception base class for all exceptions thrown by LOW_netSegment. */ 00048 class_DERIVE_FROM_EXCEPTION( network_error, LOW_exception); 00049 00050 00051 00052 //===================================================================================== 00053 // 00054 // constructors 00055 // 00056 00057 /** Constructor. 00058 */ 00059 LOW_network(); 00060 00061 /** Destructor. 00062 Automatically disposes all segments. 00063 */ 00064 ~LOW_network(); 00065 00066 00067 //===================================================================================== 00068 // 00069 // methods 00070 // 00071 00072 /** Add a link to the network. 00073 Triggers discovery of network segments. 00074 Returns silently when link is already registered. 00075 00076 @param inLink The link to be added. 00077 */ 00078 void addLink( LOW_link *inLink); 00079 00080 00081 /** Remove a link from the network. 00082 Destroys all segments on this link. 00083 00084 @param inLink The link to be removed. 00085 @throw network_error When link is not registered. 00086 */ 00087 void removeLink( LOW_link *inLink); 00088 00089 00090 /** Get list of all network segments on the network. 00091 @return List of all segments. 00092 */ 00093 LOW_netSegment::netSegPtrVec_t getSegments() const; 00094 00095 00096 /** Get a specific device. 00097 00098 Devices are searched in the internal lists of all segments only. 00099 No bus actions are performed. 00100 00101 <B>Note:</B>:The device type to look for is selected by the template parameter. 00102 00103 @param inDevID ID of the device to get. 00104 @return Requested device. 00105 */ 00106 template<class devType> devType* getDevice( const LOW_deviceID inDevID) const; 00107 00108 00109 /** Get devices of a specific type. 00110 00111 Devices are searched in the internal lists of all segments only. 00112 No bus actions are performed. Selecting any device type will result 00113 in the complete list of devices known to be present on the network. 00114 00115 <B>Note:</B>: The device type to look for is selected by the template parameter. 00116 To select any device type use LOW_device. 00117 00118 @return Vector of found devices. 00119 */ 00120 template<class devType> vector<devType*> getDevices() const; 00121 00122 00123 /** Search for devices on the network. 00124 00125 Selecting any device type will result in searching the whole network. 00126 00127 <B>Note:</B>: The device type to look for is selected by the template parameter. 00128 To select any device type use LOW_device. 00129 00130 <B>Note:</B>: The bus will be actively searched. Newly found devices will be 00131 added to the internal lists of the segments. 00132 00133 @param inOnlyAlarm Determines whether to look only for alarming devices of the 00134 requested type. 00135 @return Vector of found devices. 00136 */ 00137 template<class devType> vector<devType*> searchDevices( const bool inOnlyAlarm = false) const; 00138 00139 00140 /** Verify existance of a specific device on the network. 00141 00142 <B>Note:</B>: In case you already own a reference to the device, use the 00143 corresponding method from LOW_device. 00144 00145 <B>Note:</B>: The bus will be actively searched. Newly found devices will be 00146 added to the internal lists of the segments. 00147 00148 @param inDevID ID of the device to verify. 00149 @param inOnlyAlarm Determines whether to report existance only when 00150 the device is alarming. 00151 @return Boolean indicates wheter the device could be found or not. 00152 */ 00153 bool verifyDevice( const LOW_deviceID inDevID, const bool inOnlyAlarm = false) const; 00154 00155 00156 00157 //======================================================================================= 00158 protected: 00159 00160 //===================================================================================== 00161 // 00162 // attributes 00163 // 00164 00165 LOW_netSegment::netSegPtrVec_t segmentsList; /**< List of all segments on the network. */ 00166 LOW_link::linkPtrVec_t linkList; /**< List of links the network consts of. */ 00167 00168 00169 //===================================================================================== 00170 // 00171 // methods 00172 // 00173 00174 /** Trigger discovery of network segments. 00175 Found segments are added to the internal segment list. 00176 00177 @param inLink The link where segments should be discovered on. 00178 */ 00179 void addSegments( LOW_link &inLink); 00180 }; 00181 00182 00183 00184 //===================================================================================== 00185 // DEFINITIONS COMPILERS CANNOT HANDLE TO GO DIRECTLY INTO THE LIBRARY 00186 //===================================================================================== 00187 00188 00189 //===================================================================================== 00190 // 00191 // template definitions 00192 // 00193 00194 template<class devType> devType* LOW_network::getDevice( const LOW_deviceID inDevID) const 00195 { 00196 for( unsigned int segI=0; segI<segmentsList.size(); segI++) { 00197 try { 00198 return segmentsList[segI]->getDevice<devType>( inDevID); 00199 } 00200 catch( LOW_device::noDevice_error ex) {} // for now ignore exception 00201 } 00202 throw LOW_device::noDevice_error( "Device not found on whole network", __FILE__, __LINE__); 00203 } 00204 00205 00206 template<class devType> vector<devType*> LOW_network::getDevices() const 00207 { 00208 vector<devType*> retVal; 00209 00210 for( unsigned int segI=0; segI<segmentsList.size(); segI++) { 00211 vector<devType*> segDevs = segmentsList[segI]->getDevices<devType>(); 00212 for( unsigned int devI=0; devI<segDevs.size(); devI++) 00213 retVal.push_back( segDevs[devI]); 00214 } 00215 00216 return retVal; 00217 } 00218 00219 00220 template<class devType> vector<devType*> LOW_network::searchDevices( const bool inOnlyAlarm) const 00221 { 00222 vector<devType*> retVal; 00223 00224 for( unsigned int segI=0; segI<segmentsList.size(); segI++) { 00225 vector<devType*> segDevs = segmentsList[segI]->searchDevices<devType>( inOnlyAlarm); 00226 for( unsigned int devI=0; devI<segDevs.size(); devI++) 00227 retVal.push_back( segDevs[devI]); 00228 } 00229 00230 return retVal; 00231 } 00232 00233 00234 #endif