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 
23 {
24 }
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 
54 {
55  return m_consumer;
56 }
57 
59 {
60  return m_producer;
61 }
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 }
Channel
Unidirectional point-to-point messaging channel.
Definition: Channel.h:34
HashTable< ProcessID, Channel * >
ChannelRegistry.h
HashIterator
Iterate through a HashTable.
Definition: HashIterator.h:39
HashIterator.h
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
ChannelRegistry::m_consumer
HashTable< ProcessID, Channel * > m_consumer
Contains registered consumer channels.
Definition: ChannelRegistry.h:138
Channel.h
ChannelRegistry::NotFound
@ NotFound
Definition: ChannelRegistry.h:50
ChannelRegistry::getConsumer
Channel * getConsumer(const ProcessID pid)
Get one consumer.
Definition: ChannelRegistry.cpp:35
ChannelRegistry::Success
@ Success
Definition: ChannelRegistry.h:46
ChannelRegistry::registerConsumer
Result registerConsumer(const ProcessID pid, Channel *channel)
Register consumer channel.
Definition: ChannelRegistry.cpp:63
HashTable::remove
virtual int remove(const K &key)
Remove value(s) for the given key.
Definition: HashTable.h:178
ChannelRegistry::~ChannelRegistry
virtual ~ChannelRegistry()
Destructor.
Definition: ChannelRegistry.cpp:26
HashTable::get
virtual const V * get(const K &key) const
Returns the first value for the given key.
Definition: HashTable.h:287
ChannelRegistry::getConsumers
HashTable< ProcessID, Channel * > & getConsumers()
Get all consumers.
Definition: ChannelRegistry.cpp:53
ChannelRegistry::m_producer
HashTable< ProcessID, Channel * > m_producer
Contains registered producer channels.
Definition: ChannelRegistry.h:141
ChannelRegistry::registerProducer
Result registerProducer(const ProcessID pid, Channel *channel)
Register producer channel.
Definition: ChannelRegistry.cpp:71
ChannelRegistry::unregisterProducer
Result unregisterProducer(const ProcessID pid)
Unregister producer channel.
Definition: ChannelRegistry.cpp:91
HashIterator::hasCurrent
virtual bool hasCurrent() const
Check if there is a current item.
Definition: HashIterator.h:83
ChannelRegistry::ChannelRegistry
ChannelRegistry()
Constructor.
Definition: ChannelRegistry.cpp:22
ChannelRegistry::getProducer
Channel * getProducer(const ProcessID pid)
Get one producer.
Definition: ChannelRegistry.cpp:44
ChannelRegistry::unregisterConsumer
Result unregisterConsumer(const ProcessID pid)
Unregister consumer channel.
Definition: ChannelRegistry.cpp:79
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
ChannelRegistry::getProducers
HashTable< ProcessID, Channel * > & getProducers()
Get all producers.
Definition: ChannelRegistry.cpp:58
HashTable::insert
virtual bool insert(const K &key, const V &value)
Inserts the given item to the HashTable.
Definition: HashTable.h:133
ChannelRegistry::Result
Result
Result codes.
Definition: ChannelRegistry.h:44