aisl-sdk/mods/module.c

55 lines
1.2 KiB
C

/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file interface.c
* @author Ilja Kartašov <ik@lowenware.com>
* @brief Interface source file for AISL SDK modules
*
* @see https://lowenware.com/
*/
#include <stdlib.h>
#include <string.h>
#include "module.h"
#include "ctx.h"
aisl_status_t
aislx_module_on_event(aislx_module_t mod, aisl_evt_t const evt)
{
aislx_ctx_t ctx;
aisl_evt_stream_open_t so_evt;
switch(evt->code)
{
case AISL_EVENT_STREAM_OPEN:
so_evt = (aisl_evt_stream_open_t)evt;
if (strncmp(so_evt->path, mod->end_point, mod->ep_length))
return AISL_IDLE;
break;
case AISL_EVENT_STREAM_HEADER:
case AISL_EVENT_STREAM_INPUT:
case AISL_EVENT_STREAM_REQUEST:
case AISL_EVENT_STREAM_OUTPUT:
case AISL_EVENT_STREAM_CLOSE:
if (!(ctx = aisl_get_context((aisl_stream_t)evt->source)))
return AISL_SUCCESS;
if (ctx->mod == mod)
break;
/* go through default */
default:
return AISL_IDLE;
}
return mod->on_event(mod, evt);
}