00001 // 00002 // Copyright (C) 2005 Andras Varga 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef __INET_INTERFACETABLE_H 00019 #define __INET_INTERFACETABLE_H 00020 00021 #include <vector> 00022 #include <omnetpp.h> 00023 #include "INETDefs.h" 00024 #include "IInterfaceTable.h" 00025 #include "InterfaceEntry.h" 00026 #include "NotificationBoard.h" 00027 00028 00066 class INET_API InterfaceTable : public cSimpleModule, public IInterfaceTable, protected INotifiable 00067 { 00068 protected: 00069 NotificationBoard *nb; // cached pointer 00070 00071 // primary storage for interfaces: vector indexed by id; may contain NULLs; 00072 // slots are never reused to ensure id uniqueness 00073 typedef std::vector<InterfaceEntry *> InterfaceVector; 00074 InterfaceVector idToInterface; 00075 00076 // fields to support getNumInterfaces() and getInterface(pos) 00077 int tmpNumInterfaces; // caches number of non-NULL elements of idToInterface; -1 if invalid 00078 InterfaceEntry **tmpInterfaceList; // caches non-NULL elements of idToInterface; NULL if invalid 00079 00080 protected: 00081 // displays summary above the icon 00082 virtual void updateDisplayString(); 00083 00084 // discover and store which nwlayer/host gates connect to this interface 00085 virtual void discoverConnectingGates(InterfaceEntry *entry, cModule *ifmod); 00086 00087 // called from InterfaceEntry 00088 virtual void interfaceChanged(InterfaceEntry *entry, int category); 00089 00090 // internal 00091 virtual void invalidateTmpInterfaceList(); 00092 00093 public: 00094 InterfaceTable(); 00095 virtual ~InterfaceTable(); 00096 virtual std::string getFullPath() const {return cSimpleModule::getFullPath();} 00097 00098 protected: 00099 virtual int numInitStages() const {return 2;} 00100 virtual void initialize(int stage); 00101 00105 virtual void handleMessage(cMessage *); 00106 00107 public: 00112 virtual void receiveChangeNotification(int category, const cPolymorphic *details); 00113 00121 virtual void addInterface(InterfaceEntry *entry, cModule *ifmod); 00122 00128 virtual void deleteInterface(InterfaceEntry *entry); 00129 00133 virtual int getNumInterfaces(); 00134 00144 virtual InterfaceEntry *getInterface(int pos); 00145 00151 virtual InterfaceEntry *getInterfaceById(int id); 00152 00157 virtual InterfaceEntry *getInterfaceByNodeOutputGateId(int id); 00158 00163 virtual InterfaceEntry *getInterfaceByNodeInputGateId(int id); 00164 00169 virtual InterfaceEntry *getInterfaceByNetworkLayerGateIndex(int index); 00170 00174 virtual InterfaceEntry *getInterfaceByName(const char *name); 00175 00182 virtual InterfaceEntry *getFirstLoopbackInterface(); 00183 }; 00184 00185 #endif 00186