IOCallback

Defines the callback signature for a function which handles I/O events.

Summary
IOCallbackDefines the callback signature for a function which handles I/O events.
CopyrightThis program is free software.
Files
C-kern/api/io/iocallback.hHeader file IOCallback.
C-kern/io/iocallback.cImplementation file IOCallback impl.
Types
struct iocallback_tExport iocallback_t.
iocallback_fCallback function for handling ioevent_t.
Functions
test
unittest_io_iocallbackTests implementation of iocallback_t .
iocallback_tDeclares a pointer to callback interface implementing object.
objectThe value of the first argument of iocallback_f.
iimplThe pointer to callback function iocallback_f.
lifetime
iocallback_FREEStatic initializer.
iocallback_INITStatic initializer.
query
isinit_iocallbackReturns true if iocallback_t.iimpl is not 0.
execute
call_iocallbackCalls iocallback_t.iimpl with iocallback_t.object as its first parameter.
generic
genericcast_iocallbackCasts parameter iocb into pointer to iocallback_t.
iocallback_DECLAREDeclares a subtype of iocallback_t, i.e.
inline implementation
Macros
genericcast_iocallbackImplements iocallback_t.genericcast_iocallback.
call_iocallbackImplements iocallback_t.call_iocallback.
isinit_iocallbackImplements iocallback_t.isinit_iocallback.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2012 Jörg Seebohn

Files

C-kern/api/io/iocallback.h

Header file IOCallback.

C-kern/io/iocallback.c

Implementation file IOCallback impl.

Types

struct iocallback_t

typedef struct iocallback_t iocallback_t

Export iocallback_t.  Callback interface implementing object.

iocallback_f

typedef void (
   *iocallback_f
) (void * iohandler, sys_iochannel_t fd, uint8_t ioevents)

Callback function for handling ioevent_t.

TODO: Remove it or change signature to handle groups of events.

(In) Parameter

iohandlerThe object which implements the io callback.
ioeventsEvery set bit in this integer value signals a different io event.  See ioevent_e for a list of all possible set bits and their meaning.
fdThe file descriptior for which all ioevents have occurred.

Functions

Summary
test
unittest_io_iocallbackTests implementation of iocallback_t .

test

unittest_io_iocallback

int unittest_io_iocallback(void)

Tests implementation of iocallback_t .

iocallback_t

struct iocallback_t

Declares a pointer to callback interface implementing object.

Summary
objectThe value of the first argument of iocallback_f.
iimplThe pointer to callback function iocallback_f.
lifetime
iocallback_FREEStatic initializer.
iocallback_INITStatic initializer.
query
isinit_iocallbackReturns true if iocallback_t.iimpl is not 0.
execute
call_iocallbackCalls iocallback_t.iimpl with iocallback_t.object as its first parameter.
generic
genericcast_iocallbackCasts parameter iocb into pointer to iocallback_t.
iocallback_DECLAREDeclares a subtype of iocallback_t, i.e.

object

void * object

The value of the first argument of iocallback_f.

iimpl

iocallback_f iimpl

The pointer to callback function iocallback_f.

lifetime

iocallback_FREE

#define iocallback_FREE iocallback_INIT(0,
)

Static initializer.  Sets pointer to object and pointer to callback function to 0.

iocallback_INIT

#define iocallback_INIT(object,
iimpl) { (object), (iimpl) }

Static initializer.  Sets pointer to object and pointer to callback function to the supplied parameter values.

query

isinit_iocallback

bool isinit_iocallback(const iocallback_t *iocb)

Returns true if iocallback_t.iimpl is not 0.

execute

call_iocallback

void call_iocallback(const iocallback_t *iocb,
sys_iochannel_t fd,
uint8_t ioevents)

Calls iocallback_t.iimpl with iocallback_t.object as its first parameter.

generic

genericcast_iocallback

iocallback_t * genericcast_iocallback(void *iocb,
TYPENAME iohandler_t) ;

Casts parameter iocb into pointer to iocallback_t.  The parameter iocb has to be of type “pointer to declared_t” where declared_t is the name used as first parameter in iocallback_DECLARE.  The second parameter must be the same as in iocallback_DECLARE.

iocallback_DECLARE

