aqhome: started rewriting IPC module.
started with basic event interface using unix fd and timers.
This commit is contained in:
140
aqhome/events2/fdobject.c
Normal file
140
aqhome/events2/fdobject.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project Gwenhywfar.
|
||||
* Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "./fdobject_p.h"
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
|
||||
|
||||
|
||||
GWEN_INHERIT(AQH_OBJECT, AQH_FDOBJECT)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static void _cbEnable(AQH_OBJECT *o);
|
||||
static void _cbDisable(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_FdObject_new(AQH_EVENT_LOOP *eventLoop, int fd, int mode)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
o=AQH_Object_new(eventLoop);
|
||||
GWEN_NEW_OBJECT(AQH_FDOBJECT, xo);
|
||||
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_FDOBJECT, o, xo, _freeData);
|
||||
xo->fd=fd;
|
||||
xo->fdMode=mode;
|
||||
|
||||
AQH_Object_SetEnableFn(o, _cbEnable);
|
||||
AQH_Object_SetDisableFn(o, _cbDisable);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=(AQH_FDOBJECT*)p;
|
||||
GWEN_FREE_OBJECT(xo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_FdObject_GetFdMode(const AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo)
|
||||
return xo->fdMode;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_FdObject_SetFdMode(AQH_OBJECT *o, int i)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo)
|
||||
xo->fdMode=i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_FdObject_GetFd(const AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo)
|
||||
return xo->fd;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbEnable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
|
||||
eventLoop=AQH_Object_GetEventLoop(o);
|
||||
if (eventLoop)
|
||||
AQH_EventLoop_AddFdObject(eventLoop, o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbDisable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
|
||||
eventLoop=AQH_Object_GetEventLoop(o);
|
||||
if (eventLoop)
|
||||
AQH_EventLoop_DelFdObject(eventLoop, o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user