FreeNOS
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Attributes
ChannelServer< Base, MsgType > Class Template Reference

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. More...
 
virtual ~ChannelServer ()
 Destructor function. More...
 
int run ()
 Enters an infinite loop, serving incoming requests. More...
 
void setTimeout (const uint msec)
 Set a sleep timeout. More...
 

Protected Types

typedef void(Base::* IPCHandlerFunction) (MsgType *)
 Member function pointer inside Base, to handle IPC messages. More...
 
typedef void(Base::* IRQHandlerFunction) (Size)
 Member function pointer inside Base, to handle interrupts. More...
 

Protected Member Functions

void addIPCHandler (const Size slot, IPCHandlerFunction h, const bool sendReply=true)
 Register a new IPC message action handler. More...
 
void addIRQHandler (const Size slot, IRQHandlerFunction h)
 Register a new IRQ message vector handler. More...
 
virtual void timeout ()
 Called when sleep timeout is reached. More...
 
virtual bool retryRequests ()
 Retry any pending requests. More...
 
virtual void onProcessTerminated (const ProcessID pid)
 Called whenever another Process is terminated. More...
 
void retryAllRequests ()
 Keep retrying requests until all served. More...
 

Protected Attributes

Base * m_instance
 Server object instance. More...
 
ChannelClientm_client
 Client for sending replies. More...
 
ChannelRegistrym_registry
 Contains registered channels. More...
 
MemoryChannel m_kernelEvent
 Kernel event channel. More...
 
Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCountm_ipcHandlers
 IPC handler functions. More...
 
Index< MessageHandler< IRQHandlerFunction >, MaximumHandlerCountm_irqHandlers
 IRQ handler functions. More...
 
ProcessID m_self
 ProcessID of ourselves. More...
 
Timer::Info m_time
 System timer value. More...
 
Timer::Info m_expiry
 System timer expiration value. More...
 

Private Member Functions

void processAll ()
 Process all current events and channels. More...
 
void sleepUntilWakeup ()
 Let this process sleep until more events are raised. More...
 
Result accept (const ProcessID pid, const Memory::Range range, const bool hardReset=true)
 Accept new channel connection. More...
 
void recoverChannels ()
 Read existing shares to recover MemoryChannels after restart. More...
 
Result readKernelEvents ()
 Read and process kernel events. More...
 
Result readChannels ()
 Read each Channel for messages. More...
 

Static Private Attributes

static const Size MaximumHandlerCount = 255u
 Maximum number of IPC/IRQ handlers. More...
 

Detailed Description

template<class Base, class MsgType>
class ChannelServer< Base, MsgType >

Template class which serves incoming messages from Channels using MessageHandlers.

Parameters
MsgTypeType of Message to serve.

Definition at line 79 of file ChannelServer.h.

Member Typedef Documentation

◆ IPCHandlerFunction

template<class Base , class MsgType >
typedef void(Base::* ChannelServer< Base, MsgType >::IPCHandlerFunction) (MsgType *)
protected

Member function pointer inside Base, to handle IPC messages.

Definition at line 89 of file ChannelServer.h.

◆ IRQHandlerFunction

template<class Base , class MsgType >
typedef void(Base::* ChannelServer< Base, MsgType >::IRQHandlerFunction) (Size)
protected

Member function pointer inside Base, to handle interrupts.

Definition at line 92 of file ChannelServer.h.

Member Enumeration Documentation

◆ Result

template<class Base , class MsgType >
enum ChannelServer::Result

Result codes.

Enumerator
Success 
InvalidArgument 
InvalidSize 
IOError 

Definition at line 99 of file ChannelServer.h.

Constructor & Destructor Documentation

◆ ChannelServer()

template<class Base , class MsgType >
ChannelServer< Base, MsgType >::ChannelServer ( Base *  inst)
inline

Constructor function.

Definition at line 112 of file ChannelServer.h.

◆ ~ChannelServer()

template<class Base , class MsgType >
virtual ChannelServer< Base, MsgType >::~ChannelServer ( )
inlinevirtual

Destructor function.

Definition at line 150 of file ChannelServer.h.

Member Function Documentation

◆ accept()

template<class Base , class MsgType >
Result ChannelServer< Base, MsgType >::accept ( const ProcessID  pid,
const Memory::Range  range,
const bool  hardReset = true 
)
inlineprivate

Accept new channel connection.

Parameters
pidProcessID
rangeMemory range of shared mapping
hardResetTrue if the channel contents should be reset to initial state.
Returns
Result code

Definition at line 314 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::readKernelEvents(), and ChannelServer< DatastoreServer, DatastoreMessage >::recoverChannels().

◆ addIPCHandler()

template<class Base , class MsgType >
void ChannelServer< Base, MsgType >::addIPCHandler ( const Size  slot,
IPCHandlerFunction  h,
const bool  sendReply = true 
)
inlineprotected

Register a new IPC message action handler.

Parameters
slotAction value to trigger h.
hHandler to execute.
sendReplyTrue if the handler needs to send a reply

