2012-02-11 19:12:02 +01:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 The Music Player Daemon Project
|
2012-02-11 19:12:02 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-07-29 07:32:36 +02:00
|
|
|
#ifndef MPD_TAG_HANDLER_HXX
|
|
|
|
#define MPD_TAG_HANDLER_HXX
|
2012-02-11 19:12:02 +01:00
|
|
|
|
|
|
|
#include "check.h"
|
2013-07-30 20:10:24 +02:00
|
|
|
#include "TagType.h"
|
2014-08-29 22:43:36 +02:00
|
|
|
#include "Chrono.hxx"
|
2012-02-11 19:12:02 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A callback table for receiving metadata of a song.
|
|
|
|
*/
|
|
|
|
struct tag_handler {
|
|
|
|
/**
|
2014-08-29 22:43:36 +02:00
|
|
|
* Declare the duration of a song. Do not call
|
2012-02-11 19:12:02 +01:00
|
|
|
* this when the duration could not be determined, because
|
|
|
|
* there is no magic value for "unknown duration".
|
|
|
|
*/
|
2014-08-29 22:43:36 +02:00
|
|
|
void (*duration)(SongTime duration, void *ctx);
|
2012-02-11 19:12:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A tag has been read.
|
|
|
|
*
|
|
|
|
* @param the value of the tag; the pointer will become
|
|
|
|
* invalid after returning
|
|
|
|
*/
|
2013-10-20 13:32:59 +02:00
|
|
|
void (*tag)(TagType type, const char *value, void *ctx);
|
2012-02-11 19:24:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A name-value pair has been read. It is the codec specific
|
|
|
|
* representation of tags.
|
|
|
|
*/
|
|
|
|
void (*pair)(const char *key, const char *value, void *ctx);
|
2012-02-11 19:12:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
tag_handler_invoke_duration(const struct tag_handler *handler, void *ctx,
|
2014-08-29 22:43:36 +02:00
|
|
|
SongTime duration)
|
2012-02-11 19:12:02 +01:00
|
|
|
{
|
2013-07-29 07:32:36 +02:00
|
|
|
assert(handler != nullptr);
|
2012-02-11 19:12:02 +01:00
|
|
|
|
2013-07-29 07:32:36 +02:00
|
|
|
if (handler->duration != nullptr)
|
2014-08-29 22:43:36 +02:00
|
|
|
handler->duration(duration, ctx);
|
2012-02-11 19:12:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
tag_handler_invoke_tag(const struct tag_handler *handler, void *ctx,
|
2013-10-20 13:32:59 +02:00
|
|
|
TagType type, const char *value)
|
2012-02-11 19:12:02 +01:00
|
|
|
{
|
2013-07-29 07:32:36 +02:00
|
|
|
assert(handler != nullptr);
|
2012-02-11 19:12:02 +01:00
|
|
|
assert((unsigned)type < TAG_NUM_OF_ITEM_TYPES);
|
2013-07-29 07:32:36 +02:00
|
|
|
assert(value != nullptr);
|
2012-02-11 19:12:02 +01:00
|
|
|
|
2013-07-29 07:32:36 +02:00
|
|
|
if (handler->tag != nullptr)
|
2012-02-11 19:12:02 +01:00
|
|
|
handler->tag(type, value, ctx);
|
|
|
|
}
|
|
|
|
|
2012-02-11 19:24:51 +01:00
|
|
|
static inline void
|
|
|
|
tag_handler_invoke_pair(const struct tag_handler *handler, void *ctx,
|
|
|
|
const char *name, const char *value)
|
|
|
|
{
|
2013-07-29 07:32:36 +02:00
|
|
|
assert(handler != nullptr);
|
|
|
|
assert(name != nullptr);
|
|
|
|
assert(value != nullptr);
|
2012-02-11 19:24:51 +01:00
|
|
|
|
2013-07-29 07:32:36 +02:00
|
|
|
if (handler->pair != nullptr)
|
2012-02-11 19:24:51 +01:00
|
|
|
handler->pair(name, value, ctx);
|
|
|
|
}
|
|
|
|
|
2012-02-11 19:12:02 +01:00
|
|
|
/**
|
2013-09-05 19:11:50 +02:00
|
|
|
* This #tag_handler implementation adds tag values to a #TagBuilder object
|
2012-02-11 19:12:02 +01:00
|
|
|
* (casted from the context pointer).
|
|
|
|
*/
|
|
|
|
extern const struct tag_handler add_tag_handler;
|
|
|
|
|
2012-02-12 18:25:10 +01:00
|
|
|
/**
|
2013-09-05 19:11:50 +02:00
|
|
|
* This #tag_handler implementation adds tag values to a #TagBuilder object
|
2012-02-12 18:25:10 +01:00
|
|
|
* (casted from the context pointer), and supports the has_playlist
|
|
|
|
* attribute.
|
|
|
|
*/
|
|
|
|
extern const struct tag_handler full_tag_handler;
|
|
|
|
|
2012-02-11 19:12:02 +01:00
|
|
|
#endif
|