blob: 9ecd7531e44c6c8d40e1a70ec525c3db02fda5c2 [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 Zhu7717d202012-12-29 18:01:36 -080030
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080031class ObjectDb
Zhenkai Zhu7717d202012-12-29 18:01:36 -080032{
33public:
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080034 // database will be create in <folder>/<first-pair-of-hash-bytes>/<rest-of-hash>
35 ObjectDb (const boost::filesystem::path &folder, const std::string &hash);
36 ~ObjectDb ();
Zhenkai Zhu7717d202012-12-29 18:01:36 -080037
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080038 void
39 saveContentObject (const Ccnx::Name &deviceName, sqlite3_int64 segment, const Ccnx::Bytes &data);
Zhenkai Zhu7717d202012-12-29 18:01:36 -080040
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080041 Ccnx::BytesPtr
42 fetchSegment (const Ccnx::Name &deviceName, sqlite3_int64 segment);
Zhenkai Zhu7717d202012-12-29 18:01:36 -080043
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080044 // sqlite3_int64
45 // getNumberOfSegments (const Ccnx::Name &deviceName);
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080046
47 static bool
48 DoesExist (const boost::filesystem::path &folder, const Ccnx::Name &deviceName, const std::string &hash);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080049
50private:
51 sqlite3 *m_db;
Zhenkai Zhu7717d202012-12-29 18:01:36 -080052};
53
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080054#endif // OBJECT_DB_H