Exemplo n.º 1
0
static int
nds_claim_interface(LibHalContext *ctx, char *udi, DBusError *error)
{
	DBusConnection *connection;
	char *interface_xml =
		"<method name=\"EnablePrinterScanningViaSNMP\">\n"
		"  <arg name=\"interval\" direction=\"in\" type=\"i\"/>\n"
		"  <arg name=\"community\" direction=\"in\" type=\"s\"/>\n"
		"  <arg name=\"network\" direction=\"in\" type=\"s\"/>\n"
		"  <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
		"</method>\n"
		"<method name=\"DisablePrinterScanningViaSNMP\">\n"
		"  <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
		"</method>\n"
		"<method name=\"ScanForPrintersViaSNMP\">\n"
		"  <arg name=\"community\" direction=\"in\" type=\"s\"/>\n"
		"  <arg name=\"network\" direction=\"in\" type=\"s\"/>\n"
		"  <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
		"</method>\n";

	HAL_DEBUG(("nds_claim_interface(0x%8.8x, %s, 0x%8.8x): %s",
			ctx, udi, error, DBUS_INTERFACE));

	if ((connection = libhal_ctx_get_dbus_connection(ctx)) == NULL) {
		HAL_WARNING(("Could not get DBus connection"));
		return (-1);
	}

	if (libhal_device_claim_interface(ctx, udi,
			DBUS_INTERFACE, interface_xml, error) == 0) {
		HAL_WARNING(("Could not claim interface: %s", error->message));
		return (-1);
	}

	dbus_connection_setup_with_g_main(connection, NULL);
	dbus_connection_add_filter(connection, nds_filter_function, ctx, NULL);
	dbus_connection_set_exit_on_disconnect(connection, 0);

	return (0);
}
Exemplo n.º 2
0
int
main (int argc, char *argv[])
{
 	off_t address = 0;
 	size_t length = 0;
 	int fd;
 	int state;
	int retval = 0;
	struct pci_access *pacc;
 	struct pci_dev *dev;

	DBusError err;

	setup_logger ();
	udi = getenv ("UDI");

	HAL_DEBUG (("udi=%s", udi));
	if (udi == NULL) {
		HAL_ERROR (("No device specified"));
		return -2;
	}

	dbus_error_init (&err);
	if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
		HAL_ERROR (("Cannot connect to hald"));
		retval = -3;
		goto out;
	}

	if (!libhal_device_addon_is_ready (halctx, udi, &err)) {
		retval = -4;
		goto out;
	}


	conn = libhal_ctx_get_dbus_connection (halctx);
	dbus_connection_setup_with_g_main (conn, NULL);
	dbus_connection_set_exit_on_disconnect (conn, 0);

	dbus_connection_add_filter (conn, filter_function, NULL, NULL);

 	/* Search for the graphics card. */
 	/* Default values: */
 	/* address = 0x90300000; */
 	/* length = 0x20000; */

 	pacc = pci_alloc();
 	pci_init(pacc);
 	pci_scan_bus(pacc);
 	for(dev=pacc->devices; dev; dev=dev->next) {	/* Iterate over all devices */
 		pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
 		if ((dev->vendor_id == 0x1002) && (dev->device_id == 0x71c5)) { // ATI X1600
 			address = dev->base_addr[2];
 			length = dev->size[2];
 		}
 	}
 	pci_cleanup(pacc);

	HAL_DEBUG (("addr 0x%x len=%d", address, length));
 
 	if (!address) {
 		HAL_DEBUG (("Failed to detect ATI X1600, aborting..."));
		retval = 1;
		goto out;
 	}
 
 	fd = open ("/dev/mem", O_RDWR);
 	
 	if (fd < 0) {
 		HAL_DEBUG (("cannot open /dev/mem"));
		retval = 1;
		goto out;
 	}
 
 	memory = mmap (NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, address);
 
 	if (memory == MAP_FAILED) {
 		HAL_ERROR (("mmap failed"));
		retval = 2;
		goto out;
 	}
 
 	/* Is it really necessary ? */
 	OUTREG(0x4dc, 0x00000005);
 	state = INREG(0x7ae4);
 	OUTREG(0x7ae4, state);

	/* Allow access to porta 0x300 through 0x304 */
	if (ioperm (0x300, 5, 1) < 0) {
		HAL_ERROR (("ioperm failed (you should be root)."));
		exit(1);
	}

	/* this works because we hardcoded the udi's in the <spawn> in the fdi files */
	if (!libhal_device_claim_interface (halctx, 
					    "/org/freedesktop/Hal/devices/macbook_pro_lcd_panel", 
					    "org.freedesktop.Hal.Device.LaptopPanel", 
					    "    <method name=\"SetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
					    "      <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
					    "    </method>\n"
					    "    <method name=\"GetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
					    "    </method>\n",
					    &err)) {
		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.LaptopPanel'"));
		retval = -4;
		goto out;
	}
	if (!libhal_device_claim_interface (halctx, 
					    "/org/freedesktop/Hal/devices/macbook_pro_light_sensor",
					    "org.freedesktop.Hal.Device.LightSensor", 
					    "    <method name=\"GetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"ai\"/>\n"
					    "    </method>\n",
					    &err)) {
		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.LightSensor'"));
		retval = -4;
		goto out;
	}
	if (!libhal_device_claim_interface (halctx, 
					    "/org/freedesktop/Hal/devices/macbook_pro_keyboard_backlight",
					    "org.freedesktop.Hal.Device.KeyboardBacklight", 
					    "    <method name=\"GetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
					    "    </method>\n"
					    "    <method name=\"SetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
					    "    </method>\n",
					    &err)) {
		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.KeyboardBacklight'"));
		retval = -4;
		goto out;
	}

	main_loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (main_loop);
	return 0;

