blob: fd22f154a1183331a7688a9529f1c11c91ba109e [file] [log] [blame]
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NDN_MANAGEMENT_NDND_CONTROL_HPP
8#define NDN_MANAGEMENT_NDND_CONTROL_HPP
9
10#include "../common.hpp"
11
12namespace ndn {
13
14class Node;
15
16namespace ndnd {
17
18class FaceInstance;
19class ForwardingEntry;
20
21/*
22 * @brief Class implementing Face and Prefix management operations for ndnd-tlv
23 *
24 * ndnd::Control should be used when connecting to ndnd-tlv daemon
25 */
26class Control
27{
28public:
29 typedef function<void()> SuccessCallback;
30 typedef function<void()> FailCallback;
31
32 typedef function<void(const ForwardingEntry&)> PrefixOperationSucceedCallback;
33 typedef function<void(const FaceInstance&)> FaceOperationSucceedCallback;
34
35 /**
36 * @brief Construct ndnd::Control object
37 */
38 Control(Node& face);
39
40 void
41 selfRegisterPrefix(const Name& prefixToRegister,
42 const SuccessCallback& onSuccess,
43 const FailCallback& onFail);
44
45 void
46 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:
62 void
63 onNdnidFetched(const shared_ptr<const Interest>& interest,
64 const shared_ptr<Data>& data);
65
66
67 void
68 recordSelfRegisteredFaceId(const ForwardingEntry& entry,
69 const SuccessCallback& onSuccess);
70
71 void
72 processFaceActionResponse(const shared_ptr<Data>& data,
73 const FaceOperationSucceedCallback& onSuccess,
74 const FailCallback& onFail);
75
76 void
77 processPrefixActionResponse(const shared_ptr<Data>& data,
78 const PrefixOperationSucceedCallback& onSuccess,
79 const FailCallback& onFail);
80
81private:
82 Node& m_face;
83 Block m_ndndId;
84 int64_t m_faceId; // internal face ID (needed for prefix de-registration)
85
86 struct FilterRequest
87 {
88 FilterRequest(const Name& prefixToRegister,
89 const SuccessCallback& onSuccess,
90 const FailCallback& onFailure)
91 : m_prefixToRegister(prefixToRegister)
92 , m_onSuccess(onSuccess)
93 , m_onFailure(onFailure)
94 {
95 }
96
97 Name m_prefixToRegister;
98 SuccessCallback m_onSuccess;
99 FailCallback m_onFailure;
100 };
101
102 typedef std::list<FilterRequest> FilterRequestList;
103 FilterRequestList m_filterRequests;
104};
105
106} // namespace ndnd
107} // namespace ndn
108
109#endif // NDN_MANAGEMENT_NDND_CONTROL_HPP