summaryrefslogtreecommitdiff
path: root/src/libpiano/piano.h
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2013-08-04 18:53:43 +0200
committerLars-Dominik Braun <lars@6xq.net>2013-08-07 17:37:33 +0200
commitee2e73cd7b5a1de68c8316e916c4ef3a88302bed (patch)
treee952d75d075598123d5ecbe92f14838ce75f6db5 /src/libpiano/piano.h
parent36ea2f13f87b9310219790c3cee498201d54f8e0 (diff)
downloadpianobar-windows-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.tar.gz
pianobar-windows-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.tar.bz2
pianobar-windows-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.zip
piano: Generic linked lists
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.
Diffstat (limited to 'src/libpiano/piano.h')
-rw-r--r--src/libpiano/piano.h42
1 files changed, 35 insertions, 7 deletions
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 <lars@6xq.net>
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 */