3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6 * Copyright (C) 2011 ST-Ericsson AB.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #include "gnssagent.h"
41 guint disconnect_watch;
42 ofono_destroy_func removed_cb;
46 static void gnss_agent_send_noreply(struct gnss_agent *agent,
47 const char *method, int type, ...)
49 DBusConnection *conn = ofono_dbus_get_connection();
53 message = dbus_message_new_method_call(agent->bus, agent->path,
54 OFONO_GNSS_POSR_AGENT_INTERFACE,
58 dbus_message_append_args_valist(message, type, args);
61 dbus_message_set_no_reply(message, TRUE);
63 g_dbus_send_message(conn, message);
66 static inline void gnss_agent_send_release(struct gnss_agent *agent)
68 gnss_agent_send_noreply(agent, "Release", DBUS_TYPE_INVALID);
71 void gnss_agent_receive_request(struct gnss_agent *agent, const char *xml)
73 gnss_agent_send_noreply(agent, "Request", DBUS_TYPE_STRING, &xml,
77 void gnss_agent_receive_reset(struct gnss_agent *agent)
79 gnss_agent_send_noreply(agent, "ResetAssistanceData",
83 ofono_bool_t gnss_agent_matches(struct gnss_agent *agent,
84 const char *path, const char *sender)
86 return g_str_equal(agent->path, path) &&
87 g_str_equal(agent->bus, sender);
90 ofono_bool_t gnss_agent_sender_matches(struct gnss_agent *agent,
93 return g_str_equal(agent->bus, sender);
96 void gnss_agent_set_removed_notify(struct gnss_agent *agent,
97 ofono_destroy_func destroy,
100 agent->removed_cb = destroy;
101 agent->removed_data = user_data;
104 void gnss_agent_free(struct gnss_agent *agent)
106 DBusConnection *conn = ofono_dbus_get_connection();
108 if (agent->disconnect_watch) {
109 gnss_agent_send_release(agent);
110 g_dbus_remove_watch(conn, agent->disconnect_watch);
111 agent->disconnect_watch = 0;
114 if (agent->removed_cb)
115 agent->removed_cb(agent->removed_data);
122 static void gnss_agent_disconnect_cb(DBusConnection *conn, void *user_data)
124 struct gnss_agent *agent = user_data;
126 agent->disconnect_watch = 0;
128 gnss_agent_free(agent);
131 struct gnss_agent *gnss_agent_new(const char *path, const char *sender)
133 struct gnss_agent *agent = g_try_new0(struct gnss_agent, 1);
134 DBusConnection *conn = ofono_dbus_get_connection();
139 agent->path = g_strdup(path);
140 agent->bus = g_strdup(sender);
142 agent->disconnect_watch = g_dbus_add_disconnect_watch(conn, sender,
143 gnss_agent_disconnect_cb,