CPN
Computational Process Networks
Public Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
CPN::PseudoNode Class Reference

#include <PseudoNode.h>

+ Inheritance diagram for CPN::PseudoNode:
+ Collaboration diagram for CPN::PseudoNode:

Public Member Functions

 PseudoNode (const std::string &name_, Key_t k, shared_ptr< Context > ctx)
 
virtual ~PseudoNode ()
 
const std::string & GetName () const
 
Key_t GetKey () const
 
shared_ptr< QueueReaderGetIQueue (const std::string &portname)
 This method is for use by the user to aquire a reader endpoint. This function blocks until the CPN::Kernel hands this node the queue associated with the endpoint. More...
 
shared_ptr< QueueWriterGetOQueue (const std::string &portname)
 This method is for use by the user to aquire a writer endpoint. This function blocks until the CPN::Kernel hands this node the queue associated with the endpoint. More...
 
void CreateReader (shared_ptr< QueueBase > q)
 for use by the CPN::Kernel to create a new read endpoint. More...
 
void CreateWriter (shared_ptr< QueueBase > q)
 for use by the CPN::Kernel to create a new writer endpoint. More...
 
void NotifyTerminate ()
 Called by the kernel when it is shutting down. More...
 
virtual void Shutdown ()
 Perform actions (like joining a thread) before destruction. More...
 
virtual bool IsPurePseudo ()
 
virtual void LogState ()
 For debugging ONLY! More...
 

Protected Attributes

Logger logger
 

Private Types

typedef std::map< Key_t,
shared_ptr< QueueReader > > 
ReaderMap
 
typedef std::map< Key_t,
shared_ptr< QueueWriter > > 
WriterMap
 

Private Member Functions

 PseudoNode (const PseudoNode &)
 
void ReleaseReader (Key_t ekey)
 
void ReleaseWriter (Key_t ekey)
 
shared_ptr< QueueReaderGetReader (Key_t ekey)
 
shared_ptr< QueueWriterGetWriter (Key_t ekey)
 

Private Attributes

Sync::ReentrantLock lock
 
Sync::ReentrantCondition cond
 
const std::string name
 
const Key_t nodekey
 
shared_ptr< D4R::Noded4rnode
 
ReaderMap readermap
 
WriterMap writermap
 
shared_ptr< Contextcontext
 

Detailed Description

Definition at line 34 of file PseudoNode.h.

Member Typedef Documentation

typedef std::map<Key_t, shared_ptr<QueueReader> > CPN::PseudoNode::ReaderMap
private

Definition at line 91 of file PseudoNode.h.

typedef std::map<Key_t, shared_ptr<QueueWriter> > CPN::PseudoNode::WriterMap
private

Definition at line 92 of file PseudoNode.h.

Constructor & Destructor Documentation

CPN::PseudoNode::PseudoNode ( const std::string &  name_,
Key_t  k,
shared_ptr< Context ctx 
)

Definition at line 31 of file PseudoNode.cc.

32  : logger(ctx.get(), Logger::WARNING, n),
33  name(n),
34  nodekey(k),
35  d4rnode(new D4R::Node(k)),
36  context(ctx)
37  {
38  }
const std::string name
Definition: PseudoNode.h:87
shared_ptr< D4R::Node > d4rnode
Definition: PseudoNode.h:89
const Key_t nodekey
Definition: PseudoNode.h:88
shared_ptr< Context > context
Definition: PseudoNode.h:96
CPN::PseudoNode::~PseudoNode ( )
virtual

Definition at line 40 of file PseudoNode.cc.

40  {
41  }
CPN::PseudoNode::PseudoNode ( const PseudoNode )
private

Member Function Documentation

void CPN::PseudoNode::CreateReader ( shared_ptr< QueueBase q)

for use by the CPN::Kernel to create a new read endpoint.

Definition at line 55 of file PseudoNode.cc.

References ASSERT, cond, d4rnode, lock, readermap, and Sync::ReentrantCondition::Signal().

55  {
57  Key_t readerkey = q->GetReaderKey();
58  d4rnode->AddReader(q);
59  q->SetReaderNode(d4rnode);
60  q->SignalReaderTagChanged();
61  ASSERT(readermap.find(readerkey) == readermap.end(), "The reader already exists");
62  shared_ptr<QueueReader> reader;
63  reader = shared_ptr<QueueReader>(new QueueReader(this, q));
64  readermap.insert(std::make_pair(readerkey, reader));
65  cond.Signal();
66  }
shared_ptr< D4R::Node > d4rnode
Definition: PseudoNode.h:89
Sync::ReentrantLock lock
Definition: PseudoNode.h:85
uint64_t Key_t
Definition: common.h:79
ReaderMap readermap
Definition: PseudoNode.h:93
Sync::ReentrantCondition cond
Definition: PseudoNode.h:86
#define ASSERT(exp,...)

