My Project
|
One can usually implement one or more methods to make it a standalone runtime state. More...
#include <NPLMiniRuntime.hpp>
Classes | |
class | CCurrentMessage |
construct this to ensure matching calls to SetCurrentMessage(). More... | |
Public Types | |
typedef boost::function< void(int, void *) > | NPLFileActivateHandler_t |
typedef boost::function< void(int, void *) > | NPLFileActivateHandlerCallback_t |
typedef std::map< std::string, typename NPLFileActivateHandler_t > | NPLFileHandlerMap_t |
typedef std::queue< NPLMiniMessage > | NPLMiniMessageQueue_t |
Public Member Functions | |
CNPLMiniState (const char *name=NULL) | |
void | Init () |
virtual const std::string & | GetName () const |
return the name of this runtime state. More... | |
virtual int | activate (const char *sNPLFilename, const char *sCode, int nCodeLength=0, int priority=2, int reliability=4) |
activate the specified file. More... | |
virtual NPL::NPLReturnCode | Activate_async (const std::string &filepath, const char *code=NULL, int nLength=0, int priority=0) |
activate the specified file in this runtime state. More... | |
virtual NPL::NPLReturnCode | ActivateLocal (const char *filepath, const char *code=NULL, int nLength=0, int priority=0) |
same as Activate_async, except that it is a short cut name. More... | |
virtual NPL::NPLReturnCode | Activate_async (NPL::NPLMessage_ptr &msg, int priority=0) |
same as Activate_async. More... | |
virtual NPL::NPLReturnCode | SendMessage (NPL::NPLMessage_ptr &msg, int priority=0) |
send a message to the current message queue. More... | |
virtual const char * | GetCurrentMsg () |
get a pointer to the current message | |
virtual int | GetCurrentMsgLength () |
get length of the current message | |
virtual NPL::INPLRuntime * | GetNPLRuntime () |
get the NPL runtime environment | |
virtual void | WriteLog (const char *text, int nTextLen=0, int nLogType=0) |
write a log message More... | |
virtual bool | SetTimer (int nIDEvent, float fElapse, const char *sNeuronFile) |
creates a timer with the specified time-out value [thread safe] More... | |
virtual bool | KillTimer (int nIDEvent) |
Destroys the specified timer [thread safe]. More... | |
virtual bool | ChangeTimer (int nIDEvent, int dueTime, int period) |
Changes the start time and the interval between method invocations for a timer, using 32-bit signed integers to measure time intervals. More... | |
virtual void | RegisterFile (const char *sFilename, NPL::INPLActivationFile *pFileHandler=NULL) |
function to register the a file handler in the current NPL state, so that it is callable from NPL script or C++ More... | |
virtual void | call (const char *sNPLFilename, const char *sCode, int nCodeLength=0) |
synchronous function call | |
virtual int | Process () |
process all queued message. More... | |
bool | RegisterFileHandler (const char *filename, const NPLFileActivateHandlerCallback_t &fileCallback) |
if USE_BOOST_SIGNAL_FILE_HANDLER is defined, we will allow multiple file handlers to subscribe to the same filename target. More... | |
![]() | |
virtual NPLReturnCode | Activate_async (NPLMessage_ptr &msg, int priority=0)=0 |
same as Activate_async. More... | |
virtual NPLReturnCode | SendMessage (NPLMessage_ptr &msg, int priority=0)=0 |
send a message to the current message queue. More... | |
Protected Member Functions | |
void | SetCurrentMessage (const char *msg, int nLength) |
int | ProcessMsg (const NPLMiniMessage &msg) |
process a single message. More... | |
Protected Attributes | |
const char * | m_current_msg |
pointer to the current message. More... | |
int | m_current_msg_length |
length of the current message. More... | |
std::string | m_name |
the name of this runtime state. More... | |
ParaEngine::Mutex | m_mutex |
NPL::INPLRuntime * | m_pNPLRuntime |
NPLMiniMessageQueue_t | m_input_queue |
the input message queue | |
NPLFileHandlerMap_t | m_file_handlers_map |
file handlers map. More... | |
int | m_processed_msg_count |
for stats | |
One can usually implement one or more methods to make it a standalone runtime state.
Depending on how you implement the activate() method, the message can be handled either in the calling thread or in the main thread. the main thread is the thread where NPLRuntime::Run() method is called at regular interval to process the message.
the default implementation can register message handler according to filename using callbacks. please note that filename is usually used as message target in traditional message system. Since we use std::string as filename internally, hence if the file name is less than 16 bytes, no memory allocation is needed. Note: this only applies to MiniState, for full featured NPL runtime, there is no such limit.
|
inlinevirtual |
activate the specified file.
It can either be local or remote file.
Implements NPL::INPLRuntimeState.
|
inlinevirtual |
activate the specified file in this runtime state.
the file can be script or DLL. The function will just insert the message into the message queue and return immediately.
code | it is a chunk of code that should be executed in the destination neuron. this code usually set the values of POL global variables. |
nLength | the code length. if this is 0, length is determined from code, however, it must not exceed 4096 bytes. if it is specified. it can be any code length |
priority | bigger is higher. 0 is the default. if 1, it will be inserted to the front of the queue. |
Implements NPL::INPLRuntimeState.
|
inlinevirtual |
same as Activate_async.
except that input are read from NPLMesage. e.g. NPLMessage_ptr msg(new NPLMessage()); return Activate_async(msg, priority);
msg | the caller is should only new but never delete the NPLMessage_ptr. And that the message must be created in the same thread, usually just before calling this function |
|
inlinevirtual |
same as Activate_async, except that it is a short cut name.
and may be used by external dlls to activate a file on this local state asynchrounously.
Implements NPL::INPLRuntimeState.
|
inlinevirtual |
Changes the start time and the interval between method invocations for a timer, using 32-bit signed integers to measure time intervals.
[thread safe]
nIDEvent | Specifies the timer to be destroyed.For nIDEvent<=0, they are reserved for internal uses can not be killed by this function. This value must be the same as the nIDEvent value passed to the SetTimer function that created the timer. |
dueTime | The amount of time to delay before the invoking the callback method specified when the Timer was constructed, in milliseconds. Specify zero (0) to restart the timer immediately. however, the current implementation does not accept dueTime that is larger than MAX_TIMER_DUE_TIME 10000000, which is 10000 seconds. |
period:The | time interval between invocations of the callback method specified when the Timer was constructed, in milliseconds. |
Implements NPL::INPLRuntimeState.
|
inlinevirtual |
return the name of this runtime state.
if "", it is considered an anonymous name
Implements NPL::INPLRuntimeState.
|
inlinevirtual |
Destroys the specified timer [thread safe].
nIDEvent | Specifies the timer to be destroyed.For nIDEvent<=0, they are reserved for internal uses can not be killed by this function. This value must be the same as the nIDEvent value passed to the SetTimer function that created the timer. |
Implements NPL::INPLRuntimeState.
|
inlinevirtual |
process all queued message.
This is usually called by the NPLMiniRuntime from the main thread.
|
inlineprotected |
process a single message.
|
inlinevirtual |
function to register the a file handler in the current NPL state, so that it is callable from NPL script or C++
sFilename | any name with cpp file extension can be used. usually it is "states.cpp". The name does not need to be same as the real cpp file. |
pFileHandler | if NULL it will unregister. If not, it is the file handler pointer, the pointer must be always valid, it is usually a static singleton object. |
Implements NPL::INPLRuntimeState.
|
inline |
if USE_BOOST_SIGNAL_FILE_HANDLER is defined, we will allow multiple file handlers to subscribe to the same filename target.
but the caller will need to link with the boost signal lib. if not defined, only one handler is allowed per file. The latest registered handler will overwrite the previous one.
|
inlinevirtual |
send a message to the current message queue.
This function is rarely needed to call directly, use Activate_async instead. e.g. NPLMessage_ptr msg(new NPLMessage()); return SendMessage(msg, priority);
msg | the message to send. Please note that when the function returns, the msg will be reset to null. |
|
inlinevirtual |
creates a timer with the specified time-out value [thread safe]
nIDEvent | Specifies a positive timer identifier. For nIDEvent<=0, they are reserved for internal uses. If the NPL runtime already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. |
fElapse | Specifies the time-out value, in seconds. Please note that a timer will not be repeatedly activated if its timeout is shorter than the frame rate of the NPL simulation pipeline . |
sNeuronFile | The NPL file to be activated when the time-out value elapses. For more information about the file name See NPL.activate(). |
Implements NPL::INPLRuntimeState.
|
inlinevirtual |
write a log message
text | the content of the log message. |
nTextLen | the log text length in byte. if 0, text length will be determined automatically. |
nLogType | if this is 0, it is a normal log message. if this is 1, we will print current time, and runtime state name with the log message. |
Implements NPL::INPLRuntimeState.
|
protected |
pointer to the current message.
it is only valid during activation call. NULL will be returned
|
protected |
length of the current message.
it is only valid during activation call.
|
protected |
file handlers map.
|
protected |
the name of this runtime state.
if "", it is considered an anonymous name