summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2016-02-08 11:52:46 -0500
committerMike Blumenkrantz <zmike@osg.samsung.com>2016-02-06 20:59:55 -0500
commitf501bb454200beecafcf88e71c235aa5b1aa422a (patch)
treed478f56920e562b719e11253253979245ebf8846 /src
parentfae6e09644a9ac4305009618f3d68d60c4e11abf (diff)
convert array usage in empdd to lists
Diffstat (limited to 'src')
-rw-r--r--src/bin/empdd.c47
1 files changed, 15 insertions, 32 deletions
diff --git a/src/bin/empdd.c b/src/bin/empdd.c
index bdc3ada..94dafea 100644
--- a/src/bin/empdd.c
+++ b/src/bin/empdd.c
@@ -35,8 +35,8 @@ typedef struct EMPD
35 struct mpd_parser *parser; 35 struct mpd_parser *parser;
36 36
37 37
38 Eina_Array *pending; 38 Eina_List *pending;
39 Eina_Array *current_queue; 39 Eina_List *current_queue;
40 void *cur; 40 void *cur;
41 E_Slist *cmds, *last; 41 E_Slist *cmds, *last;
42 42
@@ -344,7 +344,7 @@ static void
344queue_list_send(Eldbus_Message *msg, unsigned int start, long num) 344queue_list_send(Eldbus_Message *msg, unsigned int start, long num)
345{ 345{
346 Eldbus_Message_Iter *iter, *array, *struc; 346 Eldbus_Message_Iter *iter, *array, *struc;
347 Eina_Iterator *it; 347 Eina_List *l;
348 struct mpd_song *so; 348 struct mpd_song *so;
349 unsigned int cur = 0; 349 unsigned int cur = 0;
350 Eina_Bool sig = !msg; 350 Eina_Bool sig = !msg;
@@ -353,8 +353,7 @@ queue_list_send(Eldbus_Message *msg, unsigned int start, long num)
353 msg = eldbus_service_signal_new(empd_iface, EMPD_SIGNAL_QUEUE_LIST); 353 msg = eldbus_service_signal_new(empd_iface, EMPD_SIGNAL_QUEUE_LIST);
354 iter = eldbus_message_iter_get(msg); 354 iter = eldbus_message_iter_get(msg);
355 array = eldbus_message_iter_container_new(iter, 'a', "(stusssisssii)"); 355 array = eldbus_message_iter_container_new(iter, 'a', "(stusssisssii)");
356 it = eina_array_iterator_new(empd->current_queue); 356 EINA_LIST_FOREACH(queue_list, l, so)
357 EINA_ITERATOR_FOREACH(it, so)
358 { 357 {
359 /* holy shit. */ 358 /* holy shit. */
360 const char *track = mpd_song_get_tag(so, MPD_TAG_TRACK, 0); 359 const char *track = mpd_song_get_tag(so, MPD_TAG_TRACK, 0);
@@ -370,7 +369,6 @@ queue_list_send(Eldbus_Message *msg, unsigned int start, long num)
370 eldbus_message_iter_container_close(array, struc); 369 eldbus_message_iter_container_close(array, struc);
371 if (mpd_song_get_pos(so) == num) break; 370 if (mpd_song_get_pos(so) == num) break;
372 } 371 }
373 eina_iterator_free(it);
374 eldbus_message_iter_container_close(iter, array); 372 eldbus_message_iter_container_close(iter, array);
375 if (sig) 373 if (sig)
376 eldbus_service_signal_send(empd_iface, msg); 374 eldbus_service_signal_send(empd_iface, msg);
@@ -555,12 +553,12 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
555 mpd_status_get_next_song_pos(st), mpd_status_get_next_song_id(st), empd_dbupdate); 553 mpd_status_get_next_song_pos(st), mpd_status_get_next_song_id(st), empd_dbupdate);
556 if (((!empd->current_queue) && (!mpd_status_get_queue_length(st))) || 554 if (((!empd->current_queue) && (!mpd_status_get_queue_length(st))) ||
557 ((!empd_queue_version) && empd->current_queue && 555 ((!empd_queue_version) && empd->current_queue &&
558 (eina_array_count(empd->current_queue) == mpd_status_get_queue_length(st)))) 556 (eina_list_count(empd->current_queue) == mpd_status_get_queue_length(st))))
559 empd_queue_version = mpd_status_get_queue_version(st); 557 empd_queue_version = mpd_status_get_queue_version(st);
560 if ((empd_queue_version && (empd_queue_version != mpd_status_get_queue_version(st))) || 558 if ((empd_queue_version && (empd_queue_version != mpd_status_get_queue_version(st))) ||
561 ((!empd->current_queue) && (mpd_status_get_queue_length(st))) || 559 ((!empd->current_queue) && (mpd_status_get_queue_length(st))) ||
562 (empd->current_queue && mpd_status_get_queue_length(st) && 560 (empd->current_queue && mpd_status_get_queue_length(st) &&
563 (eina_array_count(empd->current_queue) != mpd_status_get_queue_length(st)))) 561 (eina_list_count(empd->current_queue) != mpd_status_get_queue_length(st))))
564 { 562 {
565 if (queue_fetch()) 563 if (queue_fetch())
566 empd_queue_version = mpd_status_get_queue_version(st); 564 empd_queue_version = mpd_status_get_queue_version(st);
@@ -622,12 +620,10 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
622 { 620 {
623 if (!strcmp(name, "Id")) 621 if (!strcmp(name, "Id"))
624 { 622 {
625 /* at end of current song, push to array 623 /* at end of current song, push to list
626 * for sending all at once later 624 * for sending all at once later
627 */ 625 */
628 if (!empd->pending) 626 empd->pending = eina_list_append(empd->pending, so);
629 empd->pending = eina_array_new(10);
630 eina_array_push(empd->pending, so);
631 empd->cur = NULL; 627 empd->cur = NULL;
632 } 628 }
633 } 629 }
@@ -654,11 +650,7 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
654 { 650 {
655 if (res != MPD_PARSER_SUCCESS) 651 if (res != MPD_PARSER_SUCCESS)
656 break; 652 break;
657 if (empd->current_queue) 653 E_FREE_LIST(empd->current_queue, mpd_song_free);
658 {
659 eina_array_foreach(empd->current_queue, queue_item_each_free, NULL);
660 eina_array_free(empd->current_queue);
661 }
662 empd->current_queue = empd->pending; 654 empd->current_queue = empd->pending;
663 empd->pending = NULL; 655 empd->pending = NULL;
664 if (empd->current_queue) 656 if (empd->current_queue)
@@ -673,13 +665,11 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
673 665
674 if (res == MPD_PARSER_PAIR) 666 if (res == MPD_PARSER_PAIR)
675 { 667 {
676 if (!empd->pending)
677 empd->pending = eina_array_new(10);
678 //fprintf(stderr, "[%s]|FEED\n", cmd_txt[cmd_get()]); 668 //fprintf(stderr, "[%s]|FEED\n", cmd_txt[cmd_get()]);
679 if ((!empd->cur) || (!mpd_entity_feed(empd->cur, &(struct mpd_pair){name, value}))) 669 if ((!empd->cur) || (!mpd_entity_feed(empd->cur, &(struct mpd_pair){name, value})))
680 { 670 {
681 empd->cur = mpd_entity_begin(&(struct mpd_pair){name, value}); 671 empd->cur = mpd_entity_begin(&(struct mpd_pair){name, value});
682 eina_array_push(empd->pending, empd->cur); 672 empd->pending = eina_list_append(empd->pending, empd->cur);
683 } 673 }
684 } 674 }
685 else if (res == MPD_PARSER_ERROR) 675 else if (res == MPD_PARSER_ERROR)
@@ -698,7 +688,6 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
698 } 688 }
699 else 689 else
700 { 690 {
701 Eina_Iterator *it = NULL;
702 struct mpd_entity *ent; 691 struct mpd_entity *ent;
703 Eldbus_Message *msg; 692 Eldbus_Message *msg;
704 Eldbus_Message_Iter *iter, *array; 693 Eldbus_Message_Iter *iter, *array;
@@ -709,9 +698,7 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
709 msg = empd->cmds->data; 698 msg = empd->cmds->data;
710 iter = eldbus_message_iter_get(msg); 699 iter = eldbus_message_iter_get(msg);
711 array = eldbus_message_iter_container_new(iter, 'a', "(iv)"); 700 array = eldbus_message_iter_container_new(iter, 'a', "(iv)");
712 if (empd->pending) 701 EINA_LIST_FREE(empd->pending, ent)
713 it = eina_array_iterator_new(empd->pending);
714 EINA_ITERATOR_FOREACH(it, ent)
715 { 702 {
716 const struct mpd_song *so; 703 const struct mpd_song *so;
717 const struct mpd_playlist *pl; 704 const struct mpd_playlist *pl;
@@ -751,22 +738,18 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
751 eldbus_message_iter_arguments_append(s2, "st", 738 eldbus_message_iter_arguments_append(s2, "st",
752 mpd_directory_get_path(dir), mpd_directory_get_last_modified(dir)); 739 mpd_directory_get_path(dir), mpd_directory_get_last_modified(dir));
753 break; 740 break;
754 default: continue; 741 default:
742 mpd_entity_free(ent);
743 continue;
755 } 744 }
756 eldbus_message_iter_container_close(variant, s2); 745 eldbus_message_iter_container_close(variant, s2);
757 eldbus_message_iter_container_close(struc, variant); 746 eldbus_message_iter_container_close(struc, variant);
758 eldbus_message_iter_container_close(array, struc); 747 eldbus_message_iter_container_close(array, struc);
748 mpd_entity_free(ent);
759 } 749 }
760 eina_iterator_free(it);
761 eldbus_message_iter_container_close(iter, array); 750 eldbus_message_iter_container_close(iter, array);
762 eldbus_connection_send(dbus_conn, msg, NULL, NULL, -1); 751 eldbus_connection_send(dbus_conn, msg, NULL, NULL, -1);
763 empd->cur = NULL; 752 empd->cur = NULL;
764 if (empd->pending)
765 {
766 eina_array_foreach(empd->pending, lsinfo_item_each_free, NULL);
767 eina_array_free(empd->pending);
768 empd->pending = NULL;
769 }
770 } 753 }
771 } 754 }
772 break; 755 break;