Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

virtualinterface.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique
00002 
00003 // This file is part of Qolyester.
00004 
00005 // Qolyester is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 // Qolyester is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 
00019 #include "config.hh"
00020 
00021 #ifdef QOLYESTER_ENABLE_VIRTUAL
00022 
00023 # ifndef QOLYESTER_DAEMON_NET_VIRTUALINTERFACE_HXX
00024 #  define QOLYESTER_DAEMON_NET_VIRTUALINTERFACE_HXX 1
00025 
00026 #  include "virtualinterface.hh"
00027 
00028 namespace olsr {
00029 
00030   namespace net {
00031 
00032     VirtualInterface::VirtualInterface()
00033       : info_(),
00034         addr_(info_.addr()),
00035         prefix_(0),
00036         events_()
00037     {}
00038 
00039     VirtualInterface::VirtualInterface(const sys::VirtualInterfaceInfo& info)
00040       : info_(info),
00041         addr_(info_.addr()),
00042         prefix_(info_.prefix()),
00043         events_()
00044     {}
00045 
00046     VirtualInterface::VirtualInterface(const This& other)
00047       : Super(other),
00048         info_(other.info_),
00049         addr_(info_.addr()),
00050         prefix_(info_.prefix()),
00051         events_()
00052     {}
00053 
00054     VirtualInterface::~VirtualInterface() {
00055       debug << "Destroying interface instance {\n";
00056       for (events_t::iterator i = events_.begin(); i != events_.end();
00057            /* ++i elsewhere */) {
00058         debug << "  Destroying " << (*i)->name() << "\n";
00059         events_t::iterator tmp = i++;
00060         scheduler.destroy(*tmp);
00061       }
00062       debug << "}" << std::endl;
00063     }
00064 
00065     unsigned
00066     VirtualInterface::mtu() const {
00067       return info_.mtu();
00068     }
00069 
00070     sch::IOEvent::p_t
00071     VirtualInterface::recv_p() const {
00072       return info_.socket().read_p();
00073     }
00074 
00075     sch::IOEvent::p_t
00076     VirtualInterface::send_p() const {
00077       return info_.socket().write_p();
00078     }
00079 
00080     void
00081     VirtualInterface::insert_event(sch::IOEvent* e) {
00082       debug << "Inserting " << e->name() << " into interface" << std::endl;
00083       events_.insert(e);
00084     }
00085 
00086     void
00087     VirtualInterface::erase_event(sch::IOEvent* e) {
00088       debug << "Erasing " << e->name() << " from interface" << std::endl;
00089       events_.erase(e);
00090     }
00091 
00092     void
00093     VirtualInterface::destroy_all_events() {
00094       while (!events_.empty()) {
00095         sch::IOEvent*   e = *events_.begin();
00096         events_.erase(events_.begin());
00097         scheduler.destroy(e);
00098       }
00099     }
00100 
00101     pkt::Packet
00102     VirtualInterface::receive() const {
00103 //      std::string             fromf;
00104 //         utl::Data            d = info_.socket().receive(fromf);
00105       try {
00106         utl::Data               d = info_.socket().receive();
00107         address_t               froma(d.raw(), address_t::address_size);
00108         d += address_t::address_size;
00109         debug << up << "paquet received from switch: ip=" << froma
00110               << std::endl;
00111 
00112         return pkt::Packet(froma, d);
00113       } catch (sys::UnixClosedConnection&) {
00114         terminate_now.set_mark();
00115         throw std::runtime_error("VirtualInterface::receive(): "
00116                                  "closed connection");
00117       }
00118     }
00119 
00120     void
00121     VirtualInterface::send(const pkt::Packet& p) const {
00122       try {
00123         info_.socket().send(p.data());
00124       } catch (sys::UnixClosedConnection&) {
00125         terminate_now.set_mark();
00126         throw std::runtime_error("VirtualInterface::send(): "
00127                                  "closed connection");
00128       }
00129       address_t froma = p.sender();
00130       debug << up << "paquet sent from " << froma << std::endl;
00131 
00132     }
00133 
00134     bool
00135     VirtualInterface::operator<(const This& rhs) const {
00136       return addr_ < rhs.addr_;
00137     }
00138 
00139     VirtualInterface&
00140     VirtualInterface::make_key(const address_t& a) {
00141       const_cast<address_t&>(dummy_for_find_.addr_) = a;
00142       return dummy_for_find_;
00143     }
00144 
00145   } // namespace net
00146 
00147 } // namespace olsr
00148 
00149 # endif // ! QOLYESTER_DAEMON_NET_VIRTUALINTERFACE_HXX
00150 
00151 #endif // QOLYESTER_ENABLE_VIRTUAL

Generated on Thu Jul 28 21:21:48 2005 for Qolyester daemon by  doxygen 1.4.1