blob: cabc46d5e605bcdeb4311ded2291642b25ec5df0 [file] [log] [blame]
Alexander Afanasyev68f2a952013-01-08 14:34:16 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 */
21
Zhenkai Zhu7717d202012-12-29 18:01:36 -080022#ifndef OBJECT_DB_H
23#define OBJECT_DB_H
24
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080025#include <string>
26#include <sqlite3.h>
27#include <ccnx-common.h>
28#include <ccnx-name.h>
29#include <boost/filesystem.hpp>
Zhenkai Zhuc3fd51e2013-01-22 10:45:54 -080030#include <boost/shared_ptr.hpp>
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080031#include <ctime>
32#include <vector>
Zhenkai Zhu7717d202012-12-29 18:01:36 -080033
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080034class ObjectDb
Zhenkai Zhu7717d202012-12-29 18:01:36 -080035{
36public:
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080037 // database will be create in <folder>/<first-pair-of-hash-bytes>/<rest-of-hash>
38 ObjectDb (const boost::filesystem::path &folder, const std::string &hash);
39 ~ObjectDb ();
Zhenkai Zhu7717d202012-12-29 18:01:36 -080040
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080041 void
42 saveContentObject (const Ccnx::Name &deviceName, sqlite3_int64 segment, const Ccnx::Bytes &data);
Zhenkai Zhu7717d202012-12-29 18:01:36 -080043
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080044 Ccnx::BytesPtr
45 fetchSegment (const Ccnx::Name &deviceName, sqlite3_int64 segment);
Zhenkai Zhu7717d202012-12-29 18:01:36 -080046
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080047 // sqlite3_int64
48 // getNumberOfSegments (const Ccnx::Name &deviceName);
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080049
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080050 time_t
51 secondsSinceLastUse();
52
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080053 static bool
54 DoesExist (const boost::filesystem::path &folder, const Ccnx::Name &deviceName, const std::string &hash);
Alexander Afanasyevb2e608d2013-01-23 20:00:53 -080055
56private:
57 void
58 willStartSave ();
59
60 void
61 didStopSave ();
62
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080063private:
64 sqlite3 *m_db;
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080065 time_t m_lastUsed;
Zhenkai Zhu7717d202012-12-29 18:01:36 -080066};
67
Zhenkai Zhuc3fd51e2013-01-22 10:45:54 -080068typedef boost::shared_ptr<ObjectDb> ObjectDbPtr;
69
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080070#endif // OBJECT_DB_H