#include "com.h" #if INTERFACE #include typedef void * (*interface_query_t)(void *, iid_t iid); #define INTERFACE_IMPL_QUERY(iface, container, member) \ void * INTERFACE_IMPL_QUERY_NAME(iface, container)(void * i, iid_t id) \ { \ return com_query(INTERFACE_MAP_NAME(container), countof(INTERFACE_MAP_NAME(container)), id, container_of(i, container, member)); \ } #define INTERFACE_OPS_TYPE(iface) iface ## _ops static iface ## _ops container ## _ ## iface #define INTERFACE_IMPL_QUERY_METHOD(iface, container) .query = INTERFACE_IMPL_QUERY_NAME(iface, container) #define INTERFACE_IMPL_METHOD(method, method_impl) , .method = method_impl #define INTERFACE_IMPL_NAME(iface, container) container ## _ ## iface #define INTERFACE_IMPL_QUERY_NAME(iface, container) container ## _ ## iface ## _ ## query struct interface_map_t { iid_t id; int offset; }; #define METHOD_PROLOG(iface, container, member) container * pThis = container_of(iface, container, member) #define INTERFACE_MAP_NAME(container) container ## _map #define INTERFACE_MAP_ENTRY(container, iid, member) { iid, offsetof(container, member) } #define INTERFACE_MAP_END(container) {0,0} }; typedef const char * const iid_t; #if 0 struct query_t { query_t_ops * ops; }; struct query_t_ops { void * (*query)(void *, iid_t * iid); }; struct anon_test_t { anon_test_t_ops * ops; }; struct anon_test_t_ops : query_t_ops { void (*foo)(); }; #endif #endif exception_def InterfaceNotFoundException = {"InterfaceNotFoundException", &Exception}; void * com_query(interface_map_t * map, int mapnum, iid_t id, void * base) { for(int i=0; i