blob: f66e9797ada08f6b197a7eceb13bf178dd89f224 [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
24#include <string>
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070025#include <ndnx-wrapper.h>
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080026#include <hash-helper.h>
27#include <boost/filesystem.hpp>
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080028#include <boost/tuple/tuple.hpp>
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080029
30// everything related to managing object files
31
32class ObjectManager
33{
34public:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070035 ObjectManager (Ndnx::NdnxWrapperPtr ndnx, const boost::filesystem::path &folder, const std::string &appName);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080036 virtual ~ObjectManager ();
37
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080038 /**
39 * @brief Creates and saves local file in a local database file
40 *
41 * Format: /<appname>/file/<hash>/<devicename>/<segment>
42 */
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080043 boost::tuple<HashPtr /*object-db name*/, size_t /* number of segments*/>
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070044 localFileToObjects (const boost::filesystem::path &file, const Ndnx::Name &deviceName);
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080045
46 bool
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070047 objectsToLocalFile (/*in*/const Ndnx::Name &deviceName, /*in*/const Hash &hash, /*out*/ const boost::filesystem::path &file);
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080048
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080049private:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070050 Ndnx::NdnxWrapperPtr m_ndnx;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080051 boost::filesystem::path m_folder;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080052 std::string m_appName;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080053};
54
55typedef boost::shared_ptr<ObjectManager> ObjectManagerPtr;
56
57namespace Error {
58struct ObjectManager : virtual boost::exception, virtual std::exception { };
59}
60
61#endif // OBJECT_MANAGER_H