Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / modules / tizen / Filesystem / Node.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 #ifndef WRTDEVICEAPIS_FILESYSTEM_NODE_H_
17 #define WRTDEVICEAPIS_FILESYSTEM_NODE_H_
18
19 #include <ctime>
20 #include <cstddef>
21 #include <sys/stat.h>
22 #include <set>
23 #include <dpl/shared_ptr.h>
24 #include <dpl/enable_shared_from_this.h>
25 #include <dpl/mutex.h>
26
27 #include <Filesystem/Enums.h>
28 #include <Filesystem/INode.h>
29 #include "Path.h"
30 #include "Stream.h"
31
32 namespace WrtDeviceApis {
33 namespace Filesystem {
34 class Node :
35     public Api::INode,
36     public DPL::EnableSharedFromThis<Node>
37 {
38   public:
39     static Api::INodePtr resolve(const Api::IPathPtr& path);
40
41   public:
42     Api::IPathPtr getPath() const;
43     Api::NodeType getType() const;
44     int getPermissions() const;
45     void setPermissions(int perms);
46     std::size_t getSize() const;
47     std::time_t getCreated() const;
48     std::time_t getModified() const;
49     Api::INodePtr getParent() const;
50     int getMode() const;
51
52     Api::INodePtr getChild(const Api::IPathPtr& path);
53     NameList getChildNames() const;
54     Api::NodeList getChildNodes(
55         const Api::NodeFilterPtr& filter = Api::NodeFilterPtr()) const;
56     void getChildNodes(const Api::EventListNodesPtr& event);
57     Api::INodePtr createChild(const Api::IPathPtr & path,
58                               Api::NodeType,
59                               int options);
60     Api::IStreamPtr open(int mode);
61     void open(const Api::EventOpenPtr& event);
62     void remove(int options);
63     void read(const Api::EventReadTextPtr& event);
64
65     void onStreamClose(const StreamPtr& stream);
66
67   private:
68     typedef std::set<StreamPtr> StreamList;
69
70   private:
71     static bool exists(const Api::IPathPtr& path);
72     static struct stat stat(const Api::IPathPtr& path);
73
74   private:
75     Node(const Api::IPathPtr& path, Api::NodeType type);
76
77     Node* createAsFile(const Api::IPathPtr& path,
78                        int options);
79     void createAsFileInternal(const Api::IPathPtr& path);
80
81     Node* createAsDirectory(const Api::IPathPtr& path,
82                             int options);
83     void createAsDirectoryInternal(const Api::IPathPtr& path);
84
85     void removeAsFile(const Api::IPathPtr& path);
86     void removeAsDirectory(const Api::IPathPtr& path,
87                            bool recursive);
88
89     void OnRequestReceived(const Api::EventListNodesPtr& event);
90     void OnRequestReceived(const Api::EventOpenPtr& event);
91
92     void OnRequestReceived(const Api::EventReadTextPtr& event);
93     std::string readText();
94
95     std::string toUri(int widgetId) const;
96
97   private:
98     Api::IPathPtr m_path;
99     Api::NodeType m_type;
100     int m_perms;
101     StreamList m_openStreams;
102     mutable DPL::Mutex m_openStreamsMutex;
103 };
104
105 typedef DPL::SharedPtr<Node> NodePtr;
106 } // Filesystem
107 } // WrtDeviceApis
108
109 #endif /* WRTDEVICEAPIS_FILESYSTEM_NODE_H_ */