blob: 4123713979d57b04c4fce674726827e8c0508306 [file] [log] [blame]
Alexander Afanasyeva199f972013-01-02 19:37:26 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012-2013 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 ACTION_LOG_H
23#define ACTION_LOG_H
24
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080025#include "db-helper.h"
Alexander Afanasyeva199f972013-01-02 19:37:26 -080026#include "sync-log.h"
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080027#include "action-item.pb.h"
28#include "ccnx-wrapper.h"
29#include "ccnx-pco.h"
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080030
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080031#include <boost/tuple/tuple.hpp>
Alexander Afanasyeva199f972013-01-02 19:37:26 -080032
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080033class ActionLog;
34typedef boost::shared_ptr<ActionLog> ActionLogPtr;
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080035typedef boost::shared_ptr<ActionItem> ActionItemPtr;
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080036
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080037class ActionLog : public DbHelper
Alexander Afanasyeva199f972013-01-02 19:37:26 -080038{
39public:
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080040 ActionLog (Ccnx::CcnxWrapperPtr ccnx, const boost::filesystem::path &path,
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080041 SyncLogPtr syncLog,
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080042 const std::string &sharedFolder);
Alexander Afanasyeva199f972013-01-02 19:37:26 -080043
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080044 //////////////////////////
45 // Local operations //
46 //////////////////////////
Alexander Afanasyeva199f972013-01-02 19:37:26 -080047 void
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080048 AddLocalActionUpdate (const std::string &filename,
49 const Hash &hash,
50 time_t wtime,
51 int mode,
52 int seg_num);
53
54 // void
55 // AddActionMove (const std::string &oldFile, const std::string &newFile);
Alexander Afanasyeva199f972013-01-02 19:37:26 -080056
57 void
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080058 AddLocalActionDelete (const std::string &filename);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080059
Zhenkai Zhuc3fd51e2013-01-22 10:45:54 -080060 bool
61 KnownFileState(const std::string &filename, const Hash &hash);
62
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080063 //////////////////////////
64 // Remote operations //
65 //////////////////////////
66
67 void
68 AddRemoteAction (const Ccnx::Name &deviceName, sqlite3_int64 seqno, Ccnx::PcoPtr actionPco);
69
70 /**
71 * @brief Add remote action using just action's parsed content object
72 *
73 * This function extracts device name and sequence number from the content object's and calls the overloaded method
74 */
75 void
76 AddRemoteAction (Ccnx::PcoPtr actionPco);
77
78 ///////////////////////////
79 // General operations //
80 ///////////////////////////
81
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080082 Ccnx::PcoPtr
83 LookupActionPco (const Ccnx::Name &deviceName, sqlite3_int64 seqno);
84
85 Ccnx::PcoPtr
86 LookupActionPco (const Ccnx::Name &actionName);
87
88 ActionItemPtr
89 LookupAction (const Ccnx::Name &deviceName, sqlite3_int64 seqno);
90
91 ActionItemPtr
92 LookupAction (const Ccnx::Name &actionName);
93
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080094
95
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080096public:
97 // for test purposes
98 sqlite3_int64
99 LogSize ();
100
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800101private:
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800102 boost::tuple<sqlite3_int64 /*version*/, Ccnx::CcnxCharbufPtr /*device name*/, sqlite3_int64 /*seq_no*/>
103 GetLatestActionForFile (const std::string &filename);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800104
105 static void
106 apply_action_xFun (sqlite3_context *context, int argc, sqlite3_value **argv);
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -0800107
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800108private:
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -0800109 SyncLogPtr m_syncLog;
110
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800111 Ccnx::CcnxWrapperPtr m_ccnx;
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800112 std::string m_sharedFolderName;
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800113};
114
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800115namespace Error {
116struct ActionLog : virtual boost::exception, virtual std::exception { };
117}
118
119
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800120#endif // ACTION_LOG_H