Пример #1
0
gboolean
load_dlna (SnappyMP * mp)
{
  guint owner_id, player_id, root_id;
  GError *error = NULL;
  GDBusInterfaceInfo *ifaceinfo;
  GDBusConnection *connection;

  g_type_init ();

  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);

  /* Build the introspection data structures from the XML */
  introspection_data =
      g_dbus_node_info_new_for_xml (mpris_introspection_xml, NULL);
  g_assert (introspection_data != NULL);

  /* register media player interface */
  ifaceinfo =
      g_dbus_node_info_lookup_interface (introspection_data,
      MPRIS_PLAYER_INTERFACE);
  mp->player_id =
      g_dbus_connection_register_object (connection, MPRIS_OBJECT_NAME,
      ifaceinfo, &interface_vtable, mp, NULL, &error);

  /* register root interface */
  ifaceinfo =
      g_dbus_node_info_lookup_interface (introspection_data,
      MPRIS_ROOT_INTERFACE);
  mp->root_id =
      g_dbus_connection_register_object (connection, MPRIS_OBJECT_NAME,
      ifaceinfo, &root_vtable, NULL, NULL, &error);
  if (error != NULL) {
    g_warning ("unable to register MPRIS root interface: %s", error->message);
    g_error_free (error);
  }

  mp->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
      "org.mpris.MediaPlayer2.snappy",
      G_BUS_NAME_OWNER_FLAGS_NONE,
      NULL,
      (GBusNameAcquiredCallback) on_name_acquired,
      (GBusNameLostCallback) on_name_lost, mp, NULL);
  g_assert (mp->owner_id > 0);

  mp->name = g_strdup ("snappy");

  return TRUE;
}
Пример #2
0
static GDBusInterfaceInfo *
org_gtk_Menus_get_interface (void)
{
  static GDBusInterfaceInfo *interface_info;

  if (interface_info == NULL)
    {
      GError *error = NULL;
      GDBusNodeInfo *info;

      info = g_dbus_node_info_new_for_xml ("<node>"
                                           "  <interface name='org.gtk.Menus'>"
                                           "    <method name='Start'>"
                                           "      <arg type='au' name='groups' direction='in'/>"
                                           "      <arg type='a(uuaa{sv})' name='content' direction='out'/>"
                                           "    </method>"
                                           "    <method name='End'>"
                                           "      <arg type='au' name='groups' direction='in'/>"
                                           "    </method>"
                                           "    <signal name='Changed'>"
                                           "      arg type='a(uuuuaa{sv})' name='changes'/>"
                                           "    </signal>"
                                           "  </interface>"
                                           "</node>", &error);
      if (info == NULL)
        g_error ("%s\n", error->message);
      interface_info = g_dbus_node_info_lookup_interface (info, "org.gtk.Menus");
      g_assert (interface_info != NULL);
      g_dbus_interface_info_ref (interface_info);
      g_dbus_node_info_unref (info);
    }

  return interface_info;
}
Пример #3
0
LouDBusProxy *
loudbus_proxy_new (gchar *service, gchar *object, gchar *interface, 
                   GError **errorp)
{
  LouDBusProxy *proxy;         // The proxy we're creating

  // Allocate space for the struct.
  proxy = g_malloc0 (sizeof (LouDBusProxy));
  if (proxy == NULL)
    {
      LOG ("loudbus_proxy_new: Could not allocate proxy.");
      return NULL;
    } // if (proxy == NULL)

  LOG ("Creating proxy for (%s,%s,%s)", service, object, interface);
  proxy->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                G_DBUS_PROXY_FLAGS_NONE,
                                                NULL,
                                                service,
                                                object,
                                                interface,
                                                NULL,
                                                errorp);
  if (proxy->proxy == NULL)
    {
      LOG ("loudbus_proxy_new: Could not build proxy.");
      g_free (proxy);
      return NULL;
    } // if we failed to create the proxy.

  // Get the node information
  proxy->ninfo = g_dbus_proxy_get_node_info (proxy->proxy);
  if (proxy->ninfo == NULL)
    {
      LOG ("loudbus_proxy_new: Could not get node info.");
      g_object_unref (proxy->proxy);
      g_free (proxy);
      return NULL;
    } // if we failed to get node information

  // Get the interface information
  proxy->iinfo = g_dbus_node_info_lookup_interface(proxy->ninfo, interface);
  if (proxy->iinfo == NULL)
    {
      LOG ("loudbus_proxy_new: Could not get interface info.");
      g_object_unref (proxy->proxy);
      g_dbus_node_info_unref (proxy->ninfo);
      g_free (proxy);
      return NULL;
    } // if we failed to get interface information

  // We will be looking stuff up in the interface, so build a cache
  g_dbus_interface_info_cache_build (proxy->iinfo);

  // Set the signature
  proxy->signature = loudbus_proxy_signature ();

  // And we seem to be done
  return proxy;
} // loudbus_proxy_new
Пример #4
0
static void
new_connection_cb (GDBusServer *server,
		   GDBusConnection *connection,
		   ServiceData *svc)
{
	GError *error = NULL;
	rb_debug ("new connection to metadata service");

	/* don't allow more than one connection at a time */
	if (svc->connection) {
		rb_debug ("metadata service already has a client.  go away.");
		return;
	}
	g_dbus_connection_register_object (connection,
					   RB_METADATA_DBUS_OBJECT_PATH,
					   g_dbus_node_info_lookup_interface (svc->node_info, RB_METADATA_DBUS_INTERFACE),
					   &metadata_vtable,
					   svc,
					   NULL,
					   &error);
	if (error != NULL) {
		rb_debug ("unable to register metadata object: %s", error->message);
		g_clear_error (&error);
	} else {
		svc->connection = g_object_ref (connection);
		g_signal_connect (connection, "closed", G_CALLBACK (connection_closed_cb), svc);

		g_dbus_connection_set_exit_on_close (connection, (svc->external == FALSE));
	}
}
Пример #5
0
void dbus_pinyin()
{
    loop = g_main_loop_new(NULL, FALSE);
    GError *error = NULL;
    
    node_info = g_dbus_node_info_new_for_xml (_lock_dbus_iface_xml, &error);
    if ( error != NULL ) {
        g_critical("Unable to parse interface xml: %s\n", error->message);
        g_error_free(error);
    }

    interface_info = g_dbus_node_info_lookup_interface(node_info, 
            DBUS_PYSQL_INFACE );
    if ( interface_info == NULL ) {
        g_critical("Unable to find interface '"DBUS_PYSQL_INFACE"'");
    }

    lock_service_owner_id = 0;
    lock_service_reg_id = 0;
    retry_reg_timeout_id = 0;
    _retry_registration(NULL);

    /*g_timeout_add_seconds( 15, do_exit, NULL );*/
    g_main_loop_run(loop);
    g_main_loop_unref(loop);

    return ;
}
void AbstractDBusInterface::registerObject()
{
	if(!mConnection)
	{
		throw std::runtime_error("forgot to call setDBusConnection on AbstractDBusInterface");
	}

	if(introspectionXml.empty())
	{
		cerr<<"no interface to export: "<<mInterfaceName<<endl;
		throw -1;
	}

	if(!boost::algorithm::ends_with(introspectionXml,"</node>"))
	{
		introspectionXml += "</interface>"
				"</node>";
	}

	GError* error=NULL;

	GDBusNodeInfo* introspection = g_dbus_node_info_new_for_xml(introspectionXml.c_str(), &error);

	if(!introspection || error)
	{

		DebugOut(DebugOut::Error)<<"Error in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<endl;
		DebugOut(DebugOut::Error)<<error->message<<endl;
		DebugOut(DebugOut::Error)<<"probably bad xml:"<<endl;
		DebugOut(DebugOut::Error)<<introspectionXml<<endl;

		g_error_free(error);

		return;
	}

	GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, mInterfaceName.c_str());


	const GDBusInterfaceVTable vtable = { handleMyMethodCall, nullptr, nullptr };

	GError* error2=NULL;

	DebugOut()<<"registering DBus path: "<<mObjectPath<<endl;

	regId = g_dbus_connection_register_object(mConnection, mObjectPath.c_str(), mInterfaceInfo, &vtable, this, NULL, &error2);
	g_dbus_node_info_unref(introspection);
	if(error2)
	{
		DebugOut(DebugOut::Error)<<error2->message<<endl;
		g_error_free(error2);
	}

	if(regId == 0)
	{
		DebugOut(DebugOut::Error)<<"We failed to register on DBus"<<endl;
	}
}
static GDBusInterfaceInfo * hev_dbus_interface_test_get_info(GDBusInterfaceSkeleton *skeleton)
{
	HevDBusInterfaceTest *self = HEV_DBUS_INTERFACE_TEST(skeleton);
	HevDBusInterfaceTestPrivate *priv = HEV_DBUS_INTERFACE_TEST_GET_PRIVATE(self);

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	return g_dbus_node_info_lookup_interface(priv->node_info, HEV_DBUS_INTERFACE_TEST_NAME);
}
AutomotiveManager::AutomotiveManager(GDBusConnection *connection)
	:mConnection(connection)
{
	GError* error = NULL;

	GDBusNodeInfo* introspection = g_dbus_node_info_new_for_xml(introspection_xml, &error);
	GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, "org.automotive.Manager");

	regId = g_dbus_connection_register_object(mConnection, "/", mInterfaceInfo, &interfaceVTable, this, NULL, &error);

	if(error) throw -1;

	g_assert(regId > 0);
}
static void
infinoted_plugin_dbus_bus_acquired_func(GDBusConnection* connection,
                                        const gchar* name,
                                        gpointer user_data)
{
  GDBusNodeInfo* node_info;
  GDBusInterfaceInfo* interface_info;
  GDBusInterfaceVTable vtable;
  GError* error;

  node_info = g_dbus_node_info_new_for_xml(
    infinoted_plugin_dbus_introspection,
    NULL
  );

  g_assert(node_info != NULL);

  interface_info = g_dbus_node_info_lookup_interface(
    node_info,
    "org.infinote.server"
  );

  g_assert(interface_info != NULL);

  vtable.method_call = infinoted_plugin_dbus_method_call_func;
  vtable.get_property = NULL;
  vtable.set_property = NULL;

  error = NULL;
  g_dbus_connection_register_object(
    connection,
    "/org/infinote/infinoted",
    interface_info,
    &vtable,
    user_data,
    NULL,
    &error
  );

  if(error != NULL)
  {
    g_warning("Failed to register D-Bus object: %s\n", error->message);
    g_error_free(error);
    error = NULL;
  }

  g_dbus_node_info_unref(node_info);
}
Пример #10
0
void register_agent_callbacks(gboolean interactive_console, GHashTable *pin_dictonary, gpointer main_loop_object, GError **error)
{
    GDBusInterfaceVTable bt_agent_table;
    memset(&bt_agent_table, 0x0, sizeof(bt_agent_table));

    if(pin_dictonary)
        _pin_hash_table = pin_dictonary;
    if(main_loop_object)
        _mainloop = (GMainLoop *) main_loop_object;

    _interactive = interactive_console;

    GDBusNodeInfo *bt_agent_node_info = g_dbus_node_info_new_for_xml(_bt_agent_introspect_xml, error);
    GDBusInterfaceInfo *bt_agent_interface_info = g_dbus_node_info_lookup_interface(bt_agent_node_info, AGENT_DBUS_INTERFACE);
    bt_agent_table.method_call = _bt_agent_method_call_func;
    _bt_agent_registration_id = g_dbus_connection_register_object(g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error), AGENT_PATH, bt_agent_interface_info, &bt_agent_table, NULL, _bt_agent_g_destroy_notify, error);
    g_dbus_node_info_unref(bt_agent_node_info);
}
AutomotiveManager::AutomotiveManager(GDBusConnection *connection)
	:mConnection(connection)
{
	GError* error = NULL;

	GDBusNodeInfo* introspection = g_dbus_node_info_new_for_xml(introspection_xml, &error);
	GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, "org.automotive.Manager");

	regId = g_dbus_connection_register_object(mConnection, "/", mInterfaceInfo, &interfaceVTable, this, NULL, &error);
	g_dbus_node_info_unref(introspection);

	if(error){
		g_error_free(error);
		throw -1;
	}

	g_assert(regId > 0);

	g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL,NULL), "org.freedesktop.DBus", "org.freedesktop.DBus",
																					   "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
																					   signalCallback, this, NULL);
}
void AbstractDBusInterface::registerObject()
{
	if(!mConnection)
	{
		throw std::runtime_error("forgot to call setDBusConnection on AbstractDBusInterface");
	}
	
	if(introspectionXml.empty())
	{
		cerr<<"no interface to export: "<<mInterfaceName<<endl;
		throw -1;
	}

	introspectionXml += "</interface>";
	introspectionXml += "</node>";
	
	GError* error=NULL;

	GDBusNodeInfo* introspection = g_dbus_node_info_new_for_xml(introspectionXml.c_str(), &error);
	
	if(!introspection)
	{
		cerr<<"Error in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<endl;
		cerr<<error->message<<endl;
		cerr<<"probably bad xml:"<<endl;
		cerr<<introspectionXml<<endl;
		return;
	}

	GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, mInterfaceName.c_str());
	
	const GDBusInterfaceVTable vtable = { NULL, AbstractDBusInterface::getProperty, AbstractDBusInterface::setProperty };
	
	regId = g_dbus_connection_register_object(mConnection, mObjectPath.c_str(), mInterfaceInfo, &vtable, NULL, NULL, &error);
	
	if(error) throw -1;
	
	g_assert(regId > 0);
}
AutomotiveManager::AutomotiveManager(GDBusConnection *connection)
	:mConnection(connection)
{
	GError* error = NULL;

	GDBusNodeInfo* introspection = g_dbus_node_info_new_for_xml(introspection_xml, &error);
	GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, "org.automotive.Manager");

	regId = g_dbus_connection_register_object(mConnection, "/", mInterfaceInfo, &interfaceVTable, this, NULL, &error);
	g_dbus_node_info_unref(introspection);

	auto errorPtr = amb::make_super(error);

	if(errorPtr){
		DebugOut(DebugOut::Error) << "registering dbus object: " << "'org.automotive.Manager' " << errorPtr->message << endl;
		throw -1;
	}

	g_assert(regId > 0);

	g_dbus_connection_signal_subscribe(mConnection, "org.freedesktop.DBus", "org.freedesktop.DBus",
																					   "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
																					   signalCallback, this, NULL);
}
Пример #14
0
static void
impl_activate(PeasActivatable *activatable)
{
	XmrMprisPlugin *plugin;
	GError *error = NULL;

	GDBusInterfaceInfo *ifaceinfo;

	plugin = XMR_MPRIS_PLUGIN(activatable);
	g_object_get(plugin, "object", &plugin->window, NULL);
	g_object_get(plugin->window, "player", &plugin->player, NULL);

	g_signal_connect(plugin->window, "track-changed",
				G_CALLBACK(track_changed), plugin);
	g_signal_connect(plugin->player, "tick", G_CALLBACK(player_tick), plugin);

	plugin->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
	if (error != NULL)
	{
		xmr_debug("Unable to connect to D-Bus session bus: %s", error->message);
		return ;
	}

	/* parse introspection data */
	plugin->node_info = g_dbus_node_info_new_for_xml(mpris_introspection_xml, &error);
	if (error != NULL)
	{
		xmr_debug("Unable to read MPRIS interface specificiation: %s", error->message);
		return;
	}

	/* register root interface */
	ifaceinfo = g_dbus_node_info_lookup_interface (plugin->node_info, MPRIS_ROOT_INTERFACE);
	plugin->root_id = g_dbus_connection_register_object(plugin->connection,
							     MPRIS_OBJECT_NAME,
							     ifaceinfo,
							     &root_vtable,
							     plugin,
							     NULL,
							     &error);
	if (error != NULL)
	{
		xmr_debug("unable to register MPRIS root interface: %s", error->message);
		g_error_free (error);
	}

	/* register player interface */
	ifaceinfo = g_dbus_node_info_lookup_interface(plugin->node_info, MPRIS_PLAYER_INTERFACE);
	plugin->player_id = g_dbus_connection_register_object(plugin->connection,
							       MPRIS_OBJECT_NAME,
							       ifaceinfo,
							       &player_vtable,
							       plugin,
							       NULL,
							       &error);
	if (error != NULL)
	{
		xmr_debug("Unable to register MPRIS player interface: %s", error->message);
		g_error_free (error);
	}

	plugin->name_own_id = g_bus_own_name(G_BUS_TYPE_SESSION,
					      MPRIS_BUS_NAME_PREFIX ".xmradio",
					      G_BUS_NAME_OWNER_FLAGS_NONE,
					      NULL,
					      (GBusNameAcquiredCallback) name_acquired_cb,
					      (GBusNameLostCallback) name_lost_cb,
					      g_object_ref(plugin),
					      g_object_unref);
}
Пример #15
0
gboolean gnome_media_keys_will_be_useful()
{
    GDBusConnection *bus = NULL;
    GVariant *response = NULL;
    GDBusNodeInfo *node_info = NULL;
    GDBusInterfaceInfo *interface_info;
    GDBusMethodInfo *method_info;
    const gchar *xml_data;
    gboolean result = TRUE;

    bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);

    if (!bus)
    {
        result = FALSE;
        goto out;
    }

    response = g_dbus_connection_call_sync(bus,
                                           "org.gnome.SettingsDaemon",
                                           "/org/gnome/SettingsDaemon/MediaKeys",
                                           "org.freedesktop.DBus.Introspectable",
                                           "Introspect",
                                           NULL,
                                           G_VARIANT_TYPE ("(s)"),
                                           G_DBUS_CALL_FLAGS_NO_AUTO_START,
                                           -1,
                                           NULL,
                                           NULL);

    if (!response)
    {
        result = FALSE;
        goto out;
    }

    g_variant_get(response, "(&s)", &xml_data);

    node_info = g_dbus_node_info_new_for_xml(xml_data, NULL);

    if (!node_info)
    {
        result = FALSE;
        goto out;
    }

    interface_info = g_dbus_node_info_lookup_interface(node_info, "org.gnome.SettingsDaemon.MediaKeys");

    if (!interface_info)
    {
        result = FALSE;
        goto out;
    }

    method_info = g_dbus_interface_info_lookup_method(interface_info, "GrabMediaPlayerKeys");

    if (!method_info)
    {
        result = FALSE;
        goto out;
    }

out:
    if (bus)
        g_object_unref(bus);
    if (response)
        g_variant_unref(response);
    if (node_info)
        g_dbus_node_info_unref(node_info);

    return result;
}