+ Here is the call graph for this function:

void CPN::PseudoNode::CreateWriter ( shared_ptr< QueueBase q)

for use by the CPN::Kernel to create a new writer endpoint.

Definition at line 68 of file PseudoNode.cc.

References ASSERT, cond, d4rnode, lock, Sync::ReentrantCondition::Signal(), and writermap.

68  {
70  Key_t writerkey = q->GetWriterKey();
71  d4rnode->AddWriter(q);
72  q->SetWriterNode(d4rnode);
73  q->SignalWriterTagChanged();
74  ASSERT(writermap.find(writerkey) == writermap.end(), "The writer already exists.");
75  shared_ptr<QueueWriter> writer;
76  writer = shared_ptr<QueueWriter>(new QueueWriter(this, q));
77  writermap.insert(std::make_pair(writerkey, writer));
78  cond.Signal();
79  }
shared_ptr< D4R::Node > d4rnode
Definition: PseudoNode.h:89
WriterMap writermap
Definition: PseudoNode.h:94
Sync::ReentrantLock lock
Definition: PseudoNode.h:85
uint64_t Key_t
Definition: common.h:79
Sync::ReentrantCondition cond
Definition: PseudoNode.h:86
#define ASSERT(exp,...)

+ Here is the call graph for this function:

shared_ptr< QueueReader > CPN::PseudoNode::GetIQueue ( const std::string &  portname)

This method is for use by the user to aquire a reader endpoint. This function blocks until the CPN::Kernel hands this node the queue associated with the endpoint.

Parameters
portnamethe port name of the reader to get.
Returns
a shared pointer to a reader for he given endpoint name

Definition at line 43 of file PseudoNode.cc.

References context, GetReader(), and nodekey.

43  {
44  context->CheckTerminated();
45  Key_t ekey = context->GetCreateReaderKey(nodekey, portname);
46  return GetReader(ekey);
47  }
const Key_t nodekey
Definition: PseudoNode.h:88
shared_ptr< QueueReader > GetReader(Key_t ekey)
Definition: PseudoNode.cc:132
uint64_t Key_t
Definition: common.h:79
shared_ptr< Context > context
Definition: PseudoNode.h:96

+ Here is the call graph for this function:

Key_t CPN::PseudoNode::GetKey ( ) const
inline
Returns
the process network wide unique id for this node

Definition at line 43 of file PseudoNode.h.

Referenced by CPN::NodeBase::EntryPoint().

43 { return nodekey; }
const Key_t nodekey
Definition: PseudoNode.h:88

+ Here is the caller graph for this function:

const std::string& CPN::PseudoNode::GetName ( ) const
inline
Returns
the unique name of this node

Definition at line 40 of file PseudoNode.h.

Referenced by CPN::NodeBase::EntryPoint(), and CPN::NodeBase::GetParam().

40 { return name; }
const std::string name
Definition: PseudoNode.h:87

+ Here is the caller graph for this function:

shared_ptr< QueueWriter > CPN::PseudoNode::GetOQueue ( const std::string &  portname)

This method is for use by the user to aquire a writer endpoint. This function blocks until the CPN::Kernel hands this node the queue associated with the endpoint.

Parameters
portnamethe port name fo the writer to get.
Returns
a shared pointer to a writer for the given endpoint name.

Definition at line 49 of file PseudoNode.cc.

References context, GetWriter(), and nodekey.

49  {
50  context->CheckTerminated();
51  Key_t ekey = context->GetCreateWriterKey(nodekey, portname);
52  return GetWriter(ekey);
53  }
const Key_t nodekey
Definition: PseudoNode.h:88
shared_ptr< QueueWriter > GetWriter(Key_t ekey)
Definition: PseudoNode.cc:147
uint64_t Key_t
Definition: common.h:79
shared_ptr< Context > context
Definition: PseudoNode.h:96

+ Here is the call graph for this function:

shared_ptr< QueueReader > CPN::PseudoNode::GetReader ( Key_t  ekey)
private

Definition at line 132 of file PseudoNode.cc.

References cond, context, lock, readermap, and Sync::ReentrantCondition::Wait().

Referenced by GetIQueue().

