summaryrefslogtreecommitdiff
path: root/src/module/e_mod_main.c
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-05-17 01:08:22 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-05-17 11:01:25 -0300
commitf5a44fe80fe0ae34fe9ec9587fea7ead67defd1b (patch)
treeeafc69d895746522f07ec9db94be73533261526a /src/module/e_mod_main.c
parente1c2ae60f826e8d5d0245029345c717ac8b9d884 (diff)
Checking when pulseadio dies
Informing the app/module that pulseaudio dies when then handling this situation properly avoiding crashes (in case of the module, avoiding crash the entire enlightenment).
Diffstat (limited to '')
-rw-r--r--src/module/e_mod_main.c262
1 files changed, 152 insertions, 110 deletions
diff --git a/src/module/e_mod_main.c b/src/module/e_mod_main.c
index 0935050..c6c2a36 100644
--- a/src/module/e_mod_main.c
+++ b/src/module/e_mod_main.c
@@ -50,6 +50,7 @@ struct _Context
50{ 50{
51 char *theme; 51 char *theme;
52 Ecore_Exe *epulse; 52 Ecore_Exe *epulse;
53 Ecore_Event_Handler *disconnected_handler;
53 Ecore_Event_Handler *epulse_event_handler; 54 Ecore_Event_Handler *epulse_event_handler;
54 Ecore_Event_Handler *sink_default_handler; 55 Ecore_Event_Handler *sink_default_handler;
55 Ecore_Event_Handler *sink_changed_handler; 56 Ecore_Event_Handler *sink_changed_handler;
@@ -132,6 +133,8 @@ _mixer_popup_update(Instance *inst, int mute, int vol)
132 e_slider_value_set(inst->slider, vol); 133 e_slider_value_set(inst->slider, vol);
133} 134}
134 135
136static void _popup_del(Instance *inst);
137
135static void 138static void
136_mixer_gadget_update(void) 139_mixer_gadget_update(void)
137{ 140{
@@ -141,25 +144,38 @@ _mixer_gadget_update(void)
141 144
142 EINA_LIST_FOREACH(mixer_context->instances, l, inst) 145 EINA_LIST_FOREACH(mixer_context->instances, l, inst)
143 { 146 {
144 pa_volume_t vol = pa_cvolume_avg(&mixer_context->sink_default->volume);
145 msg = alloca(sizeof(Edje_Message_Int_Set) + (2 * sizeof(int))); 147 msg = alloca(sizeof(Edje_Message_Int_Set) + (2 * sizeof(int)));
146 msg->count = 3; 148 msg->count = 3;
147 msg->val[0] = mixer_context->sink_default->mute;
148 msg->val[1] = PA_VOLUME_TO_INT(vol);
149 msg->val[2] = msg->val[1];
150 edje_object_message_send(inst->gadget, EDJE_MESSAGE_INT_SET, 0, msg);
151 149
150 if (!mixer_context->sink_default)
151 {
152 msg->val[0] = EINA_FALSE;
153 msg->val[1] = 0;
154 msg->val[2] = 0;
155 if (inst->popup)
156 _popup_del(inst);
157 }
158 else
159 {
160 pa_volume_t vol =
161 pa_cvolume_avg(&mixer_context->sink_default->volume);
162 msg->val[0] = mixer_context->sink_default->mute;
163 msg->val[1] = PA_VOLUME_TO_INT(vol);
164 msg->val[2] = msg->val[1];
165 if (inst->popup)
166 _mixer_popup_update(inst, mixer_context->sink_default->mute,
167 msg->val[1]);
168 }
169 edje_object_message_send(inst->gadget, EDJE_MESSAGE_INT_SET, 0, msg);
152 edje_object_signal_emit(inst->gadget, "e,action,volume,change", "e"); 170 edje_object_signal_emit(inst->gadget, "e,action,volume,change", "e");
153
154 if (inst->popup)
155 _mixer_popup_update(inst, mixer_context->sink_default->mute,
156 msg->val[1]);
157 } 171 }
158} 172}
159 173
160static void 174static void
161_volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED) 175_volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
162{ 176{
177 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default);
178
163 Sink *s = mixer_context->sink_default; 179 Sink *s = mixer_context->sink_default;
164 pa_cvolume v = s->volume; 180 pa_cvolume v = s->volume;
165 pa_cvolume_inc(&v, VOLUME_STEP); 181 pa_cvolume_inc(&v, VOLUME_STEP);
@@ -170,6 +186,8 @@ _volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
170static void 186static void
171_volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED) 187_volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
172{ 188{
189 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default);
190
173 Sink *s = mixer_context->sink_default; 191 Sink *s = mixer_context->sink_default;
174 pa_cvolume v = s->volume; 192 pa_cvolume v = s->volume;
175 pa_cvolume_dec(&v, VOLUME_STEP); 193 pa_cvolume_dec(&v, VOLUME_STEP);
@@ -180,6 +198,8 @@ _volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
180static void 198static void
181_volume_mute_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED) 199_volume_mute_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
182{ 200{
201 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default);
202
183 Sink *s = mixer_context->sink_default; 203 Sink *s = mixer_context->sink_default;
184 int mute = !s->mute; 204 int mute = !s->mute;
185 if (!epulse_sink_mute_set(s->index, mute)) 205 if (!epulse_sink_mute_set(s->index, mute))
@@ -334,7 +354,6 @@ _popup_add_slider(Instance *inst)
334 pa_volume_t vol = pa_cvolume_avg(&mixer_context->sink_default->volume); 354 pa_volume_t vol = pa_cvolume_avg(&mixer_context->sink_default->volume);
335 int value = PA_VOLUME_TO_INT(vol); 355 int value = PA_VOLUME_TO_INT(vol);
336 Evas_Object *slider = e_slider_add(e_comp_get(inst->popup)->evas); 356 Evas_Object *slider = e_slider_add(e_comp_get(inst->popup)->evas);
337 EINA_SAFETY_ON_NULL_RETURN_VAL(slider, NULL);
338 357
339 evas_object_show(slider); 358 evas_object_show(slider);
340 e_slider_orientation_set(slider, 1); 359 e_slider_orientation_set(slider, 1);
@@ -366,6 +385,8 @@ _popup_new(Instance *inst)
366 Eina_List *l; 385 Eina_List *l;
367 int pos = 0; 386 int pos = 0;
368 387
388 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default);
389
369 inst->popup = e_gadcon_popup_new(inst->gcc, 0); 390 inst->popup = e_gadcon_popup_new(inst->gcc, 0);
370 evas = e_comp_get(inst->gcc)->evas; 391 evas = e_comp_get(inst->gcc)->evas;
371 392
@@ -630,108 +651,129 @@ _sink_changed_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
630 } 651 }
631 } 652 }
632 653
633 return ECORE_CALLBACK_DONE; 654 return ECORE_CALLBACK_DONE;
634} 655 }
635
636static Eina_Bool
637_sink_added_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
638 void *info)
639{
640 Epulse_Event *ev = info;
641 Eina_List *l;
642 Sink *s;
643
644 EINA_LIST_FOREACH(mixer_context->sinks, l, s)
645 if (s->index == ev->index)
646 return ECORE_CALLBACK_DONE;
647
648 s = malloc(sizeof(*s));
649 s->index = ev->index;
650 s->volume = ev->volume;
651 s->name = strdup(ev->name);
652 s->mute = ev->mute;
653 656
654 mixer_context->sinks = eina_list_append(mixer_context->sinks, s); 657 static Eina_Bool
655 return ECORE_CALLBACK_DONE; 658 _disconnected_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
656} 659 void *info EINA_UNUSED)
660 {
661 Sink *s;
657 662
658static Eina_Bool 663 EINA_LIST_FREE(mixer_context->sinks, s)
659_sink_removed_cb(void *data EINA_UNUSED, int type EINA_UNUSED, 664 {
660 void *info) 665 free(s->name);
661{ 666 free(s);
662 Epulse_Event *ev = info; 667 }
663 Eina_List *l, *ll; 668
664 Sink *s; 669 mixer_context->sinks = NULL;
665 Eina_Bool need_change_sink; 670 mixer_context->sink_default = NULL;
666 671 _mixer_gadget_update();
667 need_change_sink = (ev->index == mixer_context->sink_default->index) 672
668 ? EINA_TRUE : EINA_FALSE; 673 return ECORE_CALLBACK_DONE;
669 674 }
670 EINA_LIST_FOREACH_SAFE(mixer_context->sinks, l, ll, s) 675
671 { 676 static Eina_Bool
672 if (ev->index == s->index) 677 _sink_added_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
673 { 678 void *info)
674 free(s->name); 679 {
675 free(s); 680 Epulse_Event *ev = info;
676 mixer_context->sinks = 681 Eina_List *l;
677 eina_list_remove_list(mixer_context->sinks, l); 682 Sink *s;
678 } 683
679 } 684 EINA_LIST_FOREACH(mixer_context->sinks, l, s)
680 685 if (s->index == ev->index)
681 if (need_change_sink) 686 return ECORE_CALLBACK_DONE;
682 { 687
683 s = mixer_context->sinks->data; 688 s = malloc(sizeof(*s));
684 mixer_context->sink_default = s; 689 s->index = ev->index;
685 _mixer_gadget_update(); 690 s->volume = ev->volume;
686 } 691 s->name = strdup(ev->name);
687 692 s->mute = ev->mute;
688 return ECORE_CALLBACK_DONE; 693
689} 694 mixer_context->sinks = eina_list_append(mixer_context->sinks, s);
690 695 return ECORE_CALLBACK_DONE;
691EAPI void * 696 }
692e_modapi_init(E_Module *m) 697
693{ 698 static Eina_Bool
694 char buf[4096]; 699 _sink_removed_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
695 700 void *info)
696 EINA_SAFETY_ON_FALSE_RETURN_VAL(epulse_common_init("epulse_mod"), 701 {
697 NULL); 702 Epulse_Event *ev = info;
698 EINA_SAFETY_ON_FALSE_RETURN_VAL(epulse_init() > 0, NULL); 703 Eina_List *l, *ll;
699 if (!mixer_context) 704 Sink *s;
700 { 705 Eina_Bool need_change_sink;
701 mixer_context = E_NEW(Context, 1); 706
702 707 need_change_sink = (ev->index == mixer_context->sink_default->index)
703 mixer_context->sink_default_handler = 708 ? EINA_TRUE : EINA_FALSE;
704 ecore_event_handler_add(SINK_DEFAULT, _sink_default_cb, NULL); 709
705 mixer_context->sink_changed_handler = 710 EINA_LIST_FOREACH_SAFE(mixer_context->sinks, l, ll, s)
706 ecore_event_handler_add(SINK_CHANGED, _sink_changed_cb, NULL); 711 {
707 mixer_context->sink_added_handler = 712 if (ev->index == s->index)
708 ecore_event_handler_add(SINK_ADDED, _sink_added_cb, NULL); 713 {
709 mixer_context->sink_removed_handler = 714 free(s->name);
710 ecore_event_handler_add(SINK_REMOVED, _sink_removed_cb, NULL); 715 free(s);
711 mixer_context->module = m; 716 mixer_context->sinks =
712 snprintf(buf, sizeof(buf), "%s/mixer.edj", 717 eina_list_remove_list(mixer_context->sinks, l);
713 e_module_dir_get(mixer_context->module)); 718 }
714 mixer_context->theme = strdup(buf); 719 }
715 } 720
716 721 if (need_change_sink)
717 e_gadcon_provider_register(&_gadcon_class); 722 {
718 _actions_register(); 723 s = mixer_context->sinks->data;
719 724 mixer_context->sink_default = s;
720 return m; 725 _mixer_gadget_update();
721} 726 }
722 727
723EAPI int 728 return ECORE_CALLBACK_DONE;
724e_modapi_shutdown(E_Module *m EINA_UNUSED) 729 }
725{ 730
726 Sink *s; 731 EAPI void *
727 732 e_modapi_init(E_Module *m)
728 _actions_unregister(); 733 {
729 e_gadcon_provider_unregister((const E_Gadcon_Client_Class *)&_gadcon_class); 734 char buf[4096];
730 735
731 if (!mixer_context) 736 EINA_SAFETY_ON_FALSE_RETURN_VAL(epulse_common_init("epulse_mod"),
732 { 737 NULL);
733 if (mixer_context->theme) 738 EINA_SAFETY_ON_FALSE_RETURN_VAL(epulse_init() > 0, NULL);
734 free(mixer_context->theme); 739 if (!mixer_context)
740 {
741 mixer_context = E_NEW(Context, 1);
742
743 mixer_context->sink_default_handler =
744 ecore_event_handler_add(SINK_DEFAULT, _sink_default_cb, NULL);
745 mixer_context->sink_changed_handler =
746 ecore_event_handler_add(SINK_CHANGED, _sink_changed_cb, NULL);
747 mixer_context->sink_added_handler =
748 ecore_event_handler_add(SINK_ADDED, _sink_added_cb, NULL);
749 mixer_context->sink_removed_handler =
750 ecore_event_handler_add(SINK_REMOVED, _sink_removed_cb, NULL);
751 mixer_context->disconnected_handler =
752 ecore_event_handler_add(DISCONNECTED, _disconnected_cb, NULL);
753 mixer_context->module = m;
754 snprintf(buf, sizeof(buf), "%s/mixer.edj",
755 e_module_dir_get(mixer_context->module));
756 mixer_context->theme = strdup(buf);
757 }
758
759 e_gadcon_provider_register(&_gadcon_class);
760 _actions_register();
761
762 return m;
763 }
764
765 EAPI int
766 e_modapi_shutdown(E_Module *m EINA_UNUSED)
767 {
768 Sink *s;
769
770 _actions_unregister();
771 e_gadcon_provider_unregister((const E_Gadcon_Client_Class *)&_gadcon_class);
772
773 if (!mixer_context)
774 {
775 if (mixer_context->theme)
776 free(mixer_context->theme);
735 777
736 ecore_event_handler_del(mixer_context->sink_default_handler); 778 ecore_event_handler_del(mixer_context->sink_default_handler);
737 ecore_event_handler_del(mixer_context->sink_changed_handler); 779 ecore_event_handler_del(mixer_context->sink_changed_handler);