[HAL] Need more information on how to use the callback libhal_ctx_set_device_added()

Fabrice Nansi fabricenansi at yahoo.com
Tue Apr 15 08:12:26 PDT 2008


Hello,

I wrote the following program to use this callback. But it does not work!
Could any one can help?

NB: I am using the C API. 

Thanks.

#include <hal/libhal.h>
/*
* #include etc...
*/

LibHalContext *ctx;
DBusConnection *conn;
DBusError err;
char *vendor;
char *product;
int new_device;//this variable is used for synchronisation in this draft. But Mutex will be used later!!

/*
 *      Function: video_device_added()
 */
void video_device_added(LibHalContext *ctx, const char *udi)
{
        char *parent_udi;
        char *device_path;
        
        device_path = libhal_device_get_property_string(ctx, udi, "video4linux.device", &err);

        if(strncmp(device_path, "/dev/video", 10) == 0)
	{
                /* Get the parent of this v4l2 device  */
                parent_udi = libhal_device_get_property_string(ctx, udi, "info.parent", &err);

                /* From the parent device, we obtain the vendor and product informations */
                vendor = libhal_device_get_property_string(ctx, parent_udi, "info.vendor", &err);
                product = libhal_device_get_property_string(ctx, parent_udi, "info.product", &err);

                new_device = 1;
        }
}

/*
 * Function: video_init
 */
int video_init(void)
{
        new_device = 0;

        ctx = libhal_ctx_new();
        dbus_error_init(&err);
        conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);

	libhal_ctx_set_dbus_connection(ctx, conn);
        libhal_ctx_set_device_added(ctx, video_device_added);
        libhal_ctx_init(ctx, &err);
        
        return 0;
}

int main(int argc, char** argv)
{
        video_init();

	while(new_device == 0){};

        printf("vendor                                  = %s\n",dev->vendor_name);
        printf("product                                 = %s\n",dev->product_name);

        return 0;
}






      _____________________________________________________________________________ 
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr


More information about the hal mailing list