From ee2e73cd7b5a1de68c8316e916c4ef3a88302bed Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 4 Aug 2013 18:53:43 +0200 Subject: piano: Generic linked lists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduces generic linked list structure and functions (like append, delete, …). Removes a lot of copy&pasted code and improves code readability/reusability. Heads up: This change breaks libpiano’s ABI. --- src/libpiano/piano.h | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'src/libpiano/piano.h') diff --git a/src/libpiano/piano.h b/src/libpiano/piano.h index 04f33b5..ce66171 100644 --- a/src/libpiano/piano.h +++ b/src/libpiano/piano.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2008-2011 +Copyright (c) 2008-2013 Lars-Dominik Braun Permission is hereby granted, free of charge, to any person obtaining a copy @@ -42,19 +42,23 @@ THE SOFTWARE. #define PIANO_RPC_HOST "tuner.pandora.com" #define PIANO_RPC_PATH "/services/json/?" +typedef struct PianoListHead { + struct PianoListHead *next; +} PianoListHead_t; + typedef struct PianoUserInfo { char *listenerId; char *authToken; } PianoUserInfo_t; typedef struct PianoStation { + PianoListHead_t head; char isCreator; char isQuickMix; char useQuickMix; /* station will be included in quickmix */ char *name; char *id; char *seedId; - struct PianoStation *next; } PianoStation_t; typedef enum { @@ -78,6 +82,7 @@ typedef enum { } PianoAudioQuality_t; typedef struct PianoSong { + PianoListHead_t head; char *artist; char *stationId; char *album; @@ -92,28 +97,27 @@ typedef struct PianoSong { float fileGain; PianoSongRating_t rating; PianoAudioFormat_t audioFormat; - struct PianoSong *next; } PianoSong_t; /* currently only used for search results */ typedef struct PianoArtist { + PianoListHead_t head; char *name; char *musicId; char *seedId; int score; - struct PianoArtist *next; } PianoArtist_t; typedef struct PianoGenre { + PianoListHead_t head; char *name; char *musicId; - struct PianoGenre *next; } PianoGenre_t; typedef struct PianoGenreCategory { + PianoListHead_t head; char *name; PianoGenre_t *genres; - struct PianoGenreCategory *next; } PianoGenreCategory_t; typedef struct PianoPartner { @@ -298,6 +302,27 @@ typedef enum { PIANO_RET_P_RATE_LIMIT = PIANO_RET_OFFSET+1039, } PianoReturn_t; +/* list stuff */ +#ifndef __GNUC__ +# define __attribute__(x) +#endif +size_t PianoListCount (const PianoListHead_t * const l); +#define PianoListCountP(l) PianoListCount(&(l)->head) +void *PianoListAppend (PianoListHead_t * const l, PianoListHead_t * const e) + __attribute__ ((warn_unused_result)); +#define PianoListAppendP(l,e) PianoListAppend(&(l)->head, &(e)->head) +void *PianoListDelete (PianoListHead_t * const l, PianoListHead_t * const e) + __attribute__ ((warn_unused_result)); +#define PianoListDeleteP(l,e) PianoListDelete(&(l)->head, &(e)->head) +#define PianoListNextP(e) ((void *) (e)->head.next) +void *PianoListPrepend (PianoListHead_t * const l, PianoListHead_t * const e) + __attribute__ ((warn_unused_result)); +#define PianoListPrependP(l,e) PianoListPrepend (&(l)->head, &(e)->head) +void *PianoListGet (PianoListHead_t * const l, const size_t n); +#define PianoListGetP(l,n) PianoListGet (&(l)->head, n) +#define PianoListForeachP(l) for (; (l) != NULL; (l) = (void *) (l)->head.next) + +/* memory management */ PianoReturn_t PianoInit (PianoHandle_t *, const char *, const char *, const char *, const char *, const char *); @@ -306,12 +331,15 @@ void PianoDestroyPlaylist (PianoSong_t *); void PianoDestroySearchResult (PianoSearchResult_t *); void PianoDestroyStationInfo (PianoStationInfo_t *); +/* pandora rpc */ PianoReturn_t PianoRequest (PianoHandle_t *, PianoRequest_t *, PianoRequestType_t); PianoReturn_t PianoResponse (PianoHandle_t *, PianoRequest_t *); void PianoDestroyRequest (PianoRequest_t *); -PianoStation_t *PianoFindStationById (PianoStation_t *, const char *); +/* misc */ +PianoStation_t *PianoFindStationById (PianoStation_t * const, + const char * const); const char *PianoErrorToStr (PianoReturn_t); #endif /* _PIANO_H */ -- cgit v1.2.3