out:
        HAL_DEBUG (("An error occured, exiting cleanly"));

        LIBHAL_FREE_DBUS_ERROR (&err);

        if (halctx != NULL) {
                libhal_ctx_shutdown (halctx, &err);
                LIBHAL_FREE_DBUS_ERROR (&err);
                libhal_ctx_free (halctx);
        }

        return retval;
}
Exemplo n.º 3
0
int
main (int argc, char *argv[])
{
	DBusError err;
	int retval = 0;

	setup_logger ();
	setup_cb ();
	udi = getenv ("UDI");

	HAL_DEBUG (("udi=%s", udi));
	if (udi == NULL) {
		HAL_ERROR (("No device specified"));
		return -2;
	}

	dbus_error_init (&err);
	if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
		HAL_ERROR (("Cannot connect to hald"));
		retval = -3;
		goto out;
	}

	conn = libhal_ctx_get_dbus_connection (halctx);
	dbus_connection_setup_with_g_main (conn, NULL);

	dbus_connection_add_filter (conn, filter_function, NULL, NULL);

	if (!libhal_device_claim_interface (halctx,
					    "/org/freedesktop/Hal/devices/omapfb_bl",
					    "org.freedesktop.Hal.Device.LaptopPanel",
					    "    <method name=\"SetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
					    "      <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
					    "    </method>\n"
					    "    <method name=\"GetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
					    "    </method>\n",
					    &err)) {
		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.LaptopPanel'"));
		retval = -4;
		goto out;
	}

	if (!libhal_device_addon_is_ready (halctx, udi, &err)) {
		retval = -4;
		goto out;
	}

	bl_data.backlight_init (&bl_data);
	main_loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (main_loop);
	return 0;

