2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef WRTDEVICEAPIS_FILESYSTEM_MANAGER_H_
17 #define WRTDEVICEAPIS_FILESYSTEM_MANAGER_H_
22 #include <dpl/shared_ptr.h>
23 #include <Filesystem/IManager.h>
24 #include <Filesystem/IPath.h>
28 namespace WrtDeviceApis {
29 namespace Filesystem {
30 class Manager : public Api::IManager
34 * Checks if file exists.
35 * @param real file path.
36 * @return true when file exists, false otherwise.
37 * @throw PlatformException If unable to validate if file exists.
39 static bool fileExists(const std::string &file);
45 Api::IPathPtr getBasePath() const;
47 Api::IPathPtr getLocationPath(Api::LocationType type) const;
49 Api::LocationPaths getLocationPaths() const;
51 Api::LocationTypes getLocations() const;
53 void getNode(const Api::EventResolvePtr& event);
55 std::size_t getMaxPathLength() const;
57 void copy(const Api::EventCopyPtr& event);
59 void move(const Api::EventMovePtr& event);
61 void remove(const Api::EventRemovePtr& event);
63 void find(const Api::EventFindPtr& event);
66 * Finds files in the filesystem whish match specified filters.
67 * @param path Starting path.
68 * @param filter Filters @see FindFilters.
69 * @param result List with found files.
70 * @param event DPL event, if set then search process can be cancelled
71 * @remarks For filter FF_NAME value is treated as perl like regex pattern.
72 * Use @Regex::escpae() if you want to treat it as normal string.
74 void find(const Api::IPathPtr& path,
75 const Api::FiltersMap& filter,
76 Api::NodeList& result,
77 const Api::EventFindPtr& event = Api::EventFindPtr(NULL));
80 * @warning Operates on specified as it is - it DOES NOT take its real path.
81 * This is because all filesystem operation will probably change
82 * their approach to real path and will allow to refer to nodes
83 * only by virtual roots.
85 bool access(const Api::IPathPtr& path,
86 int accessType) const;
88 void addOpenedNode(const Api::INodePtr& node);
89 void removeOpenedNode(const Api::INodePtr& node);
90 bool checkIfOpened(const Api::IPathPtr& path) const;
93 bool matchFilters(const std::string& name,
94 const struct stat& info,
95 const Api::FiltersMap& filter);
97 void OnRequestReceived(const Api::EventResolvePtr& event);
98 void OnRequestReceived(const Api::EventCopyPtr& event);
99 void OnRequestReceived(const Api::EventMovePtr& event);
100 void OnRequestReceived(const Api::EventRemovePtr& event);
101 void OnRequestReceived(const Api::EventFindPtr& event);
104 typedef std::map<Api::LocationType, Api::IPathPtr> Locations;
108 * Initializes statics of Manager class.
109 * Used only internally.
110 * @return True on success, false otherwsie.
114 static void setupLocation(Api::LocationType location,
117 void copyElement(const std::string &src,
118 const std::string &dest,
119 bool recursive = true) const;
122 * Check two paths to copy/move. Checks if they are not the same and
123 * required permissions.
127 void checkPaths(Api::IPathPtr &src, Api::IPathPtr &dest);
128 bool pathExists(const std::string &path);
131 static Locations m_locations; ///< Paths to default locations.
132 static const std::size_t m_maxPathLength; ///< Maximum path length.
133 static Api::NodeList m_openedNodes; ///< List of nodes that has opened
139 #endif // WRTDEVICEAPIS_FILESYSTEM_MANAGER_H_