blob: b710646672a36f42d6146b1eabe08e8fa7ae9521 [file] [log] [blame]
Alexander Afanasyev71b43e72012-12-27 01:03:43 -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
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>
29
30// temporarily ignoring all potential database errors
31
32class DbHelper
33{
34public:
35 DbHelper (const std::string &path);
36 ~DbHelper ();
37
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080038 void
39 updateDeviceSeqno ();
40
41 std::string
42 LookupForwardingAlias (const std::string &deviceName);
43
44 void
45 updateForwardingAlias ();
46
47 /**
48 * Create an entry in SyncLog and SyncStateNodes corresponding to the current state of SyncNodes
49 */
50 void
51 rememberStateInStateLog ();
52
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080053private:
54 static void
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080055 hash_xStep (sqlite3_context *context, int argc, sqlite3_value **argv);
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080056
57 static void
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080058 hash_xFinal (sqlite3_context *context);
59
60 static void
61 hash2str_Func (sqlite3_context *context, int argc, sqlite3_value **argv);
62
63 static void
64 str2hash_Func (sqlite3_context *context, int argc, sqlite3_value **argv);
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080065
66private:
67 sqlite3 *m_db;
68};
69
70namespace Error {
71struct Db : virtual boost::exception, virtual std::exception { };
72}
73
74
75#endif // SQLITE_HELPER_H