本文整理汇总了C++中EVENT_DEBUG函数的典型用法代码示例。如果您正苦于以下问题:C++ EVENT_DEBUG函数的具体用法?C++ EVENT_DEBUG怎么用?C++ EVENT_DEBUG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVENT_DEBUG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: virEventPollCalculateTimeout
/* Iterates over all registered timeouts and determine which
* will be the first to expire.
* @timeout: filled with expiry time of soonest timer, or -1 if
* no timeout is pending
* returns: 0 on success, -1 on error
*/
static int virEventPollCalculateTimeout(int *timeout) {
unsigned long long then = 0;
int i;
EVENT_DEBUG("Calculate expiry of %zu timers", eventLoop.timeoutsCount);
/* Figure out if we need a timeout */
for (i = 0 ; i < eventLoop.timeoutsCount ; i++) {
if (eventLoop.timeouts[i].frequency < 0)
continue;
EVENT_DEBUG("Got a timeout scheduled for %llu", eventLoop.timeouts[i].expiresAt);
if (then == 0 ||
eventLoop.timeouts[i].expiresAt < then)
then = eventLoop.timeouts[i].expiresAt;
}
/* Calculate how long we should wait for a timeout if needed */
if (then > 0) {
unsigned long long now;
if (virTimeMillisNow(&now) < 0)
return -1;
*timeout = then - now;
if (*timeout < 0)
*timeout = 0;
} else {
*timeout = -1;
}
EVENT_DEBUG("Timeout at %llu due in %d ms", then, *timeout);
return 0;
}
示例2: EVENT_DEBUG
void ewol::context::InputManager::transfertEvent(ewol::WidgetShared _source, ewol::WidgetShared _destination) {
if( _source == nullptr
|| _destination == nullptr) {
// prevent errors ...
return;
}
for(int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
ewol::WidgetShared tmpWidget = m_eventInputSaved[iii].curentWidgetEvent.lock();
if (tmpWidget == _source) {
// inform the widget that it does not receive the event now
EVENT_DEBUG("GUI : Input ID=" << iii << " == >" << m_eventInputSaved[iii].destinationInputId << " [EVENT_INPUT_TYPE_ABORT] " << m_eventInputSaved[iii].posEvent);
localEventInput(gale::key::type::finger, tmpWidget, m_eventInputSaved[iii].destinationInputId, gale::key::status::abort, m_eventInputSaved[iii].posEvent);
// set the new widget ...
m_eventInputSaved[iii].curentWidgetEvent = _destination;
// inform the widget that he receive the event property now...
EVENT_DEBUG("GUI : Input ID=" << iii << " == >" << m_eventInputSaved[iii].destinationInputId << " [EVENT_INPUT_TYPE_TRANSFERT] " << m_eventInputSaved[iii].posEvent);
localEventInput(gale::key::type::finger, _destination, m_eventInputSaved[iii].destinationInputId, gale::key::status::transfert, m_eventInputSaved[iii].posEvent);
}
tmpWidget = m_eventMouseSaved[iii].curentWidgetEvent.lock();
if (tmpWidget == _source) {
// inform the widget that it does not receive the event now
EVENT_DEBUG("GUI : Input ID=" << iii << " == >" << m_eventMouseSaved[iii].destinationInputId << " [EVENT_INPUT_TYPE_ABORT] " << m_eventMouseSaved[iii].posEvent);
localEventInput(gale::key::type::mouse, tmpWidget, m_eventMouseSaved[iii].destinationInputId, gale::key::status::abort, m_eventMouseSaved[iii].posEvent);
// set the new widget ...
m_eventMouseSaved[iii].curentWidgetEvent = _destination;
// inform the widget that he receive the event property now...
EVENT_DEBUG("GUI : Input ID=" << iii << " == >" << m_eventMouseSaved[iii].destinationInputId << " [EVENT_INPUT_TYPE_TRANSFERT] " << m_eventMouseSaved[iii].posEvent);
localEventInput(gale::key::type::mouse, _destination, m_eventMouseSaved[iii].destinationInputId, gale::key::status::transfert, m_eventMouseSaved[iii].posEvent);
}
}
}
示例3: virEventPollRunOnce
/*
* Run a single iteration of the event loop, blocking until
* at least one file handle has an event, or a timer expires
*/
int virEventPollRunOnce(void)
{
struct pollfd *fds = NULL;
int ret, timeout, nfds;
virMutexLock(&eventLoop.lock);
eventLoop.running = 1;
virThreadSelf(&eventLoop.leader);
virEventPollCleanupTimeouts();
virEventPollCleanupHandles();
if (!(fds = virEventPollMakePollFDs(&nfds)) ||
virEventPollCalculateTimeout(&timeout) < 0)
goto error;
virMutexUnlock(&eventLoop.lock);
retry:
PROBE(EVENT_POLL_RUN,
"nhandles=%d timeout=%d",
nfds, timeout);
ret = poll(fds, nfds, timeout);
if (ret < 0) {
EVENT_DEBUG("Poll got error event %d", errno);
if (errno == EINTR || errno == EAGAIN) {
goto retry;
}
virReportSystemError(errno, "%s",
_("Unable to poll on file handles"));
goto error_unlocked;
}
EVENT_DEBUG("Poll got %d event(s)", ret);
virMutexLock(&eventLoop.lock);
if (virEventPollDispatchTimeouts() < 0)
goto error;
if (ret > 0 &&
virEventPollDispatchHandles(nfds, fds) < 0)
goto error;
virEventPollCleanupTimeouts();
virEventPollCleanupHandles();
eventLoop.running = 0;
virMutexUnlock(&eventLoop.lock);
VIR_FREE(fds);
return 0;
error:
virMutexUnlock(&eventLoop.lock);
error_unlocked:
VIR_FREE(fds);
return -1;
}
示例4: Event_AddHandler
/**********************************************************************
* %FUNCTION: Event_AddHandler
* %ARGUMENTS:
* es -- event selector
* fd -- file descriptor to watch
* flags -- combination of EVENT_FLAG_READABLE and EVENT_FLAG_WRITEABLE
* fn -- callback function to call when event is triggered
* data -- extra data to pass to callback function
* %RETURNS:
* A newly-allocated EventHandler, or NULL.
***********************************************************************/
EventHandler *
Event_AddHandler(EventSelector *es,
int fd,
unsigned int flags,
EventCallbackFunc fn,
void *data)
{
EventHandler *eh;
/* Specifically disable timer and deleted flags */
flags &= (~(EVENT_TIMER_BITS | EVENT_FLAG_DELETED));
/* Bad file descriptor */
if (fd < 0) {
errno = EBADF;
return NULL;
}
eh = malloc(sizeof(EventHandler));
if (!eh) return NULL;
eh->fd = fd;
eh->flags = flags;
eh->tmout.tv_usec = 0;
eh->tmout.tv_sec = 0;
eh->fn = fn;
eh->data = data;
/* Add immediately. This is safe even if we are in a handler. */
eh->next = es->handlers;
es->handlers = eh;
EVENT_DEBUG(("Event_AddHandler(es=%p, fd=%d, flags=%u) -> %p\n", es, fd, flags, eh));
return eh;
}
示例5: Event_DelHandler
/**********************************************************************
* %FUNCTION: Event_DelHandler
* %ARGUMENTS:
* es -- event selector
* eh -- event handler
* %RETURNS:
* 0 if OK, non-zero if there is an error
* %DESCRIPTION:
* Deletes the event handler eh
***********************************************************************/
int
Event_DelHandler(EventSelector *es,
EventHandler *eh)
{
/* Scan the handlers list */
EventHandler *cur, *prev;
EVENT_DEBUG(("Event_DelHandler(es=%p, eh=%p)\n", es, eh));
for (cur=es->handlers, prev=NULL; cur; prev=cur, cur=cur->next) {
if (cur == eh) {
if (es->nestLevel) {
eh->flags |= EVENT_FLAG_DELETED;
es->opsPending = 1;
return 0;
} else {
if (prev) prev->next = cur->next;
else es->handlers = cur->next;
DestroyHandler(cur);
return 0;
}
}
}
/* Handler not found */
return 1;
}
示例6: virEventPollRemoveHandle
/*
* Unregister a callback from a file handle
* NB, it *must* be safe to call this from within a callback
* For this reason we only ever set a flag in the existing list.
* Actual deletion will be done out-of-band
*/
int virEventPollRemoveHandle(int watch) {
int i;
PROBE(EVENT_POLL_REMOVE_HANDLE,
"watch=%d",
watch);
if (watch <= 0) {
VIR_WARN("Ignoring invalid remove watch %d", watch);
return -1;
}
virMutexLock(&eventLoop.lock);
for (i = 0 ; i < eventLoop.handlesCount ; i++) {
if (eventLoop.handles[i].deleted)
continue;
if (eventLoop.handles[i].watch == watch) {
EVENT_DEBUG("mark delete %d %d", i, eventLoop.handles[i].fd);
eventLoop.handles[i].deleted = 1;
virEventPollInterruptLocked();
virMutexUnlock(&eventLoop.lock);
return 0;
}
}
virMutexUnlock(&eventLoop.lock);
return -1;
}
示例7: virReportOOMError
/*
* Allocate a pollfd array containing data for all registered
* file handles. The caller must free the returned data struct
* returns: the pollfd array, or NULL on error
*/
static struct pollfd *virEventPollMakePollFDs(int *nfds) {
struct pollfd *fds;
int i;
*nfds = 0;
for (i = 0 ; i < eventLoop.handlesCount ; i++) {
if (eventLoop.handles[i].events && !eventLoop.handles[i].deleted)
(*nfds)++;
}
/* Setup the poll file handle data structs */
if (VIR_ALLOC_N(fds, *nfds) < 0) {
virReportOOMError();
return NULL;
}
*nfds = 0;
for (i = 0 ; i < eventLoop.handlesCount ; i++) {
EVENT_DEBUG("Prepare n=%d w=%d, f=%d e=%d d=%d", i,
eventLoop.handles[i].watch,
eventLoop.handles[i].fd,
eventLoop.handles[i].events,
eventLoop.handles[i].deleted);
if (!eventLoop.handles[i].events || eventLoop.handles[i].deleted)
continue;
fds[*nfds].fd = eventLoop.handles[i].fd;
fds[*nfds].events = eventLoop.handles[i].events;
fds[*nfds].revents = 0;
(*nfds)++;
//EVENT_DEBUG("Wait for %d %d", eventLoop.handles[i].fd, eventLoop.handles[i].events);
}
return fds;
}
示例8: Event_AddHandlerWithTimeout
/**********************************************************************
* %FUNCTION: Event_AddHandlerWithTimeout
* %ARGUMENTS:
* es -- event selector
* fd -- file descriptor to watch
* flags -- combination of EVENT_FLAG_READABLE and EVENT_FLAG_WRITEABLE
* t -- Timeout after which to call handler, even if not readable/writable.
* If t.tv_sec < 0, calls normal Event_AddHandler with no timeout.
* fn -- callback function to call when event is triggered
* data -- extra data to pass to callback function
* %RETURNS:
* A newly-allocated EventHandler, or NULL.
***********************************************************************/
EventHandler *
Event_AddHandlerWithTimeout(EventSelector *es,
int fd,
unsigned int flags,
struct timeval t,
EventCallbackFunc fn,
void *data)
{
EventHandler *eh;
struct timeval now;
/* If timeout is negative, just do normal non-timing-out event */
if (t.tv_sec < 0 || t.tv_usec < 0) {
return Event_AddHandler(es, fd, flags, fn, data);
}
/* Specifically disable timer and deleted flags */
flags &= (~(EVENT_FLAG_TIMER | EVENT_FLAG_DELETED));
flags |= EVENT_FLAG_TIMEOUT;
/* Bad file descriptor? */
if (fd < 0) {
errno = EBADF;
return NULL;
}
/* Bad timeout? */
if (t.tv_usec >= 1000000) {
errno = EINVAL;
return NULL;
}
eh = malloc(sizeof(EventHandler));
if (!eh) return NULL;
/* Convert time interval to absolute time */
gettimeofday(&now, NULL);
t.tv_sec += now.tv_sec;
t.tv_usec += now.tv_usec;
if (t.tv_usec >= 1000000) {
t.tv_usec -= 1000000;
t.tv_sec++;
}
eh->fd = fd;
eh->flags = flags;
eh->tmout = t;
eh->fn = fn;
eh->data = data;
/* Add immediately. This is safe even if we are in a handler. */
eh->next = es->handlers;
es->handlers = eh;
EVENT_DEBUG(("Event_AddHandlerWithTimeout(es=%p, fd=%d, flags=%u, t=%d/%d) -> %p\n", es, fd, flags, t.tv_sec, t.tv_usec, eh));
return eh;
}
示例9: free_state
/**********************************************************************
* %FUNCTION: free_state
* %ARGUMENTS:
* state -- EventTcpState to free
* %RETURNS:
* Nothing
* %DESCRIPTION:
* Frees all state associated with the TcpEvent.
***********************************************************************/
static void
free_state(EventTcpState *state)
{
if (!state) return;
EVENT_DEBUG(("tcp_free_state(state=%p)\n", state));
if (state->buf) free(state->buf);
if (state->eh) Event_DelHandler(state->es, state->eh);
free(state);
}
示例10: handle_writeable
/**********************************************************************
* %FUNCTION: handle_writeable
* %ARGUMENTS:
* es -- event selector
* fd -- the writeable socket
* flags -- ignored
* data -- the EventTcpState object
* %RETURNS:
* Nothing
* %DESCRIPTION:
* Continues to fill buffer. Calls callback when done.
***********************************************************************/
static void
handle_writeable(EventSelector *es,
int fd,
unsigned int flags,
void *data)
{
EventTcpState *state = (EventTcpState *) data;
int done = state->cur - state->buf;
int togo = state->len - done;
int n;
/* Timed out? */
if (flags & EVENT_FLAG_TIMEOUT) {
errno = ETIMEDOUT;
if (state->f) {
(state->f)(es, state->socket, state->buf, done, EVENT_TCP_FLAG_TIMEOUT,
state->data);
} else {
close(fd);
}
free_state(state);
return;
}
/* togo had better not be zero here! */
n = write(fd, state->cur, togo);
EVENT_DEBUG(("tcp_handle_writeable(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data));
if (n <= 0) {
/* error */
if (state->f) {
(state->f)(es, state->socket, state->buf, done,
EVENT_TCP_FLAG_IOERROR,
state->data);
} else {
close(fd);
}
free_state(state);
return;
}
state->cur += n;
done += n;
if (done >= state->len) {
/* Written enough! */
if (state->f) {
(state->f)(es, state->socket, state->buf, done,
EVENT_TCP_FLAG_COMPLETE, state->data);
} else {
close(fd);
}
free_state(state);
return;
}
}
示例11: Event_CreateSelector
/**********************************************************************
* %FUNCTION: Event_CreateSelector
* %ARGUMENTS:
* None
* %RETURNS:
* A newly-allocated EventSelector, or NULL if out of memory.
* %DESCRIPTION:
* Creates a new EventSelector.
***********************************************************************/
EventSelector *
Event_CreateSelector(void)
{
EventSelector *es = malloc(sizeof(EventSelector));
if (!es) return NULL;
es->handlers = NULL;
es->nestLevel = 0;
es->destroyPending = 0;
es->opsPending = 0;
EVENT_DEBUG(("CreateSelector() -> %p\n", (void *) es));
return es;
}
示例12: handle_accept
/**********************************************************************
* %FUNCTION: handle_accept
* %ARGUMENTS:
* es -- event selector
* fd -- socket
* flags -- ignored
* data -- the accept callback function
* %RETURNS:
* Nothing
* %DESCRIPTION:
* Calls accept; if a connection arrives, calls the accept callback
* function with connected descriptor
***********************************************************************/
static void
handle_accept(EventSelector *es,
int fd,
unsigned int flags,
void *data)
{
int conn;
EventTcpAcceptFunc f;
EVENT_DEBUG(("tcp_handle_accept(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data));
conn = accept(fd, NULL, NULL);
if (conn < 0) return;
f = (EventTcpAcceptFunc) data;
f(es, conn);
}
示例13: virEventPollCleanupHandles
/* Used post dispatch to actually remove any handles that
* were previously marked as deleted. This asynchronous
* cleanup is needed to make dispatch re-entrant safe.
*/
static void virEventPollCleanupHandles(void)
{
size_t i;
size_t gap;
VIR_DEBUG("Cleanup %zu", eventLoop.handlesCount);
/* Remove deleted entries, shuffling down remaining
* entries as needed to form contiguous series
*/
for (i = 0; i < eventLoop.handlesCount;) {
if (!eventLoop.handles[i].deleted) {
i++;
continue;
}
PROBE(EVENT_POLL_PURGE_HANDLE,
"watch=%d",
eventLoop.handles[i].watch);
if (eventLoop.handles[i].ff) {
virFreeCallback ff = eventLoop.handles[i].ff;
void *opaque = eventLoop.handles[i].opaque;
virMutexUnlock(&eventLoop.lock);
ff(opaque);
virMutexLock(&eventLoop.lock);
}
if ((i+1) < eventLoop.handlesCount) {
memmove(eventLoop.handles+i,
eventLoop.handles+i+1,
sizeof(struct virEventPollHandle)*(eventLoop.handlesCount
-(i+1)));
}
eventLoop.handlesCount--;
}
/* Release some memory if we've got a big chunk free */
gap = eventLoop.handlesAlloc - eventLoop.handlesCount;
if (eventLoop.handlesCount == 0 ||
(gap > eventLoop.handlesCount && gap > EVENT_ALLOC_EXTENT)) {
EVENT_DEBUG("Found %zu out of %zu handles slots used, releasing %zu",
eventLoop.handlesCount, eventLoop.handlesAlloc, gap);
VIR_SHRINK_N(eventLoop.handles, eventLoop.handlesAlloc, gap);
}
}
示例14: virEventPollAddTimeout
/*
* Register a callback for a timer event
* NB, it *must* be safe to call this from within a callback
* For this reason we only ever append to existing list.
*/
int virEventPollAddTimeout(int frequency,
virEventTimeoutCallback cb,
void *opaque,
virFreeCallback ff)
{
unsigned long long now;
int ret;
if (virTimeMillisNow(&now) < 0) {
return -1;
}
virMutexLock(&eventLoop.lock);
if (eventLoop.timeoutsCount == eventLoop.timeoutsAlloc) {
EVENT_DEBUG("Used %zu timeout slots, adding at least %d more",
eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT);
if (VIR_RESIZE_N(eventLoop.timeouts, eventLoop.timeoutsAlloc,
eventLoop.timeoutsCount, EVENT_ALLOC_EXTENT) < 0) {
virMutexUnlock(&eventLoop.lock);
return -1;
}
}
eventLoop.timeouts[eventLoop.timeoutsCount].timer = nextTimer++;
eventLoop.timeouts[eventLoop.timeoutsCount].frequency = frequency;
eventLoop.timeouts[eventLoop.timeoutsCount].cb = cb;
eventLoop.timeouts[eventLoop.timeoutsCount].ff = ff;
eventLoop.timeouts[eventLoop.timeoutsCount].opaque = opaque;
eventLoop.timeouts[eventLoop.timeoutsCount].deleted = 0;
eventLoop.timeouts[eventLoop.timeoutsCount].expiresAt =
frequency >= 0 ? frequency + now : 0;
eventLoop.timeoutsCount++;
ret = nextTimer-1;
virEventPollInterruptLocked();
PROBE(EVENT_POLL_ADD_TIMEOUT,
"timer=%d frequency=%d cb=%p opaque=%p ff=%p",
ret, frequency, cb, opaque, ff);
virMutexUnlock(&eventLoop.lock);
return ret;
}
示例15: Event_AddTimerHandler
/**********************************************************************
* %FUNCTION: Event_AddTimerHandler
* %ARGUMENTS:
* es -- event selector
* t -- time interval after which to trigger event
* fn -- callback function to call when event is triggered
* data -- extra data to pass to callback function
* %RETURNS:
* A newly-allocated EventHandler, or NULL.
***********************************************************************/
EventHandler *
Event_AddTimerHandler(EventSelector *es,
struct timeval t,
EventCallbackFunc fn,
void *data)
{
EventHandler *eh;
struct timeval now;
/* Check time interval for validity */
if (t.tv_sec < 0 || t.tv_usec < 0 || t.tv_usec >= 1000000) {
errno = EINVAL;
return NULL;
}
eh = malloc(sizeof(EventHandler));
if (!eh) return NULL;
/* Convert time interval to absolute time */
gettimeofday(&now, NULL);
t.tv_sec += now.tv_sec;
t.tv_usec += now.tv_usec;
if (t.tv_usec >= 1000000) {
t.tv_usec -= 1000000;
t.tv_sec++;
}
eh->fd = -1;
eh->flags = EVENT_FLAG_TIMER;
eh->tmout = t;
eh->fn = fn;
eh->data = data;
/* Add immediately. This is safe even if we are in a handler. */
eh->next = es->handlers;
es->handlers = eh;
EVENT_DEBUG(("Event_AddTimerHandler(es=%p, t=%d/%d) -> %p\n", es, t.tv_sec,t.tv_usec, eh));
return eh;
}