blob: 5d578867f1e6fe5b972a4b1749b7cbeea9fabafb [file] [log] [blame]
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080011 */
12
Alexander Afanasyeve289b532014-02-09 22:14:44 -080013#ifndef NDN_MANAGEMENT_NDND_CONTROLLER_HPP
14#define NDN_MANAGEMENT_NDND_CONTROLLER_HPP
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080015
Alexander Afanasyeve289b532014-02-09 22:14:44 -080016#include "controller.hpp"
17
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080018namespace ndn {
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080019namespace ndnd {
20
21class FaceInstance;
22class ForwardingEntry;
23
24/*
25 * @brief Class implementing Face and Prefix management operations for ndnd-tlv
26 *
27 * ndnd::Control should be used when connecting to ndnd-tlv daemon
28 */
Alexander Afanasyeve289b532014-02-09 22:14:44 -080029class Controller : public ndn::Controller
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080030{
31public:
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080032 typedef function<void(const ForwardingEntry&)> PrefixOperationSucceedCallback;
33 typedef function<void(const FaceInstance&)> FaceOperationSucceedCallback;
34
35 /**
36 * @brief Construct ndnd::Control object
37 */
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080038 Controller(Face& face);
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080039
Alexander Afanasyeve289b532014-02-09 22:14:44 -080040 virtual void
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080041 selfRegisterPrefix(const Name& prefixToRegister,
42 const SuccessCallback& onSuccess,
43 const FailCallback& onFail);
44
Alexander Afanasyeve289b532014-02-09 22:14:44 -080045 virtual void
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080046 selfDeregisterPrefix(const Name& prefixToRegister,
47 const SuccessCallback& onSuccess,
48 const FailCallback& onFail);
49
50protected:
51 void
52 startFaceAction(const FaceInstance& entry,
53 const FaceOperationSucceedCallback& onSuccess,
54 const FailCallback& onFailure);
55
56 void
57 startPrefixAction(const ForwardingEntry& entry,
58 const PrefixOperationSucceedCallback& onSuccess,
59 const FailCallback& onFailure);
60
61private:
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070062 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080063 onNdnidFetched(const Interest& interest, Data& data);
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080064
65 void
66 recordSelfRegisteredFaceId(const ForwardingEntry& entry,
67 const SuccessCallback& onSuccess);
68
69 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080070 processFaceActionResponse(Data& data,
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080071 const FaceOperationSucceedCallback& onSuccess,
72 const FailCallback& onFail);
73
74 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080075 processPrefixActionResponse(Data& data,
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080076 const PrefixOperationSucceedCallback& onSuccess,
77 const FailCallback& onFail);
78
79private:
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080080 Face& m_face;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080081 Block m_ndndId;
82 int64_t m_faceId; // internal face ID (needed for prefix de-registration)
83
84 struct FilterRequest
85 {
86 FilterRequest(const Name& prefixToRegister,
87 const SuccessCallback& onSuccess,
88 const FailCallback& onFailure)
89 : m_prefixToRegister(prefixToRegister)
90 , m_onSuccess(onSuccess)
91 , m_onFailure(onFailure)
92 {
93 }
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070094
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080095 Name m_prefixToRegister;
96 SuccessCallback m_onSuccess;
97 FailCallback m_onFailure;
98 };
99
100 typedef std::list<FilterRequest> FilterRequestList;
101 FilterRequestList m_filterRequests;
102};
103
104} // namespace ndnd
105} // namespace ndn
106
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800107#endif // NDN_MANAGEMENT_NDND_CONTROLLER_HPP