132  {
134  shared_ptr<QueueReader> reader;
135  while (!reader) {
136  ReaderMap::iterator entry = readermap.find(ekey);
137  if (entry == readermap.end()) {
138  context->CheckTerminated();
139  cond.Wait(lock);
140  } else {
141  reader = shared_ptr<QueueReader>(entry->second);
142  }
143  }
144  return reader;
145  }
void Wait(ReentrantLock &lock) const
Sync::ReentrantLock lock
Definition: PseudoNode.h:85
ReaderMap readermap
Definition: PseudoNode.h:93
Sync::ReentrantCondition cond
Definition: PseudoNode.h:86
shared_ptr< Context > context
Definition: PseudoNode.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

shared_ptr< QueueWriter > CPN::PseudoNode::GetWriter ( Key_t  ekey)
private

Definition at line 147 of file PseudoNode.cc.

References cond, context, lock, Sync::ReentrantCondition::Wait(), and writermap.

Referenced by GetOQueue().

147  {
149  shared_ptr<QueueWriter> writer;
150  while (!writer) {
151  WriterMap::iterator entry = writermap.find(ekey);
152  if (entry == writermap.end()) {
153  context->CheckTerminated();
154  cond.Wait(lock);
155  } else {
156  writer = shared_ptr<QueueWriter>(entry->second);
157  }
158  }
159  return writer;
160 
161  }
void Wait(ReentrantLock &lock) const
WriterMap writermap
Definition: PseudoNode.h:94
Sync::ReentrantLock lock
Definition: PseudoNode.h:85
Sync::ReentrantCondition cond
Definition: PseudoNode.h:86
shared_ptr< Context > context
Definition: PseudoNode.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CPN::PseudoNode::IsPurePseudo ( )
virtual

Reimplemented in CPN::NodeBase.

Definition at line 163 of file PseudoNode.cc.

163  {
164  return true;
165  }
void CPN::PseudoNode::LogState ( )
virtual

For debugging ONLY!

Reimplemented in CPN::NodeBase.

Definition at line 167 of file PseudoNode.cc.

References D4R::Tag::Count(), d4rnode, Logger::Error(), D4R::Tag::Key(), logger, nodekey, D4R::Tag::QueueKey(), D4R::Tag::QueueSize(), readermap, and writermap.

Referenced by CPN::NodeBase::LogState().

167  {
168  logger.Error("Logging (key: %llu), %u readers, %u writers",
169  nodekey, readermap.size(), writermap.size());
170  D4R::Tag tag = d4rnode->GetPrivateTag();
171  logger.Error("Private key: (%llu, %llu, %llu, %llu)", tag.Count(), tag.Key(), tag.QueueSize(), tag.QueueKey());
172  tag = d4rnode->GetPublicTag();
173  logger.Error("Public key: (%llu, %llu, %llu, %llu)", tag.Count(), tag.Key(), tag.QueueSize(), tag.QueueKey());
174  ReaderMap::iterator r = readermap.begin();
175  while (r != readermap.end()) {
176  r->second->GetQueue()->LogState();
177  ++r;
178  }
179  WriterMap::iterator w = writermap.begin();
180  while (w != writermap.end()) {
181  w->second->GetQueue()->LogState();
182  ++w;
183  }
184  }
shared_ptr< D4R::Node > d4rnode
Definition: PseudoNode.h:89
const Key_t nodekey
Definition: PseudoNode.h:88
uint64_t QueueKey() const
Definition: D4RTag.h:71
WriterMap writermap
Definition: PseudoNode.h:94
void Error(const char *fmt,...)
Definition: Logger.cc:159
uint64_t Key() const
Definition: D4RTag.h:62
ReaderMap readermap
Definition: PseudoNode.h:93
uint64_t QueueSize() const
Definition: D4RTag.h:66
uint64_t Count() const
Definition: D4RTag.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CPN::PseudoNode::NotifyTerminate ( )

Called by the kernel when it is shutting down.

Definition at line 123 of file PseudoNode.cc.

References cond, lock, readermap, Sync::ReentrantCondition::Signal(), and writermap.

123  {
125  cond.Signal();
126  WriterMap::iterator witr = writermap.begin();
127  while (witr != writermap.end()) { (witr++)->second->NotifyTerminate(); }
128  ReaderMap::iterator ritr = readermap.begin();
129  while (ritr != readermap.end()) { (ritr++)->second->NotifyTerminate(); }
130  }
WriterMap writermap
Definition: PseudoNode.h:94
Sync::ReentrantLock lock
Definition: PseudoNode.h:85
ReaderMap readermap
Definition: PseudoNode.h:93
Sync::ReentrantCondition cond
Definition: PseudoNode.h:86

