summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Stanislawski <l.stanislaws@samsung.com>2014-06-26 13:03:33 +0200
committerLukasz Stanislawski <l.stanislaws@samsung.com>2014-07-10 10:18:53 +0200
commitd86ed905a5fe10b2525ee4012c8740fcb3577ef7 (patch)
tree54d50e7677d22e48b5b4ed0e6c2ef297cea29f20
parent1b07fd2471ca032e8fb1cd88c4de013ae7a328dd (diff)
atspi: improve code reusage
atspi d-bus signals have similar signatures, however use dbus variant type to encode signal specific data. This patch adds utility function to construct atspi dbus signal with custom variant data.
-rw-r--r--src/lib/elm_atspi_bridge.c136
1 files changed, 44 insertions, 92 deletions
diff --git a/src/lib/elm_atspi_bridge.c b/src/lib/elm_atspi_bridge.c
index 16be16617..b26d54f51 100644
--- a/src/lib/elm_atspi_bridge.c
+++ b/src/lib/elm_atspi_bridge.c
@@ -83,6 +83,7 @@ static void _cache_build(void *obj);
83static void _object_register(Eo *obj, char *path); 83static void _object_register(Eo *obj, char *path);
84static void _iter_interfaces_append(Eldbus_Message_Iter *iter, const Eo *obj); 84static void _iter_interfaces_append(Eldbus_Message_Iter *iter, const Eo *obj);
85static Eina_Bool _elm_atspi_bridge_key_down_event_notify(void *data, int type, void *event); 85static Eina_Bool _elm_atspi_bridge_key_down_event_notify(void *data, int type, void *event);
86static void _object_signal_send(Eldbus_Service_Interface *infc, int sig_id, const char *minor, unsigned int det1, unsigned int det2, const char *variant_sig, ...);
86 87
87EO_CALLBACKS_ARRAY_DEFINE(_events_cb, 88EO_CALLBACKS_ARRAY_DEFINE(_events_cb,
88 { ELM_INTERFACE_ATSPI_ACCESSIBLE_EVENT_PROPERTY_CHANGED, _property_changed_signal_send}, 89 { ELM_INTERFACE_ATSPI_ACCESSIBLE_EVENT_PROPERTY_CHANGED, _property_changed_signal_send},
@@ -546,7 +547,7 @@ _accessible_interfaces_get(const Eldbus_Service_Interface *iface, const Eldbus_M
546 return ret; 547 return ret;
547} 548}
548 549
549static uint64_t 550static uint64_t
550_elm_atspi_state_set_to_atspi_state_set(Elm_Atspi_State_Set states) 551_elm_atspi_state_set_to_atspi_state_set(Elm_Atspi_State_Set states)
551{ 552{
552 uint64_t ret = 0; 553 uint64_t ret = 0;
@@ -2674,8 +2675,6 @@ _handle_listener_change(void *data EINA_UNUSED, const Eldbus_Message *msg)
2674static Eina_Bool 2675static Eina_Bool
2675_state_changed_signal_send(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) 2676_state_changed_signal_send(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
2676{ 2677{
2677 Eldbus_Message *msg;
2678 Eldbus_Message_Iter *iter, *viter;
2679 Eldbus_Service_Interface *events = data; 2678 Eldbus_Service_Interface *events = data;
2680 Elm_Atspi_Event_State_Changed_Data *state_data = event_info; 2679 Elm_Atspi_Event_State_Changed_Data *state_data = event_info;
2681 char *type_desc; 2680 char *type_desc;
@@ -2712,30 +2711,16 @@ _state_changed_signal_send(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descr
2712 return EINA_FALSE; 2711 return EINA_FALSE;
2713 } 2712 }
2714 2713
2715 msg = eldbus_service_signal_new(events, ATSPI_OBJECT_EVENT_STATE_CHANGED); 2714 _object_signal_send(events, ATSPI_OBJECT_EVENT_STATE_CHANGED, type_desc, state_data->new_value, 0, NULL);
2716 iter = eldbus_message_iter_get(msg);
2717
2718 eldbus_message_iter_arguments_append(iter, "sii", type_desc, state_data->new_value, 0);
2719 2715
2720 viter = eldbus_message_iter_container_new(iter, 'v', "i");
2721 EINA_SAFETY_ON_NULL_RETURN_VAL(viter, EINA_FALSE);
2722
2723 eldbus_message_iter_arguments_append(viter, "i", 0);
2724 eldbus_message_iter_container_close(iter, viter);
2725
2726 _iter_object_reference_append(iter, _root);
2727
2728 eldbus_service_signal_send(events, msg);
2729 DBG("signal sent StateChanged:%s:%d", type_desc, state_data->new_value); 2716 DBG("signal sent StateChanged:%s:%d", type_desc, state_data->new_value);
2730 2717
2731 return EINA_TRUE; 2718 return EINA_TRUE;
2732} 2719}
2733 2720
2734static Eina_Bool 2721static Eina_Bool
2735_property_changed_signal_send(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) 2722_property_changed_signal_send(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
2736{ 2723{
2737 Eldbus_Message *msg;
2738 Eldbus_Message_Iter *iter, *siter, *viter;
2739 Eldbus_Service_Interface *events = data; 2724 Eldbus_Service_Interface *events = data;
2740 const char *property = event_info; 2725 const char *property = event_info;
2741 char *path, *atspi_desc; 2726 char *path, *atspi_desc;
@@ -2779,27 +2764,11 @@ _property_changed_signal_send(void *data, Eo *obj, const Eo_Event_Description *d
2779 return EINA_FALSE; 2764 return EINA_FALSE;
2780 } 2765 }
2781 2766
2782 msg = eldbus_service_signal_new(events, ATSPI_OBJECT_EVENT_PROPERTY_CHANGED);
2783 EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE);
2784
2785 iter = eldbus_message_iter_get(msg);
2786 siter = eldbus_message_iter_container_new(iter, 'r', NULL);
2787 EINA_SAFETY_ON_NULL_RETURN_VAL(siter, EINA_FALSE);
2788
2789 eldbus_message_iter_arguments_append(siter, "suu", atspi_desc, 0, 0);
2790
2791 viter = eldbus_message_iter_container_new(siter, 'v', "s");
2792 EINA_SAFETY_ON_NULL_RETURN_VAL(viter, EINA_FALSE);
2793
2794 path = _path_from_access_object(obj); 2767 path = _path_from_access_object(obj);
2795 eldbus_message_iter_arguments_append(viter, "s", path);
2796 free(path);
2797 2768
2798 eldbus_message_iter_arguments_append(siter, "v", viter); 2769 _object_signal_send(events, ATSPI_OBJECT_EVENT_PROPERTY_CHANGED, atspi_desc, 0, 0, "s", path);
2799 eldbus_message_iter_container_close(siter, viter); 2770 free(path);
2800 2771
2801 eldbus_message_iter_container_close(iter, siter);
2802 eldbus_service_signal_send(events, msg);
2803 DBG("signal sent PropertyChanged:%s", property); 2772 DBG("signal sent PropertyChanged:%s", property);
2804 2773
2805 return EINA_TRUE; 2774 return EINA_TRUE;
@@ -2820,8 +2789,6 @@ static Eina_Bool
2820_children_changed_signal_send(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) 2789_children_changed_signal_send(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
2821{ 2790{
2822 Eldbus_Service_Interface *events = data; 2791 Eldbus_Service_Interface *events = data;
2823 Eldbus_Message_Iter *iter, *viter;
2824 Eldbus_Message *msg;
2825 const char *atspi_desc = NULL; 2792 const char *atspi_desc = NULL;
2826 Elm_Atspi_Event_Children_Changed_Data *ev_data = event_info; 2793 Elm_Atspi_Event_Children_Changed_Data *ev_data = event_info;
2827 int idx; 2794 int idx;
@@ -2860,32 +2827,17 @@ _children_changed_signal_send(void *data, Eo *obj, const Eo_Event_Description *d
2860 2827
2861 if (!atspi_desc) return EINA_FALSE; 2828 if (!atspi_desc) return EINA_FALSE;
2862 2829
2863 msg = eldbus_service_signal_new(events, ATSPI_OBJECT_EVENT_CHILDREN_CHANGED); 2830 _object_signal_send(events, ATSPI_OBJECT_EVENT_CHILDREN_CHANGED, atspi_desc, idx, 0, "(so)", eldbus_connection_unique_name_get(_a11y_bus), ev_data->child);
2864 EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE);
2865
2866 iter = eldbus_message_iter_get(msg);
2867 eldbus_message_iter_arguments_append(iter, "sii", atspi_desc, idx, 0);
2868
2869 viter = eldbus_message_iter_container_new(iter, 'v', "(so)");
2870 EINA_SAFETY_ON_NULL_RETURN_VAL(viter, EINA_FALSE);
2871
2872 _iter_object_reference_append(viter, ev_data->child);
2873 eldbus_message_iter_container_close(iter, viter);
2874 2831
2875 _iter_object_reference_append(iter, _root);
2876
2877 eldbus_service_signal_send(events, msg);
2878 DBG("signal sent childrenChanged:%s:%d", atspi_desc, idx); 2832 DBG("signal sent childrenChanged:%s:%d", atspi_desc, idx);
2879 2833
2880 return EINA_TRUE; 2834 return EINA_TRUE;
2881} 2835}
2882 2836
2883static Eina_Bool 2837static Eina_Bool
2884_window_signal_send(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info EINA_UNUSED) 2838_window_signal_send(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc, void *event_info EINA_UNUSED)
2885{ 2839{
2886 const char *event_desc; 2840 const char *event_desc;
2887 Eldbus_Message *msg;
2888 Eldbus_Message_Iter *iter, *viter;
2889 Eldbus_Service_Interface *window = data; 2841 Eldbus_Service_Interface *window = data;
2890 enum _Atspi_Window_Signals type; 2842 enum _Atspi_Window_Signals type;
2891 2843
@@ -2919,31 +2871,18 @@ _window_signal_send(void *data, Eo *obj, const Eo_Event_Description *desc, void
2919 return EINA_FALSE; 2871 return EINA_FALSE;
2920 } 2872 }
2921 2873
2922 msg = eldbus_service_signal_new(window, type); 2874 _object_signal_send(window, type, event_desc, 0, 0, "i", 0);
2923 EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE);
2924
2925 iter = eldbus_message_iter_get(msg);
2926 eldbus_message_iter_arguments_append(iter, "sii", event_desc, 0, 0);
2927 2875
2928 viter = eldbus_message_iter_container_new(iter, 'v', "i");
2929 EINA_SAFETY_ON_NULL_RETURN_VAL(viter, EINA_FALSE);
2930
2931 eldbus_message_iter_arguments_append(viter, "i", 0);
2932 eldbus_message_iter_container_close(iter, viter);
2933
2934 _iter_object_reference_append(iter, obj);
2935
2936 eldbus_service_signal_send(window, msg);
2937 DBG("signal sent Window:%s", event_desc); 2876 DBG("signal sent Window:%s", event_desc);
2877
2938 return EINA_TRUE; 2878 return EINA_TRUE;
2939} 2879}
2940 2880
2941static Eina_Bool 2881static Eina_Bool
2942_selection_signal_send(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info EINA_UNUSED) 2882_selection_signal_send(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc, void *event_info EINA_UNUSED)
2943{ 2883{
2944 const char *event_desc; 2884 const char *event_desc;
2945 Eldbus_Message *msg; 2885 Eldbus_Message *msg;
2946 Eldbus_Message_Iter *iter, *viter;
2947 Eldbus_Service_Interface *selection = data; 2886 Eldbus_Service_Interface *selection = data;
2948 2887
2949 enum _Atspi_Object_Signals type; 2888 enum _Atspi_Object_Signals type;
@@ -2967,18 +2906,7 @@ _selection_signal_send(void *data, Eo *obj, const Eo_Event_Description *desc, vo
2967 msg = eldbus_service_signal_new(selection, type); 2906 msg = eldbus_service_signal_new(selection, type);
2968 EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE); 2907 EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE);
2969 2908
2970 iter = eldbus_message_iter_get(msg); 2909 _object_signal_send(selection, type, event_desc, 0, 0, "i", 0);
2971 eldbus_message_iter_arguments_append(iter, "sii", event_desc, 0, 0);
2972
2973 viter = eldbus_message_iter_container_new(iter, 'v', "i");
2974 EINA_SAFETY_ON_NULL_RETURN_VAL(viter, EINA_FALSE);
2975
2976 eldbus_message_iter_arguments_append(viter, "i", 0);
2977 eldbus_message_iter_container_close(iter, viter);
2978
2979 _iter_object_reference_append(iter, obj);
2980
2981 eldbus_service_signal_send(selection, msg);
2982 2910
2983 return EINA_TRUE; 2911 return EINA_TRUE;
2984} 2912}
@@ -2986,8 +2914,11 @@ _selection_signal_send(void *data, Eo *obj, const Eo_Event_Description *desc, vo
2986static void _object_signal_send(Eldbus_Service_Interface *infc, int sig_id, const char *minor, unsigned int det1, unsigned int det2, const char *variant_sig, ...) 2914static void _object_signal_send(Eldbus_Service_Interface *infc, int sig_id, const char *minor, unsigned int det1, unsigned int det2, const char *variant_sig, ...)
2987{ 2915{
2988 Eldbus_Message *msg; 2916 Eldbus_Message *msg;
2989 Eldbus_Message_Iter *iter , *viter; 2917 Eldbus_Message_Iter *iter , *iter_stack[64];
2990 va_list va; 2918 va_list va;
2919 Eo *atspi_obj;
2920 char *path;
2921 int top = 0;
2991 2922
2992 EINA_SAFETY_ON_NULL_RETURN(infc); 2923 EINA_SAFETY_ON_NULL_RETURN(infc);
2993 EINA_SAFETY_ON_NULL_RETURN(minor); 2924 EINA_SAFETY_ON_NULL_RETURN(minor);
@@ -3002,30 +2933,51 @@ static void _object_signal_send(Eldbus_Service_Interface *infc, int sig_id, cons
3002 2933
3003 if (variant_sig) 2934 if (variant_sig)
3004 { 2935 {
3005 viter = eldbus_message_iter_container_new(iter, 'v', variant_sig); 2936 iter_stack[top] = eldbus_message_iter_container_new(iter, 'v', variant_sig);
2937
3006 const char *tmp = variant_sig; 2938 const char *tmp = variant_sig;
3007 while (*tmp) 2939 while (*tmp)
3008 { 2940 {
3009 switch (*tmp) 2941 switch (*tmp)
3010 { 2942 {
2943 case '(':
2944 iter_stack[top + 1] = eldbus_message_iter_container_new(iter_stack[top], 'r', NULL);
2945 top++;
2946 break;
3011 case 's': 2947 case 's':
3012 eldbus_message_iter_basic_append(viter, 's', va_arg(va, char*)); 2948 eldbus_message_iter_basic_append(iter_stack[top], 's', va_arg(va, char*));
2949 break;
2950 case 'i':
2951 eldbus_message_iter_basic_append(iter_stack[top], 'i', va_arg(va, int));
2952 break;
2953 case 'o':
2954 atspi_obj = va_arg(va, Eo*);
2955 path = _path_from_access_object(atspi_obj);
2956 eldbus_message_iter_basic_append(iter_stack[top], 'o', path);
2957 free(path);
2958 break;
2959 case ')':
2960 eldbus_message_iter_container_close(iter_stack[top - 1], iter_stack[top]);
2961 top--;
3013 break; 2962 break;
3014 default: 2963 default:
3015 ERR("Not supported type: %c. Invalid variant signature %s. ", *tmp, variant_sig); 2964 ERR("Not supported d-bus type: %c.", *tmp);
3016 break; 2965 break;
3017 } 2966 }
3018 tmp++; 2967 tmp++;
3019 } 2968 }
3020 } 2969 }
3021 else // AT-SPI implementation forces checks on signature even if varint is not used. 2970 else // AT-SPI implementation forces checks on variant in signature even if not used.
3022 { 2971 {
3023 viter = eldbus_message_iter_container_new(iter, 'v', "i"); 2972 iter_stack[top] = eldbus_message_iter_container_new(iter, 'v', "i");
3024 eldbus_message_iter_basic_append(viter, 'i', 0); 2973 eldbus_message_iter_basic_append(iter_stack[top], 'i', 0);
3025 } 2974 }
3026 2975
3027 va_end(va); 2976 va_end(va);
3028 eldbus_message_iter_container_close(iter, viter); 2977 if (top != 0)
2978 ERR("Invalid d-bus signature: () do not match.");
2979
2980 eldbus_message_iter_container_close(iter, iter_stack[0]);
3029 2981
3030 _iter_object_reference_append(iter, _root); 2982 _iter_object_reference_append(iter, _root);
3031 2983