Ticket #253: binding_dbus.c_added_zoom_in.diff

File binding_dbus.c_added_zoom_in.diff, 4.3 KB (added by Singesang, 13 years ago)
  • binding_dbus.c

     
    2626#include "main.h"
    2727#include "navit.h"
    2828#include "coord.h"
     29#include "point.h"
    2930#include "plugin.h"
    3031#include "debug.h"
    3132#include "item.h"
     
    168169
    169170        return empty_reply(connection, message);
    170171}
     172
    171173static int
    172174pcoord_get_from_message(DBusMessage *message, struct pcoord *pc)
    173175{
     
    191193        dbus_message_iter_next(&iter2);
    192194        if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INVALID)
    193195                return 0;
     196    dbg(0, " pro -> %i x -> %i y -> %i\n", &pc->pro, &pc->x, &pc->y);
    194197        return 1;
    195198}
    196199
     200static int
     201point_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct point *p)
     202{
     203    DBusMessageIter iter2;
     204
     205        dbg(0,"%s\n", dbus_message_iter_get_signature(iter));
     206       
     207    // iterate into (ii) with iter2
     208    dbus_message_iter_recurse(iter, &iter2);
     209
     210        // get x
     211    if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INT32)
     212                return 0;
     213        dbus_message_iter_get_basic(&iter2, &p->x);
     214    // got x
     215       
     216    // process to the next value
     217    dbus_message_iter_next(&iter2);
     218   
     219    // get y
     220        if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INT32)
     221                return 0;
     222        dbus_message_iter_get_basic(&iter2, &p->y);
     223    // got y
     224
     225    dbg(0, " x -> %i  y -> %i\n", p->x, p->y);
     226       
     227    // a final test if that was the last value
     228    dbus_message_iter_next(&iter2);
     229
     230        if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INVALID)
     231                return 0;
     232       
     233    // everything went right :D
     234        return 1;
     235}
     236
    197237static DBusHandlerResult
    198238request_navit_set_center(DBusConnection *connection, DBusMessage *message)
    199239{
     
    209249}
    210250
    211251static DBusHandlerResult
     252request_navit_zoom_in(DBusConnection *connection, DBusMessage *message)
     253{
     254        int factor;
     255    struct point p;
     256        struct navit *navit;
     257        DBusMessageIter iter;
     258
     259        navit=object_get_from_message(message, "navit");
     260        if (! navit)
     261                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     262
     263        dbus_message_iter_init(message, &iter);
     264        dbg(0,"%s\n", dbus_message_iter_get_signature(&iter));
     265       
     266    // get zoom factor
     267    dbus_message_iter_get_basic(&iter, &factor);
     268   
     269    // check if there's also a point given
     270    if (!dbus_message_iter_has_next(&iter))
     271    {
     272        navit_zoom_in(navit, factor, NULL);
     273            return empty_reply(connection, message);
     274    }
     275
     276    dbus_message_iter_next(&iter);
     277    if (!point_get_from_message(message, &iter, &p))
     278        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     279   
     280    navit_zoom_in(navit, factor, &p);
     281        return empty_reply(connection, message);
     282
     283}
     284
     285static DBusHandlerResult
    212286request_navit_set_layout(DBusConnection *connection, DBusMessage *message)
    213287{
    214288        char *new_layout_name;
     
    233307static DBusHandlerResult
    234308navit_handler_func(DBusConnection *connection, DBusMessage *message, void *user_data)
    235309{
    236         dbg(0,"type=%s interface=%s path=%s member=%s signature=%s\n", dbus_message_type_to_string(dbus_message_get_type(message)), dbus_message_get_interface(message), dbus_message_get_path(message), dbus_message_get_member(message), dbus_message_get_signature(message));
     310        dbg(0,"\n\ttype=%s\n\tinterface=%s\n\tpath=%s\n\tmember=%s\n\tsignature=%s\n", dbus_message_type_to_string(dbus_message_get_type(message)), dbus_message_get_interface(message), dbus_message_get_path(message), dbus_message_get_member(message), dbus_message_get_signature(message));
    237311#if 0
    238312        if (dbus_message_is_method_call (message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
    239313                DBusMessage *reply;
     
    262336        if (dbus_message_is_method_call (message, "org.navit_project.navit.navit", "set_center") &&
    263337                dbus_message_has_signature(message,"(iii)"))
    264338                return request_navit_set_center(connection, message);
     339        if (dbus_message_is_method_call (message, "org.navit_project.navit.navit", "zoom_in") &&
     340                dbus_message_has_signature(message, "i(ii)"))
     341                return request_navit_zoom_in(connection, message);
     342        if (dbus_message_is_method_call (message, "org.navit_project.navit.navit", "zoom_in") &&
     343                dbus_message_has_signature(message, "i"))
     344                return request_navit_zoom_in(connection, message);
    265345        if (dbus_message_is_method_call (message, "org.navit_project.navit.navit", "set_layout") &&
    266346                dbus_message_has_signature(message,"s"))
    267347                return request_navit_set_layout(connection, message);