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 
44 class 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  }
74  Request;
75 
76  public:
77 
81  enum Result
82  {
89  };
90 
91  public:
92 
96  ChannelClient();
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 */
Channel
Unidirectional point-to-point messaging channel.
Definition: Channel.h:34
ChannelClient::ChannelClient
ChannelClient()
Constructor.
Definition: ChannelClient.cpp:24
ChannelRegistry.h
StrictSingleton
Singleton design pattern: only one instance is allowed.
Definition: Singleton.h:39
ChannelClient::m_requests
Index< Request, MaximumRequests > m_requests
Contains ongoing requests.
Definition: ChannelClient.h:232
ChannelClient::NotFound
@ NotFound
Definition: ChannelClient.h:88
ChannelClient::receiveAny
virtual Result receiveAny(void *buffer, const Size msgSize, ProcessID *pid)
Try to receive message from any channel.
Definition: ChannelClient.cpp:140
CallbackFunction
Represents a callback function.
Definition: Callback.h:34
Index.h
ChannelClient::IOError
@ IOError
Definition: ChannelClient.h:86
ChannelClient::Request::operator==
const bool operator==(const struct Request &req) const
Definition: ChannelClient.h:64
Index
Index is a N-sized array of pointers to items of type T.
Definition: Index.h:36
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
ChannelClient::syncReceiveFrom
virtual Result syncReceiveFrom(void *buffer, const Size msgSize, const ProcessID pid)
Synchronous receive from one process.
Definition: ChannelClient.cpp:277
ChannelClient::Success
@ Success
Definition: ChannelClient.h:83
ChannelClient::MaximumRequests
static const Size MaximumRequests
Maximum number of concurrent outgoing requests.
Definition: ChannelClient.h:49
Channel.h
ChannelClient::findProducer
Channel * findProducer(const ProcessID pid, const Size msgSize)
Get producer for a process.
Definition: ChannelClient.cpp:260
ChannelClient::Request::callback
CallbackFunction * callback
Definition: ChannelClient.h:62
ChannelClient::OutOfMemory
@ OutOfMemory
Definition: ChannelClient.h:87
ChannelClient::connect
virtual Result connect(const ProcessID pid, const Size msgSize)
Connect to a process.
Definition: ChannelClient.cpp:44
Callback.h
ChannelClient::~ChannelClient
virtual ~ChannelClient()
Destructor.
Definition: ChannelClient.cpp:30
ChannelClient::Request
Holds an outgoing request.
Definition: ChannelClient.h:57
ChannelClient::MaxConnectRetries
static const Size MaxConnectRetries
Maximum number of retries for establishing new connection.
Definition: ChannelClient.h:52
ChannelClient::Request::operator!=
const bool operator!=(const struct Request &req) const
Definition: ChannelClient.h:69
ChannelMessage.h
ChannelClient::syncSendTo
virtual Result syncSendTo(const void *buffer, const Size msgSize, const ProcessID pid)
Synchronous send to one process.
Definition: ChannelClient.cpp:292
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
ChannelClient::syncSendReceive
virtual Result syncSendReceive(void *buffer, const Size msgSize, const ProcessID pid)
Synchronous send and receive to/from one process.
Definition: ChannelClient.cpp:322
ChannelClient::InvalidArgument
@ InvalidArgument
Definition: ChannelClient.h:84
ChannelClient::Result
Result
Result codes.
Definition: ChannelClient.h:81
ChannelClient
Client for using Channels on the local processor.
Definition: ChannelClient.h:44
Singleton.h
ChannelClient::getRegistry
ChannelRegistry & getRegistry()
Get channel registry.
Definition: ChannelClient.cpp:34
ChannelClient::Request::pid
ProcessID pid
Definition: ChannelClient.h:60
ChannelClient::initialize
virtual Result initialize()
Initialize the ChannelClient.
Definition: ChannelClient.cpp:39
ChannelClient::sendRequest
virtual Result sendRequest(const ProcessID pid, void *buffer, const Size msgSize, CallbackFunction *callback)
Send asynchronous request message.
Definition: ChannelClient.cpp:156
ChannelRegistry
Registration for Channels.
Definition: ChannelRegistry.h:37
ChannelClient::Request::message
ChannelMessage * message
Definition: ChannelClient.h:61
ChannelClient::Request
struct ChannelClient::Request Request
Holds an outgoing request.
ChannelClient::InvalidSize
@ InvalidSize
Definition: ChannelClient.h:85
ChannelClient::Request::active
bool active
Definition: ChannelClient.h:59
ChannelClient::findConsumer
Channel * findConsumer(const ProcessID pid, const Size msgSize)
Get consumer for a process.
Definition: ChannelClient.cpp:243
ChannelClient::m_pid
const ProcessID m_pid
Current Process ID.
Definition: ChannelClient.h:235
ChannelClient::processResponse
virtual Result processResponse(const ProcessID pid, ChannelMessage *msg)
Process a response message.
Definition: ChannelClient.cpp:220
ChannelClient::m_registry
ChannelRegistry m_registry
Contains registered channels.
Definition: ChannelClient.h:229
ChannelMessage
Basic message format for sending on a Channel.
Definition: ChannelMessage.h:34