FreeNOS
ChannelClient.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIBIPC_CHANNELCLIENT_H
19#define __LIBIPC_CHANNELCLIENT_H
20
21#include <Singleton.h>
22#include <Callback.h>
23#include <Index.h>
24#include "ChannelRegistry.h"
25#include "Channel.h"
26#include "ChannelMessage.h"
27
44class ChannelClient : public StrictSingleton<ChannelClient>
45{
46 private:
47
49 static const Size MaximumRequests = 32u;
50
52 static const Size MaxConnectRetries = 16u;
53
57 typedef struct Request
58 {
59 bool active;
63
64 const bool operator == (const struct Request & req) const
65 {
66 return req.message == message && req.callback == callback;
67 }
68
69 const bool operator != (const struct Request & req) const
70 {
71 return req.message != message || req.callback != callback;
72 }
73 }
75
76 public:
77
90
91 public:
92
97
101 virtual ~ChannelClient();
102
109
115 virtual Result initialize();
116
128 virtual Result connect(const ProcessID pid, const Size msgSize);
129
139 virtual Result receiveAny(void *buffer, const Size msgSize, ProcessID *pid);
140
155 virtual Result sendRequest(const ProcessID pid,
156 void *buffer,
157 const Size msgSize,
158 CallbackFunction *callback);
159
168 virtual Result processResponse(const ProcessID pid,
169 ChannelMessage *msg);
170
180 virtual Result syncReceiveFrom(void *buffer, const Size msgSize, const ProcessID pid);
181
191 virtual Result syncSendTo(const void *buffer, const Size msgSize, const ProcessID pid);
192
202 virtual Result syncSendReceive(void *buffer, const Size msgSize, const ProcessID pid);
203
204 private:
205
214 Channel * findConsumer(const ProcessID pid, const Size msgSize);
215
224 Channel * findProducer(const ProcessID pid, const Size msgSize);
225
226 private:
227
230
233
236};
237
243#endif /* __LIBIPC_CHANNELCLIENT_H */
Represents a callback function.
Definition Callback.h:35
Client for using Channels on the local processor.
virtual Result sendRequest(const ProcessID pid, void *buffer, const Size msgSize, CallbackFunction *callback)
Send asynchronous request message.
static const Size MaximumRequests
Maximum number of concurrent outgoing requests.
Index< Request, MaximumRequests > m_requests
Contains ongoing requests.
ChannelRegistry m_registry
Contains registered channels.
virtual Result processResponse(const ProcessID pid, ChannelMessage *msg)
Process a response message.
virtual Result syncSendReceive(void *buffer, const Size msgSize, const ProcessID pid)
Synchronous send and receive to/from one process.
Channel * findConsumer(const ProcessID pid, const Size msgSize)
Get consumer for a process.
Result
Result codes.
virtual ~ChannelClient()
Destructor.
virtual Result initialize()
Initialize the ChannelClient.
struct ChannelClient::Request Request
Holds an outgoing request.
ChannelRegistry & getRegistry()
Get channel registry.
virtual Result receiveAny(void *buffer, const Size msgSize, ProcessID *pid)
Try to receive message from any channel.
static const Size MaxConnectRetries
Maximum number of retries for establishing new connection.
virtual Result connect(const ProcessID pid, const Size msgSize)
Connect to a process.
const ProcessID m_pid
Current Process ID.
Channel * findProducer(const ProcessID pid, const Size msgSize)
Get producer for a process.
virtual Result syncSendTo(const void *buffer, const Size msgSize, const ProcessID pid)
Synchronous send to one process.
ChannelClient()
Constructor.
virtual Result syncReceiveFrom(void *buffer, const Size msgSize, const ProcessID pid)
Synchronous receive from one process.
Basic message format for sending on a Channel.
Registration for Channels.
Unidirectional point-to-point messaging channel.
Definition Channel.h:35
Index is a N-sized array of pointers to items of type T.
Definition Index.h:37
Singleton design pattern: only one instance is allowed.
Definition Singleton.h:40
u32 ProcessID
Process Identification Number.
Definition Types.h:140
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Holds an outgoing request.
const bool operator!=(const struct Request &req) const
CallbackFunction * callback
ChannelMessage * message
const bool operator==(const struct Request &req) const