int main(int argc, char **argv) { LibHalContext *ctx = NULL; DBusError error; GMainLoop *loop = g_main_loop_new(NULL, FALSE); char *udi; if ((udi = getenv("UDI")) == NULL) { return (0); } drop_privileges(); setup_logger(); dbus_error_init(&error); if ((ctx = libhal_ctx_init_direct(&error)) == NULL) { return (0); } if (!libhal_device_addon_is_ready(ctx, udi, &error)) { return (0); } if (nds_claim_interface(ctx, udi, &error) != 0) { return (0); } g_main_loop_run(loop); /* NOTREACHED */ }
static gboolean hald_addon_bme_setup_hal(void) { DBusError error; gboolean result = FALSE; dbus_error_init(&error); if( !(hal_ctx = libhal_ctx_init_direct(&error)) ) { if ( dbus_error_is_set(&error) ) print_dbus_error("hal context init: %s: %s\n",&error); else log_print(("hal context init: unknown failure\n")); goto out; } if( !(hal_dbus = libhal_ctx_get_dbus_connection(hal_ctx)) ) { log_print("hal context does not have dbus connection\n"); goto out; } udi = getenv("UDI"); if (!udi) { log_print ("hal UDI not set in the environment\n"); goto out; } udi=g_strdup(udi); /* device id */ log_print("UDI: %s",udi); if( !libhal_device_addon_is_ready(hal_ctx,udi,&error) ) { if ( dbus_error_is_set(&error) ) print_dbus_error("hal addon is ready: %s: %s\n",&error); else log_print("hal addon is ready: unknown failure\n"); goto out; } dbus_connection_setup_with_g_main(hal_dbus, FALSE); dbus_connection_set_exit_on_disconnect(hal_dbus ,FALSE); result = TRUE; out: dbus_error_free(&error); return result; }
int main (int argc, char *argv[]) { char *udi; char *device_file, *raw_device_file; LibHalContext *ctx = NULL; DBusError error; char *bus; char *drive_type; int state, last_state; char *support_media_changed_str; int support_media_changed; int fd = -1; if ((udi = getenv ("UDI")) == NULL) goto out; if ((device_file = getenv ("HAL_PROP_BLOCK_DEVICE")) == NULL) goto out; if ((raw_device_file = getenv ("HAL_PROP_BLOCK_SOLARIS_RAW_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; drop_privileges (); 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); if ((ctx = libhal_ctx_init_direct (&error)) == NULL) { goto out; } my_dbus_error_free (&error); if (!libhal_device_addon_is_ready (ctx, udi, &error)) { goto out; } my_dbus_error_free (&error); printf ("Doing addon-storage for %s (bus %s) (drive_type %s) (udi %s)\n", device_file, bus, drive_type, udi); last_state = state = DKIO_NONE; /* Linux version of this addon attempts to re-open the device O_EXCL * every 2 seconds, trying to figure out if some other app, * like a cd burner, is using the device. Aside from questionable * value of this (apps should use HAL's locked property or/and * Solaris in_use facility), but also frequent opens/closes * keeps media constantly spun up. All this needs more thought. */ for (;;) { if (is_mounted (device_file)) { close_device (&fd); sleep (SLEEP_PERIOD); } else if ((fd < 0) && ((fd = open (raw_device_file, O_RDONLY | O_NONBLOCK)) < 0)) { HAL_DEBUG (("open failed for %s: %s", raw_device_file, strerror (errno))); sleep (SLEEP_PERIOD); } else { /* Check if a disc is in the drive */ /* XXX initial call always returns inserted * causing unnecessary rescan - optimize? */ if (ioctl (fd, DKIOCSTATE, &state) == 0) { if (state == last_state) { HAL_DEBUG (("state has not changed %d %s", state, device_file)); continue; } else { HAL_DEBUG (("new state %d %s", state, device_file)); } switch (state) { case DKIO_EJECTED: HAL_DEBUG (("Media removal detected on %s", device_file)); last_state = state; libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", FALSE, &error); my_dbus_error_free (&error); /* attempt to unmount all childs */ unmount_childs (ctx, udi); /* could have a fs on the main block device; do a rescan to remove it */ libhal_device_rescan (ctx, udi, &error); my_dbus_error_free (&error); break; case DKIO_INSERTED: HAL_DEBUG (("Media insertion detected on %s", device_file)); last_state = state; libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", TRUE, &error); my_dbus_error_free (&error); /* could have a fs on the main block device; do a rescan to add it */ libhal_device_rescan (ctx, udi, &error); my_dbus_error_free (&error); break; case DKIO_DEV_GONE: HAL_DEBUG (("Device gone detected on %s", device_file)); last_state = state; unmount_childs (ctx, udi); close_device (&fd); goto out; case DKIO_NONE: default: break; } } else { HAL_DEBUG (("DKIOCSTATE failed: %s\n", strerror(errno))); sleep (SLEEP_PERIOD); } } } out: if (ctx != NULL) { my_dbus_error_free (&error); libhal_ctx_shutdown (ctx, &error); libhal_ctx_free (ctx); } return 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; }
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; }
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 err; int retval = 0; hal_set_proc_title_init (argc, argv); setup_logger (); device_udi = getenv ("UDI"); HAL_DEBUG (("device:[%s]", device_udi)); if (device_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; } /* update_properties */ libhal_device_set_property_bool (halctx, device_udi, "battery.present", TRUE, &err); LIBHAL_FREE_DBUS_ERROR (&err); if (!libhal_device_property_exists (halctx, device_udi, "battery.is_rechargeable", &err)) { LIBHAL_FREE_DBUS_ERROR (&err); libhal_device_set_property_bool (halctx, device_udi, "battery.is_rechargeable", FALSE, &err); } LIBHAL_FREE_DBUS_ERROR (&err); libhal_device_set_property_int (halctx, device_udi, "battery.charge_level.design", 7, &err); LIBHAL_FREE_DBUS_ERROR (&err); libhal_device_set_property_int (halctx, device_udi, "battery.charge_level.last_full", 7, &err); LIBHAL_FREE_DBUS_ERROR (&err); libhal_device_set_property_string (halctx, device_udi, "info.category", "battery", &err); LIBHAL_FREE_DBUS_ERROR (&err); libhal_device_set_property_string (halctx, device_udi, "battery.command_interface", "csr", &err); /* monitor change */ libhal_ctx_set_device_property_modified (halctx, property_modified); /* Initial fillup */ dev_props = property_cache_item_get (device_udi); HAL_ERROR (("** Initial fillup done")); /* init usb */ usb_init (); /* do coldplug */ check_all_batteries (NULL); /* only add capability when initial charge_level key has been set */ LIBHAL_FREE_DBUS_ERROR (&err); libhal_device_add_capability (halctx, device_udi, "battery", &err); LIBHAL_FREE_DBUS_ERROR (&err); if (!libhal_device_addon_is_ready (halctx, device_udi, &err)) { retval = -4; goto out; } hal_set_proc_title ("hald-addon-usb-csr: listening on '%s'", libhal_device_get_property_string(halctx, device_udi, "info.product", &err)); main_loop = g_main_loop_new (NULL, FALSE); #ifdef HAVE_GLIB_2_14 g_timeout_add_seconds (TIMEOUT, check_all_batteries, NULL); #else g_timeout_add (1000L * TIMEOUT, check_all_batteries, NULL); #endif 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; }