this system allows dialects to register named interfaces, which are collections of function pointers. an op can then implement this interface, providing callbacks for the interface's virtual function pointers. C code can request a pointer to an op's implementation of a given interface and call virtual functions with no knowledge required about the op itself. this functonality will also be extended to types, attributes, and dialects themselves.
55 lines
1.7 KiB
C
55 lines
1.7 KiB
C
#include <mie/dialect/dialect.h>
|
|
#include <mie/interface/interface-definition.h>
|
|
#include <mie/interface/interface-map.h>
|
|
#include <mie/interface/interface.h>
|
|
|
|
#define INTERFACE_NS_ID \
|
|
MIE_ID(0xd2, 0x40, 0x70, 0x93, 0x4b, 0x2b, 0x46, 0xb2, 0x96, 0x48, \
|
|
0x69, 0xe4, 0x0a, 0x0d, 0x70, 0x55)
|
|
|
|
void mie_interface_map_init(struct mie_interface_map *map)
|
|
{
|
|
memset(map, 0x0, sizeof *map);
|
|
|
|
mie_id ns_id = INTERFACE_NS_ID;
|
|
mie_id_map_init(&map->m_entries, &ns_id);
|
|
}
|
|
|
|
void mie_interface_map_cleanup(struct mie_interface_map *map)
|
|
{
|
|
/* TODO */
|
|
}
|
|
|
|
enum mie_status mie_interface_map_put(
|
|
struct mie_interface_map *map, struct mie_interface *iface)
|
|
{
|
|
struct mie_id_builder id_ctx;
|
|
mie_id_builder_begin(&id_ctx, mie_id_map_get_ns(&map->m_entries));
|
|
mie_id_builder_add_cstr(&id_ctx, iface->if_def->if_parent->d_name);
|
|
mie_id_builder_add_char(&id_ctx, '.');
|
|
mie_id_builder_add_cstr(&id_ctx, iface->if_def->if_name);
|
|
mie_id_builder_end(&id_ctx, &iface->if_id);
|
|
|
|
mie_id_map_put_id(&map->m_entries, &iface->if_id);
|
|
|
|
return MIE_SUCCESS;
|
|
}
|
|
|
|
const struct mie_interface *mie_interface_map_get(
|
|
const struct mie_interface_map *map, const char *dialect_name,
|
|
const char *iface_name)
|
|
{
|
|
mie_id id;
|
|
struct mie_id_builder id_ctx;
|
|
mie_id_builder_begin(&id_ctx, mie_id_map_get_ns(&map->m_entries));
|
|
mie_id_builder_add_cstr(&id_ctx, dialect_name);
|
|
mie_id_builder_add_char(&id_ctx, '.');
|
|
mie_id_builder_add_cstr(&id_ctx, iface_name);
|
|
mie_id_builder_end(&id_ctx, &id);
|
|
|
|
const mie_id *result = mie_id_map_get(&map->m_entries, &id);
|
|
const struct mie_interface *iface
|
|
= b_unbox(const struct mie_interface, result, if_id);
|
|
return iface;
|
|
}
|