2015-09-24 20:52:02 +00:00
|
|
|
/*
|
2018-07-30 02:07:02 +00:00
|
|
|
* This is the source code of tgnet library v. 1.1
|
2015-09-24 20:52:02 +00:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2018-07-30 02:07:02 +00:00
|
|
|
* Copyright Nikolai Kudashov, 2015-2018.
|
2015-09-24 20:52:02 +00:00
|
|
|
*/
|
|
|
|
|
2015-09-29 22:50:53 +00:00
|
|
|
#include <unistd.h>
|
2016-10-11 11:57:01 +00:00
|
|
|
#include <sys/eventfd.h>
|
2015-09-24 20:52:02 +00:00
|
|
|
#include "EventObject.h"
|
|
|
|
#include "Connection.h"
|
|
|
|
#include "Timer.h"
|
|
|
|
|
|
|
|
EventObject::EventObject(void *object, EventObjectType type) {
|
|
|
|
eventObject = object;
|
|
|
|
eventType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventObject::onEvent(uint32_t events) {
|
|
|
|
switch (eventType) {
|
|
|
|
case EventObjectTypeConnection: {
|
|
|
|
Connection *connection = (Connection *) eventObject;
|
|
|
|
connection->onEvent(events);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EventObjectTypeTimer: {
|
|
|
|
Timer *timer = (Timer *) eventObject;
|
|
|
|
timer->onEvent();
|
|
|
|
break;
|
|
|
|
}
|
2016-10-11 11:57:01 +00:00
|
|
|
case EventObjectTypePipe: {
|
2015-09-29 22:50:53 +00:00
|
|
|
int *pipe = (int *) eventObject;
|
|
|
|
char ch;
|
|
|
|
ssize_t size = 1;
|
|
|
|
while (size > 0) {
|
|
|
|
size = read(pipe[0], &ch, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-10-11 11:57:01 +00:00
|
|
|
case EventObjectTypeEvent: {
|
|
|
|
int *eventFd = (int *) eventObject;
|
|
|
|
uint64_t count;
|
|
|
|
eventfd_read(eventFd[0], &count);
|
|
|
|
break;
|
|
|
|
}
|
2015-09-24 20:52:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|