blob: b00c84627a21e4189ff074a92f16350f91524ecd [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Lijing Wang9f77a8c2016-12-25 14:44:04 -08003 * Copyright (c) 2013-2017, Regents of the University of California.
Alexander Afanasyev68f2a952013-01-08 14:34:16 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Alexander Afanasyev68f2a952013-01-08 14:34:16 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * ChronoShare is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * ChronoShare 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 General Public License for more details.
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * You should have received copies of the GNU General Public License along with
16 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080019 */
20
Lijing Wang9f77a8c2016-12-25 14:44:04 -080021#ifndef CHRONOSHARE_SRC_OBJECT_MANAGER_HPP
22#define CHRONOSHARE_SRC_OBJECT_MANAGER_HPP
23
24#include "core/chronoshare-common.hpp"
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080025
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080026#include <boost/filesystem.hpp>
Lijing Wang9f77a8c2016-12-25 14:44:04 -080027
28#include <ndn-cxx/face.hpp>
29#include <ndn-cxx/security/key-chain.hpp>
30#include <ndn-cxx/util/digest.hpp>
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080031
32// everything related to managing object files
33
Lijing Wang9f77a8c2016-12-25 14:44:04 -080034namespace ndn {
35namespace chronoshare {
36
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080037class ObjectManager
38{
39public:
Lijing Wang9f77a8c2016-12-25 14:44:04 -080040 ObjectManager(Face& face, KeyChain& keyChain,
41 const boost::filesystem::path& folder, const std::string& appName);
42
43 virtual
44 ~ObjectManager();
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080045
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080046 /**
47 * @brief Creates and saves local file in a local database file
48 *
49 * Format: /<appname>/file/<hash>/<devicename>/<segment>
50 */
Lijing Wang9f77a8c2016-12-25 14:44:04 -080051 std::tuple<ConstBufferPtr /*object-db name*/, size_t /* number of segments*/>
52 localFileToObjects(const boost::filesystem::path& file, const Name& deviceName);
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080053
54 bool
Lijing Wang9f77a8c2016-12-25 14:44:04 -080055 objectsToLocalFile(/*in*/ const Name& deviceName, /*in*/ const Buffer& hash,
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080056 /*out*/ const boost::filesystem::path& file);
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080057
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080058private:
Lijing Wang9f77a8c2016-12-25 14:44:04 -080059 Face& m_face;
60 KeyChain& m_keyChain;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080061 boost::filesystem::path m_folder;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080062 std::string m_appName;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080063};
64
Lijing Wang9f77a8c2016-12-25 14:44:04 -080065typedef shared_ptr<ObjectManager> ObjectManagerPtr;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080066
Lijing Wang9f77a8c2016-12-25 14:44:04 -080067namespace error {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080068struct ObjectManager : virtual boost::exception, virtual std::exception
69{
70};
Lijing Wang9f77a8c2016-12-25 14:44:04 -080071} // namespace error
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080072
Lijing Wang9f77a8c2016-12-25 14:44:04 -080073} // namespace chronoshare
74} // namespace ndn
75
76#endif // CHRONOSHARE_SRC_OBJECT_MANAGER_HPP