#define MAX_PLAYLIST_LEN 100
-int mc_playlist_create(const char *playlist_name, mc_playlist_h *playlist)
-{
- mc_retvm_if(!MC_STRING_VALID(playlist_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist_name");
- mc_retvm_if(playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
-
- mc_playlist_s *_playlist = (mc_playlist_s*)calloc(1, sizeof(mc_playlist_s));
- mc_retvm_if(_playlist == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+typedef struct {
+ char *index;
+ media_controller_metadata_s *metadata;
+} mc_playlist_item_s;
- _playlist->playlist_name = g_strdup(playlist_name);
-
- *playlist = (mc_playlist_h)_playlist;
+static void __release_playlist_item(mc_playlist_item_s *playlist_item)
+{
+ mc_retm_if(playlist_item == NULL, "invalid playlist_item");
- return MEDIA_CONTROLLER_ERROR_NONE;
+ MC_SAFE_FREE(playlist_item->index);
+ mc_metadata_destroy(playlist_item->metadata);
+ MC_SAFE_FREE(playlist_item);
}
-static int __mc_playlist_item_release(mc_playlist_item_s *playlist_item)
+static void __item_destroy(gpointer data)
{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
+ mc_playlist_item_s *item = (mc_playlist_item_s *)data;
- mc_retvm_if(playlist_item == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist_item");
+ if (item)
+ __release_playlist_item(item);
+}
- MC_SAFE_FREE(playlist_item->index);
- MC_SAFE_FREE(playlist_item->title);
- MC_SAFE_FREE(playlist_item->artist);
- MC_SAFE_FREE(playlist_item->album);
- MC_SAFE_FREE(playlist_item->author);
- MC_SAFE_FREE(playlist_item->genre);
- MC_SAFE_FREE(playlist_item->duration);
- MC_SAFE_FREE(playlist_item->date);
- MC_SAFE_FREE(playlist_item->copyright);
- MC_SAFE_FREE(playlist_item->description);
- MC_SAFE_FREE(playlist_item->track_num);
- MC_SAFE_FREE(playlist_item->picture);
- MC_SAFE_FREE(playlist_item);
+static void __query_destroy(gpointer data)
+{
+ char *query_str = (char *)data;
- return ret ;
+ SQLITE3_SAFE_FREE(query_str);
}
int _mc_playlist_update(mc_priv_type_e type, const char *controller_name, mc_playlist_h playlist)
GList *query_list = NULL;
int length = 0;
int idx = 0;
+ char *sql_str = NULL;
+ mc_playlist_item_s *_item = NULL;
mc_playlist_s *_playlist = (mc_playlist_s*)playlist;
mc_retvm_if(_playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
length = g_list_length(_playlist->item_list);
for (idx = 0; idx < length; idx++) {
- mc_playlist_item_s *_item = NULL;
_item = (mc_playlist_item_s*)g_list_nth_data(_playlist->item_list, idx);
-
- if (_item != NULL && _item->index != NULL) {
- char *sql_str = NULL;
-
+ if (_item != NULL && _item->index != NULL && _item->metadata != NULL) {
sql_str = sqlite3_mprintf("INSERT INTO '%q' (server_name, playlist_name, item_index, title, artist, album, author, genre, duration, date, copyright, description, track_num, picture) VALUES (%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);",
- MC_DB_TABLE_PLAYLIST, _playlist->server_name, _playlist->playlist_name, _item->index, _item->title, _item->artist, _item->album, _item->author, _item->genre, _item->duration, _item->date, _item->copyright, _item->description, _item->track_num, _item->picture);
+ MC_DB_TABLE_PLAYLIST, _playlist->server_name, _playlist->playlist_name, _item->index,
+ _item->metadata->title, _item->metadata->artist, _item->metadata->album, _item->metadata->author, _item->metadata->genre, _item->metadata->duration, _item->metadata->date, _item->metadata->copyright, _item->metadata->description, _item->metadata->track_num, _item->metadata->picture);
if (sql_str != NULL)
query_list = g_list_append(query_list, sql_str);
}
}
} else {
- char *sql_str = NULL;
-
sql_str = sqlite3_mprintf("INSERT INTO '%q' (server_name, playlist_name, item_index, title, artist, album, author, genre, duration, date, copyright, description, track_num, picture) VALUES (%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);",
MC_DB_TABLE_PLAYLIST, _playlist->server_name, _playlist->playlist_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
RELEASE:
- for (idx = 0; idx < length; idx++) {
- __mc_playlist_item_release((mc_playlist_item_s*)g_list_nth_data(_playlist->item_list, idx));
- }
+ g_list_free_full(_playlist->item_list, __item_destroy);
+ g_list_free_full(query_list, __query_destroy);
- if (_playlist->item_list != NULL) {
- g_list_free(_playlist->item_list);
- _playlist->item_list = NULL;
- }
+ return ret;
+}
- length = g_list_length(query_list);
+int mc_playlist_create(const char *playlist_name, mc_playlist_h *playlist)
+{
+ mc_retvm_if(!MC_STRING_VALID(playlist_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist_name");
+ mc_retvm_if(playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
- for (idx = 0; idx < length; idx++) {
- char *query_str = g_list_nth_data(query_list, idx);
- SQLITE3_SAFE_FREE(query_str);
- }
+ mc_playlist_s *_playlist = (mc_playlist_s*)calloc(1, sizeof(mc_playlist_s));
+ mc_retvm_if(_playlist == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
- g_list_free(query_list);
+ _playlist->playlist_name = g_strdup(playlist_name);
- return ret;
+ *playlist = (mc_playlist_h)_playlist;
+
+ return MEDIA_CONTROLLER_ERROR_NONE;
}
int mc_playlist_update_item(mc_playlist_h playlist, const char *index, mc_meta_e attribute, const char *value)
mc_playlist_item_s *_playlist_item = NULL;
int length = 0;
int idx = 0;
- bool find = FALSE;
+ gboolean found = FALSE;
mc_retvm_if(_playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
mc_retvm_if(!MC_STRING_VALID(index), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid index");
if (_item != NULL) {
if (g_strcmp0(_item->index, index) == 0) {
_playlist_item = _item;
- find = TRUE;
-
+ found = TRUE;
+ break;
}
}
}
}
- if (find == FALSE) {
+ if (!found) {
_playlist_item = (mc_playlist_item_s*)calloc(1, sizeof(mc_playlist_item_s));
mc_retvm_if(_playlist_item == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "memory alloc fail");
+ _playlist_item->metadata = (media_controller_metadata_s*)calloc(1, sizeof(media_controller_metadata_s));
+ if (_playlist_item->metadata == NULL) {
+ mc_error("memory alloc fail");
+ MC_SAFE_FREE(_playlist_item);
+ return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
+ }
+
_playlist_item->index = g_strdup(index);
+ } else {
+ mc_retvm_if(_playlist_item->metadata == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "invalid playlist item");
}
switch (attribute) {
case MC_META_MEDIA_TITLE:
- MC_SAFE_FREE(_playlist_item->title);
- if (value != NULL)
- _playlist_item->title = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->title);
+ _playlist_item->metadata->title = g_strdup(value);
break;
case MC_META_MEDIA_ARTIST:
- MC_SAFE_FREE(_playlist_item->artist);
- if (value != NULL)
- _playlist_item->artist = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->artist);
+ _playlist_item->metadata->artist = g_strdup(value);
break;
case MC_META_MEDIA_ALBUM:
- MC_SAFE_FREE(_playlist_item->album);
- if (value != NULL)
- _playlist_item->album = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->album);
+ _playlist_item->metadata->album = g_strdup(value);
break;
case MC_META_MEDIA_AUTHOR:
- MC_SAFE_FREE(_playlist_item->author);
- if (value != NULL)
- _playlist_item->author = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->author);
+ _playlist_item->metadata->author = g_strdup(value);
break;
case MC_META_MEDIA_GENRE:
- MC_SAFE_FREE(_playlist_item->genre);
- if (value != NULL)
- _playlist_item->genre = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->genre);
+ _playlist_item->metadata->genre = g_strdup(value);
break;
case MC_META_MEDIA_DURATION:
- MC_SAFE_FREE(_playlist_item->duration);
- if (value != NULL)
- _playlist_item->duration = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->duration);
+ _playlist_item->metadata->duration = g_strdup(value);
break;
case MC_META_MEDIA_DATE:
- MC_SAFE_FREE(_playlist_item->date);
- if (value != NULL)
- _playlist_item->date = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->date);
+ _playlist_item->metadata->date = g_strdup(value);
break;
case MC_META_MEDIA_COPYRIGHT:
- MC_SAFE_FREE(_playlist_item->copyright);
- if (value != NULL)
- _playlist_item->copyright = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->copyright);
+ _playlist_item->metadata->copyright = g_strdup(value);
break;
case MC_META_MEDIA_DESCRIPTION:
- MC_SAFE_FREE(_playlist_item->description);
- if (value != NULL)
- _playlist_item->description = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->description);
+ _playlist_item->metadata->description = g_strdup(value);
break;
case MC_META_MEDIA_TRACK_NUM:
- MC_SAFE_FREE(_playlist_item->track_num);
- if (value != NULL)
- _playlist_item->track_num = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->track_num);
+ _playlist_item->metadata->track_num = g_strdup(value);
break;
case MC_META_MEDIA_PICTURE:
- MC_SAFE_FREE(_playlist_item->picture);
- if (value != NULL)
- _playlist_item->picture = strdup(value);
+ MC_SAFE_FREE(_playlist_item->metadata->picture);
+ _playlist_item->metadata->picture = g_strdup(value);
break;
default:
mc_error("Invalid Parameter [%d]", attribute);
- if (find == FALSE)
- __mc_playlist_item_release(_playlist_item);
+ if (!found)
+ __release_playlist_item(_playlist_item);
return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER;
}
- if (find == FALSE)
+ if (!found)
_playlist->item_list = g_list_append(_playlist->item_list, _playlist_item);
return ret;
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
mc_playlist_s *_playlist = (mc_playlist_s*)playlist;
- mc_playlist_item_s *playlist_item = NULL;
- int length = 0;
- int idx = 0;
mc_retvm_if(_playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
MC_SAFE_FREE(_playlist->server_name);
MC_SAFE_FREE(_playlist->playlist_name);
-
- if (_playlist->item_list != NULL) {
- length = g_list_length(_playlist->item_list);
- for (idx = 0; idx < length; idx++) {
- playlist_item = (mc_playlist_item_s*)g_list_nth_data(_playlist->item_list, idx);
-
- if (playlist_item != NULL) {
- MC_SAFE_FREE(playlist_item->index);
- MC_SAFE_FREE(playlist_item->title);
- MC_SAFE_FREE(playlist_item->artist);
- MC_SAFE_FREE(playlist_item->album);
- MC_SAFE_FREE(playlist_item->author);
- MC_SAFE_FREE(playlist_item->genre);
- MC_SAFE_FREE(playlist_item->duration);
- MC_SAFE_FREE(playlist_item->date);
- MC_SAFE_FREE(playlist_item->copyright);
- MC_SAFE_FREE(playlist_item->description);
- MC_SAFE_FREE(playlist_item->track_num);
- MC_SAFE_FREE(playlist_item->picture);
- MC_SAFE_FREE(playlist_item->picture);
- MC_SAFE_FREE(playlist_item);
- }
- }
- }
-
+ g_list_free_full(_playlist->item_list, __item_destroy);
MC_SAFE_FREE(_playlist);
return ret;