#define iocallback_DECLARE(
   declared_t,
   iohandler_t
) typedef struct declared_t declared_t ; struct declared_t { iohandler_t * object ; void (* iimpl) ( iohandler_t * iohandler, sys_iochannel_t fd, uint8_t ioevents) ; }

Declares a subtype of iocallback_t, i.e. a specific io handler implementation.  The declared callback type is structural compatible with the generic iocallback_t.  See iocallback_t for a list of declared fields.

Parameter

declared_tThe name of the structure which is declared as a subtype of iocallback_t.  The name should have the suffix “_t”.
iohandler_tThe object which implements the io callback handler.  The type of iocallback_t.object is set to (iohandler_t*) instead of (void*).  Also the type of the first parameter of iocallback_f is set to (iohandler_t*).

Macros

genericcast_iocallback

#define genericcast_iocallback(
   iocb,
   iohandler_t
) ( __extension__ ({ static_assert( offsetof(iocallback_t, object) == offsetof(typeof(*(iocb)), object) && (typeof((iocb)->object)*)0 == (iohandler_t**)0 && offsetof(iocallback_t, iimpl) == offsetof(typeof(*(iocb)), iimpl) && (typeof((iocb)->iimpl)*)0 == (void(**)(iohandler_t*, sys_iochannel_t, uint8_t))0, "ensure same structure") ; (iocallback_t*) (iocb) ; }))

Implements iocallback_t.genericcast_iocallback.

call_iocallback

#define call_iocallback(
   iocb,
   fd,
   ioevents
) ((iocb)->iimpl((iocb)->object, (fd), (ioevents)))

Implements iocallback_t.call_iocallback.

isinit_iocallback

#define isinit_iocallback(iocb) (0 != (iocb)->iimpl)

Implements iocallback_t.isinit_iocallback.

Defines the callback signature for a function which handles I/O events.
Implements IOCallback.
typedef struct iocallback_t iocallback_t
Export iocallback_t.
struct iocallback_t
Declares a pointer to callback interface implementing object.
typedef void (
   *iocallback_f
) (void * iohandler, sys_iochannel_t fd, uint8_t ioevents)
Callback function for handling ioevent_t.
struct ioevent_t
Associates one or more ioevent_e with an ioevent_id_t.
int unittest_io_iocallback(void)
Tests implementation of iocallback_t .
void * object
The value of the first argument of iocallback_f.
iocallback_f iimpl
The pointer to callback function iocallback_f.
#define iocallback_FREE iocallback_INIT(0,
)
Static initializer.
#define iocallback_INIT(object,
iimpl) { (object), (iimpl) }
Static initializer.
bool isinit_iocallback(const iocallback_t *iocb)
Returns true if iocallback_t.iimpl is not 0.
void call_iocallback(const iocallback_t *iocb,
sys_iochannel_t fd,
uint8_t ioevents)
Calls iocallback_t.iimpl with iocallback_t.object as its first parameter.
iocallback_t * genericcast_iocallback(void *iocb,
TYPENAME iohandler_t) ;
Casts parameter iocb into pointer to iocallback_t.
#define iocallback_DECLARE(
   declared_t,
   iohandler_t
) typedef struct declared_t declared_t ; struct declared_t { iohandler_t * object ; void (* iimpl) ( iohandler_t * iohandler, sys_iochannel_t fd, uint8_t ioevents) ; }
Declares a subtype of iocallback_t, i.e.
#define genericcast_iocallback(
   iocb,
   iohandler_t
) ( __extension__ ({ static_assert( offsetof(iocallback_t, object) == offsetof(typeof(*(iocb)), object) && (typeof((iocb)->object)*)0 == (iohandler_t**)0 && offsetof(iocallback_t, iimpl) == offsetof(typeof(*(iocb)), iimpl) && (typeof((iocb)->iimpl)*)0 == (void(**)(iohandler_t*, sys_iochannel_t, uint8_t))0, "ensure same structure") ; (iocallback_t*) (iocb) ; }))
Implements iocallback_t.genericcast_iocallback.
#define call_iocallback(
   iocb,
   fd,
   ioevents
) ((iocb)->iimpl((iocb)->object, (fd), (ioevents)))
Implements iocallback_t.call_iocallback.
#define isinit_iocallback(iocb) (0 != (iocb)->iimpl)
Implements iocallback_t.isinit_iocallback.
Defines list of IO events.
Close