Event Library v2.1
What is it:Event library is an advanced & extremely fast event engine which works almost like a virtual machine.
It supports from basic signal messages to full static callbacks.
It was developed mainly to be used with NEO MD Myth extended menu so its
super fast and it can be used with any setup.
Here's a full explanation of how it works(its copy/paste from other thread):
There is a small stack of events.
Events can be callback or message-type events or anything custom event type.
Because the system supports "static functions" , there is a function rellocator index pointer , that pushes ELT_EXLUSIVE callbacks on the very bottom of the stack.
The stack pointer will not move beyond the static allocator's index , because this section is reserved and "sorts"(not really) the static functions only when they are pushed/popped to have both a stack & a static table in 1 single event table.
When you push an exclusive function , it is a bit expensive call if you have many messages because it involves swapping and some jumps, so push them when you create the interface or when you have to load some content.
Callback Signals/messages/keys can be sent instantly without limits.They get called/demoted instantly & move the stack pointer.
Each event is treated as an object that gets demoted/promoted depends
the case.
The loop is starting from the last -> first object to serve this porpuse.
Each cycle cannot call more than N(->config.Private.maxIterationsPerCycle) instructions.
The last address is moving to the very bottom of the stack pointer on each
"pop" but will never pass the static allocator.
The system does not "call" any function nor using the function stack.
All the critical code is inlined in macros & using the active configuration stack.
Now you're going to ask if its really just an event library.
The answer is no , its just a system that you can "push/pop"(not manually) events while doing some tasks just like a very basic cpu/state machine optimized just for this task.
Basic features:-Open source
-Does not uses any library at all(it's super portable!)
-Does not use function stack
-Does not use any real function
-Supports effects
-All important code is inlined using macros
-Static function allocator
-Stack based execution of commands
-No sorting or pointless data copying at runtime
-Can be used with platforms with limited hardware
-Supports debug handlers
-Configurable stacks
-Execution sync timer
-Supports custom handlers for input listener/host and timer
-Does not allocate/copy buffers at runtime.
-Can convert values to proper message handlers
-Supports # amount of arguments per cycle ( # = defined in header )
-Supports # amount of total events per cycle ( # = can be changed at runtime )
-The code is efficient and will not cause trouble to an existing project
-Efficient message system and even listener that gives you full control of the events
-Uses index ids for direct access to objects
-Fixed loops to active objects range
Quick example showing some basic functions:Please study the interface for moreAdvanced example:http://www.neoflash.com/forum/index.php/topic,5839.msg41882.html#msg41882/*
Minimal ELIB example
*/
#include "../elib/elib.h"
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
static struct timeval timerStart;
static struct timeval timerNow;
static ELIB_Configuration config;
enum
{
MY_RUN_COMMAND_THREAD = 255,
MY_MSG_THREAD
};
static ELIB_Ptr getTimeMethod()
{
gettimeofday(&timerNow, NULL);
config.Runtime.SystemTicks = (timerNow.tv_sec-timerStart.tv_sec)*1000+(timerNow.tv_usec-timerStart.tv_usec)/1000;
}
static ELIB_Ptr eventHandler()
{
if(!config.Runtime.BindedEvent)
return;
config.Runtime.Result = ELR_POSITIVE;
switch(config.Runtime.BindedEvent->type)
{
default:
return;
case ELD_MESSAGE:
{
switch(config.Runtime.BindedEvent->callback.message)
{
case MY_MSG_THREAD:
printf("My message proccessed!\n");
return;
}
return;
}
case ELD_INPUT_EVENT:
{
/*Since keys are only executing specific events , we dont need to push keys!*/
/*if(event->key.state == ELK_PRESSED)
{
switch(config.Runtime.BindedEvent->key.code)
{
case ...
}
}*/
return;
}
}
}
static ELIB_Ptr run()
{
printf("Running...\n");
/*spam!*/
ELIB_PushMessage(config,MY_MSG_THREAD);
/*Return positive result*/
config.Runtime.Result = ELR_POSITIVE;
}
int main(int argc, char **argv)
{
config.Public.maxIterationsPerCycle = 8;
config.Public.keyRepeat = 0;
config.Public.messageRepeat = 0;
config.Public.cycleSyncTime = 60;
config.Public.eventCallback = eventHandler;
config.Public.timerCallback = getTimeMethod;
//config.Public.debugCallback = ELIB_NULL;
ELIB_Init(&config);
//Push exlusive to the static function rellocator
ELIB_PushExclusive(config,MY_RUN_COMMAND_THREAD,run,NULL,NULL);
ELIB_Run();
return 0;
}