/* control-world.c * * Copyright 2007-2008 OpenMoko, Inc. * Authored by Chia-I Wu * * 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 "diversity-control.h" #include "control-marshal.h" #include #include static gboolean control_world_get_self(DiversityWorld *world, gchar **OUT_path, GError **error); static gboolean control_world_get_tunneled(DiversityWorld *world, gboolean *OUT_tunneled, GError **error); static gboolean control_world_connect_ap(DiversityWorld *world, gchar *IN_path, GError **error); static gboolean control_world_connect_wired(DiversityWorld *world, GError **error); static void control_world_viewport_add(DiversityWorld *world, gdouble IN_lon1, gdouble IN_lat1, gdouble IN_lon2, gdouble IN_lat2, DBusGMethodInvocation *context); static gboolean control_world_viewport_remove(DiversityWorld *world, gchar *IN_path, GError **error); static gboolean control_world_tag_add(DiversityWorld *world, gdouble IN_lon, gdouble IN_lat, const gchar *IN_description, gchar **OUT_tag, GError **error); static gboolean control_world_tag_remove(DiversityWorld *world, gchar *IN_path, GError **error); #include "control-world-glue.h" static gboolean control_world_get_self(DiversityWorld *world, gchar **OUT_path, GError **error) { DiversityControl *ctrl = diversity_control_from_world(world); DiversityBard *bard; DiversityControlExport *export; bard = diversity_world_get_self(world); if (!bard) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "no ego?"); return FALSE; } export = diversity_control_object_export(ctrl, DIVERSITY_OBJECT(bard), NULL); *OUT_path = g_strdup(export->path); return TRUE; } static gboolean control_world_get_tunneled(DiversityWorld *world, gboolean *OUT_tunneled, GError **error) { *OUT_tunneled = diversity_world_get_tunneled(world); return TRUE; } static gboolean control_world_connect_ap(DiversityWorld *world, gchar *IN_path, GError **error) { DiversityControl *ctrl = diversity_control_from_world(world); DiversityObject *obj; obj = diversity_control_object_lookup(ctrl, IN_path); if (!obj || obj->type != DIVERSITY_OBJECT_TYPE_AP) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "non-existing AP %s\n", IN_path); return FALSE; } diversity_world_connect_ap(world, DIVERSITY_AP(obj)); return TRUE; } static gboolean control_world_connect_wired(DiversityWorld *world, GError **error) { diversity_world_connect_wired(world); return TRUE; } static void control_world_viewport_add(DiversityWorld *world, gdouble IN_lon1, gdouble IN_lat1, gdouble IN_lon2, gdouble IN_lat2, DBusGMethodInvocation *context) { DiversityControl *ctrl = diversity_control_from_world(world); DiversityViewport *view; DiversityControlExport *export; gchar *sender; view = diversity_viewport_new(IN_lon1, IN_lat1, IN_lon2, IN_lat2); if (!view) { GError *error; g_set_error(&error, DIVERSITY_CONTROL_ERROR, 0, "failed to create viewport"); dbus_g_method_return_error(context, error); return; } sender = dbus_g_method_get_sender(context); export = diversity_control_object_export(ctrl, DIVERSITY_OBJECT(view), sender); diversity_world_add_viewport(world, view); dbus_g_method_return(context, export->path); } static gboolean control_world_viewport_remove(DiversityWorld *world, gchar *IN_path, GError **error) { DiversityControl *ctrl = diversity_control_from_world(world); DiversityObject *obj; DiversityViewport *view; obj = diversity_control_object_lookup(ctrl, IN_path); if (!obj) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "failed to remove %s", IN_path); return FALSE; } view = DIVERSITY_VIEWPORT(obj); diversity_control_object_unexport(ctrl, DIVERSITY_OBJECT(view)); diversity_world_remove_viewport(world, view); return TRUE; } static gboolean control_world_tag_add(DiversityWorld *world, gdouble IN_lon, gdouble IN_lat, const gchar *IN_description, gchar **OUT_tag, GError **error) { DiversityControl *ctrl = diversity_control_from_world(world); DiversityObject *tag; DiversityControlExport *export; tag = g_object_new(DIVERSITY_TYPE_TAG, NULL); if (!tag) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "failed to create tag"); return FALSE; } diversity_object_geometry_set(tag, IN_lon, IN_lat, 0.0, 0.0); diversity_object_set_accuracy(tag, DIVERSITY_OBJECT_ACCURACY_EXACT); diversity_tag_set(DIVERSITY_TAG(tag), DIVERSITY_TAG_DESCRIPTION, IN_description); export = diversity_control_object_export(ctrl, tag, NULL); diversity_world_add_object(world, tag); *OUT_tag = g_strdup(export->path); return TRUE; } static gboolean control_world_tag_remove(DiversityWorld *world, gchar *IN_path, GError **error) { DiversityControl *ctrl = diversity_control_from_world(world); DiversityObject *obj, *tag; obj = diversity_control_object_lookup(ctrl, IN_path); if (!obj) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "failed to remove %s", IN_path); return FALSE; } tag = DIVERSITY_OBJECT(obj); diversity_world_remove_object(world, tag); return TRUE; }