blob: 6c4ace272cf39c50dd05efddd7137723de5ad104 [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:
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080044 FileState (const boost::filesystem::path &path);
45 ~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
51 UpdateFile (const std::string &filename, const Hash &hash, const Ccnx::CcnxCharbuf &device_name, sqlite3_int64 seqno,
52 time_t atime, time_t mtime, time_t ctime, int mode, int seg_num);
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -080053
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080054 /**
55 * @brief Delete file
56 */
57 void
58 DeleteFile (const std::string &filename);
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -080059
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080060 /**
61 * @brief Set "complete" flag
62 *
63 * The call will do nothing if FileState does not have a record for the file (e.g., file got subsequently deleted)
64 */
65 void
66 SetFileComplete (const std::string &filename);
67
68 /**
69 * @brief Lookup file state using file name
70 */
71 FileItemPtr
72 LookupFile (const std::string &filename) ;
73
74 /**
75 * @brief Lookup file state using content hash (multiple items may be returned)
76 */
77 FileItemsPtr
78 LookupFilesForHash (const Hash &hash);
79
80 /**
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080081 * @brief Lookup all files in the specified folder and call visitor(file) for each file
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080082 */
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080083 void
84 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 -080085
86 /**
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080087 * @brief Lookup all files in the specified folder (wrapper around the overloaded version)
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080088 */
89 FileItemsPtr
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080090 LookupFilesInFolder (const std::string &folder, int offset=0, int limit=-1);
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080091
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080092 /**
93 * @brief Recursively lookup all files in the specified folder and call visitor(file) for each file
94 */
95 FileItemsPtr
96 LookupFilesInFolderRecursively (const boost::function<void (const FileItem&)> &visitor, const std::string &folder, int offset=0, int limit=-1);
97
98 /**
99 * @brief Recursively lookup all files in the specified folder (wrapper around the overloaded version)
100 */
101 FileItemsPtr
102 LookupFilesInFolderRecursively (const std::string &folder, int offset=0, int limit=-1);
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800103};
104
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -0800105typedef boost::shared_ptr<FileState> FileStatePtr;
106
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800107namespace Error {
108struct FileState : virtual boost::exception, virtual std::exception { };
109}
110
111
112#endif // ACTION_LOG_H