Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_network.h

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

Generated on Tue Feb 3 11:30:26 2004 for OneWireLibrary++ by doxygen 1.3.2