Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / nacl_io / dir_node.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef LIBRARIES_NACL_IO_DIR_NODE_H_
6 #define LIBRARIES_NACL_IO_DIR_NODE_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "nacl_io/getdents_helper.h"
13 #include "nacl_io/node.h"
14
15 namespace nacl_io {
16
17 class DevFs;
18 class Html5Fs;
19 class HttpFs;
20 class MemFs;
21 class DirNode;
22
23 typedef sdk_util::ScopedRef<DirNode> ScopedDirNode;
24
25 class DirNode : public Node {
26  protected:
27   explicit DirNode(Filesystem* fs);
28   virtual ~DirNode();
29
30  public:
31   typedef std::map<std::string, ScopedNode> NodeMap_t;
32
33   virtual Error FTruncate(off_t size);
34   virtual Error GetDents(size_t offs,
35                          struct dirent* pdir,
36                          size_t count,
37                          int* out_bytes);
38   virtual Error Read(const HandleAttr& attr,
39                      void* buf,
40                      size_t count,
41                      int* out_bytes);
42   virtual Error Write(const HandleAttr& attr,
43                       const void* buf,
44                       size_t count,
45                       int* out_bytes);
46   virtual Error Fchmod(mode_t mode);
47
48   // Adds a finds or adds a directory entry as an INO, updating the refcount
49   virtual Error AddChild(const std::string& name, const ScopedNode& node);
50   virtual Error RemoveChild(const std::string& name);
51   virtual Error FindChild(const std::string& name, ScopedNode* out_node);
52   virtual int ChildCount();
53
54  protected:
55   void BuildCache_Locked();
56   void ClearCache_Locked();
57
58  private:
59   GetDentsHelper cache_;
60   NodeMap_t map_;
61   bool cache_built_;
62
63   friend class DevFs;
64   friend class Html5Fs;
65   friend class HttpFs;
66   friend class MemFs;
67 };
68
69 }  // namespace nacl_io
70
71 #endif  // LIBRARIES_NACL_IO_DIR_NODE_H_