gboolean mprisPlayer_emit_status_change(MprisPlayer* pInstance) { //ugly duplication, but I have no interest in learning this gobject cr*p //segfaults when trying to make member value of the GValue static GValue value; memset(&value, 0, sizeof(GValue)); g_value_init(&value, DBUS_STRUCT_INT_INT_INT_INT); int playStatus = 2; switch (pInstance->pCore->getPlaybackState()) { case Gejengel::Playing: playStatus = 0; break; case Gejengel::Paused: playStatus = 1; break; case Gejengel::Stopped: playStatus = 2; break; } g_value_take_boxed(&value, dbus_g_type_specialized_construct(DBUS_STRUCT_INT_INT_INT_INT)); dbus_g_type_struct_set(&value, 0, playStatus, 1, 0, 2, 0, 3, 0, G_MAXUINT); g_signal_emit(pInstance, statusChangedSignal, 0, g_value_get_boxed(&value)); return TRUE; }
/** * up_device_get_statistics: **/ gboolean up_device_get_statistics (UpDevice *device, const gchar *type, DBusGMethodInvocation *context) { GError *error; GPtrArray *array = NULL; GPtrArray *complex; UpStatsItem *item; GValue *value; guint i; g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); g_return_val_if_fail (type != NULL, FALSE); /* doesn't even try to support this */ if (!device->priv->has_statistics) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "device does not support getting stats"); dbus_g_method_return_error (context, error); goto out; } /* get the correct data */ if (g_strcmp0 (type, "charging") == 0) array = up_history_get_profile_data (device->priv->history, TRUE); else if (g_strcmp0 (type, "discharging") == 0) array = up_history_get_profile_data (device->priv->history, FALSE); /* maybe the device doesn't support histories */ if (array == NULL) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "device has no statistics"); dbus_g_method_return_error (context, error); goto out; } /* always 101 items of data */ if (array->len != 101) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "statistics invalid as have %i items", array->len); dbus_g_method_return_error (context, error); goto out; } /* copy data to dbus struct */ complex = g_ptr_array_sized_new (array->len); for (i=0; i<array->len; i++) { item = (UpStatsItem *) g_ptr_array_index (array, i); value = g_new0 (GValue, 1); g_value_init (value, UP_DBUS_STRUCT_DOUBLE_DOUBLE); g_value_take_boxed (value, dbus_g_type_specialized_construct (UP_DBUS_STRUCT_DOUBLE_DOUBLE)); dbus_g_type_struct_set (value, 0, up_stats_item_get_value (item), 1, up_stats_item_get_accuracy (item), -1); g_ptr_array_add (complex, g_value_get_boxed (value)); g_free (value); } dbus_g_method_return (context, complex); out: if (array != NULL) g_ptr_array_unref (array); return TRUE; }
gboolean mprisPlayer_get_status(MprisPlayer* pInstance, GValue** pStatus, GError** pError) { static GValue value; memset(&value, 0, sizeof(GValue)); g_value_init(&value, DBUS_STRUCT_INT_INT_INT_INT); int playStatus = 2; switch (pInstance->pCore->getPlaybackState()) { case Gejengel::Playing: playStatus = 0; break; case Gejengel::Paused: playStatus = 1; break; case Gejengel::Stopped: playStatus = 2; break; } g_value_take_boxed(&value, dbus_g_type_specialized_construct(DBUS_STRUCT_INT_INT_INT_INT)); dbus_g_type_struct_set(&value, 0, playStatus, 1, 0, 2, 0, 3, 0, G_MAXUINT); g_signal_emit(pInstance, statusChangedSignal, 0, g_value_get_boxed(&value)); *pStatus = reinterpret_cast<GValue*>(g_value_get_boxed(&value)); return TRUE; }
void empathy_account_request_presence (EmpathyAccount *account, TpConnectionPresenceType type, const gchar *status, const gchar *message) { EmpathyAccountPriv *priv = GET_PRIV (account); GValue value = {0, }; GValueArray *arr; g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE); g_value_take_boxed (&value, dbus_g_type_specialized_construct (TP_STRUCT_TYPE_SIMPLE_PRESENCE)); arr = (GValueArray *) g_value_get_boxed (&value); g_value_set_uint (arr->values, type); g_value_set_static_string (arr->values + 1, status); g_value_set_static_string (arr->values + 2, message); tp_cli_dbus_properties_call_set (TP_PROXY (priv->account), -1, TP_IFACE_ACCOUNT, "RequestedPresence", &value, empathy_account_requested_presence_cb, NULL, NULL, G_OBJECT (account)); g_value_unset (&value); }
/** * tp_properties_mixin_get_properties: * @obj: An object with this mixin * @properties: an array of integer property IDs * @ret: set to an array of D-Bus structures if %TRUE is returned * @error: Set to the error if %FALSE is returned * * Retrieve the values of the given properties, as in the GetProperties * D-Bus method. * * Returns: %TRUE on success */ gboolean tp_properties_mixin_get_properties (GObject *obj, const GArray *properties, GPtrArray **ret, GError **error) { TpPropertiesMixin *mixin = TP_PROPERTIES_MIXIN (obj); TpPropertiesMixinClass *mixin_cls = TP_PROPERTIES_MIXIN_CLASS ( G_OBJECT_GET_CLASS (obj)); GType value_type = TP_STRUCT_TYPE_PROPERTY_VALUE; guint i; /* Check input property identifiers */ for (i = 0; i < properties->len; i++) { guint prop_id = g_array_index (properties, guint, i); /* Valid? */ if (prop_id >= mixin_cls->num_props) { g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, "invalid property identifier %d", prop_id); return FALSE; } /* Permitted? */ if (!tp_properties_mixin_is_readable (obj, prop_id)) { g_set_error (error, TP_ERRORS, TP_ERROR_PERMISSION_DENIED, "permission denied for property identifier %d", prop_id); return FALSE; } } /* If we got this far, return the actual values */ *ret = g_ptr_array_sized_new (properties->len); for (i = 0; i < properties->len; i++) { guint prop_id = g_array_index (properties, guint, i); GValue val_struct = { 0, }; /* id/value struct */ g_value_init (&val_struct, value_type); g_value_take_boxed (&val_struct, dbus_g_type_specialized_construct (value_type)); dbus_g_type_struct_set (&val_struct, 0, prop_id, 1, mixin->properties[prop_id].value, G_MAXUINT); g_ptr_array_add (*ret, g_value_get_boxed (&val_struct)); } return TRUE; }
/** * tp_properties_mixin_emit_changed: * @obj: an object with the properties mixin * @props: a set of property IDs * * Emit the PropertiesChanged signal to indicate that the values of the * given property IDs have changed; the actual values are automatically * added using their stored values. */ void tp_properties_mixin_emit_changed (GObject *obj, const TpIntSet *props) { TpPropertiesMixin *mixin = TP_PROPERTIES_MIXIN (obj); TpPropertiesMixinClass *mixin_cls = TP_PROPERTIES_MIXIN_CLASS ( G_OBJECT_GET_CLASS (obj)); GPtrArray *prop_arr; GValue prop_list = { 0, }; TpIntSetIter iter = TP_INTSET_ITER_INIT (props); guint len = tp_intset_size (props); if (len == 0) { return; } prop_arr = g_ptr_array_sized_new (len); if (DEBUGGING) printf (TP_ANSI_BOLD_ON TP_ANSI_FG_CYAN "%s: emitting properties changed for propert%s:\n", G_STRFUNC, (len > 1) ? "ies" : "y"); while (tp_intset_iter_next (&iter)) { GValue prop_val = { 0, }; guint prop_id = iter.element; g_value_init (&prop_val, TP_STRUCT_TYPE_PROPERTY_VALUE); g_value_take_boxed (&prop_val, dbus_g_type_specialized_construct (TP_STRUCT_TYPE_PROPERTY_VALUE)); dbus_g_type_struct_set (&prop_val, 0, prop_id, 1, mixin->properties[prop_id].value, G_MAXUINT); g_ptr_array_add (prop_arr, g_value_get_boxed (&prop_val)); if (DEBUGGING) printf (" %s\n", mixin_cls->signatures[prop_id].name); } if (DEBUGGING) { printf (TP_ANSI_RESET); fflush (stdout); } tp_svc_properties_interface_emit_properties_changed ( (TpSvcPropertiesInterface *) obj, prop_arr); g_value_init (&prop_list, TP_ARRAY_TYPE_PROPERTY_VALUE_LIST); g_value_take_boxed (&prop_list, prop_arr); g_value_unset (&prop_list); }
static void gabble_im_factory_get_contact_caps (GabbleCapsChannelManager *manager, TpHandle handle, const GabbleCapabilitySet *caps, GPtrArray *arr) { /* We don't need to check this contact's capabilities, we assume every * contact support text channels. */ /* NOTE: if any more contact caps are added here which are not * assumed then be sure to change the implementation of * gabble_connection_get_handle_contact_capabilities, as that uses * this function to fill the contact caps hash for all contacts * (even offline). */ GValue monster = {0, }; GHashTable *fixed_properties; GValue *channel_type_value; GValue *target_handle_type_value; gchar *text_allowed_properties[] = { TP_IFACE_CHANNEL ".TargetHandle", NULL }; g_assert (handle != 0); g_value_init (&monster, TP_STRUCT_TYPE_REQUESTABLE_CHANNEL_CLASS); g_value_take_boxed (&monster, dbus_g_type_specialized_construct ( TP_STRUCT_TYPE_REQUESTABLE_CHANNEL_CLASS)); fixed_properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); channel_type_value = tp_g_value_slice_new (G_TYPE_STRING); g_value_set_static_string (channel_type_value, TP_IFACE_CHANNEL_TYPE_TEXT); g_hash_table_insert (fixed_properties, TP_IFACE_CHANNEL ".ChannelType", channel_type_value); target_handle_type_value = tp_g_value_slice_new (G_TYPE_UINT); g_value_set_uint (target_handle_type_value, TP_HANDLE_TYPE_CONTACT); g_hash_table_insert (fixed_properties, TP_IFACE_CHANNEL ".TargetHandleType", target_handle_type_value); dbus_g_type_struct_set (&monster, 0, fixed_properties, 1, text_allowed_properties, G_MAXUINT); g_hash_table_unref (fixed_properties); g_ptr_array_add (arr, g_value_get_boxed (&monster)); }
/** * tp_properties_mixin_list_properties: * @obj: An object with this mixin * @ret: Output parameter which will be set to a GPtrArray of D-Bus structures * if %TRUE is returned * @error: Set to the error if %FALSE is returned * * List all available properties and their flags, as in the ListProperties * D-Bus method. * * Returns: %TRUE on success */ gboolean tp_properties_mixin_list_properties (GObject *obj, GPtrArray **ret, GError **error) { TpPropertiesMixin *mixin = TP_PROPERTIES_MIXIN (obj); TpPropertiesMixinClass *mixin_cls = TP_PROPERTIES_MIXIN_CLASS ( G_OBJECT_GET_CLASS (obj)); GType spec_type = TP_STRUCT_TYPE_PROPERTY_SPEC; guint i; *ret = g_ptr_array_sized_new (mixin_cls->num_props); for (i = 0; i < mixin_cls->num_props; i++) { const TpPropertySignature *sig = &mixin_cls->signatures[i]; TpProperty *prop = &mixin->properties[i]; const gchar *dbus_sig; GValue val = { 0, }; switch (sig->type) { case G_TYPE_BOOLEAN: dbus_sig = "b"; break; case G_TYPE_INT: dbus_sig = "i"; break; case G_TYPE_UINT: dbus_sig = "u"; break; case G_TYPE_STRING: dbus_sig = "s"; break; default: g_assert_not_reached (); continue; }; g_value_init (&val, spec_type); g_value_take_boxed (&val, dbus_g_type_specialized_construct (spec_type)); dbus_g_type_struct_set (&val, 0, i, 1, sig->name, 2, dbus_sig, 3, prop->flags, G_MAXUINT); g_ptr_array_add (*ret, g_value_get_boxed (&val)); } return TRUE; }
static void __data_list_ptr_array_add(GPtrArray *ptr_array, const gchar *name, const gchar *type) { GValue value = { 0, }; g_value_init(&value, DBUS_STRUCT_STRING_STRING); g_value_take_boxed(&value, dbus_g_type_specialized_construct( DBUS_STRUCT_STRING_STRING)); dbus_g_type_struct_set(&value, 0, g_strdup(name), 1, g_strdup(type), G_MAXUINT); g_ptr_array_add(ptr_array, g_value_get_boxed(&value)); }
/** * geoclue_accuracy_new: * @level: A #GeoclueAccuracyLevel * @horizontal_accuracy: Horizontal accuracy in meters * @vertical_accuracy: Vertical accuracy in meters * * Creates a new #GeoclueAccuracy with given values. Use 0 for * horizontal_accuracy and vertical_accuracy if @level is not * %GEOCLUE_ACCURACY_LEVEL_DETAILED. * * Return value: New #GeoclueAccuracy. */ GeoclueAccuracy * geoclue_accuracy_new (GeoclueAccuracyLevel level, double horizontal_accuracy, double vertical_accuracy) { GValue accuracy_struct = {0, }; g_value_init (&accuracy_struct, GEOCLUE_ACCURACY_TYPE); g_value_take_boxed (&accuracy_struct, dbus_g_type_specialized_construct (GEOCLUE_ACCURACY_TYPE)); dbus_g_type_struct_set (&accuracy_struct, 0, level, 1, horizontal_accuracy, 2, vertical_accuracy, G_MAXUINT); return (GeoclueAccuracy *) g_value_get_boxed (&accuracy_struct); }
/** * up_device_get_history: **/ gboolean up_device_get_history (UpDevice *device, const gchar *type_string, guint timespan, guint resolution, DBusGMethodInvocation *context) { GError *error; GPtrArray *array = NULL; GPtrArray *complex; UpHistoryItem *item; GValue *value; guint i; UpHistoryType type = UP_HISTORY_TYPE_UNKNOWN; g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); g_return_val_if_fail (type_string != NULL, FALSE); /* doesn't even try to support this */ if (!device->priv->has_history) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "device does not support getting history"); dbus_g_method_return_error (context, error); goto out; } /* get the correct data */ if (g_strcmp0 (type_string, "rate") == 0) type = UP_HISTORY_TYPE_RATE; else if (g_strcmp0 (type_string, "charge") == 0) type = UP_HISTORY_TYPE_CHARGE; else if (g_strcmp0 (type_string, "time-full") == 0) type = UP_HISTORY_TYPE_TIME_FULL; else if (g_strcmp0 (type_string, "time-empty") == 0) type = UP_HISTORY_TYPE_TIME_EMPTY; /* something recognised */ if (type != UP_HISTORY_TYPE_UNKNOWN) array = up_history_get_data (device->priv->history, type, timespan, resolution); /* maybe the device doesn't have any history */ if (array == NULL) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "device has no history"); dbus_g_method_return_error (context, error); goto out; } /* copy data to dbus struct */ complex = g_ptr_array_sized_new (array->len); for (i=0; i<array->len; i++) { item = (UpHistoryItem *) g_ptr_array_index (array, i); value = g_new0 (GValue, 1); g_value_init (value, UP_DBUS_STRUCT_UINT_DOUBLE_UINT); g_value_take_boxed (value, dbus_g_type_specialized_construct (UP_DBUS_STRUCT_UINT_DOUBLE_UINT)); dbus_g_type_struct_set (value, 0, up_history_item_get_time (item), 1, up_history_item_get_value (item), 2, up_history_item_get_state (item), -1); g_ptr_array_add (complex, g_value_get_boxed (value)); g_free (value); } dbus_g_method_return (context, complex); out: if (array != NULL) g_ptr_array_unref (array); return TRUE; }
EmpathyTpTube * empathy_tp_tube_new_stream_tube (EmpathyContact *contact, TpSocketAddressType type, const gchar *hostname, guint port, const gchar *service, GHashTable *parameters) { MissionControl *mc; McAccount *account; TpConnection *connection; TpChannel *channel; gchar *object_path; GHashTable *params; GValue *address; GValue *control_param; EmpathyTpTube *tube = NULL; GError *error = NULL; GHashTable *request; GHashTable *channel_properties; GValue *value; g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); g_return_val_if_fail (hostname != NULL, NULL); g_return_val_if_fail (service != NULL, NULL); mc = empathy_mission_control_dup_singleton (); account = empathy_contact_get_account (contact); connection = mission_control_get_tpconnection (mc, account, NULL); g_object_unref (mc); tp_connection_run_until_ready (connection, FALSE, NULL, NULL); request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); /* org.freedesktop.Telepathy.Channel.ChannelType */ value = tp_g_value_slice_new (G_TYPE_STRING); g_value_set_string (value, EMP_IFACE_CHANNEL_TYPE_STREAM_TUBE); g_hash_table_insert (request, TP_IFACE_CHANNEL ".ChannelType", value); /* org.freedesktop.Telepathy.Channel.TargetHandleType */ value = tp_g_value_slice_new (G_TYPE_UINT); g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT); g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandleType", value); /* org.freedesktop.Telepathy.Channel.TargetHandleType */ value = tp_g_value_slice_new (G_TYPE_UINT); g_value_set_uint (value, empathy_contact_get_handle (contact)); g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value); /* org.freedesktop.Telepathy.Channel.Type.StreamTube.Service */ value = tp_g_value_slice_new (G_TYPE_STRING); g_value_set_string (value, service); g_hash_table_insert (request, EMP_IFACE_CHANNEL_TYPE_STREAM_TUBE ".Service", value); if (!tp_cli_connection_interface_requests_run_create_channel (connection, -1, request, &object_path, &channel_properties, &error, NULL)) { DEBUG ("Error requesting channel: %s", error->message); g_clear_error (&error); g_object_unref (connection); return NULL; } DEBUG ("Offering a new stream tube"); channel = tp_channel_new_from_properties (connection, object_path, channel_properties, NULL); tp_channel_run_until_ready (channel, NULL, NULL); #define ADDRESS_TYPE dbus_g_type_get_struct ("GValueArray",\ G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID) params = g_hash_table_new (g_str_hash, g_str_equal); address = tp_g_value_slice_new (ADDRESS_TYPE); g_value_take_boxed (address, dbus_g_type_specialized_construct (ADDRESS_TYPE)); dbus_g_type_struct_set (address, 0, hostname, 1, port, G_MAXUINT); control_param = tp_g_value_slice_new (G_TYPE_STRING); if (!emp_cli_channel_type_stream_tube_run_offer_stream_tube ( TP_PROXY(channel), -1, type, address, TP_SOCKET_ACCESS_CONTROL_LOCALHOST, control_param, parameters, &error, NULL)) { DEBUG ("Couldn't offer tube: %s", error->message); g_clear_error (&error); goto OUT; } DEBUG ("Stream tube offered"); tube = empathy_tp_tube_new (channel); OUT: g_object_unref (channel); g_free (object_path); g_hash_table_destroy (request); g_hash_table_destroy (channel_properties); tp_g_value_slice_free (address); tp_g_value_slice_free (control_param); g_object_unref (connection); return tube; }