/* diversity-xmpp-backend - Communication with (diversity) XMPP server * * Copyright 2008 OpenMoko, Inc. * Authored by Daniel Willmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include #include #include #include "diversity-xmpp.h" #include "diversity-xmpp-backend.h" #include "xmpp-geoloc.h" static struct { DiversityWorld *world; DiversityXmpp *xmpp; } priv; static void on_geoloc_message(DiversityXmpp *self, gchar *jid, gdouble lat, gdouble lon, gdouble alt, gdouble err, DiversityWorld *world) { DiversityBard *bard; g_debug("geoloc_signal handled from %s: Lat=%f, Lon=%f", jid, lat, lon); if (!(bard = diversity_world_lookup_object(world, DIVERSITY_OBJECT_TYPE_BARD, jid))) { bard = diversity_bard_new(); diversity_bard_set_uid(bard, jid); diversity_bard_set_fullname(bard, jid); diversity_object_geometry_set(bard, lon, lat, 0, 0); diversity_world_add_object(world, bard); } else { diversity_object_geometry_set(bard, lon, lat, 0, 0); } } static void on_self_geometry_changed(DiversityBard *self, gdouble lon, gdouble lat, gdouble width, gdouble height, DiversityXmpp *xmpp) { xmpp_geoloc_publish_position(xmpp, lat, lon, 0, 0); } int xmpp_init(DiversityWorld *world, GError **error) { DiversityBard *self; struct DiversityXmppUserInfo userinfo = { "daniel@thebe.totalueberwachung.de", "daniel", "", "diversity" }; struct DiversityXmppServerInfo serverinfo = { "134.169.172.64", 15222 }; if (!g_thread_supported()) { g_thread_init(NULL); } priv.world = world; g_object_ref(world); priv.xmpp = diversity_xmpp_new("xmpp", error); if (!priv.xmpp) { xmpp_fini(); return FALSE; } diversity_xmpp_userinfo_set(priv.xmpp, &userinfo); diversity_xmpp_serverinfo_set(priv.xmpp, &serverinfo); diversity_xmpp_connect(priv.xmpp); self = diversity_world_get_self(priv.world); g_signal_connect(self, "geometry-changed", G_CALLBACK(on_self_geometry_changed), priv.xmpp); /* FIXME: Geoloc stuff needs to be its own class */ g_signal_connect(priv.xmpp, "geoloc-message-received", G_CALLBACK(on_geoloc_message), priv.world); return TRUE; } void xmpp_fini(void) { GError *error = NULL; if (priv.xmpp) { g_object_unref(G_OBJECT(priv.xmpp)); priv.xmpp = NULL; } if (priv.world) { g_object_unref(G_OBJECT(priv.world)); priv.world = NULL; } }