1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
/* vi: set et sw=4 ts=8 cino=t0,(0: */
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */
/*
* This file is part of mission-control
*
* Copyright (C) 2007 Nokia Corporation.
*
* Contact: Naba Kumar <naba.kumar@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**
* SECTION:mcd-mission
* @title: McdMission
* @short_description: Base class for server classes
* @see_also:
* @stability: Unstable
* @include: mcd-mission.h
*
* It is the base class for every object in mission-control. It defines
* a set of virtual functions and set of corresponding action signals.
* all virtual functions results in emission of their corresponding action
* signals. The virtual functions define states of the object, such
* as memory conserved state, connected state, locked state, low power state,
* lit state, sleeping state etc. Each of the object states can also be queried
* independently as properties.
*
* There are also some action signals such as abort, which is used to notify
* other objects holding hard references to it to release them (this object
* should then automatically die since all held references are released). It
* is mandatory for all other objects that hold a hard reference to it to
* listen for this signal and release the reference in signal handler.
*
* Concrete derived classes should override the sate methods to implement
* object specific state managements.
*/
#include "mcd-mission-priv.h"
#include <telepathy-glib/telepathy-glib.h>
#include "mcd-enum-types.h"
#define MCD_MISSION_PRIV(mission) (G_TYPE_INSTANCE_GET_PRIVATE ((mission), \
MCD_TYPE_MISSION, \
McdMissionPrivate))
G_DEFINE_TYPE (McdMission, mcd_mission, G_TYPE_OBJECT);
/* Private */
typedef struct _McdMissionPrivate
{
McdMission *parent;
gboolean connected;
gboolean is_disposed;
} McdMissionPrivate;
enum _McdMissionSignalType
{
CONNECTED,
DISCONNECTED,
PARENT_SET,
ABORT,
LAST_SIGNAL
};
enum _McdMissionPropertyType
{
PROP_0,
PROP_PARENT
};
static guint mcd_mission_signals[LAST_SIGNAL] = { 0 };
static void
_mcd_mission_connect (McdMission * mission)
{
McdMissionPrivate *priv;
g_return_if_fail (MCD_IS_MISSION (mission));
priv = MCD_MISSION_PRIV (mission);
if (!priv->connected)
{
priv->connected = TRUE;
g_signal_emit_by_name (mission, "connected");
}
}
static void
_mcd_mission_disconnect (McdMission * mission)
{
McdMissionPrivate *priv;
g_return_if_fail (MCD_IS_MISSION (mission));
priv = MCD_MISSION_PRIV (mission);
if (priv->connected)
{
priv->connected = FALSE;
g_signal_emit_by_name (mission, "disconnected");
}
}
static void
on_parent_abort (McdMission *parent, McdMission *mission)
{
DEBUG ("called");
_mcd_mission_set_parent (mission, NULL);
}
void
_mcd_mission_set_parent (McdMission * mission, McdMission * parent)
{
McdMissionPrivate *priv;
g_return_if_fail (MCD_IS_MISSION (mission));
g_return_if_fail ((parent == NULL) || MCD_IS_MISSION (parent));
priv = MCD_MISSION_PRIV (mission);
DEBUG ("child = %p, parent = %p", mission, parent);
if (priv->parent)
{
g_signal_handlers_disconnect_by_func (priv->parent,
on_parent_abort,
mission);
}
if (parent)
{
g_signal_connect (parent, "abort",
G_CALLBACK (on_parent_abort),
mission);
g_object_ref (parent);
}
tp_clear_object (&priv->parent);
priv->parent = parent;
g_signal_emit_by_name (mission, "parent-set", parent);
}
static void
_mcd_mission_abort (McdMission * mission)
{
g_signal_emit_by_name (G_OBJECT (mission), "abort");
}
static void
_mcd_mission_dispose (GObject * object)
{
McdMissionPrivate *priv;
g_return_if_fail (MCD_IS_MISSION (object));
priv = MCD_MISSION_PRIV (object);
if (priv->is_disposed)
{
return;
}
priv->is_disposed = TRUE;
DEBUG ("mission disposed %p", object);
if (priv->parent)
{
g_signal_handlers_disconnect_by_func (priv->parent,
on_parent_abort,
object);
}
tp_clear_object (&priv->parent);
G_OBJECT_CLASS (mcd_mission_parent_class)->dispose (object);
}
static void
_mcd_mission_finalize (GObject * object)
{
DEBUG ("mission finalized %p", object);
G_OBJECT_CLASS (mcd_mission_parent_class)->finalize (object);
}
static void
_mcd_set_property (GObject * object, guint prop_id, const GValue * val,
GParamSpec * pspec)
{
McdMission *mission = MCD_MISSION (object);
switch (prop_id)
{
case PROP_PARENT:
_mcd_mission_set_parent (mission, g_value_get_object (val));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
_mcd_get_property (GObject * object, guint prop_id, GValue * val,
GParamSpec * pspec)
{
McdMission *mission = MCD_MISSION (object);
switch (prop_id)
{
case PROP_PARENT:
g_value_set_object (val, mcd_mission_get_parent (mission));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
mcd_mission_class_init (McdMissionClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof (McdMissionPrivate));
/* virtual medthods */
object_class->finalize = _mcd_mission_finalize;
object_class->dispose = _mcd_mission_dispose;
object_class->set_property = _mcd_set_property;
object_class->get_property = _mcd_get_property;
/* virtual medthods */
klass->abort = _mcd_mission_abort;
klass->connect = _mcd_mission_connect;
klass->disconnect = _mcd_mission_disconnect;
/* signals */
mcd_mission_signals[ABORT] =
g_signal_new ("abort",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (McdMissionClass, abort_signal),
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
0);
mcd_mission_signals[CONNECTED] =
g_signal_new ("connected", G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (McdMissionClass,
connected_signal),
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
0);
mcd_mission_signals[DISCONNECTED] =
g_signal_new ("disconnected", G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (McdMissionClass,
disconnected_signal),
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
0);
mcd_mission_signals[PARENT_SET] =
g_signal_new ("parent-set", G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (McdMissionClass,
parent_set_signal),
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
0);
/* Properties */
g_object_class_install_property
(object_class, PROP_PARENT,
g_param_spec_object ("parent",
"Parent mission",
"Parent mission",
MCD_TYPE_MISSION,
G_PARAM_READWRITE));
}
static void
mcd_mission_init (McdMission * obj)
{
}
/* Public methods */
void
mcd_mission_connect (McdMission * mission)
{
g_return_if_fail (MCD_IS_MISSION (mission));
MCD_MISSION_GET_CLASS (mission)->connect (mission);
}
void
mcd_mission_disconnect (McdMission * mission)
{
g_return_if_fail (MCD_IS_MISSION (mission));
MCD_MISSION_GET_CLASS (mission)->disconnect (mission);
}
void
mcd_mission_abort (McdMission * mission)
{
g_return_if_fail (MCD_IS_MISSION (mission));
MCD_MISSION_GET_CLASS (mission)->abort (mission);
}
gboolean
mcd_mission_is_connected (McdMission * mission)
{
McdMissionPrivate *priv;
g_return_val_if_fail (MCD_IS_MISSION (mission), FALSE);
priv = MCD_MISSION_PRIV (mission);
return priv->connected;
}
McdMission *
mcd_mission_get_parent (McdMission * mission)
{
McdMissionPrivate *priv;
g_return_val_if_fail (MCD_IS_MISSION (mission), NULL);
priv = MCD_MISSION_PRIV (mission);
return priv->parent;
}
|