18#ifndef __LIBIPC_CHANNELSERVER_H
19#define __LIBIPC_CHANNELSERVER_H
21#include <FreeNOS/User.h>
22#include <FreeNOS/ProcessManager.h>
23#include <FreeNOS/ProcessEvent.h>
24#include <FreeNOS/ProcessShares.h>
135 FATAL(
"failed to get kernel event channel");
181 DEBUG(
"msec = " << msec);
185 ERROR(
"failed to retrieve system timer info");
288 DEBUG(
"EnterSleep returned: " << (
int)r);
295 ERROR(
"failed to retrieve system timer");
316 const bool hardReset =
true)
323 prodAddr = range.
virt;
329 consAddr = range.
virt;
378 ERROR(
"failed to recover share for PID " << i <<
": " << (
int)r);
429 ERROR(
"failed to unregister consumer for PID " <<
430 event.
number <<
": " << (
int)result);
436 ERROR(
"failed to unregister producer for PID " <<
437 event.
number <<
": " << (
int)result);
444 ERROR(
"failed to remove shares with VMShare for PID " <<
445 event.
number <<
": " << (
int)shareResult);
472 DEBUG(
m_self <<
": trying to receive from PID " << i.key());
485 ERROR(
m_self <<
": failed to process client response from PID " <<
486 msg.from <<
" with identifier " << msg.identifier);
503 ERROR(
m_self <<
": no producer channel found for PID: " << i.key());
507 ERROR(
m_self <<
": failed to send reply message to PID: " << i.key());
515 ERROR(
m_self <<
": invalid action " << (
int)msg.action <<
" from PID " << i.key());
Result
Enumeration of generic kernel API result codes.
Client for using Channels on the local processor.
virtual Result processResponse(const ProcessID pid, ChannelMessage *msg)
Process a response message.
Registration for Channels.
Result registerProducer(const ProcessID pid, Channel *channel)
Register producer channel.
HashTable< ProcessID, Channel * > & getConsumers()
Get all consumers.
Channel * getProducer(const ProcessID pid)
Get one producer.
Result unregisterConsumer(const ProcessID pid)
Unregister consumer channel.
Result registerConsumer(const ProcessID pid, Channel *channel)
Register consumer channel.
Channel * getConsumer(const ProcessID pid)
Get one consumer.
Result unregisterProducer(const ProcessID pid)
Unregister producer channel.
Template class which serves incoming messages from Channels using MessageHandlers.
static const Size MaximumHandlerCount
Maximum number of IPC/IRQ handlers.
Timer::Info m_expiry
System timer expiration value.
void sleepUntilWakeup()
Let this process sleep until more events are raised.
void processAll()
Process all current events and channels.
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.
ChannelRegistry & m_registry
Contains registered channels.
Result readKernelEvents()
Read and process kernel events.
virtual bool retryRequests()
Retry any pending requests.
Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCount > m_ipcHandlers
IPC handler functions.
Timer::Info m_time
System timer value.
ChannelServer(Base *inst)
Constructor function.
void setTimeout(const uint msec)
Set a sleep timeout.
void retryAllRequests()
Keep retrying requests until all served.
void(Base::* IRQHandlerFunction)(Size)
Member function pointer inside Base, to handle interrupts.
MemoryChannel m_kernelEvent
Kernel event channel.
virtual void onProcessTerminated(const ProcessID pid)
Called whenever another Process is terminated.
ProcessID m_self
ProcessID of ourselves.
virtual void timeout()
Called when sleep timeout is reached.
ChannelClient * m_client
Client for sending replies.
void addIRQHandler(const Size slot, IRQHandlerFunction h)
Register a new IRQ message vector handler.
Result readChannels()
Read each Channel for messages.
void(Base::* IPCHandlerFunction)(MsgType *)
Member function pointer inside Base, to handle IPC messages.
int run()
Enters an infinite loop, serving incoming requests.
virtual ~ChannelServer()
Destructor function.
Base * m_instance
Server object instance.
Index< MessageHandler< IRQHandlerFunction >, MaximumHandlerCount > m_irqHandlers
IRQ handler functions.
void addIPCHandler(const Size slot, IPCHandlerFunction h, const bool sendReply=true)
Register a new IPC message action handler.
Unidirectional point-to-point messaging channel.
virtual Result write(const void *buffer)
Write a message.
virtual Result read(void *buffer)
Read a message.
Iterate through a HashTable.
Index is a N-sized array of pointers to items of type T.
virtual T * get(const Size position) const
Returns the item at the given position.
void deleteAll()
Removes and delete()'s all items.
virtual bool insertAt(const Size position, T *item)
Inserts the given item at the given position.
Unidirectional point-to-point channel using shared memory.
virtual Result read(void *buffer)
Read a message.
Result setVirtual(const Address data, const Address feedback, const bool hardReset=true)
Set memory pages by virtual address.
#define MAX_PROCS
Maximum number of processes.
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
API::Result VMShare(const ProcessID pid, const API::Operation op, ProcessShares::MemoryShare *share)
Prototype for user applications.
#define PAGESIZE
ARM uses 4K pages.
#define assert(exp)
Insert program diagnostics.
#define NULL
NULL means zero.
u32 ProcessID
Process Identification Number.
unsigned long Address
A memory address.
slong Error
Error code defined in Error.h.
#define ERROR(msg)
Output an error message.
#define WARNING(msg)
Output a warning message.
#define FATAL(msg)
Output a critical message and terminate program immediatly.
unsigned int uint
Unsigned integer number.
unsigned int Size
Any sane size indicator cannot go negative.
#define DEBUG(msg)
Output a debug message to standard output.
Address virt
Virtual address.
Message handler function (dummy) container.
MessageHandler(const Func func, const bool reply)
Constructor function.
const bool operator==(const struct MessageHandler< Func > &h) const
const bool operator!=(const struct MessageHandler< Func > &h) const
const Func exec
Handler function.
const bool sendReply
Whether to send a reply or not.
Represents a process which may run on the host.
ProcessShares::MemoryShare share
ProcessID pid
Remote process id for this share.
Size tagId
Share tag id is defined by the application.
Memory::Range range
Physical memory address range.
Size coreId
CoreId for the other process.
Timer information structure.