StickerDatabase.hxx 4.43 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13
 * 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.
14 15 16 17
 *
 * 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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 */

/*
 * This is the sticker database library.  It is the backend of all the
 * sticker code in MPD.
 *
 * "Stickers" are pieces of information attached to existing MPD
 * objects (e.g. song files, directories, albums).  Clients can create
 * arbitrary name/value pairs.  MPD itself does not assume any special
 * meaning in them.
 *
 * The goal is to allow clients to share additional (possibly dynamic)
 * information about songs, which is neither stored on the client (not
 * available to other clients), nor stored in the song files (MPD has
 * no write access).
 *
 * Client developers should create a standard for common sticker
 * names, to ensure interoperability.
 *
 * Examples: song ratings; statistics; deferred tag writes; lyrics;
 * ...
 *
 */

Max Kellermann's avatar
Max Kellermann committed
42 43
#ifndef MPD_STICKER_DATABASE_HXX
#define MPD_STICKER_DATABASE_HXX
44

45
#include "Match.hxx"
46 47
#include "Compiler.h"

48 49
#include <string>

50
class Path;
51
struct Sticker;
52

53
/**
54
 * Opens the sticker database.
55
 *
56
 * Throws std::runtime_error on error.
57
 */
58 59
void
sticker_global_init(Path path);
60 61 62 63 64

/**
 * Close the sticker database.
 */
void
65
sticker_global_finish();
66 67 68 69

/**
 * Returns true if the sticker database is configured and available.
 */
70
gcc_const
71
bool
72
sticker_enabled();
73 74

/**
75 76
 * Returns one value from an object's sticker record.  Returns an
 * empty string if the value doesn't exist.
77 78
 *
 * Throws #SqliteError on error.
79
 */
80
std::string
81
sticker_load_value(const char *type, const char *uri, const char *name);
82 83 84 85

/**
 * Sets a sticker value in the specified object.  Overwrites existing
 * values.
86 87
 *
 * Throws #SqliteError on error.
88
 */
89
void
90
sticker_store_value(const char *type, const char *uri,
91
		    const char *name, const char *value);
92 93 94 95

/**
 * Deletes a sticker from the database.  All sticker values of the
 * specified object are deleted.
96 97
 *
 * Throws #SqliteError on error.
98 99
 */
bool
100
sticker_delete(const char *type, const char *uri);
101

102 103 104
/**
 * Deletes a sticker value.  Fails if no sticker with this name
 * exists.
105 106
 *
 * Throws #SqliteError on error.
107 108
 */
bool
109
sticker_delete_value(const char *type, const char *uri, const char *name);
110

111 112 113 114 115 116
/**
 * Frees resources held by the sticker object.
 *
 * @param sticker the sticker object to be freed
 */
void
117
sticker_free(Sticker *sticker);
118 119 120 121 122 123

/**
 * Determines a single value in a sticker.
 *
 * @param sticker the sticker object
 * @param name the name of the sticker
124
 * @return the sticker value, or nullptr if none was found
125
 */
126
gcc_pure
127
const char *
128
sticker_get_value(const Sticker &sticker, const char *name);
129 130 131 132 133 134 135 136 137

/**
 * Iterates over all sticker items in a sticker.
 *
 * @param sticker the sticker object
 * @param func a callback function
 * @param user_data an opaque pointer for the callback function
 */
void
138
sticker_foreach(const Sticker &sticker,
139
		void (*func)(const char *name, const char *value,
140 141
			     void *user_data),
		void *user_data);
142 143 144 145

/**
 * Loads the sticker for the specified resource.
 *
146 147
 * Throws #SqliteError on error.
 *
148 149
 * @param type the resource type, e.g. "song"
 * @param uri the URI of the resource, e.g. the song path
150
 * @return a sticker object, or nullptr if there is no sticker
151
 */
152
Sticker *
153
sticker_load(const char *type, const char *uri);
154

155 156 157 158
/**
 * Finds stickers with the specified name below the specified URI.
 *
 * @param type the resource type, e.g. "song"
159
 * @param base_uri the URI prefix of the resources, or nullptr if all
160 161
 * resources should be searched
 * @param name the name of the sticker
162 163
 * @param op the comparison operator
 * @param value the operand
164
 */
165
void
166
sticker_find(const char *type, const char *base_uri, const char *name,
167
	     StickerOperator op, const char *value,
168
	     void (*func)(const char *uri, const char *value,
169
			  void *user_data),
170
	     void *user_data);
171

172
#endif