blob: 8ec67a26295f876012d4ff833b4a0d6e0489eeef [file] [log] [blame]
Shuo Chen9c2477f2014-03-13 15:01:06 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevbb058c02018-02-15 22:49:24 +00002/*
3 * Copyright (c) 2014-2018, Regents of the University of California.
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07004 *
5 * This file is part of NDN repo-ng (Next generation of NDN repository).
6 * See AUTHORS.md for complete list of repo-ng authors and contributors.
7 *
8 * repo-ng is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Shuo Chen9c2477f2014-03-13 15:01:06 -070018 */
19
Alexander Afanasyev39d98072014-05-04 12:46:29 -070020#ifndef REPO_HANDLES_READ_HANDLE_HPP
21#define REPO_HANDLES_READ_HANDLE_HPP
Shuo Chen9c2477f2014-03-13 15:01:06 -070022
Nick Gordon190e4dc2017-10-04 16:54:10 -050023#include "common.hpp"
Shuo Chen9c2477f2014-03-13 15:01:06 -070024#include "base-handle.hpp"
25
26namespace repo {
27
Shuo Chen29c77fe2014-03-18 11:29:41 -070028class ReadHandle : public BaseHandle
Shuo Chen9c2477f2014-03-13 15:01:06 -070029{
30
31public:
Nick Gordon190e4dc2017-10-04 16:54:10 -050032 using DataPrefixRegistrationCallback = std::function<void(const ndn::Name&)>;
33 using DataPrefixUnregistrationCallback = std::function<void(const ndn::Name&)>;
34 struct RegisteredDataPrefix
Shuo Chen9c2477f2014-03-13 15:01:06 -070035 {
Nick Gordon190e4dc2017-10-04 16:54:10 -050036 const ndn::RegisteredPrefixId* prefixId;
37 int useCount;
38 };
39
40 ReadHandle(Face& face, RepoStorage& storageHandle, KeyChain& keyChain,
41 Scheduler& scheduler, size_t prefixSubsetLength);
42
43 void
44 listen(const Name& prefix) override;
45
Nick Gordon190e4dc2017-10-04 16:54:10 -050046PUBLIC_WITH_TESTS_ELSE_PRIVATE:
47 const std::map<ndn::Name, RegisteredDataPrefix>&
48 getRegisteredPrefixes()
49 {
50 return m_insertedDataPrefixes;
Shuo Chen9c2477f2014-03-13 15:01:06 -070051 }
52
Nick Gordon190e4dc2017-10-04 16:54:10 -050053 /**
54 * @param after Do something after actually removing a prefix
55 */
56 void
57 onDataDeleted(const Name& name);
58
59 /**
60 * @param after Do something after successfully registering the data prefix
61 */
62 void
63 onDataInserted(const Name& name);
Shuo Chen9c2477f2014-03-13 15:01:06 -070064
Alexander Afanasyevbb058c02018-02-15 22:49:24 +000065 void
66 connectAutoListen();
67
Shuo Chen9c2477f2014-03-13 15:01:06 -070068private:
69 /**
Shuo Chen29c77fe2014-03-18 11:29:41 -070070 * @brief Read data from backend storage
Shuo Chen9c2477f2014-03-13 15:01:06 -070071 */
72 void
73 onInterest(const Name& prefix, const Interest& interest);
74
75 void
76 onRegisterFailed(const Name& prefix, const std::string& reason);
Nick Gordon190e4dc2017-10-04 16:54:10 -050077
78private:
79 size_t m_prefixSubsetLength;
80 std::map<ndn::Name, RegisteredDataPrefix> m_insertedDataPrefixes;
81 ndn::util::signal::ScopedConnection afterDataDeletionConnection;
82 ndn::util::signal::ScopedConnection afterDataInsertionConnection;
Shuo Chen9c2477f2014-03-13 15:01:06 -070083};
84
Alexander Afanasyev39d98072014-05-04 12:46:29 -070085} // namespace repo
Shuo Chen9c2477f2014-03-13 15:01:06 -070086
Alexander Afanasyev39d98072014-05-04 12:46:29 -070087#endif // REPO_HANDLES_READ_HANDLE_HPP