summaryrefslogtreecommitdiff
path: root/wearable_src/Filesystem/Manager.h
diff options
context:
space:
mode:
Diffstat (limited to 'wearable_src/Filesystem/Manager.h')
-rwxr-xr-xwearable_src/Filesystem/Manager.h189
1 files changed, 189 insertions, 0 deletions
diff --git a/wearable_src/Filesystem/Manager.h b/wearable_src/Filesystem/Manager.h
new file mode 100755
index 0000000..47b6ea9
--- /dev/null
+++ b/wearable_src/Filesystem/Manager.h
@@ -0,0 +1,189 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_FILESYSTEMMANAGER_H_
+#define TIZENAPIS_FILESYSTEMMANAGER_H_
+
+#include <string>
+#include <map>
+#include <vector>
+#include <cstddef>
+#include <dpl/shared_ptr.h>
+#include "IManager.h"
+#include "IPath.h"
+#include <appfw/app_storage.h>
+#include "Node.h"
+#include "Path.h"
+
+namespace DeviceAPI {
+namespace Filesystem {
+class Manager : public IManager
+{
+ public:
+ /**
+ * Checks if file exists.
+ * @param real file path.
+ * @return true when file exists, false otherwise.
+ * @throw PlatformException If unable to validate if file exists.
+ */
+ static bool fileExists(const std::string &file);
+ static bool getSupportedDeviceCB(int storage, storage_type_e type, storage_state_e state, const char *path, void *user_data);
+ static void storageStateChangedCB(int storage, storage_state_e state, void *user_data);
+
+ public:
+ Manager();
+ ~Manager();
+
+ IPathPtr getBasePath() const;
+
+ StorageList getStorageList() const;
+
+ IPathPtr getLocationPath(
+ LocationType type) const;
+
+ LocationPaths getLocationPaths() const;
+
+ LocationTypes getLocations() const;
+
+ void getNode(const EventResolvePtr& event);
+
+ void getStorage(const EventGetStoragePtr& event);
+
+ void listStorages(const EventListStoragesPtr& event);
+
+ std::size_t getMaxPathLength() const;
+
+ void copy(const EventCopyPtr& event);
+
+ void move(const EventMovePtr& event);
+
+ void create(const EventCreatePtr& event);
+
+ void remove(const EventRemovePtr& event);
+
+ void find(const EventFindPtr& event);
+
+ /**
+ * Finds files in the filesystem whish match specified filters.
+ * @param path Starting path.
+ * @param filter Filters @see FindFilters.
+ * @param result List with found files.
+ * @param event DPL event, if set then search process can be cancelled
+ * @remarks For filter FF_NAME value is treated as perl like regex pattern.
+ * Use @Regex::escpae() if you want to treat it as normal string.
+ */
+ void find(
+ const IPathPtr& path,
+ const FiltersMap& filter,
+ NodeList& result,
+ const EventFindPtr& event =
+ EventFindPtr(NULL));
+
+ /**
+ * @warning Operates on specified as it is - it DOES NOT take its real path.
+ * This is because all filesystem operation will probably change
+ * their approach to real path and will allow to refer to nodes
+ * only by virtual roots.
+ */
+/* bool access(const IPathPtr& path,
+ int accessType) const;*/
+
+ void addOpenedNode(const INodePtr& node);
+ void removeOpenedNode(const INodePtr& node);
+ bool checkIfOpened(const IPathPtr& path) const;
+
+ long addStorageStateChangeListener(const EventStorageStateChangedEmitterPtr& emitter);
+ void removeStorageStateChangeListener(EventStorageStateChangedEmitter::IdType id);
+
+public :
+ class Watcher
+ {
+ private:
+ EventStorageStateChangedEmitterPtr m_emitter;
+
+ public:
+ Watcher(const EventStorageStateChangedEmitterPtr& emitter) :
+ m_emitter(emitter)
+ {
+ }
+
+ EventStorageStateChangedEmitterPtr getEmitter()
+ {
+ return m_emitter;
+ }
+
+ void emit(const EventStorageStateChangedPtr& event)
+ {
+ m_emitter->emit(event);
+ }
+ void getCurrentStoargeStateForWatch();
+ void StorageStateHasChanged(int storage, storage_state_e state);
+ };
+ typedef DPL::SharedPtr<Watcher> WatcherPtr;
+
+ protected:
+ bool matchFilters(const std::string& name,
+ const struct stat& info,
+ const FiltersMap& filter);
+
+ void OnRequestReceived(const EventResolvePtr& event);
+ void OnRequestReceived(const EventGetStoragePtr& event);
+ void OnRequestReceived(const EventListStoragesPtr& event);
+ void OnRequestReceived(const EventCopyPtr& event);
+ void OnRequestReceived(const EventMovePtr& event);
+ void OnRequestReceived(const EventCreatePtr& event);
+ void OnRequestReceived(const EventRemovePtr& event);
+ void OnRequestReceived(const EventFindPtr& event);
+
+ void addLocalStorage(std::string label, std::vector<StoragePropertiesPtr> &storageList);
+ void addWidgetStorage(const std::string &key, const std::string &value);
+ private:
+ typedef std::map<std::string,
+ IPathPtr> Locations;
+
+ typedef std::map<std::string, int> RootList;
+ typedef std::map<LocationType, std::string> SubRootList;
+ private:
+ /**
+ * Initializes statics of Manager class.
+ * Used only internally.
+ * @return True on success, false otherwsie.
+ */
+ static bool init();
+ static void setupLocation(std::string location, const char* path);
+
+ void copyElement(const std::string &src,
+ const std::string &dest,
+ bool recursive = true) const;
+
+
+ private:
+ static RootList m_rootlist;
+ static SubRootList m_subrootlist;
+ static Locations m_locations; ///< Paths to default locations.
+ static const std::size_t m_maxPathLength; ///< Maximum path length.
+ static NodeList m_openedNodes; ///< List of nodes that has opened streams.
+
+public:
+ typedef std::vector<WatcherPtr> watcherList;
+ static watcherList m_watchers;
+};
+} // Filesystem
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEMMANAGER_H_ \ No newline at end of file