out:
        HAL_DEBUG (("An error occured, exiting cleanly"));

        LIBHAL_FREE_DBUS_ERROR (&err);

        if (halctx != NULL) {
                libhal_ctx_shutdown (halctx, &err);
                LIBHAL_FREE_DBUS_ERROR (&err);
                libhal_ctx_free (halctx);
        }

        return retval;
}
int
main (int argc, char *argv[])
{
	DBusError error;
        LibHalContext *ctx_direct;
        DBusConnection *con_direct;
	char *bus;
	char *drive_type;
	char *support_media_changed_str;
        char *str;

	hal_set_proc_title_init (argc, argv);

	/* We could drop privs if we know that the haldaemon user is
	 * to be able to access block devices...
	 */
        /*drop_privileges (1);*/

	if ((udi = getenv ("UDI")) == NULL)
		goto out;
	if ((device_file = getenv ("HAL_PROP_BLOCK_DEVICE")) == NULL)
		goto out;
	if ((bus = getenv ("HAL_PROP_STORAGE_BUS")) == NULL)
		goto out;
	if ((drive_type = getenv ("HAL_PROP_STORAGE_DRIVE_TYPE")) == NULL)
		goto out;

	setup_logger ();

	support_media_changed_str = getenv ("HAL_PROP_STORAGE_CDROM_SUPPORT_MEDIA_CHANGED");
	if (support_media_changed_str != NULL && strcmp (support_media_changed_str, "true") == 0)
		support_media_changed = TRUE;
	else
		support_media_changed = FALSE;

	dbus_error_init (&error);
	con = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
	if (con == NULL) {
		HAL_ERROR (("Cannot connect to system bus"));
		goto out;
	}
	loop = g_main_loop_new (NULL, FALSE);
	dbus_connection_setup_with_g_main (con, NULL);
	dbus_connection_set_exit_on_disconnect (con, 0);

	if ((ctx_direct = libhal_ctx_init_direct (&error)) == NULL) {
		HAL_ERROR (("Cannot connect to hald"));
                goto out;
	}
	if (!libhal_device_addon_is_ready (ctx_direct, udi, &error)) {
                goto out;
	}
	con_direct = libhal_ctx_get_dbus_connection (ctx_direct);
	dbus_connection_setup_with_g_main (con_direct, NULL);
	dbus_connection_set_exit_on_disconnect (con_direct, 0);
	dbus_connection_add_filter (con_direct, direct_filter_function, NULL, NULL);


	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
		goto out;

	if (!libhal_device_addon_is_ready (ctx, udi, &error))
		goto out;

	HAL_DEBUG (("**************************************************"));
	HAL_DEBUG (("Doing addon-storage for %s (bus %s) (drive_type %s) (udi %s)", device_file, bus, drive_type, udi));
	HAL_DEBUG (("**************************************************"));

	if (strcmp (drive_type, "cdrom") == 0)
		is_cdrom = 1;
	else
		is_cdrom = 0;

	media_status = MEDIA_STATUS_UNKNOWN;


#ifdef HAVE_CONKIT
	/* TODO: ideally we should track the sessions on the seats on
	 * which the device belongs to. But right now we don't really
	 * do multi-seat so I'm going to punt on this for now.
	 */
	get_system_idle_from_ck ();

	dbus_bus_add_match (con,
			    "type='signal'"
			    ",interface='org.freedesktop.ConsoleKit.Manager'"
			    ",sender='org.freedesktop.ConsoleKit'"
                            ",member='SystemIdleHintChanged'",
			    NULL);
	dbus_bus_add_match (con,
			    "type='signal'"
			    ",interface='org.freedesktop.ConsoleKit.Seat'"
			    ",sender='org.freedesktop.ConsoleKit'"
                            ",member='ActiveSessionChanged'",
			    NULL);
#endif

        /* this is a bit weird; but we want to listen to signals about
         * locking from hald.. and signals are not pushed over direct
         * connections (for a good reason).
         */
	dbus_bus_add_match (con,
			    "type='signal'"
			    ",interface='org.freedesktop.Hal.Manager'"
			    ",sender='org.freedesktop.Hal'",
			    NULL);
	dbus_bus_add_match (con,
			    "type='signal'"
			    ",interface='org.freedesktop.Hal.Manager'"
			    ",sender='org.freedesktop.Hal'",
			    NULL);
        str = g_strdup_printf ("type='signal'"
                               ",interface='org.freedesktop.Hal.Device'"
                               ",sender='org.freedesktop.Hal'"
                               ",path='%s'",
                               udi);
	dbus_bus_add_match (con,
                            str,
			    NULL);
        g_free (str);
	dbus_connection_add_filter (con, dbus_filter_function, NULL, NULL);

	if (!libhal_device_claim_interface (ctx,
					    udi, 
					    "org.freedesktop.Hal.Device.Storage.Removable", 
					    "    <method name=\"CheckForMedia\">\n"
					    "      <arg name=\"call_had_sideeffect\" direction=\"out\" type=\"b\"/>\n"
					    "    </method>\n",
					    &error)) {
		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.Storage.Removable'"));
                goto out;
	}


	update_polling_interval ();
	g_main_loop_run (loop);

out:
	HAL_DEBUG (("An error occured, exiting cleanly"));

	LIBHAL_FREE_DBUS_ERROR (&error);

	if (ctx != NULL) {
		libhal_ctx_shutdown (ctx, &error);
		LIBHAL_FREE_DBUS_ERROR (&error);
		libhal_ctx_free (ctx);
	}

	return 0;
}
Exemplo n.º 5
0
static void
add_device (LibHalContext *ctx,
	    const char *udi,
	    const LibHalPropertySet *properties)
{
	DBusError err;
	DBusConnection *dbus_connection;
	const char* sysfs_path;
	const char* function;
	static gboolean initialized = FALSE;

	if ((sysfs_path = libhal_ps_get_string (properties, "linux.sysfs_path")) == NULL) {
		HAL_ERROR(("%s has no property linux.sysfs_path", udi));
		return;
	}
	if ((function = libhal_ps_get_string (properties, "leds.function")) == NULL) {
		HAL_ERROR(("%s has no property leds.function", udi));
		return;
	}

	/* claim the interface */
	
        if ((dbus_connection = libhal_ctx_get_dbus_connection(ctx)) == NULL) {
                HAL_WARNING (("Cannot get DBus connection"));
                return;
        }

	if (!initialized) {
		dbus_connection_add_filter (dbus_connection, filter_function, NULL, NULL);
		initialized = TRUE;
	}

	dbus_error_init (&err);

	if (function != NULL && strcmp(function, "kbd_backlight") == 0) {
		HAL_DEBUG (("Found a led which is a keyboard backlight."));
		
		if (!libhal_device_claim_interface (ctx,
						    udi,
						    "org.freedesktop.Hal.Device.KeyboardBacklight",
						    "    <method name=\"SetBrightness\">\n"
						    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
						    "      <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
						    "    </method>\n"
						    "    <method name=\"GetBrightness\">\n"
						    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
						    "    </method>\n",
						    &err)) {
			HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.KeyboardBacklight'"));
			LIBHAL_FREE_DBUS_ERROR (&err);
			return;
		}
	} else if (!libhal_device_claim_interface (ctx,
					    udi,
					    "org.freedesktop.Hal.Device.Leds",
					    "    <method name=\"SetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
					    "      <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
					    "    </method>\n"
					    "    <method name=\"GetBrightness\">\n"
					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
					    "    </method>\n",
					    &err)) {
		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.Leds'"));
		LIBHAL_FREE_DBUS_ERROR (&err);
		return;
	}
	
	g_hash_table_insert (leds, g_strdup(udi), g_strdup(sysfs_path));
}