Skip to content

Commit

Permalink
Added server commands to get tags for a file. Tags are read in a sepa…
Browse files Browse the repository at this point in the history
…rate

thredad and are returned when available as an event, so a request for tags
does not block. At the servrer side tags are stored in the cache.


git-svn-id: svn://svn.daper.net/moc/trunk@1460 910807d9-36e0-0310-a014-e9ea483e2ba4
  • Loading branch information
daper committed Jun 23, 2005
1 parent 39490ef commit 86dbd59
Show file tree
Hide file tree
Showing 13 changed files with 696 additions and 55 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ mocp_SOURCES = log.c \
audio_conversion.c \
audio_conversion.h \
rbtree.c \
rbtree.h
rbtree.h \
tags_cache.c \
tags_cache.h
EXTRA_mocp_SOURCES = gnugetopt.h \
getopt.c \
getopt1.c \
Expand Down
3 changes: 3 additions & 0 deletions config.example
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,6 @@ ASCIILines = no
# to set such a priority. This could be dangerous, because it is possible that
# a bug in MOC will freeze your computer.
#UseRealtimePriority = no

# Size of the in-memory cache for file tags in KB.
TagsCacheSize = 128
5 changes: 3 additions & 2 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,10 @@ static int get_file_time_server (const char *file)
{
int t;

send_int_to_srv (CMD_GET_FTIME);
/*send_int_to_srv (CMD_GET_FTIME);
send_str_to_srv (file);
t = get_data_int ();
t = get_data_int ();*/
t = -1;

debug ("Server time for %s: %d", file, t);
return t;
Expand Down
5 changes: 5 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ void options_init ()
option_add_int ("ForceSampleRate", 0);
option_add_str ("HTTPProxy", NULL);
option_add_int ("UseRealtimePriority", 0);
option_add_int ("TagsCacheSize", 256);
}

/* Return 1 if a parameter to an integer option is valid. */
Expand Down Expand Up @@ -233,6 +234,10 @@ int check_int_option (const char *name, const int val)
if (val < 0 || val > 500000)
return 0;
}
else if (strcasecmp(name, "TagsCacheSize")) {
if (val < 0)
return 0;
}
return 1;
}

Expand Down
15 changes: 15 additions & 0 deletions playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ struct file_tags *tags_dup (const struct file_tags *tags)
return dtags;
}

/* Return the number of butes allocated for the tags structure. */
size_t tags_mem (const struct file_tags *tags)
{
size_t s = sizeof(tags);

if (tags->title)
s += strlen (tags->title) + 1;
if (tags->album)
s += strlen (tags->album) + 1;
if (tags->artist)
s += strlen (tags->artist) + 1;

return s;
}

static int rb_compare (const void *a, const void *b, void *adata)
{
struct plist *plist = (struct plist *)adata;
Expand Down
1 change: 1 addition & 0 deletions playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ int plist_find_fname (struct plist *plist, const char *file);
struct file_tags *tags_new ();
void tags_clear (struct file_tags *tags);
void tags_copy (struct file_tags *dst, const struct file_tags *src);
size_t tags_mem (const struct file_tags *tags);
struct file_tags *tags_dup (const struct file_tags *tags);
void tags_free (struct file_tags *tags);
char *build_title (const struct file_tags *tags);
Expand Down
3 changes: 1 addition & 2 deletions playlist_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,12 @@ int plist_save (struct plist *plist, const char *file, const char *cwd)
* relative paths) */
find_common_path (common_path, sizeof(common_path), plist);

make_titles_tags (plist);

if (user_wants_interrupt()) {
error ("Saving the playlist aborted");
return 0;
}

/* TODO: this should be done before we save the playlist */
/* Get times */
for (i = 0; i < plist->num; i++)
if (!plist_deleted(plist, i)) {
Expand Down
51 changes: 34 additions & 17 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,27 @@ struct event *event_get_first (struct event_queue *q)
return q->head;
}

