2006-04-07 14:18:11 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
|
|
|
#include "dc_local.h"
|
|
|
|
|
|
|
|
int DC_processEvents(int timeout)
|
|
|
|
{
|
2006-04-11 14:22:44 +00:00
|
|
|
int retval;
|
|
|
|
static time_t start, current;
|
|
|
|
|
2006-04-07 14:18:11 +00:00
|
|
|
if (!_dc_resultcb || !_dc_subresultcb || !_dc_messagecb)
|
|
|
|
{
|
|
|
|
DC_log(LOG_ERR, "DC_processEvents: callbacks are not set up");
|
|
|
|
return DC_ERR_CONFIG;
|
|
|
|
}
|
|
|
|
|
2006-04-11 14:22:44 +00:00
|
|
|
DC_log(LOG_INFO, "DC_processEvents: Searching for events ...");
|
2006-04-07 14:18:11 +00:00
|
|
|
|
2006-04-11 14:22:44 +00:00
|
|
|
start = time(NULL);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
retval = _DC_searchForEvents(); /* implemted in rm.c */
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2006-04-07 14:18:11 +00:00
|
|
|
|
2006-05-02 07:59:27 +00:00
|
|
|
if (DC_getWUNumber(DC_WU_RUNNING) == 0)
|
|
|
|
{
|
|
|
|
DC_log(LOG_INFO, "DC_processEvents: No more running workunits ... returning");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-11 14:22:44 +00:00
|
|
|
current = time(NULL);
|
|
|
|
if (current - start > timeout)
|
|
|
|
{
|
|
|
|
DC_log(LOG_INFO, "DC_processEvents: timeout is over ... returning");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
sleep(sleep_interval);
|
|
|
|
}
|
2006-04-07 14:18:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DC_Event *DC_waitEvent(const char *wuFilter, int timeout)
|
|
|
|
{
|
|
|
|
DC_Event *event;
|
|
|
|
|
2006-04-11 14:22:44 +00:00
|
|
|
// event = look_for_results(wuFilter, NULL, timeout);
|
2006-04-07 14:18:11 +00:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
DC_Event *DC_waitWUEvent(DC_Workunit *wu, int timeout)
|
|
|
|
{
|
|
|
|
DC_Event *event;
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2006-04-10 07:40:13 +00:00
|
|
|
void DC_destroyEvent(DC_Event *event)
|
2006-04-07 14:18:11 +00:00
|
|
|
{
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case DC_EVENT_RESULT:
|
|
|
|
_DC_destroyResult(event->result);
|
|
|
|
break;
|
|
|
|
case DC_EVENT_SUBRESULT:
|
|
|
|
_DC_destroyPhysicalFile(event->subresult);
|
|
|
|
break;
|
|
|
|
case DC_EVENT_MESSAGE:
|
|
|
|
g_free(event->message);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DC_log(LOG_ERR, "Unknown event type %d", event->type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|