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