public
Description: Library to access lastfm via it's 2.0 api
Homepage: https://launchpad.net/liblastfm
Clone URL: git://github.com/LCID-Fire/liblastfm.git
Click here to lend your support to: liblastfm and make a donation at www.pledgie.com !
liblastfm / communication.h
100644 126 lines (102 sloc) 2.6 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef COMMUNICATION_H_
#define COMMUNICATION_H_
 
#include <glib.h>
#include "callback.h"
 
void communication_init();
void communication_destroy();
 
struct lfmerror
{
const guint code;
const gchar* message;
};
 
typedef struct lfmerror lfmerror;
 
struct lfmproxy;
typedef struct lfmproxy lfmproxy;
 
#define BUILD_PARAMETER_NAMES(array) \
gchar** array = NULL;\
createv(gchar, array);\
addv(gchar, array, artist_parameters[0]);\
addv(gchar, array, artist_parameters[1]);\
addv(gchar, array, artist_parameters[2]);
#define BUILD_PARAMTER_VALUES(array, astruct) \
gchar** array = NULL;\
createv(gchar, array);\
addv(gchar, array, G_STRUCT_MEMBER_P(astruct, 0));\
addv(gchar, array, G_STRUCT_MEMBER_P(astruct, 1));\
addv(gchar, array, G_STRUCT_MEMBER_P(astruct, 2));
 
//
//Token functions
//
void token_request_authorization(const gchar* token);
 
typedef gchar* (*type_converter)(gpointer data);
 
struct lfmparameter
{
const gchar* name;
type_converter converter;
};
 
typedef struct lfmparameter lfmparameter;
 
enum method_type
{
GET_METHOD,
POST_METHOD
};
 
struct lfmmethod
{
const gchar* name;
const enum method_type type;
const lfmparameter parameters[5];
const lfmparameter optional_parameters[5];
const lfmerror specific_errors[5];
};
 
typedef struct lfmmethod lfmmethod;
 
enum data_type
{
DATA_UTF8,
DATA_URL,
DATA_DATE_TIME,
DATA_BOOLEAN,
DATA_UINT,
DATA_VOID,
DATA_MULTI_UTF8,
DATA_TAGS = DATA_MULTI_UTF8,
DATA_ALBUMS = DATA_MULTI_UTF8,
DATA_ARTISTS = DATA_MULTI_UTF8,
DATA_EVENTS = DATA_MULTI_UTF8,
DATA_TRACKS = DATA_MULTI_UTF8,
DATA_USERS = DATA_MULTI_UTF8
};
 
struct utf8_syncer
{
gchar* string;
GError* error;
GCond* signal;
};
 
void utf8_sync(const gchar* string, gpointer user_data, GError* error);
 
#define IMPLEMENT_SYNC_UTF8(function, ...) \
struct utf8_syncer _syncer;\
_syncer.string = NULL;\
_syncer.error = NULL;\
_syncer.signal = g_cond_new();\
function(__VA_ARGS__, utf8_sync, &_syncer);\
GMutex* _mutex = g_mutex_new();\
g_cond_wait(_syncer.signal, _mutex);\
g_mutex_free(_mutex);\
g_cond_free(_syncer.signal);\
if(_syncer.error)\
{\
*error = _syncer.error;\
return NULL;\
}\
return _syncer.string
 
struct lfmget
{
const lfmmethod* method;
const gchar* path[5];
const enum data_type data_parser;
};
 
typedef struct lfmget lfmget;
 
gchar* utf8_array2csl(gpointer array);
gchar* uint2utf8(gpointer array);
 
//variable argument have to be ordered as defined in call
G_GNUC_NULL_TERMINATED void call_method_with_parameters(const lfmget* call, gpointer callback, gpointer user_data, ...);
 
#endif /*COMMUNICATION_H_*/