FreeNOS
ChannelRegistry.cpp
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#include <HashIterator.h>
19#include "Channel.h"
20#include "ChannelRegistry.h"
21
25
27{
29 delete i.current();
30
32 delete i.current();
33}
34
36{
37 Channel * const *ch = m_consumer.get(pid);
38 if (ch)
39 return *ch;
40 else
41 return ZERO;
42}
43
45{
46 Channel * const *ch = m_producer.get(pid);
47 if (ch)
48 return *ch;
49 else
50 return ZERO;
51}
52
57
62
64 const ProcessID pid,
65 Channel *channel)
66{
67 m_consumer.insert(pid, channel);
68 return Success;
69}
70
72 const ProcessID pid,
73 Channel *channel)
74{
75 m_producer.insert(pid, channel);
76 return Success;
77}
78
80{
81 Channel *ch = getConsumer(pid);
82 if (ch)
83 delete ch;
84
85 if (m_consumer.remove(pid) > 0)
86 return Success;
87 else
88 return NotFound;
89}
90
92{
93 Channel *ch = getProducer(pid);
94 if (ch)
95 delete ch;
96
97 if (m_producer.remove(pid) > 0)
98 return Success;
99 else
100 return NotFound;
101}
Result registerProducer(const ProcessID pid, Channel *channel)
Register producer channel.
HashTable< ProcessID, Channel * > & getConsumers()
Get all consumers.
HashTable< ProcessID, Channel * > m_consumer
Contains registered consumer channels.
Channel * getProducer(const ProcessID pid)
Get one producer.
Result unregisterConsumer(const ProcessID pid)
Unregister consumer channel.
Result
Result codes.
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.
HashTable< ProcessID, Channel * > & getProducers()
Get all producers.
HashTable< ProcessID, Channel * > m_producer
Contains registered producer channels.
virtual ~ChannelRegistry()
Destructor.
ChannelRegistry()
Constructor.
Unidirectional point-to-point messaging channel.
Definition Channel.h:35
Iterate through a HashTable.
virtual bool hasCurrent() const
Check if there is a current item.
Efficient key -> value lookups.
Definition HashTable.h:45
virtual int remove(const K &key)
Remove value(s) for the given key.
Definition HashTable.h:178
virtual const V * get(const K &key) const
Returns the first value for the given key.
Definition HashTable.h:287
virtual bool insert(const K &key, const V &value)
Inserts the given item to the HashTable.
Definition HashTable.h:133
u32 ProcessID
Process Identification Number.
Definition Types.h:140
#define ZERO
Zero value.
Definition Macros.h:43