Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Alexander Afanasyev |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #include "face.h" |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | Face::sent_interest |
| 16 | Face::sendInterest (Ptr<const Interest> interest, const SatisfiedInterestCallback &dataCallback) |
| 17 | { |
| 18 | // magic to be done in child class |
| 19 | |
| 20 | sent_interest item = m_sentInterests.find_exact (interest->getName ()); |
| 21 | if (item == m_sentInterests.end ()) |
| 22 | { |
| 23 | std::pair<sent_interest, bool> insertRes = |
| 24 | m_sentInterests.insert (interest->getName (), Ptr<sent_interest_container::payload_traits::payload_type>::Create ()); |
| 25 | |
| 26 | item = insertRes.first; |
| 27 | } |
| 28 | item->payload ()->push_back (dataCallback); |
| 29 | |
| 30 | return item; |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | Face::clearInterest (Face::sent_interest interest) |
| 35 | { |
| 36 | m_sentInterests.erase (interest); |
| 37 | } |
| 38 | |
| 39 | Face::registered_prefix |
| 40 | Face::setInterestFilter (Ptr<const Name> prefix, const ExpectedInterestCallback &interestCallback) |
| 41 | { |
| 42 | // magic to be done in child class |
| 43 | |
| 44 | registered_prefix item = m_registeredPrefixes.find_exact (*prefix); |
| 45 | if (item == m_registeredPrefixes.end ()) |
| 46 | { |
| 47 | std::pair<registered_prefix, bool> insertRes = |
| 48 | m_registeredPrefixes.insert (*prefix, Ptr<registered_prefix_container::payload_traits::payload_type>::Create ()); |
| 49 | |
| 50 | item = insertRes.first; |
| 51 | } |
| 52 | item->payload ()->push_back (interestCallback); |
| 53 | |
| 54 | return item; |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | Face::clearInterestFilter (const Name &prefix) |
| 59 | { |
| 60 | registered_prefix item = m_registeredPrefixes.find_exact (prefix); |
| 61 | if (item == m_registeredPrefixes.end ()) |
| 62 | return; |
| 63 | |
| 64 | clearInterestFilter (item); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | Face::clearInterestFilter (Face::registered_prefix filter) |
| 69 | { |
| 70 | m_registeredPrefixes.erase (filter); |
| 71 | } |
| 72 | |
| 73 | } // ndn |
| 74 | |
| 75 | // void |
| 76 | // CcnxWrapper::OnInterest (const Ptr<const ndn::Interest> &interest, Ptr<Packet> packet) |
| 77 | // { |
| 78 | // ndn::App::OnInterest (interest, packet); |
| 79 | |
| 80 | // // the app cannot set several filters for the same prefix |
| 81 | // CcnxFilterEntryContainer<InterestCallback>::iterator entry = m_interestCallbacks.longest_prefix_match (interest->GetName ()); |
| 82 | // if (entry == m_interestCallbacks.end ()) |
| 83 | // { |
| 84 | // _LOG_DEBUG ("No Interest callback set"); |
| 85 | // return; |
| 86 | // } |
| 87 | |
| 88 | // entry->payload ()->m_callback (lexical_cast<string> (interest->GetName ())); |
| 89 | // } |
| 90 | |
| 91 | // void |
| 92 | // CcnxWrapper::OnContentObject (const Ptr<const ndn::ContentObject> &contentObject, |
| 93 | // Ptr<Packet> payload) |
| 94 | // { |
| 95 | // ndn::App::OnContentObject (contentObject, payload); |
| 96 | // NS_LOG_DEBUG ("<< D " << contentObject->GetName ()); |
| 97 | |
| 98 | // CcnxFilterEntryContainer<RawDataCallback>::iterator entry = m_dataCallbacks.longest_prefix_match (contentObject->GetName ()); |
| 99 | // if (entry == m_dataCallbacks.end ()) |
| 100 | // { |
| 101 | // _LOG_DEBUG ("No Data callback set"); |
| 102 | // return; |
| 103 | // } |
| 104 | |
| 105 | // while (entry != m_dataCallbacks.end ()) |
| 106 | // { |
| 107 | // ostringstream content; |
| 108 | // payload->CopyData (&content, payload->GetSize ()); |
| 109 | |
| 110 | // entry->payload ()->m_callback (lexical_cast<string> (contentObject->GetName ()), content.str ().c_str (), content.str ().size ()); |
| 111 | |
| 112 | // m_dataCallbacks.erase (entry); |
| 113 | |
| 114 | // entry = m_dataCallbacks.longest_prefix_match (contentObject->GetName ()); |
| 115 | // } |
| 116 | // } |
| 117 | |
| 118 | // } |