blob: b0890a27feabb979a8b9418ffa2ebf9b6c2205bd [file] [log] [blame]
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -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 FILE_STATE_H
23#define FILE_STATE_H
24
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080025#include "db-helper.h"
26
27#include "ccnx-name.h"
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -080028#include "file-item.pb.h"
29#include "hash-helper.h"
30
31#include <boost/tuple/tuple.hpp>
32#include <boost/exception/all.hpp>
33
34#include <list>
35
36typedef std::list<FileItem> FileItems;
37typedef boost::shared_ptr<FileItem> FileItemPtr;
38typedef boost::shared_ptr<FileItems> FileItemsPtr;
39
40
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080041class FileState : public DbHelper
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -080042{
43public:
Yingdi Yuadb54eb2013-08-15 10:28:28 -070044 FileState (const boost::filesystem::path &path, bool cow = false);
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080045 ~FileState ();
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -080046
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080047 /**
48 * @brief Update or add a file
49 */
50 void
Alexander Afanasyev6fb5dc62013-02-27 11:34:52 -080051 UpdateFile (const std::string &filename, sqlite3_int64 version,
52 const Hash &hash, const Ccnx::CcnxCharbuf &device_name, sqlite3_int64 seqno,
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080053 time_t atime, time_t mtime, time_t ctime, int mode, int seg_num);
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -080054
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080055 /**
56 * @brief Delete file
57 */
58 void
59 DeleteFile (const std::string &filename);
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -080060
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080061 /**
62 * @brief Set "complete" flag
63 *
64 * The call will do nothing if FileState does not have a record for the file (e.g., file got subsequently deleted)
65 */
66 void
67 SetFileComplete (const std::string &filename);
68
69 /**
70 * @brief Lookup file state using file name
71 */
72 FileItemPtr
73 LookupFile (const std::string &filename) ;
74
75 /**
76 * @brief Lookup file state using content hash (multiple items may be returned)
77 */
78 FileItemsPtr
79 LookupFilesForHash (const Hash &hash);
80
81 /**
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080082 * @brief Lookup all files in the specified folder and call visitor(file) for each file
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080083 */
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080084 void
85 LookupFilesInFolder (const boost::function<void (const FileItem&)> &visitor, const std::string &folder, int offset=0, int limit=-1);
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080086
87 /**
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080088 * @brief Lookup all files in the specified folder (wrapper around the overloaded version)
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080089 */
90 FileItemsPtr
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080091 LookupFilesInFolder (const std::string &folder, int offset=0, int limit=-1);
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080092
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080093 /**
94 * @brief Recursively lookup all files in the specified folder and call visitor(file) for each file
95 */
Alexander Afanasyev6fb5dc62013-02-27 11:34:52 -080096 bool
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080097 LookupFilesInFolderRecursively (const boost::function<void (const FileItem&)> &visitor, const std::string &folder, int offset=0, int limit=-1);
98
99 /**
100 * @brief Recursively lookup all files in the specified folder (wrapper around the overloaded version)
101 */
102 FileItemsPtr
103 LookupFilesInFolderRecursively (const std::string &folder, int offset=0, int limit=-1);
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800104};
105
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -0800106typedef boost::shared_ptr<FileState> FileStatePtr;
107
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800108namespace Error {
109struct FileState : virtual boost::exception, virtual std::exception { };
110}
111
112
113#endif // ACTION_LOG_H