LCID-Fire / liblastfm
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
ac4d0c5
liblastfm / communication.h
| 19a3e61f » | LCID-Fire | 2008-07-06 | 1 | #ifndef COMMUNICATION_H_ | |
| 2 | #define COMMUNICATION_H_ | ||||
| 3 | |||||
| 4 | #include <glib.h> | ||||
| 2b8415c9 » | LCID-Fire | 2008-07-06 | 5 | #include "callback.h" | |
| 19a3e61f » | LCID-Fire | 2008-07-06 | 6 | ||
| dc2c374f » | LCID-Fire | 2008-07-08 | 7 | void communication_init(); | |
| 8 | void communication_destroy(); | ||||
| 9 | |||||
| 10 | struct lfmerror | ||||
| 11 | { | ||||
| 12 | const guint code; | ||||
| 13 | const gchar* message; | ||||
| 14 | }; | ||||
| 15 | |||||
| 16 | typedef struct lfmerror lfmerror; | ||||
| 17 | |||||
| 19a3e61f » | LCID-Fire | 2008-07-06 | 18 | struct lfmproxy; | |
| 19 | typedef struct lfmproxy lfmproxy; | ||||
| 20 | |||||
| 21 | #define BUILD_PARAMETER_NAMES(array) \ | ||||
| 22 | gchar** array = NULL;\ | ||||
| 23 | createv(gchar, array);\ | ||||
| 24 | addv(gchar, array, artist_parameters[0]);\ | ||||
| 25 | addv(gchar, array, artist_parameters[1]);\ | ||||
| 26 | addv(gchar, array, artist_parameters[2]); | ||||
| 27 | |||||
| 28 | #define BUILD_PARAMTER_VALUES(array, astruct) \ | ||||
| 29 | gchar** array = NULL;\ | ||||
| 30 | createv(gchar, array);\ | ||||
| 31 | addv(gchar, array, G_STRUCT_MEMBER_P(astruct, 0));\ | ||||
| 32 | addv(gchar, array, G_STRUCT_MEMBER_P(astruct, 1));\ | ||||
| 33 | addv(gchar, array, G_STRUCT_MEMBER_P(astruct, 2)); | ||||
| 34 | |||||
| 2b8415c9 » | LCID-Fire | 2008-07-06 | 35 | // | |
| 36 | //Token functions | ||||
| 37 | // | ||||
| 937d982d » | LCID-Fire | 2008-07-10 | 38 | void token_request_authorization(const gchar* token); | |
| 19a3e61f » | LCID-Fire | 2008-07-06 | 39 | ||
| 4663885e » | LCID-Fire | 2008-07-11 | 40 | typedef gchar* (*type_converter)(gpointer data); | |
| 19a3e61f » | LCID-Fire | 2008-07-06 | 41 | ||
| 42 | struct lfmparameter | ||||
| 43 | { | ||||
| dc2c374f » | LCID-Fire | 2008-07-08 | 44 | const gchar* name; | |
| 19a3e61f » | LCID-Fire | 2008-07-06 | 45 | type_converter converter; | |
| 46 | }; | ||||
| 47 | |||||
| 48 | typedef struct lfmparameter lfmparameter; | ||||
| 49 | |||||
| 270cc092 » | LCID-Fire | 2008-07-15 | 50 | enum method_type | |
| 51 | { | ||||
| 52 | GET_METHOD, | ||||
| 53 | POST_METHOD | ||||
| 54 | }; | ||||
| 55 | |||||
| 19a3e61f » | LCID-Fire | 2008-07-06 | 56 | struct lfmmethod | |
| 57 | { | ||||
| 58 | const gchar* name; | ||||
| 270cc092 » | LCID-Fire | 2008-07-15 | 59 | const enum method_type type; | |
| 953b92fd » | LCID-Fire | 2008-07-18 | 60 | const lfmparameter parameters[5]; | |
| 61 | const lfmparameter optional_parameters[5]; | ||||
| dc2c374f » | LCID-Fire | 2008-07-08 | 62 | const lfmerror specific_errors[5]; | |
| 19a3e61f » | LCID-Fire | 2008-07-06 | 63 | }; | |
| 64 | |||||
| 953b92fd » | LCID-Fire | 2008-07-18 | 65 | typedef struct lfmmethod lfmmethod; | |
| 66 | |||||
| 2b8415c9 » | LCID-Fire | 2008-07-06 | 67 | enum data_type | |
| 68 | { | ||||
| 69 | DATA_UTF8, | ||||
| 70 | DATA_URL, | ||||
| 71 | DATA_DATE_TIME, | ||||
| 72 | DATA_BOOLEAN, | ||||
| 270cc092 » | LCID-Fire | 2008-07-15 | 73 | DATA_UINT, | |
| 2c9dc967 » | LCID-Fire | 2008-07-19 | 74 | DATA_VOID, | |
| 75 | DATA_MULTI_UTF8, | ||||
| 76 | DATA_TAGS = DATA_MULTI_UTF8, | ||||
| 77 | DATA_ALBUMS = DATA_MULTI_UTF8, | ||||
| 78 | DATA_ARTISTS = DATA_MULTI_UTF8, | ||||
| 79 | DATA_EVENTS = DATA_MULTI_UTF8, | ||||
| 80 | DATA_TRACKS = DATA_MULTI_UTF8, | ||||
| 81 | DATA_USERS = DATA_MULTI_UTF8 | ||||
| 2b8415c9 » | LCID-Fire | 2008-07-06 | 82 | }; | |
| 83 | |||||
| 953b92fd » | LCID-Fire | 2008-07-18 | 84 | struct utf8_syncer | |
| 85 | { | ||||
| 86 | gchar* string; | ||||
| 87 | GError* error; | ||||
| 88 | GCond* signal; | ||||
| 89 | }; | ||||
| 90 | |||||
| 91 | void utf8_sync(const gchar* string, gpointer user_data, GError* error); | ||||
| 92 | |||||
| 93 | #define IMPLEMENT_SYNC_UTF8(function, ...) \ | ||||
| 94 | struct utf8_syncer _syncer;\ | ||||
| 95 | _syncer.string = NULL;\ | ||||
| 96 | _syncer.error = NULL;\ | ||||
| 97 | _syncer.signal = g_cond_new();\ | ||||
| 98 | function(__VA_ARGS__, utf8_sync, &_syncer);\ | ||||
| 99 | GMutex* _mutex = g_mutex_new();\ | ||||
| 100 | g_cond_wait(_syncer.signal, _mutex);\ | ||||
| 101 | g_mutex_free(_mutex);\ | ||||
| a840b696 » | LCID-Fire | 2008-07-19 | 102 | g_cond_free(_syncer.signal);\ | |
| 953b92fd » | LCID-Fire | 2008-07-18 | 103 | if(_syncer.error)\ | |
| 104 | {\ | ||||
| 105 | *error = _syncer.error;\ | ||||
| 106 | return NULL;\ | ||||
| 107 | }\ | ||||
| 108 | return _syncer.string | ||||
| 19a3e61f » | LCID-Fire | 2008-07-06 | 109 | ||
| 110 | struct lfmget | ||||
| 111 | { | ||||
| 112 | const lfmmethod* method; | ||||
| 113 | const gchar* path[5]; | ||||
| 270cc092 » | LCID-Fire | 2008-07-15 | 114 | const enum data_type data_parser; | |
| 19a3e61f » | LCID-Fire | 2008-07-06 | 115 | }; | |
| 116 | |||||
| 117 | typedef struct lfmget lfmget; | ||||
| 118 | |||||
| 4663885e » | LCID-Fire | 2008-07-11 | 119 | gchar* utf8_array2csl(gpointer array); | |
| 120 | gchar* uint2utf8(gpointer array); | ||||
| 19a3e61f » | LCID-Fire | 2008-07-06 | 121 | ||
| 953b92fd » | LCID-Fire | 2008-07-18 | 122 | //variable argument have to be ordered as defined in call | |
| 270cc092 » | LCID-Fire | 2008-07-15 | 123 | G_GNUC_NULL_TERMINATED void call_method_with_parameters(const lfmget* call, gpointer callback, gpointer user_data, ...); | |
| 19a3e61f » | LCID-Fire | 2008-07-06 | 124 | ||
| 125 | #endif /*COMMUNICATION_H_*/ | ||||

