Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / modules / API / Filesystem / INode.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_INODE_H_
17 #define WRTDEVICEAPIS_FILESYSTEM_INODE_H_
18
19 #include <string>
20 #include <vector>
21 #include <ctime>
22 #include <dpl/noncopyable.h>
23 #include <dpl/shared_ptr.h>
24 #include <Commons/EventReceiver.h>
25 #include "EventListNodes.h"
26 #include "EventOpen.h"
27 #include "EventReadText.h"
28 #include "Enums.h"
29 #include "IPath.h"
30 #include "IStream.h"
31 #include "INodeTypes.h"
32 #include "NodeFilter.h"
33
34 namespace WrtDeviceApis {
35 namespace Filesystem {
36 namespace Api {
37 class INode :
38     public Commons::EventRequestReceiver<EventListNodes>,
39     public Commons::EventRequestReceiver<EventOpen>,
40     public Commons::EventRequestReceiver<EventReadText>
41 {
42   public:
43     typedef std::vector<std::string> NameList;
44     typedef NameList::iterator NodeListIterator;
45
46   public:
47     virtual ~INode() = 0;
48
49     /**
50      * Gets direct child of this node.
51      * @param path Path to the child node.
52      * @return Ptr to the child node.
53      * @remarks Ownership passed to the caller.
54      */
55     virtual INodePtr getChild(const IPathPtr& path) = 0;
56
57     /**
58      * Gets path of current node.
59      * @return Node's path.
60      */
61     virtual IPathPtr getPath() const = 0;
62
63     /**
64      * Gets type of current node.
65      * @return Node's type.
66      */
67     virtual NodeType getType() const = 0;
68
69     /**
70      * Gets permissions of the virtual node (not real filesystem node).
71      * @return Node's permissions.
72      */
73     virtual int getPermissions() const = 0;
74
75     /**
76      * Sets permissions on the virtual node (not real filesystem node).
77      * @param perms Node's permissions @see Api::Filesystem::Permissions.
78      */
79     virtual void setPermissions(int perms) = 0;
80
81     /**
82      * Gets list of names of direct child nodes.
83      * @return Names of child nodes.
84      */
85     virtual NameList getChildNames() const = 0;
86
87     /**
88      * Gets list of direct child nodes.
89      * @return Child nodes.
90      * @remarks Ownership passed to the caller.
91      * @deprecated
92      */
93     virtual NodeList getChildNodes(const NodeFilterPtr& filter =
94                                        NodeFilterPtr()) const /*DEPREC*/ = 0;
95
96     /**
97      * Gets list of direct descendant nodes.
98      * @param event Get child nodes event.
99      */
100     virtual void getChildNodes(const EventListNodesPtr& event) = 0;
101
102     /**
103      * Gets stream for this node.
104      * @param mode @see Api::Filesystem::AccessMode.
105      * @return Stream connected with current node.
106      * @deprecated Use async version of thi method instead.
107      */
108     virtual IStreamPtr open(int mode) = 0;
109
110     /**
111      * Gets stream for this node.
112      * @param mode @see Api::Filesystem::AccessMode.
113      * @return Stream connected with current node.
114      */
115     virtual void open(const EventOpenPtr& event) = 0;
116
117     /**
118      * Removes underlying filesystem node.
119      * @param options Removal options (by default removal is recursive).
120      * @remarks Synchronous.
121      * Valid options:
122      * - OPT_RECURSIVE - remove node recursively.
123      */
124     virtual void remove(int options = OPT_RECURSIVE) = 0;
125
126     /**
127      * Creates child of current node.
128      * @param path Path to the node to create.
129      * @param type Type of the node @see Api::Filesystem::NodeType.
130      * @param options Additional options see remarks (no options by default).
131      * @return Ptr to newly created node.
132      * @remarks
133      * Valid options:
134      * - OPT_RECURSIVE - attempt to create all necessary sub-directories
135      */
136     virtual INodePtr createChild(const IPathPtr& path,
137                                  NodeType type,
138                                  int options = OPT_NONE) = 0;
139
140     /**
141      * Gets size of this node.
142      * @return Size.
143      */
144     virtual std::size_t getSize() const = 0;
145
146     /**
147      * Gets creation date of this node.
148      * @return Date.
149      */
150     virtual std::time_t getCreated() const = 0;
151
152     /**
153      * Gets last modification date of this node.
154      * @return Date.
155      */
156     virtual std::time_t getModified() const = 0;
157
158     /**
159      * Gets parent of this node.
160      * @return Parent node or NULL if no parent (e.g. in case of a root node).
161      */
162     virtual INodePtr getParent() const = 0;
163
164     /**
165      * Gets platform permissions.
166      * @return Platform permissions (set of flags from @see Permissions enum).
167      */
168     virtual int getMode() const = 0;
169
170     /**
171      * Reads whole file as text.
172      * @param event Read file event.
173      */
174     virtual void read(const EventReadTextPtr& event) = 0;
175
176     virtual std::string toUri(int widgetId) const = 0;
177
178   protected:
179     INode();
180 };
181 } // API
182 } // Filesystem
183 } // WrtDeviceApis
184
185 #endif /* WRTDEVICEAPIS_FILESYSTEM_INODE_H_ */