+ Here is the call graph for this function:

void CPN::PseudoNode::ReleaseReader ( Key_t  ekey)
privatevirtual

Implements CPN::QueueReleaser.

Definition at line 99 of file PseudoNode.cc.

References lock, readermap, and AutoLock< Lockable >::Unlock().

99  {
100  shared_ptr<QueueReader> reader;
102  ReaderMap::iterator entry = readermap.find(ekey);
103  if (entry != readermap.end()) {
104  reader = entry->second;
105  readermap.erase(entry);
106  }
107  arl.Unlock();
108  reader.reset();
109  }
Sync::ReentrantLock lock
Definition: PseudoNode.h:85
ReaderMap readermap
Definition: PseudoNode.h:93

+ Here is the call graph for this function:

void CPN::PseudoNode::ReleaseWriter ( Key_t  ekey)
privatevirtual

Implements CPN::QueueReleaser.

Definition at line 111 of file PseudoNode.cc.

References lock, AutoLock< Lockable >::Unlock(), and writermap.

111  {
112  shared_ptr<QueueWriter> writer;
114  WriterMap::iterator entry = writermap.find(ekey);
115  if (entry != writermap.end()) {
116  writer = entry->second;
117  writermap.erase(entry);
118  }
119  arl.Unlock();
120  writer.reset();
121  }
WriterMap writermap
Definition: PseudoNode.h:94
Sync::ReentrantLock lock
Definition: PseudoNode.h:85

+ Here is the call graph for this function:

void CPN::PseudoNode::Shutdown ( )
virtual

Perform actions (like joining a thread) before destruction.

Reimplemented in CPN::NodeBase.

Definition at line 81 of file PseudoNode.cc.

References lock, readermap, AutoLock< Lockable >::Unlock(), and writermap.

Referenced by CPN::NodeBase::Shutdown().

81  {
83  ReaderMap readers;
84  readers.swap(readermap);
85  WriterMap writers;
86  writers.swap(writermap);
87  arl.Unlock();
88  for (ReaderMap::iterator i = readers.begin(); i != readers.end(); ++i) {
89  i->second->GetQueue()->ShutdownReader();
90  }
91  for (WriterMap::iterator i = writers.begin(); i != writers.end(); ++i) {
92  i->second->GetQueue()->ShutdownWriter();
93  }
94  readers.clear();
95  writers.clear();
96 
97  }
WriterMap writermap
Definition: PseudoNode.h:94
Sync::ReentrantLock lock
Definition: PseudoNode.h:85
std::map< Key_t, shared_ptr< QueueWriter > > WriterMap
Definition: PseudoNode.h:92
ReaderMap readermap
Definition: PseudoNode.h:93
std::map< Key_t, shared_ptr< QueueReader > > ReaderMap
Definition: PseudoNode.h:91

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

Sync::ReentrantCondition CPN::PseudoNode::cond
private

Definition at line 86 of file PseudoNode.h.

Referenced by CreateReader(), CreateWriter(), GetReader(), GetWriter(), and NotifyTerminate().

shared_ptr<Context> CPN::PseudoNode::context
private

Definition at line 96 of file PseudoNode.h.

Referenced by GetIQueue(), GetOQueue(), GetReader(), and GetWriter().

shared_ptr<D4R::Node> CPN::PseudoNode::d4rnode
private

Definition at line 89 of file PseudoNode.h.

Referenced by CreateReader(), CreateWriter(), and LogState().

Sync::ReentrantLock CPN::PseudoNode::lock
private
Logger CPN::PseudoNode::logger
protected

Definition at line 76 of file PseudoNode.h.

Referenced by CPN::NodeBase::EntryPoint(), LogState(), and CPN::NodeBase::LogState().

const std::string CPN::PseudoNode::name
private

Definition at line 87 of file PseudoNode.h.

const Key_t CPN::PseudoNode::nodekey
private

Definition at line 88 of file PseudoNode.h.

Referenced by GetIQueue(), GetOQueue(), and LogState().

ReaderMap CPN::PseudoNode::readermap
private

Definition at line 93 of file PseudoNode.h.

Referenced by CreateReader(), GetReader(), LogState(), NotifyTerminate(), ReleaseReader(), and Shutdown().

WriterMap CPN::PseudoNode::writermap
private

Definition at line 94 of file PseudoNode.h.

Referenced by CreateWriter(), GetWriter(), LogState(), NotifyTerminate(), ReleaseWriter(), and Shutdown().


The documentation for this class was generated from the following files: