CPN
Computational Process Networks
Public Member Functions | Protected Attributes | Private Attributes | List of all members
CPN::ExternalEndpoint Class Reference
+ Inheritance diagram for CPN::ExternalEndpoint:
+ Collaboration diagram for CPN::ExternalEndpoint:

Public Member Functions

 ExternalEndpoint (const std::string &name, Key_t nodekey, shared_ptr< Context > context, bool iswriter_)
 
virtual ~ExternalEndpoint ()
 
bool IsWriter () const
 
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 Attributes

bool iswriter
 

Detailed Description

Definition at line 166 of file Kernel.cc.

Constructor & Destructor Documentation

CPN::ExternalEndpoint::ExternalEndpoint ( const std::string &  name,
Key_t  nodekey,
shared_ptr< Context context,
bool  iswriter_ 
)
inline

Definition at line 168 of file Kernel.cc.

170  : PseudoNode(name, nodekey, context), iswriter(iswriter_) {}
const std::string name
Definition: PseudoNode.h:87
const Key_t nodekey
Definition: PseudoNode.h:88
PseudoNode(const std::string &name_, Key_t k, shared_ptr< Context > ctx)
Definition: PseudoNode.cc:31
shared_ptr< Context > context
Definition: PseudoNode.h:96
virtual CPN::ExternalEndpoint::~ExternalEndpoint ( )
inlinevirtual

Definition at line 171 of file Kernel.cc.

171 {}

Member Function Documentation

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

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

Definition at line 55 of file PseudoNode.cc.

References ASSERT, CPN::PseudoNode::cond, CPN::PseudoNode::d4rnode, CPN::PseudoNode::lock, CPN::PseudoNode::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)
inherited

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

Definition at line 68 of file PseudoNode.cc.

References ASSERT, CPN::PseudoNode::cond, CPN::PseudoNode::d4rnode, CPN::PseudoNode::lock, Sync::ReentrantCondition::Signal(), and CPN::PseudoNode::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)
inherited

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 CPN::PseudoNode::context, CPN::PseudoNode::GetReader(), and CPN::PseudoNode::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
inlineinherited
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
inlineinherited
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)
inherited

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 CPN::PseudoNode::context, CPN::PseudoNode::GetWriter(), and CPN::PseudoNode::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:

bool CPN::PseudoNode::IsPurePseudo ( )
virtualinherited

Reimplemented in CPN::NodeBase.

Definition at line 163 of file PseudoNode.cc.

163  {
164  return true;
165  }
bool CPN::ExternalEndpoint::IsWriter ( ) const
inline

Definition at line 173 of file Kernel.cc.

References iswriter.

173 { return iswriter; }
void CPN::PseudoNode::LogState ( )
virtualinherited

For debugging ONLY!

Reimplemented in CPN::NodeBase.

Definition at line 167 of file PseudoNode.cc.

References D4R::Tag::Count(), CPN::PseudoNode::d4rnode, Logger::Error(), D4R::Tag::Key(), CPN::PseudoNode::logger, CPN::PseudoNode::nodekey, D4R::Tag::QueueKey(), D4R::Tag::QueueSize(), CPN::PseudoNode::readermap, and CPN::PseudoNode::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 ( )
inherited

Called by the kernel when it is shutting down.

Definition at line 123 of file PseudoNode.cc.

References CPN::PseudoNode::cond, CPN::PseudoNode::lock, CPN::PseudoNode::readermap, Sync::ReentrantCondition::Signal(), and CPN::PseudoNode::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::Shutdown ( )
virtualinherited

Perform actions (like joining a thread) before destruction.

Reimplemented in CPN::NodeBase.

Definition at line 81 of file PseudoNode.cc.

References CPN::PseudoNode::lock, CPN::PseudoNode::readermap, AutoLock< Lockable >::Unlock(), and CPN::PseudoNode::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

bool CPN::ExternalEndpoint::iswriter
private

Definition at line 175 of file Kernel.cc.

Referenced by IsWriter().

Logger CPN::PseudoNode::logger
protectedinherited

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