CPN
Computational Process Networks
RemoteContextServer.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 //=============================================================================
23 #ifndef CPN_REMOTECONTEXTSERVER_H
24 #define CPN_REMOTECONTEXTSERVER_H
25 #pragma once
26 #include <cpn/common.h>
27 #include <Variant/Variant.h>
28 
29 /*
30  All requests have a field named 'type' which contains a number from RCTXMT_t.
31  The basic form is:
32 
33  request = {
34  "type" : message type number,
35  "msgid" : (optional) an id that should be passed back with any reply,
36  ... data members of the request ...
37  dependent on type common ones are "key" and "name"
38  }
39 
40  Replies will be of the form:
41 
42  reply = {
43  "msgid" : message id from request,
44  "msgtype" : "reply",
45  "success" : true or false,
46  then the data under the name of the type of reply data
47  "kernelinfo" or "nodeinfo" or "endpointinfo" etc.
48  }
49 
50  There is another type of message called broadcast that is sent out by
51  the server on certain events.
52 
53  broadcast = {
54  "msgtype" : "broadcast",
55  then "kernelinfo" or "nodeinfo" etc.
56  then some status variables like "numlivenodes"
57  }
58 
59  The final type of message is the one that is for inter kernel communication
60  these messages are simply routed to the kernel that should recieve it.
61 
62  kernel = {
63  "msgtype" : "kernel",
64  "kernelkey" : the destination kernel key,
65  "type" : numberic message type,
66  then "queueattr" or "nodeattr" or other data
67  }
68 
69  the basic storage elements use these formats
70 
71  kernelinfo = {
72  "key" : key for the kernel,
73  "name" : name of the kernel,
74  "hostname" : name to use for other kernels to connect to this one,
75  "servname" : service name to use to connecto to this kernel,
76  "live" : true or false,
77  "type" : "endpointinfo",
78  "client" : the name of the RemoteContextClient that we are to send kernel message to
79  }
80 
81  nodeinfo = {
82  "key" : the node key,
83  "name" : name of this node,
84  "kernelkey" : the kernel key,
85  "started" : true or false,
86  "dead" : true or false,
87  "endpoints" : {
88  "endpointname" : key of endpoint,
89  ...
90  },
91  "type" : "endpointinfo"
92  }
93 
94  endpointinfo = {
95  "key" : The key for this endpoint,
96  "name" : the name of this endpoint,
97  "qname" : the name of the queue if set and connected
98  "nodekey" : The key of the node this endpoint belongs to,
99  "kernelkey" : the key of the kernel this node endpoint is on,
100  "live" : true or false
101  "writerkey" : the key of the writer this endpoint is connected to if a reader,
102  "readerkey" : the key of the reader this endpoint is connected to if a writer,
103  "type" : "endpointinfo"
104  }
105 
106 */
107 
108 namespace CPN {
115  public:
117  virtual ~RemoteContextServer();
121  virtual void Terminate();
125  bool IsTerminated() const { return shutdown; }
126  int DebugLevel() const { return debuglevel; }
127  int DebugLevel(int level) { return debuglevel = level; }
128  protected:
134  void DispatchMessage(const std::string &sender, const Variant &msg);
139  virtual void SendMessage(const std::string &recipient, const Variant &msg) = 0;
143  virtual void BroadcastMessage(const Variant &msg) = 0;
147  virtual void LogMessage(const std::string &msg) = 0;
148 
149  void dbprintf(int level, const char *fmt, ...);
150  private:
151 
152  void SetupKernel(const std::string &sender, const Variant &msg);
153  void SignalKernelStart(const Variant &msg);
154  void SignalKernelEnd(const Variant &msg);
155  void GetKernelInfo(const std::string &sender, const Variant &msg);
156  void CreateNodeKey(const std::string &sender, const Variant &msg);
157  void SignalNodeStart(const Variant &msg);
158  void SignalNodeEnd(const Variant &msg);
159  void GetNodeInfo(const std::string &sender, const Variant &msg);
160  void GetNumNodeLive(const std::string &sender, const Variant &msg);
161  void GetCreateEndpointKey(const std::string &sender, const Variant &msg);
162  void GetEndpointInfo(const std::string &sender, const Variant &msg);
163  void ConnectEndpoints(const Variant &msg);
164 
165  Key_t NewKey();
166 
167  void RouteKernelMessage(const Variant &msg);
168  Variant NewBroadcastMessage();
169 
170  typedef std::map<Key_t, Variant> DataMap;
172  typedef std::map<std::string, Key_t> NameKeyMap;
175 
177  bool shutdown;
178  unsigned numlivenodes;
179 
181  };
182 }
183 #endif
void GetNodeInfo(const std::string &sender, const Variant &msg)
virtual void SendMessage(const std::string &recipient, const Variant &msg)=0
Send the given message to the given client.
void ConnectEndpoints(const Variant &msg)
void GetKernelInfo(const std::string &sender, const Variant &msg)
virtual void LogMessage(const std::string &msg)=0
Log a message.
uint64_t Key_t
Definition: common.h:79
void GetNumNodeLive(const std::string &sender, const Variant &msg)
void dbprintf(int level, const char *fmt,...)
void SignalKernelStart(const Variant &msg)
virtual void BroadcastMessage(const Variant &msg)=0
Broadcast a message to all clients.
void GetEndpointInfo(const std::string &sender, const Variant &msg)
void SignalNodeEnd(const Variant &msg)
void RouteKernelMessage(const Variant &msg)
void DispatchMessage(const std::string &sender, const Variant &msg)
Process the given message.
std::map< std::string, Key_t > NameKeyMap
void SignalNodeStart(const Variant &msg)
void CreateNodeKey(const std::string &sender, const Variant &msg)
void SetupKernel(const std::string &sender, const Variant &msg)
void SignalKernelEnd(const Variant &msg)
void GetCreateEndpointKey(const std::string &sender, const Variant &msg)
std::map< Key_t, Variant > DataMap
the server for the remote context.