blob: 27d0869d37b94950f831f3b54ba76fa516d98b52 [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 Afanasyeva199f972013-01-02 19:37:26 -080044 void
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080045 AddLocalActionUpdate (const std::string &filename,
46 const Hash &hash,
47 time_t wtime,
48 int mode,
49 int seg_num);
50
51 // void
52 // AddActionMove (const std::string &oldFile, const std::string &newFile);
Alexander Afanasyeva199f972013-01-02 19:37:26 -080053
54 void
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080055 AddLocalActionDelete (const std::string &filename);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080056
Zhenkai Zhuc3fd51e2013-01-22 10:45:54 -080057 bool
58 KnownFileState(const std::string &filename, const Hash &hash);
59
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080060 Ccnx::PcoPtr
61 LookupActionPco (const Ccnx::Name &deviceName, sqlite3_int64 seqno);
62
63 Ccnx::PcoPtr
64 LookupActionPco (const Ccnx::Name &actionName);
65
66 ActionItemPtr
67 LookupAction (const Ccnx::Name &deviceName, sqlite3_int64 seqno);
68
69 ActionItemPtr
70 LookupAction (const Ccnx::Name &actionName);
71
72public:
73 // for test purposes
74 sqlite3_int64
75 LogSize ();
76
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080077private:
Alexander Afanasyev0995f322013-01-22 13:16:46 -080078 boost::tuple<sqlite3_int64 /*version*/, Ccnx::CcnxCharbufPtr /*device name*/, sqlite3_int64 /*seq_no*/>
79 GetLatestActionForFile (const std::string &filename);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080080
81 static void
82 apply_action_xFun (sqlite3_context *context, int argc, sqlite3_value **argv);
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080083
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080084private:
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080085 SyncLogPtr m_syncLog;
86
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080087 Ccnx::CcnxWrapperPtr m_ccnx;
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080088 std::string m_sharedFolderName;
Alexander Afanasyeva199f972013-01-02 19:37:26 -080089};
90
91#endif // ACTION_LOG_H