On Wed, Sep 26, 2012 at 12:48 PM, Enlightenment SVN
<[email protected]> wrote:
> Log:
> PROTO/elocation: Handle GetAddress method and signal
>
> Author: stefan
> Date: 2012-09-26 03:48:34 -0700 (Wed, 26 Sep 2012)
> New Revision: 77083
> Trac: http://trac.enlightenment.org/e/changeset/77083
>
> Modified:
> trunk/PROTO/elocation/src/bin/geoclue-test.c
>
> Modified: trunk/PROTO/elocation/src/bin/geoclue-test.c
> ===================================================================
> --- trunk/PROTO/elocation/src/bin/geoclue-test.c 2012-09-26 10:48:31
> UTC (rev 77082)
> +++ trunk/PROTO/elocation/src/bin/geoclue-test.c 2012-09-26 10:48:34
> UTC (rev 77083)
> @@ -14,9 +14,20 @@
> o Set requirements
> o Attach to signals and give out ecore events
> o Start (how to stop?) service to get position updates
> - o Look for nameOwner changed to issue IN and OUT for geoclue
> + o How to deal with AddReference and RemoveReference?
> + o Implement MasterClient interface
> */
>
> +typedef struct _gc_address
> +{
> + char *country;
> + char *countrycode;
> + char *locality;
> + char *postalcode;
> + char *region;
> + char *timezone;
> +} gc_address;
> +
> static E_DBus_Signal_Handler *cb_position_changed = NULL;
>
> static Eina_Bool
> @@ -34,6 +45,70 @@
> }
>
> void
> +unmarshal_address(DBusMessageIter *iter)
why do you use dbus method ?? normally, only edbus should be used. If
not, then edbus must be fixed
Vincent
> +{
> + DBusMessageIter arr;
> + const char *key;
> + dbus_message_iter_recurse(iter, &arr);
> + gc_address address;
> +
> + if (dbus_message_iter_get_arg_type(&arr) == DBUS_TYPE_INVALID)
> + return;
> +
> + do
> + {
> + DBusMessageIter dict;
> + dbus_message_iter_recurse(&arr, &dict);
> + do
> + {
> + char *value;
> +
> + dbus_message_iter_get_basic(&dict, &key);
> + dbus_message_iter_next(&dict);
> +
> + if (!strcmp(key, "country"))
> + {
> + dbus_message_iter_get_basic(&dict, &value);
> + address.country = value;
> + printf("Key: %s, value: %s\n", key, value);
> + }
> + else if (!strcmp(key, "countrycode"))
> + {
> + dbus_message_iter_get_basic(&dict, &value);
> + address.countrycode = value;
> + printf("Key: %s, value: %s\n", key, value);
> + }
> + else if (!strcmp(key, "locality"))
> + {
> + dbus_message_iter_get_basic(&dict, &value);
> + address.locality = value;
> + printf("Key: %s, value: %s\n", key, value);
> + }
> + else if (!strcmp(key, "postalcode"))
> + {
> + dbus_message_iter_get_basic(&dict, &value);
> + address.postalcode = value;
> + printf("Key: %s, value: %s\n", key, value);
> + }
> + else if (!strcmp(key, "region"))
> + {
> + dbus_message_iter_get_basic(&dict, &value);
> + address.region = value;
> + printf("Key: %s, value: %s\n", key, value);
> + }
> + else if (!strcmp(key, "timezone"))
> + {
> + dbus_message_iter_get_basic(&dict, &value);
> + address.timezone = value;
> + printf("Key: %s, value: %s\n", key, value);
> + }
> + }
> + while (dbus_message_iter_next(&dict));
> + }
> + while (dbus_message_iter_next(&arr));
> +}
> +
> +void
> create_cb(void *data , DBusMessage *reply, DBusError *error)
> {
> const char *object_path;
> @@ -62,6 +137,74 @@
> }
>
> void
> +status_signal_cb(void *data , DBusMessage *reply)
> +{
> + status_cb(data, reply, NULL);
> +}
> +
> +void
> +provider_info_cb(void *data , DBusMessage *reply, DBusError *error)
> +{
> + dbus_int32_t status;
> + DBusMessageIter iter;
> + char *name = NULL, *desc = NULL;
> +
> + if (!dbus_message_has_signature(reply, "ss")) return;
> +
> + dbus_message_get_args(reply, error,
> + DBUS_TYPE_STRING, &name,
> + DBUS_TYPE_STRING, &desc,
> + DBUS_TYPE_INVALID);
> +
> + printf("Provider name: %s\n description: %s\n", name, desc);
> +}
> +
> +void
> +address_cb(void *data , DBusMessage *reply, DBusError *error)
> +{
> + dbus_int32_t level, timestamp;
> + DBusMessageIter iter, sub;
> + double horizontal;
> + double vertical;
> + gc_accuracy accur;
> +
> + if (dbus_error_is_set(error))
> + {
> + printf("Error: %s - %s\n", error->name, error->message);
> + return;
> + }
> +
> + if (!dbus_message_has_signature(reply, "ia{ss}(idd)")) return;
> +
> + dbus_message_iter_init(reply, &iter);
> +
> + dbus_message_iter_get_basic(&iter, ×tamp);
> + dbus_message_iter_next(&iter);
> +
> + unmarshal_address(&iter);
> + dbus_message_iter_next(&iter);
> +
> + dbus_message_iter_recurse(&iter, &sub);
> + dbus_message_iter_get_basic(&sub, &level);
> + accur.level = level;
> + dbus_message_iter_next(&sub);
> +
> + dbus_message_iter_get_basic(&sub, &horizontal);
> + accur.horizontal = horizontal;
> + dbus_message_iter_next(&sub);
> +
> + dbus_message_iter_get_basic(&sub, &vertical);
> + accur.vertical = vertical;
> + dbus_message_iter_next(&sub);
> +}
> +
> +void
> +address_signal_cb(void *data , DBusMessage *reply)
> +{
> + address_cb(data, reply, NULL);
> +}
> +
> +void
> position_cb(void *data , DBusMessage *reply, DBusError *error)
> {
> GeocluePositionFields fields;
> @@ -144,7 +287,7 @@
> main()
> {
> E_DBus_Connection *conn;
> - DBusMessage *msg, *msg2, *msg3;
> + DBusMessage *msg;
> DBusMessageIter iter, sub;
> int ret = 0;
> struct gc_accuracy *accur;
> @@ -163,10 +306,49 @@
> ecore_event_handler_add(E_LOCATION_EVENT_IN, geoclue_start, NULL);
> ecore_event_handler_add(E_LOCATION_EVENT_OUT, geoclue_stop, NULL);
>
> - msg3 = dbus_message_new_method_call(GEOCLUE_DBUS_NAME,
> GEOCLUE_OBJECT_PATH, GEOCLUE_DBUS_NAME, "Create");
> - e_dbus_message_send(conn, msg3, create_cb, -1, NULL);
> - dbus_message_unref(msg3);
> + msg = dbus_message_new_method_call(GEOCLUE_DBUS_NAME,
> GEOCLUE_OBJECT_PATH, GEOCLUE_DBUS_NAME, "Create");
> + e_dbus_message_send(conn, msg, create_cb, -1, NULL);
> + dbus_message_unref(msg);
> + msg = NULL;
>
> + msg = dbus_message_new_method_call(UBUNTU_DBUS_NAME, UBUNTU_OBJECT_PATH,
> GEOCLUE_IFACE, "GetStatus");
> + e_dbus_message_send(conn, msg, status_cb, -1, NULL);
> + dbus_message_unref(msg);
> + msg = NULL;
> +
> + cb_position_changed = e_dbus_signal_handler_add(conn, UBUNTU_DBUS_NAME,
> UBUNTU_OBJECT_PATH, GEOCLUE_POSITION_IFACE, "GetStatus",
> + status_signal_cb, NULL);
> +
> + msg = dbus_message_new_method_call(UBUNTU_DBUS_NAME, UBUNTU_OBJECT_PATH,
> GEOCLUE_IFACE, "GetProviderInfo");
> + e_dbus_message_send(conn, msg, provider_info_cb, -1, NULL);
> + dbus_message_unref(msg);
> + msg = NULL;
> +
> + // SetOptions
> +
> + msg = dbus_message_new_method_call(UBUNTU_DBUS_NAME, UBUNTU_OBJECT_PATH,
> GEOCLUE_ADDRESS_IFACE, "GetAddress");
> + e_dbus_message_send(conn, msg, address_cb, -1, NULL);
> + dbus_message_unref(msg);
> + msg = NULL;
> +
> + cb_position_changed = e_dbus_signal_handler_add(conn, UBUNTU_DBUS_NAME,
> UBUNTU_OBJECT_PATH, GEOCLUE_ADDRESS_IFACE, "GetAddress",
> + address_signal_cb, NULL);
> +
> + msg = dbus_message_new_method_call(UBUNTU_DBUS_NAME, UBUNTU_OBJECT_PATH,
> GEOCLUE_POSITION_IFACE, "GetPosition");
> + e_dbus_message_send(conn, msg, position_cb, -1, NULL);
> + dbus_message_unref(msg);
> + msg = NULL;
> +
> + cb_position_changed = e_dbus_signal_handler_add(conn, UBUNTU_DBUS_NAME,
> UBUNTU_OBJECT_PATH, GEOCLUE_POSITION_IFACE, "GetPosition",
> + position_signal_cb, NULL);
> +
> + ecore_main_loop_begin();
> +
> + elocation_shutdown(conn);
> + e_dbus_shutdown();
> + return ret;
> +}
> +
> #if 0
> dbus_message_append_args(msg, DBUS_TYPE_INT32, &field, DBUS_TYPE_INT32,
> ×tamp,
> DBUS_TYPE_DOUBLE, &latitude,
> DBUS_TYPE_DOUBLE, &longitude,
> @@ -184,20 +366,3 @@
>
> dbus_message_iter_close_container(&iter, &sub);
> #endif
> - msg = dbus_message_new_method_call(UBUNTU_DBUS_NAME, UBUNTU_OBJECT_PATH,
> GEOCLUE_POSITION_IFACE, "GetPosition");
> - e_dbus_message_send(conn, msg, position_cb, -1, NULL);
> - dbus_message_unref(msg);
> -
> - cb_position_changed = e_dbus_signal_handler_add(conn, UBUNTU_DBUS_NAME,
> UBUNTU_OBJECT_PATH, GEOCLUE_POSITION_IFACE, "GetPosition",
> - position_signal_cb, NULL);
> -
> - msg2 = dbus_message_new_method_call(UBUNTU_DBUS_NAME, UBUNTU_OBJECT_PATH,
> GEOCLUE_IFACE, "GetStatus");
> - e_dbus_message_send(conn, msg2, status_cb, -1, NULL);
> - dbus_message_unref(msg2);
> -
> - ecore_main_loop_begin();
> -
> - elocation_shutdown(conn);
> - e_dbus_shutdown();
> - return ret;
> -}
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> enlightenment-svn mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/enlightenment-svn
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel