160
*******************************************************************************
161
* ToolsCoreServiceGetProperty -- */ /**
163
* Gets the value of a property in the object.
165
* @param[in] object The instance.
166
* @param[in] id Property ID.
167
* @param[out] value Where to set the value.
168
* @param[in] pspec Unused.
170
*******************************************************************************
174
ToolsCoreServiceGetProperty(GObject *object,
179
ToolsCoreService *self = (ToolsCoreService *) object;
183
g_mutex_lock(self->lock);
185
if (id < self->props->len) {
186
ServiceProperty *p = &g_array_index(self->props, ServiceProperty, id);
187
g_value_set_pointer(value, p->value);
190
g_mutex_unlock(self->lock);
195
*******************************************************************************
196
* ToolsCoreServiceSetProperty -- */ /**
198
* Sets a property in the given object. If the property is found, a "notify"
199
* signal is sent so that interested listeners can act on the change.
201
* @param[in] object The instance.
202
* @param[in] id Property ID.
203
* @param[in] value Value to set.
204
* @param[in] pspec Unused.
206
*******************************************************************************
210
ToolsCoreServiceSetProperty(GObject *object,
215
ServiceProperty *p = NULL;
216
ToolsCoreService *self = (ToolsCoreService *) object;
220
g_mutex_lock(self->lock);
222
if (id < self->props->len) {
223
p = &g_array_index(self->props, ServiceProperty, id);
224
p->value = g_value_get_pointer(value);
227
g_mutex_unlock(self->lock);
230
g_object_notify(object, p->name);
236
*******************************************************************************
237
* ToolsCoreServiceCtor -- */ /**
239
* Object constructor. Initialize internal state.
241
* @param[in] type Object type.
242
* @param[in] nparams Param count.
243
* @param[in] params Construction parameters.
245
* @return A new instance.
247
*******************************************************************************
251
ToolsCoreServiceCtor(GType type,
253
GObjectConstructParam *params)
256
ToolsCoreService *self;
258
object = G_OBJECT_CLASS(gToolsCoreServiceParentClass)->constructor(type,
262
self = TOOLSCORE_SERVICE(object);
263
self->lock = g_mutex_new();
264
self->props = g_array_new(FALSE, FALSE, sizeof (ServiceProperty));
271
*******************************************************************************
272
* ToolsCoreServiceDtor -- */ /**
274
* Object destructor. Frees memory associated with the object. Goes through the
275
* list of properties to make sure all of them have been cleaned up before the
276
* service exits, printing a warning otherwise.
278
* @param[in] object The object being destructed.
280
*******************************************************************************
284
ToolsCoreServiceDtor(GObject *object)
286
ToolsCoreService *self = (ToolsCoreService *) object;
289
for (i = 0; i < self->props->len; i++) {
290
ServiceProperty *p = &g_array_index(self->props, ServiceProperty, i);
291
if (p->value != NULL) {
292
g_warning("Property '%s' was not cleaned up before shut down.",
298
g_array_free(self->props, TRUE);
299
g_mutex_free(self->lock);
152
304
* Initializes the ToolsCoreService class. Sets up the signals that are sent
153
305
* by the vmtoolsd service.
438
*******************************************************************************
439
* ToolsCoreService_RegisterProperty -- */ /**
441
* Installs a new property in the service object.
443
* @param[in] obj Service object.
444
* @param[in] prop Property to install.
446
*******************************************************************************
450
ToolsCoreService_RegisterProperty(ToolsCoreService *obj,
451
ToolsServiceProperty *prop)
453
static guint PROP_ID_SEQ = 0;
455
ServiceProperty sprop;
456
ToolsCoreServiceClass *klass = TOOLSCORESERVICE_GET_CLASS(obj);
457
GParamSpec *pspec = g_param_spec_pointer(prop->name,
462
g_mutex_lock(obj->lock);
464
sprop.id = ++PROP_ID_SEQ;
465
sprop.name = g_strdup(prop->name);
467
g_array_append_val(obj->props, sprop);
468
g_object_class_install_property(G_OBJECT_CLASS(klass), sprop.id, pspec);
470
g_mutex_unlock(obj->lock);