4 Class Definitions 6 Communication Interfaces
Link Library Programming Guide  / 

5 Link-Specific Interfaces

Endpoints always need to implement interfaces specific to the link type, so they can accept messages from the connected devices. Here, datagram_link registers a datagram_link interface for its endpoint class.

void
init_local()
{
        /* The link library must always be initialised first. */
        SIMLINK_init_library();

        const class_info_t cl_methods = {
                .alloc = datagram_link_alloc,
                .init = datagram_link_init,
                .finalize = datagram_link_finalize,
                .deinit = datagram_link_deinit,
                .dealloc = datagram_link_dealloc,
                .short_desc = "link that broadcasts byte strings",
                .description = "A link that broadcasts byte strings."
        };
        conf_class_t *cl = SIM_create_class("datagram_link_impl",
                                              &cl_methods);

        /* Tell the link library what class represents the link */
        SIMLINK_register_class(cl);

        const class_info_t epcl_methods = {
                .alloc = datagram_link_endpoint_alloc,
                .init = datagram_link_endpoint_init,
                .finalize = datagram_link_endpoint_finalize,
                .deinit = SIMLINK_endpoint_disconnect,
                .dealloc = datagram_link_endpoint_dealloc,
                .short_desc = "endpoint for datagram links",
                .description = "Endpoint for datagram link objects."
        };
        conf_class_t *epcl = SIM_create_class("datagram_link_endpoint",
                                                &epcl_methods);

        static const datagram_link_interface_t dgram_link_if = {
                .receive = receive
        };
        SIM_REGISTER_INTERFACE(epcl, datagram_link, &dgram_link_if);

        /* Tell the link library what class we use for endpoints */
        SIMLINK_register_endpoint_class(epcl, "d");
}
4 Class Definitions 6 Communication Interfaces