Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 7 | #ifndef NFD_FACE_ETHERNET_FACTORY_HPP |
| 8 | #define NFD_FACE_ETHERNET_FACTORY_HPP |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 9 | |
| 10 | #include "ethernet-face.hpp" |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 11 | #include "protocol-factory.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 12 | |
| 13 | namespace nfd { |
| 14 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 15 | class NetworkInterfaceInfo; |
| 16 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 17 | class EthernetFactory : public ProtocolFactory |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 18 | { |
| 19 | public: |
| 20 | /** |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 21 | * \brief Exception of EthernetFactory |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 22 | */ |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 23 | struct Error : public ProtocolFactory::Error |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 24 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 25 | Error(const std::string& what) : ProtocolFactory::Error(what) {} |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 26 | }; |
| 27 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 28 | // from ProtocolFactory |
| 29 | virtual void |
| 30 | createFace(const FaceUri& uri, |
| 31 | const FaceCreatedCallback& onCreated, |
| 32 | const FaceConnectFailedCallback& onConnectFailed); |
| 33 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 34 | /** |
| 35 | * \brief Create an EthernetFace to communicate with the given multicast group |
| 36 | * |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 37 | * If this method is called twice with the same interface and group, only |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 38 | * one face will be created. Instead, the second call will just retrieve |
| 39 | * the existing face. |
| 40 | * |
| 41 | * \param interface Local network interface |
| 42 | * \param address Ethernet broadcast/multicast destination address |
| 43 | * |
| 44 | * \returns always a valid shared pointer to an EthernetFace object, |
| 45 | * an exception will be thrown if the creation fails |
| 46 | * |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 47 | * \throws EthernetFactory::Error or EthernetFace::Error |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 48 | */ |
| 49 | shared_ptr<EthernetFace> |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 50 | createMulticastFace(const shared_ptr<NetworkInterfaceInfo>& interface, |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 51 | const ethernet::Address& address); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 52 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 53 | private: |
| 54 | void |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 55 | afterFaceFailed(const std::string& interfaceName, |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 56 | const ethernet::Address& address); |
| 57 | |
| 58 | /** |
| 59 | * \brief Look up EthernetFace using specified interface and address |
| 60 | * |
| 61 | * \returns shared pointer to the existing EthernetFace object or |
| 62 | * empty shared pointer when such face does not exist |
| 63 | * |
| 64 | * \throws never |
| 65 | */ |
| 66 | shared_ptr<EthernetFace> |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 67 | findMulticastFace(const std::string& interfaceName, |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 68 | const ethernet::Address& address) const; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 69 | |
| 70 | private: |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 71 | typedef std::map< std::pair<std::string, ethernet::Address>, |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 72 | shared_ptr<EthernetFace> > MulticastFacesMap; |
| 73 | MulticastFacesMap m_multicastFaces; |
| 74 | }; |
| 75 | |
| 76 | } // namespace nfd |
| 77 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 78 | #endif // NFD_FACE_ETHERNET_FACTORY_HPP |