232 | 232 |
}
|
233 | 233 |
}
|
234 | 234 |
|
|
235 |
|
235 | 236 |
static gboolean
|
236 | |
test_cloud_provider_notify_change (gpointer user_data)
|
|
237 |
change_random_cloud_provider_state (gpointer user_data)
|
237 | 238 |
{
|
238 | 239 |
TestCloudProvider *cloud_provider = (TestCloudProvider *)user_data;
|
239 | 240 |
GRand *rand;
|
240 | 241 |
gint new_status;
|
|
242 |
gint account_id;
|
|
243 |
gchar *account_object_name;
|
241 | 244 |
|
242 | 245 |
rand = g_rand_new ();
|
243 | |
|
244 | |
g_print("Emit changed signal for cloud providers\n");
|
245 | |
gchar *account_object_name;
|
246 | |
account_object_name = g_strdup_printf ("/org/freedesktop/CloudProviderServerExample/%03d",
|
247 | |
g_rand_int_range(rand, 0, COUNT_PLACEHOLDER_ACCOUNTS));
|
248 | |
|
|
246 |
account_id = g_rand_int_range (rand, 0, COUNT_PLACEHOLDER_ACCOUNTS);
|
249 | 247 |
new_status = g_rand_int_range (rand,
|
250 | 248 |
CLOUD_PROVIDER_STATUS_IDLE,
|
251 | 249 |
CLOUD_PROVIDER_STATUS_ERROR + 1);
|
252 | 250 |
|
|
251 |
account_object_name = g_strdup_printf ("/org/freedesktop/CloudProviderServerExample/%03d",
|
|
252 |
account_id);
|
|
253 |
|
253 | 254 |
test_cloud_provider_set_status (cloud_provider, new_status);
|
254 | 255 |
|
|
256 |
g_print ("Change status of %03d to %d\n", account_id, new_status);
|
|
257 |
|
255 | 258 |
g_dbus_connection_emit_signal (cloud_provider->connection,
|
256 | |
NULL,
|
257 | |
account_object_name,
|
258 | |
"org.freedesktop.CloudProvider1",
|
259 | |
"CloudProviderChanged",
|
260 | |
NULL,
|
261 | |
NULL /*error*/);
|
|
259 |
NULL,
|
|
260 |
account_object_name,
|
|
261 |
"org.freedesktop.CloudProvider1",
|
|
262 |
"CloudProviderChanged",
|
|
263 |
NULL,
|
|
264 |
NULL /*error*/);
|
262 | 265 |
return TRUE;
|
263 | 266 |
}
|
264 | 267 |
|
|
270 | 273 |
{
|
271 | 274 |
gchar *name = user_data;
|
272 | 275 |
g_dbus_method_invocation_return_value (invocation,
|
273 | |
g_variant_new ("(s)", name));
|
|
276 |
g_variant_new ("(s)", name));
|
274 | 277 |
}
|
275 | 278 |
|
276 | 279 |
static void
|
|
280 | 283 |
{
|
281 | 284 |
TestCloudProvider *self = user_data;
|
282 | 285 |
g_dbus_method_invocation_return_value (invocation,
|
283 | |
g_variant_new ("(v)", g_icon_serialize(self->icon)));
|
|
286 |
g_variant_new ("(v)", g_icon_serialize(self->icon)));
|
284 | 287 |
}
|
285 | 288 |
|
286 | 289 |
static void
|
287 | 290 |
on_get_path (CloudProvider1 *cloud_provider,
|
288 | |
GDBusMethodInvocation *invocation,
|
289 | |
gpointer user_data)
|
|
291 |
GDBusMethodInvocation *invocation,
|
|
292 |
gpointer user_data)
|
290 | 293 |
{
|
291 | 294 |
TestCloudProvider *self = user_data;
|
292 | 295 |
g_dbus_method_invocation_return_value (invocation,
|
293 | |
g_variant_new ("(s)", self->path));
|
|
296 |
g_variant_new ("(s)", self->path));
|
294 | 297 |
}
|
295 | 298 |
|
296 | 299 |
static void
|
|
300 | 303 |
{
|
301 | 304 |
TestCloudProvider *self = user_data;
|
302 | 305 |
g_dbus_method_invocation_return_value (invocation,
|
303 | |
g_variant_new ("(i)", self->status));
|
|
306 |
g_variant_new ("(i)", self->status));
|
304 | 307 |
}
|
305 | 308 |
|
306 | 309 |
static void
|
|
316 | 319 |
g_debug ("Registering cloud provider server 'MyCloud'\n");
|
317 | 320 |
|
318 | 321 |
self->manager = g_dbus_object_manager_server_new ("/org/freedesktop/CloudProviderServerExample");
|
|
322 |
// export multiple accounts as DBus objects to the bus
|
319 | 323 |
for (n = 0; n < COUNT_PLACEHOLDER_ACCOUNTS; n++)
|
320 | 324 |
{
|
321 | 325 |
|
|
335 | 339 |
g_dbus_object_manager_server_export (self->manager, G_DBUS_OBJECT_SKELETON(object));
|
336 | 340 |
|
337 | 341 |
export_menu (connection, account_object_name);
|
338 | |
// FIXME: send initial changed signal to notify already running e.g. nautilus
|
339 | |
/*g_dbus_connection_emit_signal (connection,
|
340 | |
NULL,
|
341 | |
account_object_name,
|
342 | |
"org.freedesktop.CloudProvider1",
|
343 | |
"CloudProviderChanged",
|
344 | |
NULL,
|
345 | |
// NULL);
|
346 | |
*/
|
|
342 |
|
347 | 343 |
g_free(account_object_name);
|
348 | 344 |
}
|
349 | 345 |
g_dbus_object_manager_server_set_connection (self->manager, connection);
|
|
360 | 356 |
{
|
361 | 357 |
TestCloudProvider *self = (TestCloudProvider *)user_data;
|
362 | 358 |
self->timeout_handler = g_timeout_add (TIMEOUT,
|
363 | |
(GSourceFunc) test_cloud_provider_notify_change,
|
364 | |
self);
|
365 | |
test_cloud_provider_notify_change(self);
|
|
359 |
(GSourceFunc) change_random_cloud_provider_state,
|
|
360 |
self);
|
|
361 |
change_random_cloud_provider_state (self);
|
366 | 362 |
}
|
367 | 363 |
|
368 | 364 |
static void
|
|
380 | 376 |
TestCloudProvider *test_cloud_provider;
|
381 | 377 |
guint owner_id;
|
382 | 378 |
|
383 | |
|
384 | 379 |
test_cloud_provider = g_object_new (test_cloud_provider_get_type (), NULL);
|
385 | |
|
386 | 380 |
|
387 | 381 |
owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
388 | 382 |
"org.freedesktop.CloudProviderServerExample",
|
|
397 | 391 |
g_main_loop_run (loop);
|
398 | 392 |
|
399 | 393 |
g_bus_unown_name (owner_id);
|
400 | |
|
401 | 394 |
g_object_unref (test_cloud_provider);
|
402 | 395 |
|
403 | 396 |
return 0;
|