~timchen119/ubuntu/trusty/gnome-bluetooth/lp1035431

« back to all changes in this revision

Viewing changes to lib/obex-agent.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2011-02-27 15:45:22 UTC
  • mfrom: (1.3.2 upstream)
  • mto: (2.2.3 experimental) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: james.westby@ubuntu.com-20110227154522-dnnoqasv5v3mv42a
Tags: upstream-2.91.5
ImportĀ upstreamĀ versionĀ 2.91.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
 
66
66
        ObexAgentCompleteFunc complete_func;
67
67
        gpointer complete_data;
 
68
 
 
69
        ObexAgentErrorFunc error_func;
 
70
        gpointer error_data;
68
71
};
69
72
 
70
73
G_DEFINE_TYPE(ObexAgent, obex_agent, G_TYPE_OBJECT)
73
76
                                                DBusGMethodInvocation *context)
74
77
{
75
78
        ObexAgentPrivate *priv = OBEX_AGENT_GET_PRIVATE(agent);
76
 
        const char *sender = dbus_g_method_get_sender(context);
 
79
        char *sender = dbus_g_method_get_sender(context);
77
80
        gboolean result = FALSE;
78
81
 
79
82
        DBG("agent %p sender %s", agent, sender);
80
83
 
81
 
        if (g_str_equal(sender, priv->busname) == FALSE)
82
 
                return FALSE;
 
84
        if (priv->busname == NULL) {
 
85
                /* When we get called the first time, if OBEX_SERVICE
 
86
                 * was not available, we get its name here */
 
87
                priv->busname = sender;
 
88
        } else {
 
89
                if (g_str_equal(sender, priv->busname) == FALSE) {
 
90
                        g_free (sender);
 
91
                        return FALSE;
 
92
                }
 
93
 
 
94
                g_free (sender);
 
95
        }
83
96
 
84
97
        if (priv->request_func) {
85
98
                DBusGProxy *proxy;
102
115
                        guint64 transferred, DBusGMethodInvocation *context)
103
116
{
104
117
        ObexAgentPrivate *priv = OBEX_AGENT_GET_PRIVATE(agent);
105
 
        const char *sender = dbus_g_method_get_sender(context);
 
118
        char *sender = dbus_g_method_get_sender(context);
106
119
        gboolean result = FALSE;
107
120
 
108
121
        DBG("agent %p sender %s", agent, sender);
109
122
 
110
 
        if (g_str_equal(sender, priv->busname) == FALSE)
 
123
        if (g_str_equal(sender, priv->busname) == FALSE) {
 
124
                g_free (sender);
111
125
                return FALSE;
 
126
        }
 
127
 
 
128
        g_free (sender);
112
129
 
113
130
        if (priv->progress_func) {
114
131
                DBusGProxy *proxy;
130
147
                                                DBusGMethodInvocation *context)
131
148
{
132
149
        ObexAgentPrivate *priv = OBEX_AGENT_GET_PRIVATE(agent);
133
 
        const char *sender = dbus_g_method_get_sender(context);
 
150
        char *sender = dbus_g_method_get_sender(context);
134
151
        gboolean result = FALSE;
135
152
 
136
153
        DBG("agent %p sender %s", agent, sender);
137
154
 
138
 
        if (g_str_equal(sender, priv->busname) == FALSE)
 
155
        if (g_str_equal(sender, priv->busname) == FALSE) {
 
156
                g_free (sender);
139
157
                return FALSE;
 
158
        }
 
159
 
 
160
        g_free (sender);
140
161
 
141
162
        if (priv->complete_func) {
142
163
                DBusGProxy *proxy;
158
179
                                                DBusGMethodInvocation *context)
159
180
{
160
181
        ObexAgentPrivate *priv = OBEX_AGENT_GET_PRIVATE(agent);
161
 
        const char *sender = dbus_g_method_get_sender(context);
 
182
        char *sender = dbus_g_method_get_sender(context);
162
183
        gboolean result = FALSE;
163
184
 
164
185
        DBG("agent %p sender %s", agent, sender);
165
186
 
166
 
        if (g_str_equal(sender, priv->busname) == FALSE)
 
187
        if (g_str_equal(sender, priv->busname) == FALSE) {
 
188
                g_free (sender);
167
189
                return FALSE;
 
190
        }
 
191
 
 
192
        g_free (sender);
168
193
 
169
194
        if (priv->release_func)
170
195
                result = priv->release_func(context, priv->release_data);
176
201
        return result;
177
202
}
178
203
 
 
204
static gboolean obex_agent_error(ObexAgent *agent,
 
205
                                 const char *path,
 
206
                                 const char *message,
 
207
                                 DBusGMethodInvocation *context)
 
208
{
 
209
        ObexAgentPrivate *priv = OBEX_AGENT_GET_PRIVATE(agent);
 
210
        char *sender = dbus_g_method_get_sender(context);
 
211
        gboolean result = FALSE;
 
212
 
 
213
        DBG("agent %p sender %s", agent, sender);
 
214
 
 
215
        if (g_str_equal(sender, priv->busname) == FALSE) {
 
216
                g_free (sender);
 
217
                return FALSE;
 
218
        }
 
219
 
 
220
        g_free (sender);
 
221
 
 
222
        if (priv->error_func) {
 
223
                DBusGProxy *proxy;
 
224
 
 
225
                proxy = dbus_g_proxy_new_for_name(connection, OBEX_SERVICE,
 
226
                                                path, OBEX_TRANSFER_INTERFACE);
 
227
 
 
228
                result = priv->error_func(context, proxy, message,
 
229
                                                        priv->progress_data);
 
230
 
 
231
                g_object_unref(proxy);
 
232
        } else
 
233
                dbus_g_method_return(context);
 
234
 
 
235
        return result;
 
236
}
 
237
 
179
238
#include "obex-agent-glue.h"
180
239
 
181
240
static void obex_agent_init(ObexAgent *agent)
309
368
        priv->complete_func = func;
310
369
        priv->complete_data = data;
311
370
}
 
371
 
 
372
void obex_agent_set_error_func(ObexAgent *agent,
 
373
                               ObexAgentErrorFunc func, gpointer data)
 
374
{
 
375
        ObexAgentPrivate *priv = OBEX_AGENT_GET_PRIVATE(agent);
 
376
 
 
377
        DBG("agent %p", agent);
 
378
 
 
379
        priv->error_func = func;
 
380
        priv->error_data = data;
 
381
}