|
FreeNOS
|
Template class which serves incoming messages from Channels using MessageHandlers. More...
#include <ChannelServer.h>
Public Types | |
| enum | Result { Success , InvalidArgument , InvalidSize , IOError } |
| Result codes. More... | |
Public Member Functions | |
| ChannelServer (Base *inst) | |
| Constructor function. | |
| virtual | ~ChannelServer () |
| Destructor function. | |
| int | run () |
| Enters an infinite loop, serving incoming requests. | |
| void | setTimeout (const uint msec) |
| Set a sleep timeout. | |
Protected Types | |
| typedef void(Base::* | IPCHandlerFunction) (MsgType *) |
| Member function pointer inside Base, to handle IPC messages. | |
| typedef void(Base::* | IRQHandlerFunction) (Size) |
| Member function pointer inside Base, to handle interrupts. | |
Protected Member Functions | |
| void | addIPCHandler (const Size slot, IPCHandlerFunction h, const bool sendReply=true) |
| Register a new IPC message action handler. | |
| void | addIRQHandler (const Size slot, IRQHandlerFunction h) |
| Register a new IRQ message vector handler. | |
| virtual void | timeout () |
| Called when sleep timeout is reached. | |
| virtual bool | retryRequests () |
| Retry any pending requests. | |
| virtual void | onProcessTerminated (const ProcessID pid) |
| Called whenever another Process is terminated. | |
| void | retryAllRequests () |
| Keep retrying requests until all served. | |
Protected Attributes | |
| Base * | m_instance |
| Server object instance. | |
| ChannelClient * | m_client |
| Client for sending replies. | |
| ChannelRegistry & | m_registry |
| Contains registered channels. | |
| MemoryChannel | m_kernelEvent |
| Kernel event channel. | |
| Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCount > | m_ipcHandlers |
| IPC handler functions. | |
| Index< MessageHandler< IRQHandlerFunction >, MaximumHandlerCount > | m_irqHandlers |
| IRQ handler functions. | |
| ProcessID | m_self |
| ProcessID of ourselves. | |
| Timer::Info | m_time |
| System timer value. | |
| Timer::Info | m_expiry |
| System timer expiration value. | |
Private Member Functions | |
| void | processAll () |
| Process all current events and channels. | |
| void | sleepUntilWakeup () |
| Let this process sleep until more events are raised. | |
| Result | accept (const ProcessID pid, const Memory::Range range, const bool hardReset=true) |
| Accept new channel connection. | |
| void | recoverChannels () |
| Read existing shares to recover MemoryChannels after restart. | |
| Result | readKernelEvents () |
| Read and process kernel events. | |
| Result | readChannels () |
| Read each Channel for messages. | |
Static Private Attributes | |
| static const Size | MaximumHandlerCount = 255u |
| Maximum number of IPC/IRQ handlers. | |
Template class which serves incoming messages from Channels using MessageHandlers.
| MsgType | Type of Message to serve. |
Definition at line 79 of file ChannelServer.h.
|
protected |
Member function pointer inside Base, to handle IPC messages.
Definition at line 89 of file ChannelServer.h.
|
protected |
Member function pointer inside Base, to handle interrupts.
Definition at line 92 of file ChannelServer.h.
| enum ChannelServer::Result |
Result codes.
| Enumerator | |
|---|---|
| Success | |
| InvalidArgument | |
| InvalidSize | |
| IOError | |
Definition at line 99 of file ChannelServer.h.
|
inline |
Constructor function.
Definition at line 112 of file ChannelServer.h.
References SystemInformation::coreId, ProcessShares::MemoryShare::coreId, FATAL, Timer::Info::frequency, GetPID, KERNEL_PID, ChannelServer< Base, MsgType >::m_expiry, ChannelServer< Base, MsgType >::m_kernelEvent, ChannelServer< Base, MsgType >::m_self, PAGESIZE, ProcessShares::MemoryShare::pid, ProcessCtl(), ProcessShares::MemoryShare::range, API::Read, ChannelServer< Base, MsgType >::recoverChannels(), SELF, MemoryChannel::setVirtual(), API::Success, ProcessShares::MemoryShare::tagId, Timer::Info::ticks, Memory::Range::virt, and VMShare().
|
inlinevirtual |
Destructor function.
Definition at line 150 of file ChannelServer.h.
References Index< T, N >::deleteAll(), ChannelServer< Base, MsgType >::m_ipcHandlers, and ChannelServer< Base, MsgType >::m_irqHandlers.
|
inlineprivate |
Accept new channel connection.
| pid | ProcessID |
| range | Memory range of shared mapping |
| hardReset | True if the channel contents should be reset to initial state. |
Definition at line 314 of file ChannelServer.h.
References assert, Channel::Consumer, ChannelRegistry::getConsumer(), ChannelRegistry::getProducer(), ChannelServer< Base, MsgType >::m_registry, ChannelServer< Base, MsgType >::m_self, NULL, PAGESIZE, Channel::Producer, ChannelRegistry::registerConsumer(), ChannelRegistry::registerProducer(), MemoryChannel::setVirtual(), ChannelServer< Base, MsgType >::Success, and Memory::Range::virt.
Referenced by ChannelServer< Base, MsgType >::readKernelEvents(), and ChannelServer< Base, MsgType >::recoverChannels().
|
inlineprotected |
Register a new IPC message action handler.
| slot | Action value to trigger h. |
| h | Handler to execute. |
| sendReply | True if the handler needs to send a reply |
Definition at line 203 of file ChannelServer.h.
References Index< T, N >::insertAt(), and ChannelServer< Base, MsgType >::m_ipcHandlers.
|
inlineprotected |
Register a new IRQ message vector handler.
| slot | Vector value to trigger h. |
| h | Handler to execute. |
Definition at line 214 of file ChannelServer.h.
References Index< T, N >::insertAt(), and ChannelServer< Base, MsgType >::m_irqHandlers.
|
inlineprotectedvirtual |
Called whenever another Process is terminated.
| pid | ProcessID of the terminating process |
Reimplemented in NetworkServer.
Definition at line 244 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::readKernelEvents().
|
inlineprivate |
Process all current events and channels.
Definition at line 262 of file ChannelServer.h.
References ChannelServer< Base, MsgType >::readChannels(), ChannelServer< Base, MsgType >::readKernelEvents(), and ChannelServer< Base, MsgType >::retryAllRequests().
Referenced by ChannelServer< Base, MsgType >::run().
|
inlineprivate |
Read each Channel for messages.
Definition at line 464 of file ChannelServer.h.
References DEBUG, ERROR, MessageHandler< Func >::exec, Index< T, N >::get(), ChannelRegistry::getConsumers(), ChannelRegistry::getProducer(), ChannelServer< Base, MsgType >::m_client, ChannelServer< Base, MsgType >::m_instance, ChannelServer< Base, MsgType >::m_ipcHandlers, ChannelServer< Base, MsgType >::m_registry, ChannelServer< Base, MsgType >::m_self, ProcessCtl(), ChannelClient::processResponse(), Channel::read(), ChannelMessage::Response, MessageHandler< Func >::sendReply, Channel::Success, ChannelClient::Success, ChannelServer< Base, MsgType >::Success, Wakeup, and Channel::write().
Referenced by ChannelServer< Base, MsgType >::processAll().
|
inlineprivate |
Read and process kernel events.
Definition at line 390 of file ChannelServer.h.
References ChannelServer< Base, MsgType >::accept(), DEBUG, API::Delete, ERROR, MessageHandler< Func >::exec, Index< T, N >::get(), InterruptEvent, ChannelServer< Base, MsgType >::m_instance, ChannelServer< Base, MsgType >::m_irqHandlers, ChannelServer< Base, MsgType >::m_kernelEvent, ChannelServer< Base, MsgType >::m_registry, ChannelServer< Base, MsgType >::m_self, ProcessEvent::number, ChannelServer< Base, MsgType >::onProcessTerminated(), ProcessShares::MemoryShare::pid, ProcessTerminated, ProcessShares::MemoryShare::range, MemoryChannel::read(), ProcessEvent::share, ShareCreated, API::Success, Channel::Success, ChannelRegistry::Success, ChannelServer< Base, MsgType >::Success, ProcessEvent::type, ChannelRegistry::unregisterConsumer(), ChannelRegistry::unregisterProducer(), VMShare(), WARNING, and ZERO.
Referenced by ChannelServer< Base, MsgType >::processAll().
|
inlineprivate |
Read existing shares to recover MemoryChannels after restart.
Definition at line 359 of file ChannelServer.h.
References ChannelServer< Base, MsgType >::accept(), SystemInformation::coreId, ProcessShares::MemoryShare::coreId, ERROR, KERNEL_PID, ChannelServer< Base, MsgType >::m_self, MAX_PROCS, ProcessShares::MemoryShare::pid, ProcessShares::MemoryShare::range, API::Read, SELF, API::Success, ChannelServer< Base, MsgType >::Success, ProcessShares::MemoryShare::tagId, and VMShare().
Referenced by ChannelServer< Base, MsgType >::ChannelServer().
|
inlineprotected |
Keep retrying requests until all served.
Definition at line 251 of file ChannelServer.h.
References ChannelServer< Base, MsgType >::m_instance.
Referenced by ChannelServer< Base, MsgType >::processAll(), and ChannelServer< Base, MsgType >::timeout().
|
inlineprotectedvirtual |
Retry any pending requests.
Reimplemented in FileSystemServer, and NetworkServer.
Definition at line 234 of file ChannelServer.h.
|
inline |
Enters an infinite loop, serving incoming requests.
Definition at line 161 of file ChannelServer.h.
References ChannelServer< Base, MsgType >::processAll(), and ChannelServer< Base, MsgType >::sleepUntilWakeup().
Referenced by main().
|
inline |
Set a sleep timeout.
| msec | Milliseconds to sleep (approximately) |
Definition at line 179 of file ChannelServer.h.
References DEBUG, ERROR, Timer::Info::frequency, InfoTimer, ChannelServer< Base, MsgType >::m_expiry, ChannelServer< Base, MsgType >::m_time, ProcessCtl(), SELF, API::Success, and Timer::Info::ticks.
Referenced by ARP::lookupAddress().
|
inlineprivate |
Let this process sleep until more events are raised.
Definition at line 277 of file ChannelServer.h.
References DEBUG, EnterSleep, ERROR, Timer::Info::frequency, InfoTimer, ChannelServer< Base, MsgType >::m_expiry, ChannelServer< Base, MsgType >::m_time, ProcessCtl(), SELF, API::Success, Timer::Info::ticks, and ChannelServer< Base, MsgType >::timeout().
Referenced by ChannelServer< Base, MsgType >::run().
|
inlineprotectedvirtual |
Called when sleep timeout is reached.
Definition at line 222 of file ChannelServer.h.
References DEBUG, and ChannelServer< Base, MsgType >::retryAllRequests().
Referenced by ChannelServer< Base, MsgType >::sleepUntilWakeup().
|
protected |
Client for sending replies.
Definition at line 529 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::readChannels().
|
protected |
System timer expiration value.
Definition at line 550 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::ChannelServer(), ChannelServer< Base, MsgType >::setTimeout(), and ChannelServer< Base, MsgType >::sleepUntilWakeup().
|
protected |
Server object instance.
Definition at line 526 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::readChannels(), ChannelServer< Base, MsgType >::readKernelEvents(), and ChannelServer< Base, MsgType >::retryAllRequests().
|
protected |
IPC handler functions.
Definition at line 538 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::addIPCHandler(), ChannelServer< Base, MsgType >::readChannels(), and ChannelServer< Base, MsgType >::~ChannelServer().
|
protected |
IRQ handler functions.
Definition at line 541 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::addIRQHandler(), ChannelServer< Base, MsgType >::readKernelEvents(), and ChannelServer< Base, MsgType >::~ChannelServer().
|
protected |
Kernel event channel.
Definition at line 535 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::ChannelServer(), and ChannelServer< Base, MsgType >::readKernelEvents().
|
protected |
Contains registered channels.
Definition at line 532 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::accept(), ChannelServer< Base, MsgType >::readChannels(), and ChannelServer< Base, MsgType >::readKernelEvents().
|
protected |
ProcessID of ourselves.
Definition at line 544 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::accept(), ChannelServer< Base, MsgType >::ChannelServer(), ChannelServer< Base, MsgType >::readChannels(), ChannelServer< Base, MsgType >::readKernelEvents(), and ChannelServer< Base, MsgType >::recoverChannels().
|
protected |
System timer value.
Definition at line 547 of file ChannelServer.h.
Referenced by ChannelServer< Base, MsgType >::setTimeout(), and ChannelServer< Base, MsgType >::sleepUntilWakeup().
|
staticprivate |
Maximum number of IPC/IRQ handlers.
Definition at line 84 of file ChannelServer.h.