75 lines
1.4 KiB
C
75 lines
1.4 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 "interface.h"
|
||
|
|
||
|
|
||
|
aisl_mod_ctx_t
|
||
|
aisl_mod_ctx_new(aislx_mod_t mod)
|
||
|
{
|
||
|
aisl_mod_ctx_t ctx;
|
||
|
|
||
|
if ((ctx = calloc(1, mod->ctx_size)) != NULL)
|
||
|
{
|
||
|
ctx->mod = mod;
|
||
|
}
|
||
|
|
||
|
return ctx;
|
||
|
}
|
||
|
|
||
|
|
||
|
void
|
||
|
aislx_mod_ctx_free(aislx_mod_ctx_t ctx)
|
||
|
{
|
||
|
free(ctx);
|
||
|
}
|
||
|
|
||
|
|
||
|
aisl_status_t
|
||
|
aislx_mod_on_event(aislx_mod_t mod, aisl_evt_t const evt)
|
||
|
{
|
||
|
switch(evt->code)
|
||
|
{
|
||
|
case AISL_EVENT_STREAM_OPEN:
|
||
|
{
|
||
|
aisl_evt_stream_open_t so_evt = (aisl_evt_stream_open_t)evt;
|
||
|
if ( strncmp(so_evt->path, mod->end_point, mod->ep_length) != 0)
|
||
|
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:
|
||
|
{
|
||
|
aislx_mod_ctx_t ctx = aisl_get_context((aisl_stream_t)evt->source);
|
||
|
|
||
|
if (!ctx)
|
||
|
return AISL_SUCCESS;
|
||
|
|
||
|
if (ctx->mod == mod)
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
default:
|
||
|
return AISL_IDLE;
|
||
|
}
|
||
|
|
||
|
return mod->on_event(mod, evt);
|
||
|
}
|