| 1 |
/* |
| 2 |
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2024 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 23 окт. 2020 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_IO_ILOADER_H_ |
| 23 |
#define LSP_PLUG_IN_IO_ILOADER_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/resource/types.h> |
| 27 |
#include <lsp-plug.in/io/IInSequence.h> |
| 28 |
#include <lsp-plug.in/io/IInStream.h> |
| 29 |
#include <lsp-plug.in/io/Path.h> |
| 30 |
|
| 31 |
namespace lsp |
| 32 |
{ |
| 33 |
namespace resource |
| 34 |
{ |
| 35 |
/** |
| 36 |
* Interface that allows to resolve the resource name and open input stream/sequence |
| 37 |
* By default works like just a factory to the input file stream and input file sequence |
| 38 |
*/ |
| 39 |
class ILoader |
| 40 |
{ |
| 41 |
protected: |
| 42 |
status_t nError; |
| 43 |
|
| 44 |
public: |
| 45 |
explicit ILoader(); |
| 46 |
ILoader(const ILoader &) = delete; |
| 47 |
ILoader(ILoader &&) = delete; |
| 48 |
virtual ~ILoader(); |
| 49 |
|
| 50 |
ILoader & operator = (const ILoader &) = delete; |
| 51 |
ILoader & operator = (ILoader &&) = delete; |
| 52 |
|
| 53 |
protected: |
| 54 |
inline status_t set_error(status_t error) { return nError = error; } |
| 55 |
|
| 56 |
public: |
| 57 |
inline status_t last_error() const { return nError; } |
| 58 |
|
| 59 |
/** |
| 60 |
* Read contents of the resource associated with the name. Should be thread-safe to produce streams as it |
| 61 |
* can be shared across different modules in different threads. |
| 62 |
* |
| 63 |
* @param name name of resource |
| 64 |
* @return pointer to opened stream or NULL and error code is set |
| 65 |
*/ |
| 66 |
virtual io::IInStream *read_stream(const char *name); |
| 67 |
virtual io::IInStream *read_stream(const LSPString *name); |
| 68 |
|
| 69 |
/** |
| 70 |
* Read contents of the resource associated with the name. Should be thread-safe to produce streams as it |
| 71 |
* can be shared across different modules in different threads. |
| 72 |
* |
| 73 |
* @note This is the main method to be overloaded. |
| 74 |
* |
| 75 |
* @param name name of resource |
| 76 |
* @return pointer to opened stream or NULL and error code is set |
| 77 |
*/ |
| 78 |
virtual io::IInStream *read_stream(const io::Path *name); |
| 79 |
|
| 80 |
/** |
| 81 |
* Read contents of the resource associated with the name. Should be thread-safe to produce streams as it |
| 82 |
* can be shared across different modules in different threads. |
| 83 |
* |
| 84 |
* @param name name of resource |
| 85 |
* @return pointer to opened stream or NULL and error code is set |
| 86 |
*/ |
| 87 |
virtual io::IInSequence *read_sequence(const char *name, const char *charset = NULL); |
| 88 |
virtual io::IInSequence *read_sequence(const LSPString *name, const char *charset = NULL); |
| 89 |
virtual io::IInSequence *read_sequence(const io::Path *name, const char *charset = NULL); |
| 90 |
|
| 91 |
/** |
| 92 |
* Enumerate resources. Should be thread-safe as it can be called from different threads sharing the |
| 93 |
* same resource. |
| 94 |
* |
| 95 |
* @param path the location of resources within resource tree |
| 96 |
* @param list pointer to store list of resources. Resources should be |
| 97 |
* free()'d by caller after use |
| 98 |
* @return number of resources in list or negative error code |
| 99 |
*/ |
| 100 |
virtual ssize_t enumerate(const char *path, resource_t **list); |
| 101 |
virtual ssize_t enumerate(const LSPString *path, resource_t **list); |
| 102 |
virtual ssize_t enumerate(const io::Path *path, resource_t **list); |
| 103 |
}; |
| 104 |
} /* namespace resource */ |
| 105 |
} /* namespace lsp */ |
| 106 |
|
| 107 |
|
| 108 |
#endif /* LSP_PLUG_IN_IO_ILOADER_H_ */ |