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, &parameter_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;
}
Ejemplo n.º 2
0
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, &parameters, 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;
}
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;
}
Ejemplo n.º 4
0
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
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;
}
Ejemplo n.º 6
0
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
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;
}
static gboolean
sig_match_conn (TpStreamTubeChannel *self,
    SigWaitingConn *sig,
    ConnWaitingSig *c)
{
  if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_PORT)
    {
      /* Use the port to identify the connection */
      guint port;
      GSocketAddress *address;
      GError *error = NULL;

      address = g_socket_connection_get_remote_address (c->conn, &error);
      if (address == NULL)
        {
          DEBUG ("Failed to get connection address: %s", error->message);

          g_error_free (error);
          return FALSE;
        }

      dbus_g_type_struct_get (sig->param, 1, &port, G_MAXINT);

      if (port == g_inet_socket_address_get_port (
            G_INET_SOCKET_ADDRESS (address)))
        {
          DEBUG ("Identified connection %u using port %u",
              port, sig->connection_id);

          g_object_unref (address);
          return TRUE;
        }

      g_object_unref (address);
    }
  else if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS)
    {
      guchar byte;

      byte = g_value_get_uchar (sig->param);

      return byte == c->byte;
    }
  else
    {
      DEBUG ("Can't properly identify connection as we are using "
          "access control %u. Assume it's the head of the list",
          self->priv->access_control);

      return TRUE;
    }

  return FALSE;
}
Ejemplo n.º 9
0
static void remmina_tp_channel_handler_accept(TpChannel *channel, const GValue *address, const GError *error,
		gpointer user_data, GObject *weak_object)
{
	RemminaTpChannelHandler *chandler = (RemminaTpChannelHandler *) user_data;

	if (error != NULL)
	{
		g_print("remmina_tp_channel_handler_accept: %s", error->message);
		remmina_tp_channel_handler_free(chandler);
		return;
	}

	dbus_g_type_struct_get(address, 0, &chandler->host, 1, &chandler->port, G_MAXUINT);

	tp_cli_dbus_properties_call_get(channel, -1, TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, "Service",
			remmina_tp_channel_handler_get_service, chandler, NULL, NULL);
}
static void __bluetooth_ptr_array_free(gpointer data)
{
	GValue value = { 0, };

	gchar *name = NULL;
	gchar *type = NULL;

	if(data == NULL)
		return;

	g_value_init(&value, DBUS_STRUCT_STRING_STRING);
	g_value_set_boxed(&value, data);

	dbus_g_type_struct_get(&value,
			0, &name,
			1, &type,
			G_MAXUINT);

	g_free(name);
	g_free(type);
}
Ejemplo n.º 11
0
static void
tp_tube_accept_stream_cb (TpProxy *proxy,
                          const GValue *address,
                          const GError *error,
                          gpointer user_data,
                          GObject *weak_object)
{
  EmpathyTpTube *tube = EMPATHY_TP_TUBE (weak_object);
  EmpathyTpTubeAcceptData *data = (EmpathyTpTubeAcceptData *)user_data;
  EmpathyTpTubeAddress eaddress;

  eaddress.type = data->type;

  if (error)
    {
      DEBUG ("Error accepting tube: %s", error->message);
      data->callback (tube, NULL, error, data->user_data);
      return;
    }

  switch (eaddress.type)
    {
      case TP_SOCKET_ADDRESS_TYPE_UNIX:
      case TP_SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX:
        eaddress.a.socket.path = g_value_get_boxed (address);
        break;
     case TP_SOCKET_ADDRESS_TYPE_IPV4:
     case TP_SOCKET_ADDRESS_TYPE_IPV6:
        dbus_g_type_struct_get (address,
          0, &eaddress.a.inet.hostname,
          1, &eaddress.a.inet.port, G_MAXUINT);
        break;
    }

   data->callback (tube, &eaddress, NULL, data->user_data);
}
Ejemplo n.º 12
0
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(&parametersCount);
  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);
}
Ejemplo n.º 13
0
/**
 * 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);
    
}