00001 /*************************************************************************** 00002 LOW_network.cpp - 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 #include "LOW_network.h" 00019 00020 00021 //===================================================================================== 00022 // 00023 // constructors 00024 // 00025 00026 LOW_network::LOW_network() 00027 { 00028 } 00029 00030 00031 LOW_network::~LOW_network() 00032 { 00033 for( unsigned int a=0; a<segmentsList.size(); a++) 00034 delete segmentsList[a]; 00035 } 00036 00037 00038 00039 //===================================================================================== 00040 // 00041 // public methods 00042 // 00043 00044 void LOW_network::addLink( LOW_link *inLink) 00045 { 00046 __LOW_SYNCHRONIZE_METHOD_WRITE_WEAK__ 00047 00048 for( unsigned int a=0; a<linkList.size(); a++) { 00049 if ( *(linkList[a]) == *inLink ) 00050 return; 00051 } 00052 00053 linkList.push_back( inLink); 00054 addSegments( *inLink); 00055 } 00056 00057 00058 void LOW_network::removeLink( LOW_link *inLink) 00059 { 00060 __LOW_SYNCHRONIZE_METHOD_WRITE__ 00061 00062 for( unsigned int a=0; a<linkList.size(); a++) { 00063 if ( *(linkList[a]) == *inLink ) { 00064 00065 // remove all segments on this link 00066 for( LOW_netSegment::netSegPtrVec_t::iterator b=segmentsList.begin(); b!=segmentsList.end();) { 00067 if ( (*b)->getLink() == *inLink ) { 00068 delete (*b); 00069 b = segmentsList.erase( b); 00070 } 00071 else 00072 ++b; 00073 } 00074 00075 // remove the link from the list 00076 linkList.erase( linkList.begin()+a); 00077 return; 00078 } 00079 } 00080 00081 throw network_error( "Link is not registered.", __FILE__, __LINE__); 00082 } 00083 00084 00085 LOW_netSegment::netSegPtrVec_t LOW_network::getSegments() const 00086 { 00087 __LOW_SYNCHRONIZE_METHOD_READ__ 00088 00089 return segmentsList; 00090 } 00091 00092 00093 00094 bool LOW_network::verifyDevice( const LOW_deviceID inDevID, const bool inOnlyAlarm) const 00095 { 00096 __LOW_SYNCHRONIZE_METHOD_READ__ 00097 00098 LOW_device* theDev; 00099 try { 00100 theDev = getDevice<LOW_device>( inDevID); 00101 } 00102 catch ( LOW_exception ex) { 00103 return false; 00104 } 00105 00106 return theDev->verifyDevice( inOnlyAlarm); 00107 } 00108 00109 00110 00111 //===================================================================================== 00112 // 00113 // private methods 00114 // 00115 00116 void LOW_network::addSegments( LOW_link &inLink) 00117 { 00118 __LOW_SYNCHRONIZE_METHOD_WRITE_WEAK__ 00119 00120 LOW_netSegment::netSegPtrVec_t newSegments; 00121 00122 newSegments = LOW_netSegment::newSegmentsFromLink( inLink); 00123 00124 for( unsigned int a=0; a<newSegments.size(); a++) 00125 segmentsList.push_back( newSegments[a]); 00126 }