Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -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 | |
| 22 | #ifndef SQLITE_HELPER_H |
| 23 | #define SQLITE_HELPER_H |
| 24 | |
| 25 | #include <sqlite3.h> |
| 26 | #include <openssl/evp.h> |
| 27 | #include <boost/exception/all.hpp> |
| 28 | #include <string> |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 29 | #include "hash-string-converter.h" |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 30 | |
| 31 | // temporarily ignoring all potential database errors |
| 32 | |
| 33 | class DbHelper |
| 34 | { |
| 35 | public: |
| 36 | DbHelper (const std::string &path); |
| 37 | ~DbHelper (); |
| 38 | |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 39 | // done |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 40 | void |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 41 | UpdateDeviceSeqno (const std::string &name, uint64_t seqNo); |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 43 | // std::string |
| 44 | // LookupForwardingAlias (const std::string &deviceName); |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 46 | // void |
| 47 | // UpdateForwardingAlias (); |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 48 | |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 49 | // done |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 50 | /** |
| 51 | * Create an entry in SyncLog and SyncStateNodes corresponding to the current state of SyncNodes |
| 52 | */ |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 53 | HashPtr |
| 54 | RememberStateInStateLog (); |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 55 | |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 56 | // done |
| 57 | sqlite3_int64 |
| 58 | LookupSyncLog (const std::string &stateHash); |
| 59 | |
| 60 | // done |
| 61 | sqlite3_int64 |
| 62 | LookupSyncLog (const Hash &stateHash); |
| 63 | |
| 64 | // How difference is exposed will be determined later by the actual protocol |
| 65 | void |
| 66 | FindStateDifferences (const std::string &oldHash, const std::string &newHash); |
| 67 | |
| 68 | void |
| 69 | FindStateDifferences (const Hash &oldHash, const Hash &newHash); |
| 70 | |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 71 | private: |
| 72 | static void |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 73 | hash_xStep (sqlite3_context *context, int argc, sqlite3_value **argv); |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 74 | |
| 75 | static void |
Alexander Afanasyev | de1cdd0 | 2012-12-29 14:41:46 -0800 | [diff] [blame] | 76 | hash_xFinal (sqlite3_context *context); |
| 77 | |
| 78 | static void |
| 79 | hash2str_Func (sqlite3_context *context, int argc, sqlite3_value **argv); |
| 80 | |
| 81 | static void |
| 82 | str2hash_Func (sqlite3_context *context, int argc, sqlite3_value **argv); |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | sqlite3 *m_db; |
| 86 | }; |
| 87 | |
| 88 | namespace Error { |
| 89 | struct Db : virtual boost::exception, virtual std::exception { }; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | #endif // SQLITE_HELPER_H |