|
server 0.0.1
basicserverinfrastructure
|
00001 #ifndef __INTERFACE_H__ 00002 #define __INTERFACE_H__ 00003 00004 #include <sys/types.h> 00005 00006 #define MAX_IFACE 32 // ATTENTION: every iface_impl will use MAX_IFACE * sizeof(void*) 00007 00008 #define IFACE(name) ((const struct i_##name const*)&i_##name##_impl) 00009 00010 #define INIT_IFACE(name,...) \ 00011 static const struct i_##name i_##name##_impl = {&i_##name,__VA_ARGS__} 00012 00013 #define NUMARGS(...) (sizeof((const void*[]){__VA_ARGS__})/sizeof(void*)) 00014 00015 #define INIT_IMPL(...) {NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}} 00016 #define CREATE_IMPL(...) \ 00017 static struct iface_impl iface_impl = INIT_IMPL(__VA_ARGS__) 00018 00019 #define METHOD_GET(iface,method) (iface->method) 00020 00021 00022 struct interface { 00023 const char * name; 00024 const size_t nmethods; 00025 }; 00026 typedef const struct interface * iface_ptr; 00027 00028 struct iface_impl { 00029 const size_t nimpl; // number of interface implementations 00030 char simpl; // implementations sorted?? 00031 const void * impl[MAX_IFACE]; // implementations 00032 }; 00033 typedef struct iface_impl * iface_impl_ptr; 00034 00035 extern struct interface * interfaceGet(iface_impl_ptr, const iface_ptr); 00036 00037 #endif // __INTERFACE_H__ 00038 00039 // vim: set ts=4 sw=4: