2 * Copyright (C) 2007 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
11 /** Audio file selector data stored in the audio file table. */
13 /** Seconds since the epoch. */
15 /** Bitfield of set attributes. */
17 /** Counts how many times the file was selected. */
19 /** Image blob associated with this file (foreign key). */
21 /** Lyrics blob associated with this file (foreign key). */
23 /** Mp3, ogg or aac. */
24 uint8_t audio_format_id;
27 enum afs_table_flags {TBLFLAG_SKIP_CREATE};
30 const struct osl_table_description *desc;
31 struct osl_table *table;
32 enum afs_table_flags flags;
35 enum ls_sorting_method {
41 LS_SORT_BY_LAST_PLAYED,
43 LS_SORT_BY_NUM_PLAYED,
57 LS_SORT_BY_AUDIO_FORMAT,
62 enum play_mode {PLAY_MODE_MOOD, PLAY_MODE_PLAYLIST};
64 struct audio_file_data {
65 enum play_mode current_play_mode;
68 struct audio_format_info afhi;
70 struct osl_object map;
74 typedef int callback_function(const struct osl_object *, struct osl_object *);
75 __noreturn int afs_init(uint32_t cookie, int socket_fd);
76 int send_callback_request(callback_function *f, struct osl_object *query,
77 struct osl_object *result);
78 int send_standard_callback_request(int argc, char * const * const argv,
79 callback_function *f, struct osl_object *result);
80 int send_option_arg_callback_request(struct osl_object *options,
81 int argc, char * const * const argv, callback_function *f,
82 struct osl_object *result);
83 int stdin_command(int fd, struct osl_object *arg_obj, callback_function *f,
84 unsigned max_len, struct osl_object *result);
85 int string_compare(const struct osl_object *obj1, const struct osl_object *obj2);
86 int para_atol(const char *str, long *result);
87 int open_next_audio_file(struct audio_file_data *afd);
88 int close_audio_file(struct audio_file_data *afd);
91 int score_init(struct table_info *ti, const char *db);
92 void score_shutdown(enum osl_close_flags flags);
93 int admissible_file_loop(void *data, osl_rbtree_loop_func *func);
94 int admissible_file_loop_reverse(void *data, osl_rbtree_loop_func *func);
95 int score_get_best(struct osl_row **aft_row, long *score);
96 int get_score_and_aft_row(struct osl_row *score_row, long *score, struct osl_row **aft_row);
97 int score_add(const struct osl_row *row, long score);
98 int score_update(const struct osl_row *aft_row, long new_score);
99 int get_num_admissible_files(unsigned *num);
100 int score_delete(const struct osl_row *aft_row);
101 int row_belongs_to_score_table(const struct osl_row *aft_row);
104 int attribute_init(struct table_info *ti, const char *db);
105 void attribute_shutdown(enum osl_close_flags flags);
106 void get_attribute_bitmap(const uint64_t *atts, char *buf); /* needed by com_ls() */
107 int get_attribute_bitnum_by_name(const char *att_name, unsigned char *bitnum);
108 int get_attribute_text(uint64_t *atts, const char *delim, char **text);
111 int aft_init(struct table_info *ti, const char *db);
112 void aft_shutdown(enum osl_close_flags flags);
113 int aft_get_row_of_path(char *path, struct osl_row **row);
114 int open_and_update_audio_file(struct osl_row *aft_row, struct audio_file_data *afd);
115 int load_afsi(struct afs_info *afsi, struct osl_object *obj);
116 void save_afsi(struct afs_info *afsi, struct osl_object *obj);
117 int get_afsi_of_row(const struct osl_row *row, struct afs_info *afsi);
118 int get_audio_file_path_of_row(const struct osl_row *row, char **path);
119 int get_afsi_object_of_row(const struct osl_row *row, struct osl_object *obj);
120 int audio_file_loop(void *private_data, osl_rbtree_loop_func *func);
121 int aft_check_callback(const struct osl_object *query, struct osl_object *result);
124 int change_current_mood(char *mood_name);
125 void close_current_mood(void);
126 int mood_update_audio_file(const struct osl_row *aft_row, struct afs_info *old_afsi);
127 int reload_current_mood(void);
128 int mood_delete_audio_file(const struct osl_row *aft_row);
129 int mood_check_callback(__a_unused const struct osl_object *query,
130 struct osl_object *result);
134 int playlist_open(char *name);
135 void playlist_close(void);
136 int playlist_update_audio_file(struct osl_row *aft_row);
137 int playlist_check_callback(__a_unused const struct osl_object *query,
138 struct osl_object *result);
140 /** evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y */
141 #define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
144 #define DECLARE_BLOB_SYMBOLS(table_name, cmd_prefix) \
145 int table_name ## _init(struct table_info *ti, const char *db); \
146 void table_name ## _shutdown(enum osl_close_flags flags); \
147 int cmd_prefix ## _get_name_by_id(uint32_t id, char **name); \
148 int cmd_prefix ## _get_name_and_def_by_row(const struct osl_row *row, \
149 char **name, struct osl_object *def); \
150 extern struct osl_table *table_name ## _table;
152 DECLARE_BLOB_SYMBOLS(lyrics, lyr);
153 DECLARE_BLOB_SYMBOLS(images, img);
154 DECLARE_BLOB_SYMBOLS(moods, mood);
155 DECLARE_BLOB_SYMBOLS(playlists, pl);
157 enum blob_table_columns {BLOBCOL_ID, BLOBCOL_NAME, BLOBCOL_DEF, NUM_BLOB_COLUMNS};
158 #define DEFINE_BLOB_TABLE_DESC(table_name) \
159 struct osl_table_description table_name ## _table_desc = { \
160 .name = #table_name, \
161 .num_columns = NUM_BLOB_COLUMNS, \
162 .flags = OSL_LARGE_TABLE, \
163 .column_descriptions = blob_cols \
166 #define DEFINE_BLOB_TABLE_PTR(table_name) struct osl_table *table_name ## _table;
168 #define INIT_BLOB_TABLE(table_name) \
169 DEFINE_BLOB_TABLE_DESC(table_name); \
170 DEFINE_BLOB_TABLE_PTR(table_name);