StorageInterface.hxx 2.4 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef MPD_STORAGE_INTERFACE_HXX
#define MPD_STORAGE_INTERFACE_HXX

23
#include "util/Compiler.h"
24

25
#include <memory>
26 27
#include <string>

28
struct StorageFileInfo;
29 30 31 32
class AllocatedPath;

class StorageDirectoryReader {
public:
33 34
	StorageDirectoryReader() = default;
	StorageDirectoryReader(const StorageDirectoryReader &) = delete;
35
	virtual ~StorageDirectoryReader() noexcept {}
36

37
	virtual const char *Read() noexcept = 0;
38 39 40 41 42

	/**
	 * Throws #std::runtime_error on error.
	 */
	virtual StorageFileInfo GetInfo(bool follow) = 0;
43 44 45 46
};

class Storage {
public:
47 48
	Storage() = default;
	Storage(const Storage &) = delete;
49
	virtual ~Storage() noexcept {}
50

51 52 53 54
	/**
	 * Throws #std::runtime_error on error.
	 */
	virtual StorageFileInfo GetInfo(const char *uri_utf8, bool follow) = 0;
55

56 57 58
	/**
	 * Throws #std::runtime_error on error.
	 */
59
	virtual std::unique_ptr<StorageDirectoryReader> OpenDirectory(const char *uri_utf8) = 0;
60 61 62 63 64

	/**
	 * Map the given relative URI to an absolute URI.
	 */
	gcc_pure
65
	virtual std::string MapUTF8(const char *uri_utf8) const noexcept = 0;
66 67 68

	/**
	 * Map the given relative URI to a local file path.  Returns
69
	 * nullptr on error or if this storage does not
70 71 72
	 * support local files.
	 */
	gcc_pure
73
	virtual AllocatedPath MapFS(const char *uri_utf8) const noexcept;
74 75 76

	gcc_pure
	AllocatedPath MapChildFS(const char *uri_utf8,
77
				 const char *child_utf8) const noexcept;
78 79 80 81 82 83 84

	/**
	 * Check if the given URI points inside this storage.  If yes,
	 * then it returns a relative URI (pointing inside the given
	 * string); if not, returns nullptr.
	 */
	gcc_pure
85
	virtual const char *MapToRelativeUTF8(const char *uri_utf8) const noexcept = 0;
86 87 88
};

#endif