/* control-sms.c - * * Copyright 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" static gboolean control_sms_get_status(DiversitySms *sms, gint *OUT_status, GError **error); static gboolean control_sms_send(DiversitySms *sms, const gchar *IN_number, const gchar *IN_message, gboolean IN_ask_ds, GError **error); static gboolean control_sms_share_tag(DiversitySms *sms, const gchar *IN_bard, const gchar *IN_tag, GError **error); #include "control-sms-glue.h" static gboolean control_sms_get_status(DiversitySms *sms, gint *OUT_status, GError **error) { *OUT_status = diversity_sms_get_status(DIVERSITY_SMS(sms)); return TRUE; } static gboolean control_sms_send(DiversitySms *sms, const gchar *IN_number, const gchar *IN_message, gboolean IN_ask_ds, GError **error) { gboolean success; success = diversity_sms_send(DIVERSITY_SMS(sms), IN_number, IN_message, IN_ask_ds, error); if (!success) (*error)->domain = DIVERSITY_CONTROL_ERROR; return success; } static const gchar *bard_to_number(DiversityControl *ctrl, const gchar *IN_bard, GError **error) { DiversityObject *bard; const gchar *number; bard = diversity_control_object_lookup(ctrl, IN_bard); if (!bard || bard->type != DIVERSITY_OBJECT_TYPE_BARD) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "bard %s does not exist", IN_bard); return NULL; } number = diversity_bard_get_phone(DIVERSITY_BARD(bard)); if (!number) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "bard %s does not have a number", IN_bard); return NULL; } return number; } static gchar *tag_to_message(DiversityControl *ctrl, const gchar *IN_tag, GError **error) { DiversityObject *tag; gchar *message; gdouble x, y; tag = diversity_control_object_lookup(ctrl, IN_tag); if (!tag || tag->type != DIVERSITY_OBJECT_TYPE_TAG) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "tag %s does not exist", IN_tag); return NULL; } if (!diversity_object_get_accuracy(tag)) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "tag %s cannot be located", IN_tag); return NULL; } diversity_object_geometry_get(tag, &x, &y, NULL, NULL); message = (gchar *) diversity_tag_get(DIVERSITY_TAG(tag), DIVERSITY_TAG_DESCRIPTION); message = g_strdup_printf("l6n(%f,%f)\n%s", x, y, message); return message; } static gboolean control_sms_share_tag(DiversitySms *sms, const gchar *IN_bard, const gchar *IN_tag, GError **error) { DiversityControl *ctrl; gchar *number, *message; gboolean success; ctrl = diversity_control_from_equipment(DIVERSITY_EQUIPMENT(sms)); if (!ctrl) { g_set_error(error, DIVERSITY_CONTROL_ERROR, 0, "failed to retrieve control from equipment"); return FALSE; } number = (gchar *) bard_to_number(ctrl, IN_bard, error); if (!number) return FALSE; message = (gchar *) tag_to_message(ctrl, IN_tag, error); if (!message) return FALSE; success = diversity_sms_send(DIVERSITY_SMS(sms), number, message, FALSE, error); if (!success) (*error)->domain = DIVERSITY_CONTROL_ERROR; g_free(message); return success; }