[libvirt-users] event handler
Alexandr
sss at sss.chaoslab.ru
Mon Oct 14 08:33:57 UTC 2013
Michal Privoznik писал 2013-10-14 08:48:
> On 14.10.2013 02:42, Alexandr wrote:
>> good day to all.
>> i still have not solved my problem with event handling.
>> currently i have following code
>>
>>
>> void libvirt_eventloop_thr_func()
>> {
>> while(true) //TODO: stop somehow on exit
>> {
>> if(virEventRunDefaultImpl() < 0)
>> {
>> virErrorPtr err = virGetLastError();
>> fprintf(stderr, "Failed to run event loop: %s\n", err &&
>> err->message ? err->message : "Unknown error");
>> }
>> }
>> }
>>
>>
>>
>> ...
>>
>> virSetErrorFunc(NULL, libvirt_error_handler);
>> libvirt_connection = virConnectOpen("qemu:///system");
>
> Move this line ^^^ ...
>
>> if (virEventRegisterDefaultImpl() < 0)
>> {
>> virErrorPtr err = virGetLastError();
>> fprintf(stderr, "Failed to register event implementation:
>> %s\n",
>> err && err->message ? err->message: "Unknown error");
>> return -1;
>> }
>> {
>> int callback =
>> virConnectDomainEventRegisterAny(libvirt_connection, NULL,
>> VIR_DOMAIN_EVENT_ID_LIFECYCLE,
>> VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL);
>> if(callback == -1)
>> {
>> std::cout<<"Error: failed to register domain event handle
>> callback\n";
>> return -1;
>> }
>> }
>>
>> boost::thread(boost::bind(&libvirt_eventloop_thr_func));
>
> ... over here. The virConnectOpen detects if there's an even loop
> registered. And in your case you don't have any registered when calling
> it.
>
> Michal
thank you very match, it now working as expected, but one thing are
missed from documentations, current api docs says what i do not need to
call virInitialize(), but if i call virEventRegisterDefaultImpl()
without calling virInitialize() programm crashing (i have not used
virInitialize() in my programm, just virConnectOpen() as docs said).
problem solved now.
More information about the libvirt-users
mailing list