2
* Copyright 2013 Canonical Ltd.
5
* Charles Kerr <charles.kerr@canonical.com>
7
* This program is free software: you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 3, as published
9
* by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranties of
13
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
* PURPOSE. See the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "mock-object.h"
27
const int TIMEOUT_SECONDS = 5;
29
gboolean on_timeout_reached (gpointer loop)
31
g_main_loop_quit (static_cast<GMainLoop*>(loop));
32
return G_SOURCE_REMOVE;
35
void on_name_acquired (GDBusConnection * connection G_GNUC_UNUSED,
36
const char * name G_GNUC_UNUSED,
39
//g_debug ("name '%s' acquired", name);
40
g_main_loop_quit (static_cast<GMainLoop*>(loop));
43
void on_name_lost (GDBusConnection * connection G_GNUC_UNUSED,
44
const char * name G_GNUC_UNUSED,
47
//g_debug ("name '%s' lost", name);
48
g_main_loop_quit (static_cast<GMainLoop*>(loop));
53
MockObject :: set_skeleton (GDBusInterfaceSkeleton * skeleton)
55
g_assert (skeleton != NULL);
56
g_assert (my_skeleton == NULL);
57
g_assert (g_variant_is_object_path (my_object_path.c_str()));
58
g_assert (my_owner_id == 0);
60
my_skeleton = G_DBUS_INTERFACE_SKELETON (g_object_ref (skeleton));
63
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON(my_skeleton),
65
my_object_path.c_str(),
67
g_assert_no_error (err);
69
my_owner_id = g_bus_own_name_on_connection (my_bus_connection,
70
my_object_name.c_str(),
71
G_BUS_NAME_OWNER_FLAGS_NONE,
77
// wait for the name to be acquired or timeout, whichever comes first
78
const guint timeout_id = g_timeout_add_seconds (TIMEOUT_SECONDS,
81
g_main_loop_run (my_loop);
82
g_assert (g_main_context_find_source_by_id (NULL, timeout_id) != NULL);
83
g_source_remove (timeout_id);
90
MockObject :: MockObject (GMainLoop * loop,
91
GDBusConnection * bus_connection,
92
const std::string & object_name,
93
const std::string & object_path):
95
my_loop (g_main_loop_ref (loop)),
96
my_bus_connection (G_DBUS_CONNECTION (g_object_ref (bus_connection))),
97
my_object_name (object_name),
98
my_object_path (object_path),
103
MockObject :: ~MockObject ()
105
g_main_loop_unref (my_loop);
107
if (my_owner_id != 0)
109
g_bus_unown_name (my_owner_id);
116
g_dbus_interface_skeleton_unexport (my_skeleton);
118
g_clear_object (&my_skeleton);
121
g_clear_object (&my_bus_connection);