Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Filesystem / Manager.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_MANAGER_H_
17 #define WRTDEVICEAPIS_FILESYSTEM_MANAGER_H_
18
19 #include <map>
20 #include <vector>
21 #include <cstddef>
22 #include <dpl/shared_ptr.h>
23 #include <Filesystem/IManager.h>
24 #include <Filesystem/IPath.h>
25 #include "Node.h"
26 #include "Path.h"
27
28 namespace WrtDeviceApis {
29 namespace Filesystem {
30
31 class Manager : public Api::IManager
32 {
33   public:
34     /**
35      * Checks if file exists.
36      * @param real file path.
37      * @return true when file exists, false otherwise.
38      * @throw PlatformException If unable to validate if file exists.
39      */
40     static bool fileExists(const std::string &file);
41
42   public:
43     Manager();
44     ~Manager();
45
46     Api::IPathPtr getBasePath() const;
47
48     Api::IPathPtr getLocationPath(Api::LocationType type) const;
49
50     Api::LocationPaths getLocationPaths() const;
51
52     Api::LocationTypes getLocations() const;
53
54     void getNode(const Api::EventResolvePtr& event);
55
56     std::size_t getMaxPathLength() const;
57
58     void copy(const Api::EventCopyPtr& event);
59
60     void move(const Api::EventMovePtr& event);
61
62     void remove(const Api::EventRemovePtr& event);
63
64     void find(const Api::EventFindPtr& event);
65
66     /**
67      * Finds files in the filesystem whish match specified filters.
68      * @param path Starting path.
69      * @param filter Filters @see FindFilters.
70      * @param result List with found files.
71      * @param event DPL event, if set then search process can be cancelled
72      * @remarks For filter FF_NAME value is treated as perl like regex pattern.
73      *          Use @Regex::escpae() if you want to treat it as normal string.
74      */
75     void find(const Api::IPathPtr& path,
76               const Api::FiltersMap& filter,
77               Api::NodeList& result,
78               const Api::EventFindPtr& event = Api::EventFindPtr(NULL));
79
80     /**
81      * @warning Operates on specified as it is - it DOES NOT take its real path.
82      *          This is because all filesystem operation will probably change
83      *          their approach to real path and will allow to refer to nodes
84      *          only by virtual roots.
85      */
86     bool access(const Api::IPathPtr& path,
87             int accessType) const;
88
89     void addOpenedNode(const Api::INodePtr& node);
90     void removeOpenedNode(const Api::INodePtr& node);
91     bool checkIfOpened(const Api::IPathPtr& path) const;
92
93   protected:
94     bool matchFilters(const std::string& name,
95             const struct stat& info,
96             const Api::FiltersMap& filter);
97
98     void OnRequestReceived(const Api::EventResolvePtr& event);
99     void OnRequestReceived(const Api::EventCopyPtr& event);
100     void OnRequestReceived(const Api::EventMovePtr& event);
101     void OnRequestReceived(const Api::EventRemovePtr& event);
102     void OnRequestReceived(const Api::EventFindPtr& event);
103
104   private:
105     typedef std::map<Api::LocationType, Api::IPathPtr> Locations;
106
107   private:
108     /**
109      * Initializes statics of Manager class.
110      * Used only internally.
111      * @return True on success, false otherwsie.
112      */
113     static bool init();
114
115     static void setupLocation(Api::LocationType location,
116                               const char* path);
117
118     void copyElement(const std::string &src,
119                      const std::string &dest,
120                      bool recursive = true) const;
121
122   private:
123     static Locations m_locations; ///< Paths to default locations.
124     static const std::size_t m_maxPathLength; ///< Maximum path length.
125     static Api::NodeList m_openedNodes; ///< List of nodes that has opened streams.
126 };
127
128 } // Filesystem
129 } // WrtDeviceApis
130
131 #endif // WRTDEVICEAPIS_FILESYSTEM_MANAGER_H_