blob: 6e9beb46686cb86c5d11e4975e8a739b93fc01ba [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080020 */
21
22#ifndef NDN_DETAIL_REGISTERED_PREFIX_HPP
23#define NDN_DETAIL_REGISTERED_PREFIX_HPP
24
25#include "../common.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080026#include "../name.hpp"
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080027#include "../interest.hpp"
28
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070029#include "interest-filter-record.hpp"
Joao Pereiraba1e3b92015-06-01 17:50:37 -040030#include "management/nfd-command-options.hpp"
31#include "management/nfd-control-parameters.hpp"
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070032
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080033namespace ndn {
34
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070035class RegisteredPrefix : noncopyable
Alexander Afanasyev90164962014-03-06 08:29:59 +000036{
37public:
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070038 /** \brief a callback on command success
Alexander Afanasyev90164962014-03-06 08:29:59 +000039 */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070040 typedef function<void(const nfd::ControlParameters&)> SuccessCallback;
Alexander Afanasyev90164962014-03-06 08:29:59 +000041
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070042 /** \brief a callback on command failure
43 */
44 typedef function<void(uint32_t/*code*/,const std::string&/*reason*/)> FailureCallback;
Alexander Afanasyev90164962014-03-06 08:29:59 +000045
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070046 RegisteredPrefix(const Name& prefix,
47 const shared_ptr<InterestFilterRecord>& filter,
Joao Pereiraba1e3b92015-06-01 17:50:37 -040048 const nfd::CommandOptions& options)
Alexander Afanasyev90164962014-03-06 08:29:59 +000049 : m_prefix(prefix)
50 , m_filter(filter)
Joao Pereiraba1e3b92015-06-01 17:50:37 -040051 , m_options(options)
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080052 {
53 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070054
55 const Name&
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080056 getPrefix() const
57 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000058 return m_prefix;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080059 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070060
Alexander Afanasyev90164962014-03-06 08:29:59 +000061 const shared_ptr<InterestFilterRecord>&
62 getFilter() const
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080063 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000064 return m_filter;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080065 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070066
Joao Pereiraba1e3b92015-06-01 17:50:37 -040067 const nfd::CommandOptions&
68 getCommandOptions() const
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070069 {
Joao Pereiraba1e3b92015-06-01 17:50:37 -040070 return m_options;
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070071 }
72
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080073private:
Alexander Afanasyev90164962014-03-06 08:29:59 +000074 Name m_prefix;
Alexander Afanasyev90164962014-03-06 08:29:59 +000075 shared_ptr<InterestFilterRecord> m_filter;
Joao Pereiraba1e3b92015-06-01 17:50:37 -040076 nfd::CommandOptions m_options;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080077};
78
Alexander Afanasyev90164962014-03-06 08:29:59 +000079/**
80 * @brief Opaque class representing ID of the registered prefix
81 */
82class RegisteredPrefixId;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080083
84/**
Alexander Afanasyev90164962014-03-06 08:29:59 +000085 * @brief Functor to match RegisteredPrefixId
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080086 */
Alexander Afanasyev90164962014-03-06 08:29:59 +000087class MatchRegisteredPrefixId
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080088{
Alexander Afanasyev90164962014-03-06 08:29:59 +000089public:
90 explicit
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091 MatchRegisteredPrefixId(const RegisteredPrefixId* registeredPrefixId)
92 : m_id(registeredPrefixId)
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080093 {
94 }
95
96 bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070097 operator()(const shared_ptr<RegisteredPrefix>& registeredPrefix) const
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080098 {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070099 return (reinterpret_cast<const RegisteredPrefixId*>(registeredPrefix.get()) == m_id);
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800100 }
101private:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700102 const RegisteredPrefixId* m_id;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800103};
104
Alexander Afanasyev90164962014-03-06 08:29:59 +0000105
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800106} // namespace ndn
107
108#endif // NDN_DETAIL_REGISTERED_PREFIX_HPP