CPN
Computational Process Networks
LocalContext.h
Go to the documentation of this file.
1 //=============================================================================
2 // Computational Process Networks class library
3 // Copyright (C) 1997-2006 Gregory E. Allen and The University of Texas
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Library General Public License as published
7 // by the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
14 //
15 // The GNU Public License is available in the file LICENSE, or you
16 // can write to the Free Software Foundation, Inc., 59 Temple Place -
17 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
18 // World Wide Web at http://www.fsf.org.
19 //=============================================================================
26 #ifndef CPN_LOCALCONTEXT_H
27 #define CPN_LOCALCONTEXT_H
28 #pragma once
29 #include "common_priv.h"
30 #include <cpn/Context.h>
33 #include <string>
34 #include <map>
35 
36 namespace CPN {
37 
40  class CPN_LOCAL LocalContext : public Context {
41  public:
42  typedef std::map< std::string, Key_t > NameMap;
43 
45  struct KernelInfo {
46  std::string name;
47  std::string hostname;
48  std::string servname;
50  bool live;
51  bool dead;
53  };
54 
56  struct NodeInfo {
57  std::string name;
59  bool started;
62  bool dead;
63  };
64 
66  struct PortInfo {
67  std::string name;
68  std::string qname;
71  bool dead;
72  };
73 
74  typedef std::map< Key_t, shared_ptr<KernelInfo> > KernelMap;
75  typedef std::map< Key_t, shared_ptr<NodeInfo> > NodeMap;
76  typedef std::map< Key_t, shared_ptr<PortInfo> > PortMap;
77 
78  LocalContext();
79  virtual ~LocalContext();
80 
81  virtual void Log(int level, const std::string &msg);
82  virtual int LogLevel() const;
83  virtual int LogLevel(int level);
84 
85  virtual Key_t SetupKernel(const std::string &name, const std::string &hostname,
86  const std::string &servname, KernelBase *kernel);
87  virtual Key_t SetupKernel(const std::string &name, KernelBase *kernel);
88  virtual Key_t GetKernelKey(const std::string &kernel);
89  virtual std::string GetKernelName(Key_t kernelkey);
90  virtual void GetKernelConnectionInfo(Key_t kernelkey, std::string &hostname, std::string &servname);
91  virtual void SignalKernelEnd(Key_t kernelkey);
92  virtual Key_t WaitForKernelStart(const std::string &kernel);
93  virtual void SignalKernelStart(Key_t kernelkey);
94 
95  virtual void SendCreateWriter(Key_t kernelkey, const SimpleQueueAttr &attr);
96  virtual void SendCreateReader(Key_t kernelkey, const SimpleQueueAttr &attr);
97  virtual void SendCreateQueue(Key_t kernelkey, const SimpleQueueAttr &attr);
98  virtual void SendCreateNode(Key_t kernelkey, const NodeAttr &attr);
99 
100  virtual Key_t CreateNodeKey(Key_t kernelkey, const std::string &nodename);
101  virtual Key_t GetNodeKey(const std::string &nodename);
102  virtual std::string GetNodeName(Key_t nodekey);
103  virtual Key_t GetNodeKernel(Key_t nodekey);
104  virtual void SignalNodeStart(Key_t nodekey);
105  virtual void SignalNodeEnd(Key_t nodekey);
106  virtual Key_t WaitForNodeStart(const std::string &nodename);
107  virtual void WaitForNodeEnd(const std::string &nodename);
108  virtual void WaitForAllNodeEnd();
109 
110  virtual Key_t GetCreateReaderKey(Key_t nodekey, const std::string &portname);
111  virtual Key_t GetReaderNode(Key_t portkey);
112  virtual Key_t GetReaderKernel(Key_t portkey);
113  virtual std::string GetReaderName(Key_t portkey);
114 
115  virtual Key_t GetCreateWriterKey(Key_t nodekey, const std::string &portname);
116  virtual Key_t GetWriterNode(Key_t portkey);
117  virtual Key_t GetWriterKernel(Key_t portkey);
118  virtual std::string GetWriterName(Key_t portkey);
119 
120  virtual void ConnectEndpoints(Key_t writerkey, Key_t readerkey, const std::string &qname);
121  virtual Key_t GetReadersWriter(Key_t readerkey);
122  virtual Key_t GetWritersReader(Key_t writerkey);
123 
124  virtual void Terminate();
125  virtual bool IsTerminated();
126  private:
127 
128  void InternalCheckTerminated();
129 
130  int loglevel;
140  unsigned numlivenodes;
141  bool shutdown;
142 
143  Key_t NewKey() { return ++counter; }
145  };
146 
147 }
148 
149 #endif
150 
std::map< Key_t, shared_ptr< KernelInfo > > KernelMap
Definition: LocalContext.h:74
Attributes for a node.
Definition: NodeAttr.h:58
unsigned numlivenodes
Definition: LocalContext.h:140
The Context abstract data type.
uint64_t Key_t
Definition: common.h:79
std::map< Key_t, shared_ptr< NodeInfo > > NodeMap
Definition: LocalContext.h:75
A local implementation of the Context interface.
Definition: LocalContext.h:40
#define CPN_LOCAL
Definition: common.h:37
The CPN::Context abstraction that holds all the global state for the process network.
Definition: Context.h:47
KernelMap kernelmap
Definition: LocalContext.h:136
PthreadCondition kernellivedead
Definition: LocalContext.h:133
PthreadMutex lock
Definition: LocalContext.h:131
std::map< std::string, Key_t > NameMap
Definition: LocalContext.h:42
std::map< Key_t, shared_ptr< PortInfo > > PortMap
Definition: LocalContext.h:76
PthreadCondition nodelivedead
Definition: LocalContext.h:132
This is a simplified internal representation of the queue attributes needed to create a queue...
Definition: QueueAttr.h:237