NS_METHOD csTpDBusTubeMember::Create(gpointer aGLibItem, void **aResult) { guint handle; const gchar *unique_name; GValue structure = { 0 }; g_value_init(&structure, TP_STRUCT_TYPE_DBUS_TUBE_MEMBER); g_value_set_static_boxed(&structure, aGLibItem); if (!dbus_g_type_struct_get(&structure, 0, &handle, 1, &unique_name, G_MAXUINT)) return NS_ERROR_FAILURE; nsCString cUniqueName = nsDependentCString(unique_name); csITpDBusTubeMember *it = new csTpDBusTubeMember(handle, cUniqueName); if (!it) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(it); nsresult rv = it->QueryInterface(NS_GET_IID(csITpDBusTubeMember), aResult); NS_RELEASE(it); return rv; }
NS_METHOD csTpStatusSpec::Create(gpointer aGLibItem, void **aResult) { guint type; gboolean may_set_on_self; gboolean exclusive; GHashTable *parameter_types; GValue structure = { 0 }; g_value_init(&structure, TP_STRUCT_TYPE_STATUS_SPEC); g_value_set_static_boxed(&structure, aGLibItem); if (!dbus_g_type_struct_get(&structure, 0, &type, 1, &may_set_on_self, 2, &exclusive, 3, ¶meter_types, G_MAXUINT)) return NS_ERROR_FAILURE; nsCOMPtr<nsIArray> cParameterTypes; csTpStringStringMap::Create((gpointer)parameter_types, getter_AddRefs(cParameterTypes)); csITpStatusSpec *it = new csTpStatusSpec(type, may_set_on_self, exclusive, cParameterTypes); if (!it) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(it); nsresult rv = it->QueryInterface(NS_GET_IID(csITpStatusSpec), aResult); NS_RELEASE(it); return rv; }
NS_METHOD csTpLastActivityAndStatuses::Create(gpointer aGLibItem, void **aResult) { guint last_activity; GHashTable *statuses; GValue structure = { 0 }; g_value_init(&structure, TP_STRUCT_TYPE_LAST_ACTIVITY_AND_STATUSES); g_value_set_static_boxed(&structure, aGLibItem); if (!dbus_g_type_struct_get(&structure, 0, &last_activity, 1, &statuses, G_MAXUINT)) return NS_ERROR_FAILURE; nsCOMPtr<nsIArray> cStatuses; csTpMultipleStatusMap::Create((gpointer)statuses, getter_AddRefs(cStatuses)); csITpLastActivityAndStatuses *it = new csTpLastActivityAndStatuses(last_activity, cStatuses); if (!it) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(it); nsresult rv = it->QueryInterface(NS_GET_IID(csITpLastActivityAndStatuses), aResult); NS_RELEASE(it); return rv; }
NS_METHOD csTpMediaStreamInfo::Create(gpointer aGLibItem, void **aResult) { guint identifier; guint contact; guint type; guint state; guint direction; guint pending_send_flags; GValue structure = { 0 }; g_value_init(&structure, TP_STRUCT_TYPE_MEDIA_STREAM_INFO); g_value_set_static_boxed(&structure, aGLibItem); if (!dbus_g_type_struct_get(&structure, 0, &identifier, 1, &contact, 2, &type, 3, &state, 4, &direction, 5, &pending_send_flags, G_MAXUINT)) return NS_ERROR_FAILURE; csITpMediaStreamInfo *it = new csTpMediaStreamInfo(identifier, contact, type, state, direction, pending_send_flags); if (!it) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(it); nsresult rv = it->QueryInterface(NS_GET_IID(csITpMediaStreamInfo), aResult); NS_RELEASE(it); return rv; }
NS_METHOD csTpSocketNetmaskIPv6::Create(gpointer aGLibItem, void **aResult) { const gchar *address; guchar prefix_length; GValue structure = { 0 }; g_value_init(&structure, TP_STRUCT_TYPE_SOCKET_NETMASK_IPV6); g_value_set_static_boxed(&structure, aGLibItem); if (!dbus_g_type_struct_get(&structure, 0, &address, 1, &prefix_length, G_MAXUINT)) return NS_ERROR_FAILURE; nsCString cAddress = nsDependentCString(address); csITpSocketNetmaskIPv6 *it = new csTpSocketNetmaskIPv6(cAddress, prefix_length); if (!it) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(it); nsresult rv = it->QueryInterface(NS_GET_IID(csITpSocketNetmaskIPv6), aResult); NS_RELEASE(it); return rv; }
NS_METHOD csTpTubeInfo::Create(gpointer aGLibItem, void **aResult) { guint identifier; guint initiator; guint type; const gchar *service; GHashTable *parameters; guint state; GValue structure = { 0 }; g_value_init(&structure, TP_STRUCT_TYPE_TUBE_INFO); g_value_set_static_boxed(&structure, aGLibItem); if (!dbus_g_type_struct_get(&structure, 0, &identifier, 1, &initiator, 2, &type, 3, &service, 4, ¶meters, 5, &state, G_MAXUINT)) return NS_ERROR_FAILURE; nsCString cService = nsDependentCString(service); nsCOMPtr<nsIArray> cParameters; csTpStringVariantMap::Create((gpointer)parameters, getter_AddRefs(cParameters)); csITpTubeInfo *it = new csTpTubeInfo(identifier, initiator, type, cService, cParameters, state); if (!it) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(it); nsresult rv = it->QueryInterface(NS_GET_IID(csITpTubeInfo), aResult); NS_RELEASE(it); return rv; }
static inline gboolean gtk_arg_static_to_value (GtkArg *arg, GValue *value) { switch (G_TYPE_FUNDAMENTAL (arg->type)) { case G_TYPE_CHAR: g_value_set_char (value, GTK_VALUE_CHAR (*arg)); break; case G_TYPE_UCHAR: g_value_set_uchar (value, GTK_VALUE_UCHAR (*arg)); break; case G_TYPE_BOOLEAN: g_value_set_boolean (value, GTK_VALUE_BOOL (*arg)); break; case G_TYPE_INT: g_value_set_int (value, GTK_VALUE_INT (*arg)); break; case G_TYPE_UINT: g_value_set_uint (value, GTK_VALUE_UINT (*arg)); break; case G_TYPE_LONG: g_value_set_long (value, GTK_VALUE_LONG (*arg)); break; case G_TYPE_ULONG: g_value_set_ulong (value, GTK_VALUE_ULONG (*arg)); break; case G_TYPE_ENUM: g_value_set_enum (value, GTK_VALUE_ENUM (*arg)); break; case G_TYPE_FLAGS: g_value_set_flags (value, GTK_VALUE_FLAGS (*arg)); break; case G_TYPE_FLOAT: g_value_set_float (value, GTK_VALUE_FLOAT (*arg)); break; case G_TYPE_DOUBLE: g_value_set_double (value, GTK_VALUE_DOUBLE (*arg)); break; case G_TYPE_STRING: g_value_set_static_string (value, GTK_VALUE_STRING (*arg)); break; case G_TYPE_BOXED: g_value_set_static_boxed (value, GTK_VALUE_BOXED (*arg)); break; case G_TYPE_POINTER: g_value_set_pointer (value, GTK_VALUE_POINTER (*arg)); break; case G_TYPE_OBJECT: g_value_set_object (value, GTK_VALUE_POINTER (*arg)); break; default: return FALSE; } return TRUE; }
NS_METHOD csTpLocalPendingInfo::Create(gpointer aGLibItem, void **aResult) { guint to_be_added; guint actor; guint reason; const gchar *message; GValue structure = { 0 }; g_value_init(&structure, TP_STRUCT_TYPE_LOCAL_PENDING_INFO); g_value_set_static_boxed(&structure, aGLibItem); if (!dbus_g_type_struct_get(&structure, 0, &to_be_added, 1, &actor, 2, &reason, 3, &message, G_MAXUINT)) return NS_ERROR_FAILURE; nsCString cMessage = nsDependentCString(message); csITpLocalPendingInfo *it = new csTpLocalPendingInfo(to_be_added, actor, reason, cMessage); if (!it) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(it); nsresult rv = it->QueryInterface(NS_GET_IID(csITpLocalPendingInfo), aResult); NS_RELEASE(it); return rv; }
static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { ExampleCallStream *self = EXAMPLE_CALL_STREAM (object); switch (property_id) { case PROP_OBJECT_PATH: g_value_set_string (value, self->priv->object_path); break; case PROP_INTERFACES: g_value_set_static_boxed (value, empty_strv); break; case PROP_HANDLE: g_value_set_uint (value, self->priv->handle); break; case PROP_CONNECTION: g_value_set_object (value, self->priv->conn); break; case PROP_SIMULATION_DELAY: g_value_set_uint (value, self->priv->simulation_delay); break; case PROP_LOCALLY_REQUESTED: g_value_set_boolean (value, self->priv->locally_requested); break; case PROP_SENDERS: { GHashTable *senders = g_hash_table_new (NULL, NULL); g_hash_table_insert (senders, GUINT_TO_POINTER (self->priv->handle), GUINT_TO_POINTER (self->priv->remote_sending_state)); g_hash_table_insert (senders, GUINT_TO_POINTER (tp_base_connection_get_self_handle ( self->priv->conn)), GUINT_TO_POINTER (self->priv->local_sending_state)); g_value_take_boxed (value, senders); } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
/** * tp_g_value_slice_new_static_boxed: * @type: a boxed type * @p: a pointer of type @type, which must remain valid forever * * Slice-allocate and initialize a #GValue. This function is convenient to * use when constructing hash tables from string to #GValue, for example. * * Returns: a #GValue of type @type whose value is @p, * to be freed with tp_g_value_slice_free() or g_slice_free() * * Since: 0.7.27 */ GValue * tp_g_value_slice_new_static_boxed (GType type, gconstpointer p) { GValue *v; g_return_val_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED, NULL); v = tp_g_value_slice_new (type); g_value_set_static_boxed (v, p); return v; }
GimpValueArray * plug_in_params_to_args (GParamSpec **pspecs, gint n_pspecs, GPParam *params, gint n_params, gboolean return_values, gboolean full_copy) { GimpValueArray *args; gint i; g_return_val_if_fail ((pspecs != NULL && n_pspecs > 0) || (pspecs == NULL && n_pspecs == 0), NULL); g_return_val_if_fail ((params != NULL && n_params > 0) || (params == NULL && n_params == 0), NULL); args = gimp_value_array_new (n_params); for (i = 0; i < n_params; i++) { GValue value = G_VALUE_INIT; GType type; gint count; /* first get the fallback compat GType that matches the pdb type */ type = gimp_pdb_compat_arg_type_to_gtype (params[i].type); /* then try to try to be more specific by looking at the param * spec (return values have one additional value (the status), * skip that, it's not in the array of param specs) */ if (i > 0 || ! return_values) { gint pspec_index = i; if (return_values) pspec_index--; /* are there param specs left? */ if (pspec_index < n_pspecs) { GType pspec_gtype; GimpPDBArgType pspec_arg_type; pspec_gtype = G_PARAM_SPEC_VALUE_TYPE (pspecs[pspec_index]); pspec_arg_type = gimp_pdb_compat_arg_type_from_gtype (pspec_gtype); /* if the param spec's GType, mapped to a pdb type, matches * the passed pdb type, use the param spec's GType */ if (pspec_arg_type == params[i].type) type = pspec_gtype; } } g_value_init (&value, type); switch (gimp_pdb_compat_arg_type_from_gtype (type)) { case GIMP_PDB_INT32: if (G_VALUE_HOLDS_INT (&value)) g_value_set_int (&value, params[i].data.d_int32); else if (G_VALUE_HOLDS_UINT (&value)) g_value_set_uint (&value, params[i].data.d_int32); else if (G_VALUE_HOLDS_ENUM (&value)) g_value_set_enum (&value, params[i].data.d_int32); else if (G_VALUE_HOLDS_BOOLEAN (&value)) g_value_set_boolean (&value, params[i].data.d_int32 ? TRUE : FALSE); else { g_printerr ("%s: unhandled GIMP_PDB_INT32 type: %s\n", G_STRFUNC, g_type_name (G_VALUE_TYPE (&value))); g_return_val_if_reached (args); } break; case GIMP_PDB_INT16: g_value_set_int (&value, params[i].data.d_int16); break; case GIMP_PDB_INT8: g_value_set_uint (&value, params[i].data.d_int8); break; case GIMP_PDB_FLOAT: g_value_set_double (&value, params[i].data.d_float); break; case GIMP_PDB_STRING: if (full_copy) g_value_set_string (&value, params[i].data.d_string); else g_value_set_static_string (&value, params[i].data.d_string); break; case GIMP_PDB_INT32ARRAY: count = g_value_get_int (gimp_value_array_index (args, i - 1)); if (full_copy) gimp_value_set_int32array (&value, params[i].data.d_int32array, count); else gimp_value_set_static_int32array (&value, params[i].data.d_int32array, count); break; case GIMP_PDB_INT16ARRAY: count = g_value_get_int (gimp_value_array_index (args, i - 1)); if (full_copy) gimp_value_set_int16array (&value, params[i].data.d_int16array, count); else gimp_value_set_static_int16array (&value, params[i].data.d_int16array, count); break; case GIMP_PDB_INT8ARRAY: count = g_value_get_int (gimp_value_array_index (args, i - 1)); if (full_copy) gimp_value_set_int8array (&value, params[i].data.d_int8array, count); else gimp_value_set_static_int8array (&value, params[i].data.d_int8array, count); break; case GIMP_PDB_FLOATARRAY: count = g_value_get_int (gimp_value_array_index (args, i - 1)); if (full_copy) gimp_value_set_floatarray (&value, params[i].data.d_floatarray, count); else gimp_value_set_static_floatarray (&value, params[i].data.d_floatarray, count); break; case GIMP_PDB_STRINGARRAY: count = g_value_get_int (gimp_value_array_index (args, i - 1)); if (full_copy) gimp_value_set_stringarray (&value, (const gchar **) params[i].data.d_stringarray, count); else gimp_value_set_static_stringarray (&value, (const gchar **) params[i].data.d_stringarray, count); break; case GIMP_PDB_COLOR: gimp_value_set_rgb (&value, ¶ms[i].data.d_color); break; case GIMP_PDB_ITEM: g_value_set_int (&value, params[i].data.d_item); break; case GIMP_PDB_DISPLAY: g_value_set_int (&value, params[i].data.d_display); break; case GIMP_PDB_IMAGE: g_value_set_int (&value, params[i].data.d_image); break; case GIMP_PDB_LAYER: g_value_set_int (&value, params[i].data.d_layer); break; case GIMP_PDB_CHANNEL: g_value_set_int (&value, params[i].data.d_channel); break; case GIMP_PDB_DRAWABLE: g_value_set_int (&value, params[i].data.d_drawable); break; case GIMP_PDB_SELECTION: g_value_set_int (&value, params[i].data.d_selection); break; case GIMP_PDB_COLORARRAY: count = g_value_get_int (gimp_value_array_index (args, i - 1)); if (full_copy) gimp_value_set_colorarray (&value, params[i].data.d_colorarray, count); else gimp_value_set_static_colorarray (&value, params[i].data.d_colorarray, count); break; case GIMP_PDB_VECTORS: g_value_set_int (&value, params[i].data.d_vectors); break; case GIMP_PDB_PARASITE: if (full_copy) g_value_set_boxed (&value, ¶ms[i].data.d_parasite); else g_value_set_static_boxed (&value, ¶ms[i].data.d_parasite); break; case GIMP_PDB_STATUS: g_value_set_enum (&value, params[i].data.d_status); break; case GIMP_PDB_END: break; } gimp_value_array_append (args, &value); g_value_unset (&value); } return args; }
static void GotParamsForNewConnection(TpConnectionManager *cm, const GPtrArray *arr, const GError *error, gpointer user_data, GObject *unused) { Get_Params_For_Connection* cb_struct = (Get_Params_For_Connection*)user_data; csITpConnectionManagerRequestConnectionCB *cb = cb_struct->connectionCB; nsCString aProtocol = cb_struct->protocolName; nsIArray *aParameters = cb_struct->parameters; if (error != NULL) { if (cb) { cb->OnRequestConnectionError(nsDependentCString(g_quark_to_string(error->domain)), error->code, nsDependentCString(error->message)); } return; } PRUint32 parametersCount; nsresult rv = aParameters->GetLength(¶metersCount); if (NS_FAILED(rv)) return; // Put all the passed parameters in a hash. // XXX: Copy of this code exists in CallRequestConnection. nsInterfaceHashtable<nsCStringHashKey, nsIVariant> parameters; parameters.Init(); for (PRUint32 i=0; i<parametersCount; i++) { nsCOMPtr<csITpStringVariantMap> param = do_QueryElementAt(aParameters, i); nsCOMPtr<nsIVariant> value; nsCString key; rv = param->GetKey(key); if (NS_FAILED(rv)) continue; rv = param->GetValue(getter_AddRefs(value)); if (NS_FAILED(rv)) continue; if (value) parameters.Put(key, value); } PRUint32 length = arr->len; GHashTable *hash = g_hash_table_new(g_str_hash, g_str_equal); for (PRUint32 i=0; i<length; i++) { GValue structure = {0}; TpConnectionManagerParam *tpparam = g_new0(TpConnectionManagerParam, 1); g_value_init(&structure, TP_STRUCT_TYPE_PARAM_SPEC); g_value_set_static_boxed(&structure, g_ptr_array_index(arr, i)); if (dbus_g_type_struct_get(&structure, 0, &tpparam->name, 1, &tpparam->flags, 2, &tpparam->dbus_signature, G_MAXUINT)) { nsCOMPtr<nsIVariant> variant; if (parameters.Get(nsDependentCString(tpparam->name), getter_AddRefs(variant))) { GValue *value = VariantToGValueWithSignature(variant, tpparam->dbus_signature); g_hash_table_insert(hash, g_strdup(tpparam->name), value); } } } NS_IF_ADDREF(cb); tp_cli_connection_manager_call_request_connection(cm, -1, nsCString(aProtocol).get(), hash, cb? RequestConnectionResponse: NULL, cb? cb: NULL, NULL, NULL); NS_IF_RELEASE(cb); NS_IF_RELEASE(aParameters); }
static void inf_tcp_connection_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) { InfTcpConnection* connection; InfTcpConnectionPrivate* priv; InfIpAddress* address; guint port; GError* error; #ifndef G_OS_WIN32 char device_name[IF_NAMESIZE]; #endif connection = INF_TCP_CONNECTION(object); priv = INF_TCP_CONNECTION_PRIVATE(connection); switch(prop_id) { case PROP_IO: g_value_set_object(value, G_OBJECT(priv->io)); break; case PROP_RESOLVER: g_value_set_object(value, G_OBJECT(priv->resolver)); break; case PROP_KEEPALIVE: g_value_set_boxed(value, &priv->keepalive); break; case PROP_STATUS: g_value_set_enum(value, priv->status); break; case PROP_REMOTE_ADDRESS: g_value_set_static_boxed(value, priv->remote_address); break; case PROP_REMOTE_PORT: g_value_set_uint(value, priv->remote_port); break; case PROP_LOCAL_ADDRESS: g_assert(priv->socket != INVALID_SOCKET); error = NULL; inf_tcp_connection_addr_info(priv->socket, TRUE, &address, NULL, &error); if(error != NULL) { g_warning(_("Failed to retrieve local address: %s"), error->message); g_error_free(error); g_value_set_boxed(value, NULL); } else { g_value_take_boxed(value, address); } break; case PROP_LOCAL_PORT: g_assert(priv->socket != INVALID_SOCKET); error = NULL; inf_tcp_connection_addr_info(priv->socket, TRUE, NULL, &port, &error); if(error != NULL) { g_warning(_("Failed to retrieve local port: %s"), error->message); g_error_free(error); g_value_set_uint(value, 0); } else { g_value_set_uint(value, port); } break; case PROP_DEVICE_INDEX: g_value_set_uint(value, priv->device_index); break; case PROP_DEVICE_NAME: #ifdef G_OS_WIN32 /* TODO: We can probably implement this using GetInterfaceInfo() */ g_warning(_("The device-name property is not implemented on Win32")); g_value_set_string(value, NULL); #else if(priv->device_index == 0) { g_value_set_string(value, NULL); } else { if(if_indextoname(priv->device_index, device_name) == NULL) { g_warning( /* Failed to get name for device <Index>: <Reason> */ _("Failed to get name for device %u: %s"), priv->device_index, strerror(errno) ); g_value_set_string(value, NULL); } else { g_value_set_string(value, device_name); } } #endif break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
static void _mcd_channel_get_property (GObject * obj, guint prop_id, GValue * val, GParamSpec * pspec) { McdChannelPrivate *priv = MCD_CHANNEL_PRIV (obj); switch (prop_id) { case PROP_TP_CHANNEL: g_value_set_object (val, priv->tp_chan); break; case PROP_OUTGOING: g_value_set_boolean (val, priv->outgoing); break; case PROP_ACCOUNT_PATH: if (priv->request != NULL) { g_object_get_property ((GObject *) priv->request, "account-path", val); break; } g_value_set_static_boxed (val, "/"); break; case PROP_USER_ACTION_TIME: if (priv->request != NULL) { g_object_get_property ((GObject *) priv->request, "user-action-time", val); break; } g_value_set_int64 (val, TP_USER_ACTION_TIME_NOT_USER_ACTION); break; case PROP_PREFERRED_HANDLER: if (priv->request != NULL) { g_object_get_property ((GObject *) priv->request, "preferred-handler", val); break; } g_value_set_static_string (val, ""); break; case PROP_REQUESTS: if (priv->request != NULL) { g_object_get_property ((GObject *) priv->request, "requests", val); break; } g_value_take_boxed (val, g_ptr_array_sized_new (0)); break; case PROP_INTERFACES: if (priv->request != NULL) { g_object_get_property ((GObject *) priv->request, "interfaces", val); break; } g_value_take_boxed (val, NULL); break; case PROP_HINTS: if (priv->request != NULL) { g_object_get_property ((GObject *) priv->request, "hints", val); break; } g_value_take_boxed (val, g_hash_table_new (NULL, NULL)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); break; } }
/** * tp_properties_mixin_set_properties: * @obj: An object with this mixin * @properties: An array of D-Bus structures containing property ID and value * @context: A D-Bus method invocation context for the SetProperties method * * Start to change properties in response to user request via D-Bus. */ void tp_properties_mixin_set_properties (GObject *obj, const GPtrArray *properties, DBusGMethodInvocation *context) { TpPropertiesMixin *mixin = TP_PROPERTIES_MIXIN (obj); TpPropertiesMixinClass *mixin_cls = TP_PROPERTIES_MIXIN_CLASS ( G_OBJECT_GET_CLASS (obj)); TpPropertiesContext *ctx = &mixin->priv->context; GError *error = NULL; GType value_type = TP_STRUCT_TYPE_PROPERTY_VALUE; guint i; /* Is another SetProperties request already in progress? */ if (ctx->dbus_ctx) { error = g_error_new (TP_ERRORS, TP_ERROR_NOT_AVAILABLE, "A SetProperties request is already in progress"); dbus_g_method_return_error (context, error); g_error_free (error); return; } ctx->dbus_ctx = context; ctx->remaining = tp_intset_new (); error = NULL; if (properties->len == 0) { DEBUG ("immediately returning from SetProperties with 0 properties"); tp_properties_context_return (ctx, NULL); return; } /* Check input property identifiers */ for (i = 0; i < properties->len; i++) { GValue val_struct = { 0, }; guint prop_id; GValue *prop_val; g_value_init (&val_struct, value_type); g_value_set_static_boxed (&val_struct, g_ptr_array_index (properties, i)); dbus_g_type_struct_get (&val_struct, 0, &prop_id, 1, &prop_val, G_MAXUINT); /* Valid? */ if (prop_id >= mixin_cls->num_props) { g_value_unset (prop_val); error = g_error_new (TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, "invalid property identifier %d", prop_id); goto ERROR; } /* Store the value in the context */ tp_intset_add (ctx->remaining, prop_id); ctx->values[prop_id] = prop_val; /* Permitted? */ if (!tp_properties_mixin_is_writable (obj, prop_id)) { error = g_error_new (TP_ERRORS, TP_ERROR_PERMISSION_DENIED, "permission denied for property identifier %d", prop_id); goto ERROR; } /* Compatible type? */ if (!g_value_type_compatible (G_VALUE_TYPE (prop_val), mixin_cls->signatures[prop_id].type)) { error = g_error_new (TP_ERRORS, TP_ERROR_NOT_AVAILABLE, "incompatible value type for property " "identifier %d", prop_id); goto ERROR; } } if (mixin_cls->set_properties) { if (mixin_cls->set_properties (obj, ctx, &error)) return; } else { tp_properties_context_return (ctx, NULL); return; } ERROR: tp_properties_context_return (ctx, error); }
/** * * Method GetData on /org/freedesktop/DeviceKit/Power/Wakeups * * <method name="GetData"> * <arg name="data" type="a(budss)" direction="out"/> (1) * </method> * (1): array | boolean Wheter the proceess on userspace * | uint PID * | double Wakeups value * | string command line * | string details **/ static void xfpm_info_update_wakeups (XfpmInfo *info) { GtkListStore *store; GError *error = NULL; static GType collection_type = G_TYPE_INVALID; static GType struct_type = G_TYPE_INVALID; GPtrArray *array = NULL; gboolean ret; guint i; if ( G_UNLIKELY (collection_type == G_TYPE_INVALID ) ) { struct_type = dbus_g_type_get_struct ("GValueArray", G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_DOUBLE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); collection_type = dbus_g_type_get_collection ("GPtrArray", struct_type); } ret = dbus_g_proxy_call (info->wakeups_proxy, "GetData", &error, G_TYPE_INVALID, collection_type, &array, NULL); if ( !ret ) { g_warning ("GetData Failed on %s : %s", UPOWER_PATH_WAKEUPS, error->message); g_error_free (error); return; } store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (info->wakeups))); gtk_list_store_clear (GTK_LIST_STORE (store)); for ( i = 0; i < array->len; i++ ) { GValue elem = { 0 }; GtkTreeIter iter; gboolean userspace; guint pid; gdouble value; gchar *cmd; gchar *formatted_cmd; gchar *details; gchar *formatted_details; gchar *pid_str; gchar *value_str; const gchar *icon; g_value_init (&elem, struct_type); g_value_set_static_boxed (&elem, g_ptr_array_index (array, i)); dbus_g_type_struct_get (&elem, 0, &userspace, 1, &pid, 2, &value, 3, &cmd, 4, &details, G_MAXUINT); if ( userspace ) { pid_str = g_strdup_printf ("%i", pid); } else { if ( pid < 0xff0 ) { pid_str = g_strdup_printf ("IRQ%i", pid); } else { pid_str = g_strdup("IRQx"); } } value_str = g_strdup_printf ("%.1f", value); icon = userspace ? "application-x-executable" : "applications-system"; formatted_cmd = gpm_stats_format_cmdline (cmd, userspace); formatted_details = gpm_stats_format_details (details); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COL_WAKEUPS_TYPE, icon, COL_WAKEUPS_PID, pid_str, COL_WAKEUPS_VALUE, value_str, COL_WAKEUPS_CMD, formatted_cmd, COL_WAKEUPS_DETAILS, formatted_details, -1); g_free (cmd); g_free (details); g_free (formatted_cmd); g_free (formatted_details); g_value_unset (&elem); } g_ptr_array_free (array, TRUE); }
static JSBool gjs_value_to_g_value_internal(JSContext *context, jsval value, GValue *gvalue, gboolean no_copy) { GType gtype; gtype = G_VALUE_TYPE(gvalue); if (gtype == 0) { gtype = gjs_value_guess_g_type(context, value); if (gtype == G_TYPE_INVALID) { gjs_throw(context, "Could not guess unspecified GValue type"); return JS_FALSE; } gjs_debug_marshal(GJS_DEBUG_GCLOSURE, "Guessed GValue type %s from JS Value", g_type_name(gtype)); g_value_init(gvalue, gtype); } gjs_debug_marshal(GJS_DEBUG_GCLOSURE, "Converting jsval to gtype %s", g_type_name(gtype)); if (gtype == G_TYPE_STRING) { /* Don't use ValueToString since we don't want to just toString() * everything automatically */ if (JSVAL_IS_NULL(value)) { g_value_set_string(gvalue, NULL); } else if (JSVAL_IS_STRING(value)) { gchar *utf8_string; if (!gjs_string_to_utf8(context, value, &utf8_string)) return JS_FALSE; g_value_take_string(gvalue, utf8_string); } else { gjs_throw(context, "Wrong type %s; string expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_CHAR) { gint32 i; if (JS_ValueToInt32(context, value, &i) && i >= SCHAR_MIN && i <= SCHAR_MAX) { g_value_set_schar(gvalue, (signed char)i); } else { gjs_throw(context, "Wrong type %s; char expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_UCHAR) { guint16 i; if (JS_ValueToUint16(context, value, &i) && i <= UCHAR_MAX) { g_value_set_uchar(gvalue, (unsigned char)i); } else { gjs_throw(context, "Wrong type %s; unsigned char expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_INT) { gint32 i; if (JS_ValueToInt32(context, value, &i)) { g_value_set_int(gvalue, i); } else { gjs_throw(context, "Wrong type %s; integer expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_DOUBLE) { gdouble d; if (JS_ValueToNumber(context, value, &d)) { g_value_set_double(gvalue, d); } else { gjs_throw(context, "Wrong type %s; double expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_FLOAT) { gdouble d; if (JS_ValueToNumber(context, value, &d)) { g_value_set_float(gvalue, d); } else { gjs_throw(context, "Wrong type %s; float expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_UINT) { guint32 i; if (JS_ValueToECMAUint32(context, value, &i)) { g_value_set_uint(gvalue, i); } else { gjs_throw(context, "Wrong type %s; unsigned integer expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_BOOLEAN) { JSBool b; /* JS_ValueToBoolean() pretty much always succeeds, * which is maybe surprising sometimes, but could * be handy also... */ if (JS_ValueToBoolean(context, value, &b)) { g_value_set_boolean(gvalue, b); } else { gjs_throw(context, "Wrong type %s; boolean expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_OBJECT) || g_type_is_a(gtype, G_TYPE_INTERFACE)) { GObject *gobj; gobj = NULL; if (JSVAL_IS_NULL(value)) { /* nothing to do */ } else if (JSVAL_IS_OBJECT(value)) { JSObject *obj; obj = JSVAL_TO_OBJECT(value); if (!gjs_typecheck_object(context, obj, gtype, JS_TRUE)) return JS_FALSE; gobj = gjs_g_object_from_object(context, obj); } else { gjs_throw(context, "Wrong type %s; object %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } g_value_set_object(gvalue, gobj); } else if (gtype == G_TYPE_STRV) { if (JSVAL_IS_NULL(value)) { /* do nothing */ } else if (gjs_object_has_property(context, JSVAL_TO_OBJECT(value), "length")) { jsval length_value; guint32 length; if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(value), NULL, "length", &length_value) || !JS_ValueToECMAUint32(context, length_value, &length)) { gjs_throw(context, "Wrong type %s; strv expected", gjs_get_type_name(value)); return JS_FALSE; } else { void *result; char **strv; if (!gjs_array_to_strv (context, value, length, &result)) return JS_FALSE; /* cast to strv in a separate step to avoid type-punning */ strv = result; g_value_take_boxed (gvalue, strv); } } else { gjs_throw(context, "Wrong type %s; strv expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_BOXED)) { void *gboxed; gboxed = NULL; if (JSVAL_IS_NULL(value)) { /* nothing to do */ } else if (JSVAL_IS_OBJECT(value)) { JSObject *obj; obj = JSVAL_TO_OBJECT(value); if (g_type_is_a(gtype, G_TYPE_ERROR)) { /* special case GError */ if (!gjs_typecheck_gerror(context, obj, JS_TRUE)) return JS_FALSE; gboxed = gjs_gerror_from_error(context, obj); } else { /* First try a union, if that fails, assume a boxed struct. Distinguishing which one is expected would require checking the associated GIBaseInfo, which is not necessary possible, if e.g. we see the GType without loading the typelib. */ if (gjs_typecheck_union(context, obj, NULL, gtype, JS_FALSE)) { gboxed = gjs_c_union_from_union(context, obj); } else { if (!gjs_typecheck_boxed(context, obj, NULL, gtype, JS_TRUE)) return JS_FALSE; gboxed = gjs_c_struct_from_boxed(context, obj); } } } else { gjs_throw(context, "Wrong type %s; boxed type %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } if (no_copy) g_value_set_static_boxed(gvalue, gboxed); else g_value_set_boxed(gvalue, gboxed); } else if (g_type_is_a(gtype, G_TYPE_VARIANT)) { GVariant *variant = NULL; if (JSVAL_IS_NULL(value)) { /* nothing to do */ } else if (JSVAL_IS_OBJECT(value)) { JSObject *obj = JSVAL_TO_OBJECT(value); if (!gjs_typecheck_boxed(context, obj, NULL, G_TYPE_VARIANT, JS_TRUE)) return JS_FALSE; variant = gjs_c_struct_from_boxed(context, obj); } else { gjs_throw(context, "Wrong type %s; boxed type %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } g_value_set_variant (gvalue, variant); } else if (g_type_is_a(gtype, G_TYPE_ENUM)) { gint64 value_int64; if (gjs_value_to_int64 (context, value, &value_int64)) { GEnumValue *v; /* See arg.c:_gjs_enum_to_int() */ v = g_enum_get_value(G_ENUM_CLASS(g_type_class_peek(gtype)), (int)value_int64); if (v == NULL) { gjs_throw(context, "%d is not a valid value for enumeration %s", JSVAL_TO_INT(value), g_type_name(gtype)); return JS_FALSE; } g_value_set_enum(gvalue, v->value); } else { gjs_throw(context, "Wrong type %s; enum %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_FLAGS)) { gint64 value_int64; if (gjs_value_to_int64 (context, value, &value_int64)) { if (!_gjs_flags_value_is_valid(context, gtype, value_int64)) return JS_FALSE; /* See arg.c:_gjs_enum_to_int() */ g_value_set_flags(gvalue, (int)value_int64); } else { gjs_throw(context, "Wrong type %s; flags %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_PARAM)) { void *gparam; gparam = NULL; if (JSVAL_IS_NULL(value)) { /* nothing to do */ } else if (JSVAL_IS_OBJECT(value)) { JSObject *obj; obj = JSVAL_TO_OBJECT(value); if (!gjs_typecheck_param(context, obj, gtype, JS_TRUE)) return JS_FALSE; gparam = gjs_g_param_from_param(context, obj); } else { gjs_throw(context, "Wrong type %s; param type %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } g_value_set_param(gvalue, gparam); } else if (g_type_is_a(gtype, G_TYPE_GTYPE)) { GType type; if (!JSVAL_IS_OBJECT(value)) { gjs_throw(context, "Wrong type %s; expect a GType object", gjs_get_type_name(value)); return JS_FALSE; } type = gjs_gtype_get_actual_gtype(context, JSVAL_TO_OBJECT(value)); g_value_set_gtype(gvalue, type); } else if (g_type_is_a(gtype, G_TYPE_POINTER)) { if (JSVAL_IS_NULL(value)) { /* Nothing to do */ } else { gjs_throw(context, "Cannot convert non-null JS value to G_POINTER"); return JS_FALSE; } } else if (JSVAL_IS_NUMBER(value) && g_value_type_transformable(G_TYPE_INT, gtype)) { /* Only do this crazy gvalue transform stuff after we've * exhausted everything else. Adding this for * e.g. ClutterUnit. */ gint32 i; if (JS_ValueToInt32(context, value, &i)) { GValue int_value = { 0, }; g_value_init(&int_value, G_TYPE_INT); g_value_set_int(&int_value, i); g_value_transform(&int_value, gvalue); } else { gjs_throw(context, "Wrong type %s; integer expected", gjs_get_type_name(value)); return JS_FALSE; } } else { gjs_debug(GJS_DEBUG_GCLOSURE, "jsval is number %d gtype fundamental %d transformable to int %d from int %d", JSVAL_IS_NUMBER(value), G_TYPE_IS_FUNDAMENTAL(gtype), g_value_type_transformable(gtype, G_TYPE_INT), g_value_type_transformable(G_TYPE_INT, gtype)); gjs_throw(context, "Don't know how to convert JavaScript object to GType %s", g_type_name(gtype)); return JS_FALSE; } return JS_TRUE; }