/* Free data associated with the event if any. */
static void free_event_data (struct event *e)
{
if (e->type == EV_PLIST_ADD) {
plist_free_item_fields (e->data);
free (e->data);
}
else if (e->type == EV_FILE_TAGS) {
struct tag_ev_response *r
= (struct tag_ev_response *)e->data;

free (r->file);
tags_free (r->tags);
free (r);
}
else if (e->type == EV_PLIST_DEL || e->type == EV_STATUS_MSG)
free (e->data);
else if (e->data)
abort (); /* BUG */
}

/* Free event queue content without the queue structure. */
void event_queue_free (struct event_queue *q)
{
Expand All @@ -528,12 +549,7 @@ void event_queue_free (struct event_queue *q)
assert (q != NULL);

while ((e = event_get_first(q))) {
if (e->type == EV_PLIST_ADD) {
plist_free_item_fields (e->data);
free (e->data);
}
else if (e->type == EV_PLIST_DEL || e->type == EV_STATUS_MSG)
free (e->data);
free_event_data (e);
event_pop (q);
}
}
Expand Down Expand Up @@ -592,8 +608,17 @@ static struct packet_buf *make_event_packet (const struct event *e)
assert (e->data != NULL);
packet_buf_add_item (b, e->data);
}
else if (e->type == EV_FILE_TAGS) {
struct tag_ev_response *r;

assert (e->data != NULL);
r = e->data;

packet_buf_add_str (b, r->file);
packet_buf_add_tags (b, r->tags);
}
else if (e->data)
abort ();
abort (); /* BUG */

return b;
}
Expand All @@ -618,17 +643,9 @@ enum noblock_io_status event_send_noblock (int sock, struct event_queue *q)
struct event *e;

e = event_get_first (q);

if (e->type == EV_PLIST_ADD) {
plist_free_item_fields (e->data);
free (e->data);
}
else if (e->type == EV_PLIST_DEL || e->type == EV_STATUS_MSG)
free (e->data);
else if (e->data)
logit ("Unhandled event data!");

free_event_data (e);
event_pop (q);

return NB_IO_OK;
}
else if (errno == EAGAIN) {
Expand Down
12 changes: 11 additions & 1 deletion protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ struct event_queue
struct event *tail;
};

/* Used as data field in the event queue for EV_FILE_TAGS. */
struct tag_ev_response
{
char *file;
struct file_tags *tags;
};

/* Status of nonblock sending/receiving function. */
enum noblock_io_status
{
Expand All @@ -40,6 +47,7 @@ enum noblock_io_status
#define EV_TAGS 0x0e /* tags for the current file has changed. */
#define EV_STATUS_MSG 0x0f /* Followed by a status message */
#define EV_MIXER_CHANGE 0x10 /* the mixer channel was changed */
#define EV_FILE_TAGS 0x11 /* tags in a response for tags request */

/* Events caused by a client that wants to modify the playlist (see
* CMD_CLI_PLIST* commands. */
Expand Down Expand Up @@ -77,7 +85,6 @@ enum noblock_io_status
#define CMD_DELETE 0x1c /* delete an item from the playlist */
#define CMD_SEND_EVENTS 0x1d /* request for events */
#define CMD_GET_ERROR 0x1e /* get the error message */
#define CMD_GET_FTIME 0x1f /* get time of a file from the server */
#define CMD_PREV 0x20 /* start playing previous song if available */
#define CMD_SEND_PLIST 0x21 /* send the playlist to the requesting client */
#define CMD_GET_PLIST 0x22 /* get the playlist from one of the clients */
Expand All @@ -97,6 +104,9 @@ enum noblock_io_status
#define CMD_GET_TAGS 0x2c /* get tags for the currently played file. */
#define CMD_TOGGLE_MIXER_CHANNEL 0x2d /* toggle the mixer channel */
#define CMD_GET_MIXER_CHANNEL_NAME 0x2e /* get the mixer channel's name */
#define CMD_GET_FILE_TAGS 0x2f /* get tags for the specified file */
#define CMD_ABORT_TAGS_REQUESTS 0x30 /* abort previous CMD_GET_FILE_TAGS
requests up to some file */

char *socket_name ();
int get_int (int sock, int *i);
Expand Down
Loading

0 comments on commit 86dbd59

Please sign in to comment.