Definition at line 203 of file ChannelServer.h.

◆ addIRQHandler()

template<class Base , class MsgType >
void ChannelServer< Base, MsgType >::addIRQHandler ( const Size  slot,
IRQHandlerFunction  h 
)
inlineprotected

Register a new IRQ message vector handler.

Parameters
slotVector value to trigger h.
hHandler to execute.

Definition at line 214 of file ChannelServer.h.

◆ onProcessTerminated()

template<class Base , class MsgType >
virtual void ChannelServer< Base, MsgType >::onProcessTerminated ( const ProcessID  pid)
inlineprotectedvirtual

Called whenever another Process is terminated.

Parameters
pidProcessID of the terminating process

Reimplemented in NetworkServer.

Definition at line 244 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::readKernelEvents().

◆ processAll()

template<class Base , class MsgType >
void ChannelServer< Base, MsgType >::processAll ( )
inlineprivate

Process all current events and channels.

Definition at line 262 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::run().

◆ readChannels()

template<class Base , class MsgType >
Result ChannelServer< Base, MsgType >::readChannels ( )
inlineprivate

Read each Channel for messages.

Returns
Result code

Definition at line 464 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::processAll().

◆ readKernelEvents()

template<class Base , class MsgType >
Result ChannelServer< Base, MsgType >::readKernelEvents ( )
inlineprivate

Read and process kernel events.

Returns
Result code.

Definition at line 390 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::processAll().

◆ recoverChannels()

template<class Base , class MsgType >
void ChannelServer< Base, MsgType >::recoverChannels ( )
inlineprivate

Read existing shares to recover MemoryChannels after restart.

Definition at line 359 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::ChannelServer().

◆ retryAllRequests()

template<class Base , class MsgType >
void ChannelServer< Base, MsgType >::retryAllRequests ( )
inlineprotected

◆ retryRequests()

template<class Base , class MsgType >
virtual bool ChannelServer< Base, MsgType >::retryRequests ( )
inlineprotectedvirtual

Retry any pending requests.

Returns
True if retry is needed again, false if all requests processed

Reimplemented in FileSystemServer, and NetworkServer.

Definition at line 234 of file ChannelServer.h.

◆ run()

template<class Base , class MsgType >
int ChannelServer< Base, MsgType >::run ( )
inline

Enters an infinite loop, serving incoming requests.

Returns
Never.

Definition at line 161 of file ChannelServer.h.

Referenced by main().

◆ setTimeout()

template<class Base , class MsgType >
void ChannelServer< Base, MsgType >::setTimeout ( const uint  msec)
inline

Set a sleep timeout.

Parameters
msecMilliseconds to sleep (approximately)

Definition at line 179 of file ChannelServer.h.

Referenced by ARP::lookupAddress().

◆ sleepUntilWakeup()

template<class Base , class MsgType >
void ChannelServer< Base, MsgType >::sleepUntilWakeup ( )
inlineprivate

Let this process sleep until more events are raised.

Definition at line 277 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::run().

◆ timeout()

template<class Base , class MsgType >
virtual void ChannelServer< Base, MsgType >::timeout ( )
inlineprotectedvirtual

Called when sleep timeout is reached.

Definition at line 222 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::sleepUntilWakeup().

Field Documentation

◆ m_client

template<class Base , class MsgType >
ChannelClient* ChannelServer< Base, MsgType >::m_client
protected

Client for sending replies.

Definition at line 529 of file ChannelServer.h.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::readChannels().

◆ m_expiry

template<class Base , class MsgType >
Timer::Info ChannelServer< Base, MsgType >::m_expiry
protected

◆ m_instance

template<class Base , class MsgType >
Base* ChannelServer< Base, MsgType >::m_instance
protected

◆ m_ipcHandlers

template<class Base , class MsgType >
Index<MessageHandler<IPCHandlerFunction>, MaximumHandlerCount> ChannelServer< Base, MsgType >::m_ipcHandlers
protected

◆ m_irqHandlers

template<class Base , class MsgType >
Index<MessageHandler<IRQHandlerFunction>, MaximumHandlerCount> ChannelServer< Base, MsgType >::m_irqHandlers
protected

◆ m_kernelEvent

template<class Base , class MsgType >
MemoryChannel ChannelServer< Base, MsgType >::m_kernelEvent
protected

◆ m_registry

template<class Base , class MsgType >
ChannelRegistry& ChannelServer< Base, MsgType >::m_registry
protected

◆ m_self

template<class Base , class MsgType >
ProcessID ChannelServer< Base, MsgType >::m_self
protected

◆ m_time

template<class Base , class MsgType >
Timer::Info ChannelServer< Base, MsgType >::m_time
protected

◆ MaximumHandlerCount

template<class Base , class MsgType >
const Size ChannelServer< Base, MsgType >::MaximumHandlerCount = 255u
staticprivate

Maximum number of IPC/IRQ handlers.

Definition at line 84 of file ChannelServer.h.


The documentation for this class was generated from the following file: