blob: bdd6b6f14e42f5b622fccb1272aa6663be0d258b [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"
weijia yuan82cf9142018-10-21 12:25:02 -070024
25#include "storage/repo-storage.hpp"
26#include "repo-command-response.hpp"
27#include "repo-command-parameter.hpp"
28#include "repo-command.hpp"
Shuo Chen9c2477f2014-03-13 15:01:06 -070029
30namespace repo {
31
weijia yuan82cf9142018-10-21 12:25:02 -070032class ReadHandle : public noncopyable
Shuo Chen9c2477f2014-03-13 15:01:06 -070033{
34
35public:
Nick Gordon190e4dc2017-10-04 16:54:10 -050036 using DataPrefixRegistrationCallback = std::function<void(const ndn::Name&)>;
37 using DataPrefixUnregistrationCallback = std::function<void(const ndn::Name&)>;
38 struct RegisteredDataPrefix
Shuo Chen9c2477f2014-03-13 15:01:06 -070039 {
Nick Gordon190e4dc2017-10-04 16:54:10 -050040 const ndn::RegisteredPrefixId* prefixId;
41 int useCount;
42 };
43
weijia yuan82cf9142018-10-21 12:25:02 -070044 ReadHandle(Face& face, RepoStorage& storageHandle, size_t prefixSubsetLength);
Nick Gordon190e4dc2017-10-04 16:54:10 -050045
46 void
weijia yuan82cf9142018-10-21 12:25:02 -070047 listen(const Name& prefix);
Nick Gordon190e4dc2017-10-04 16:54:10 -050048
Nick Gordon190e4dc2017-10-04 16:54:10 -050049PUBLIC_WITH_TESTS_ELSE_PRIVATE:
50 const std::map<ndn::Name, RegisteredDataPrefix>&
51 getRegisteredPrefixes()
52 {
53 return m_insertedDataPrefixes;
Shuo Chen9c2477f2014-03-13 15:01:06 -070054 }
55
Nick Gordon190e4dc2017-10-04 16:54:10 -050056 /**
weijia yuan3aa8d2b2018-03-06 15:35:57 -080057 * @param name Full name of the deleted Data
Nick Gordon190e4dc2017-10-04 16:54:10 -050058 */
59 void
60 onDataDeleted(const Name& name);
61
62 /**
63 * @param after Do something after successfully registering the data prefix
64 */
65 void
66 onDataInserted(const Name& name);
Shuo Chen9c2477f2014-03-13 15:01:06 -070067
Alexander Afanasyevbb058c02018-02-15 22:49:24 +000068 void
69 connectAutoListen();
70
Shuo Chen9c2477f2014-03-13 15:01:06 -070071private:
72 /**
Shuo Chen29c77fe2014-03-18 11:29:41 -070073 * @brief Read data from backend storage
Shuo Chen9c2477f2014-03-13 15:01:06 -070074 */
75 void
76 onInterest(const Name& prefix, const Interest& interest);
77
78 void
79 onRegisterFailed(const Name& prefix, const std::string& reason);
Nick Gordon190e4dc2017-10-04 16:54:10 -050080
81private:
82 size_t m_prefixSubsetLength;
83 std::map<ndn::Name, RegisteredDataPrefix> m_insertedDataPrefixes;
84 ndn::util::signal::ScopedConnection afterDataDeletionConnection;
85 ndn::util::signal::ScopedConnection afterDataInsertionConnection;
weijia yuan82cf9142018-10-21 12:25:02 -070086 Face& m_face;
87 RepoStorage& m_storageHandle;
Shuo Chen9c2477f2014-03-13 15:01:06 -070088};
89
Alexander Afanasyev39d98072014-05-04 12:46:29 -070090} // namespace repo
Shuo Chen9c2477f2014-03-13 15:01:06 -070091
Alexander Afanasyev39d98072014-05-04 12:46:29 -070092#endif // REPO_HANDLES_READ_HANDLE_HPP