/* control-object.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 "diversity-control.h" static gboolean control_object_get_type(DiversityObject *obj, gint *OUT_type, GError **error); static gboolean control_object_geometry_set(DiversityObject *obj, gdouble IN_lon, gdouble IN_lat, gdouble IN_width, gdouble IN_height, GError **error); static gboolean control_object_geometry_get(DiversityObject *obj, gdouble *OUT_lon, gdouble *OUT_lat, gdouble *OUT_width, gdouble *OUT_height, GError **error); static gboolean control_object_get_connections(DiversityObject *obj, GPtrArray **OUT_connections, GError **error); static gboolean control_object_connect(DiversityObject *obj, const gchar *IN_path, GError **error); static gboolean control_object_disconnect(DiversityObject *obj, const gchar *IN_path, GError **error); static gboolean control_object_last_seen(DiversityObject *obj, gint *OUT_epoch, GError **error); static gboolean control_object_set_persistent(DiversityObject *obj, gint IN_persistent, GError **error); static gboolean control_object_get_persistent(DiversityObject *obj, gint *OUT_persistent, GError **error); static gboolean control_object_set_public(DiversityObject *obj, gint IN_public, GError **error); static gboolean control_object_get_public(DiversityObject *obj, gint *OUT_public, GError **error); #include "control-object-glue.h" static gboolean control_object_get_type(DiversityObject *obj, gint *OUT_type, GError **error) { *OUT_type = obj->type; return TRUE; } static gboolean control_object_geometry_set(DiversityObject *obj, gdouble IN_lon, gdouble IN_lat, gdouble IN_width, gdouble IN_height, GError **error) { diversity_object_geometry_set(obj, IN_lon, IN_lat, IN_width, IN_height); return TRUE; } static gboolean control_object_geometry_get(DiversityObject *obj, gdouble *OUT_lon, gdouble *OUT_lat, gdouble *OUT_width, gdouble *OUT_height, GError **error) { diversity_object_geometry_get(obj, OUT_lon, OUT_lat, OUT_width, OUT_height); return TRUE; } static gboolean control_object_get_connections(DiversityObject *obj, GPtrArray **OUT_connections, GError **error) { DiversityControl *ctrl = diversity_control_from_object(obj); GPtrArray *array; GSList *list; guint len; list = (GSList *) diversity_object_get_connections(obj); len = g_slist_length(list); array = g_ptr_array_sized_new(len); while (list) { DiversityControlExport *export; gchar *path; export = diversity_control_object_export(ctrl, DIVERSITY_OBJECT(list->data), NULL); path = g_strdup(export->path); g_ptr_array_add(array, path); list = list->next; } *OUT_connections = array; return TRUE; } static gboolean control_object_connect(DiversityObject *obj, const gchar *IN_path, GError **error) { DiversityControl *ctrl = diversity_control_from_object(obj); DiversityObject *target; target = diversity_control_object_lookup(ctrl, IN_path); if (!target) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "non-existing object %s\n", IN_path); return FALSE; } if (obj != target) diversity_object_connect(obj, target); return TRUE; } static gboolean control_object_disconnect(DiversityObject *obj, const gchar *IN_path, GError **error) { DiversityControl *ctrl = diversity_control_from_object(obj); DiversityObject *target; target = diversity_control_object_lookup(ctrl, IN_path); if (!target) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "non-existing object %s\n", IN_path); return FALSE; } if (obj != target) diversity_object_disconnect(obj, target); return TRUE; } static gboolean control_object_last_seen(DiversityObject *obj, gint *OUT_epoch, GError **error) { *OUT_epoch = (gint) diversity_object_get_timestamp(obj); return TRUE; } static gboolean control_object_set_persistent(DiversityObject *obj, gint IN_persistent, GError **error) { diversity_object_set_persistent(obj, IN_persistent); return TRUE; } static gboolean control_object_get_persistent(DiversityObject *obj, gint *OUT_persistent, GError **error) { *OUT_persistent = diversity_object_get_persistent(obj); return TRUE; } static gboolean control_object_set_public(DiversityObject *obj, gint IN_public, GError **error) { diversity_object_set_public(obj, IN_public); return TRUE; } static gboolean control_object_get_public(DiversityObject *obj, gint *OUT_public, GError **error) { *OUT_public = diversity_object_get_public(obj); return TRUE; }