blob: 51a58809ce3ba9c3aaad7ebcf0169c0d282f9186 [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016, 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
21#ifndef OBJECT_MANAGER_H
22#define OBJECT_MANAGER_H
23
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080024#include <boost/filesystem.hpp>
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080025#include <boost/tuple/tuple.hpp>
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080026#include <ccnx-wrapper.h>
27#include <hash-helper.h>
28#include <string>
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080029
30// everything related to managing object files
31
32class ObjectManager
33{
34public:
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080035 ObjectManager(Ccnx::CcnxWrapperPtr ccnx, const boost::filesystem::path& folder,
36 const std::string& appName);
37 virtual ~ObjectManager();
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080038
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080039 /**
40 * @brief Creates and saves local file in a local database file
41 *
42 * Format: /<appname>/file/<hash>/<devicename>/<segment>
43 */
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080044 boost::tuple<HashPtr /*object-db name*/, size_t /* number of segments*/>
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080045 localFileToObjects(const boost::filesystem::path& file, const Ccnx::Name& deviceName);
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080046
47 bool
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080048 objectsToLocalFile(/*in*/ const Ccnx::Name& deviceName, /*in*/ const Hash& hash,
49 /*out*/ const boost::filesystem::path& file);
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080050
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080051private:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070052 Ndnx::NdnxWrapperPtr m_ndnx;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080053 boost::filesystem::path m_folder;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080054 std::string m_appName;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080055};
56
57typedef boost::shared_ptr<ObjectManager> ObjectManagerPtr;
58
59namespace Error {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080060struct ObjectManager : virtual boost::exception, virtual std::exception
61{
62};
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080063}
64
65#endif // OBJECT_MANAGER_H