Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 1 | /* -*- 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 Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 22 | #ifndef OBJECT_DB_H |
| 23 | #define OBJECT_DB_H |
| 24 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 25 | #include <string> |
| 26 | #include <sqlite3.h> |
| 27 | #include <ccnx-common.h> |
| 28 | #include <ccnx-name.h> |
| 29 | #include <boost/filesystem.hpp> |
Zhenkai Zhu | c3fd51e | 2013-01-22 10:45:54 -0800 | [diff] [blame] | 30 | #include <boost/shared_ptr.hpp> |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 32 | class ObjectDb |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 33 | { |
| 34 | public: |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 35 | // database will be create in <folder>/<first-pair-of-hash-bytes>/<rest-of-hash> |
| 36 | ObjectDb (const boost::filesystem::path &folder, const std::string &hash); |
| 37 | ~ObjectDb (); |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 38 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 39 | void |
| 40 | saveContentObject (const Ccnx::Name &deviceName, sqlite3_int64 segment, const Ccnx::Bytes &data); |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 42 | Ccnx::BytesPtr |
| 43 | fetchSegment (const Ccnx::Name &deviceName, sqlite3_int64 segment); |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 45 | // sqlite3_int64 |
| 46 | // getNumberOfSegments (const Ccnx::Name &deviceName); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 47 | |
| 48 | static bool |
| 49 | DoesExist (const boost::filesystem::path &folder, const Ccnx::Name &deviceName, const std::string &hash); |
Alexander Afanasyev | b2e608d | 2013-01-23 20:00:53 -0800 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | void |
| 53 | willStartSave (); |
| 54 | |
| 55 | void |
| 56 | didStopSave (); |
| 57 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 58 | private: |
| 59 | sqlite3 *m_db; |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
Zhenkai Zhu | c3fd51e | 2013-01-22 10:45:54 -0800 | [diff] [blame] | 62 | typedef boost::shared_ptr<ObjectDb> ObjectDbPtr; |
| 63 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 64 | #endif // OBJECT_DB_H |