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 {
31 class Manager : public Api::IManager
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.
40 static bool fileExists(const std::string &file);
46 Api::IPathPtr getBasePath() const;
48 Api::IPathPtr getLocationPath(Api::LocationType type) const;
50 Api::LocationPaths getLocationPaths() const;
52 Api::LocationTypes getLocations() const;
54 void getNode(const Api::EventResolvePtr& event);
56 std::size_t getMaxPathLength() const;
58 void copy(const Api::EventCopyPtr& event);
60 void move(const Api::EventMovePtr& event);
62 void remove(const Api::EventRemovePtr& event);
64 void find(const Api::EventFindPtr& event);
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.
75 void find(const Api::IPathPtr& path,
76 const Api::FiltersMap& filter,
77 Api::NodeList& result,
78 const Api::EventFindPtr& event = Api::EventFindPtr(NULL));
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.
86 bool access(const Api::IPathPtr& path,
87 int accessType) const;
89 void addOpenedNode(const Api::INodePtr& node);
90 void removeOpenedNode(const Api::INodePtr& node);
91 bool checkIfOpened(const Api::IPathPtr& path) const;
94 bool matchFilters(const std::string& name,
95 const struct stat& info,
96 const Api::FiltersMap& filter);
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);
105 typedef std::map<Api::LocationType, Api::IPathPtr> Locations;
109 * Initializes statics of Manager class.
110 * Used only internally.
111 * @return True on success, false otherwsie.
115 static void setupLocation(Api::LocationType location,
119 static Locations m_locations; ///< Paths to default locations.
120 static const std::size_t m_maxPathLength; ///< Maximum path length.
121 static Api::NodeList m_openedNodes; ///< List of nodes that has opened streams.
127 #endif // WRTDEVICEAPIS_FILESYSTEM_MANAGER_H_