CPN
Computational Process Networks
RemoteContextDaemon.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 REMOTECONTEXTDAEMON_H
24 #define REMOTECONTEXTDAEMON_H
25 #pragma once
26 #include <cpn/common.h>
28 #include <cpn/io/SocketHandle.h>
30 #include <Variant/Variant.h>
31 #include <string>
32 #include <tr1/memory>
33 #include <memory>
34 
35 namespace CPN {
36 
42  public:
44  RemoteContextDaemon(const SockAddrList &addrs);
50  void Run();
51 
52  private:
53  // These functions are for the Client
55  void Terminate();
56  void Terminate(const std::string &name);
57 
58  void Read();
59  void SendMessage(const std::string &recipient, const Variant &msg);
60  void BroadcastMessage(const Variant &msg);
61  void LogMessage(const std::string &msg);
62 
63  class Client : public SocketHandle {
64  public:
65  Client(RemoteContextDaemon *d, int nfd);
66  void Read();
67  void Send(const Variant &msg);
68  const std::string &GetName() const { return name; }
69  private:
71  std::string name;
72  };
73  friend class Client;
74  typedef std::tr1::shared_ptr<Client> ClientPtr;
75  typedef std::map<std::string, ClientPtr> ClientMap;
76 
78  };
79 
80 }
81 #endif
An abstraction of a socket address with convenience methods.
Definition: SocketAddress.h:42
A FileHandle customized with some socket specific functionality and functions.
Definition: SocketHandle.h:34
const std::string & GetName() const
std::map< std::string, ClientPtr > ClientMap
std::tr1::shared_ptr< Client > ClientPtr
void DispatchMessage(const std::string &sender, const Variant &msg)
Process the given message.
std::vector< SocketAddress > SockAddrList
Definition: SocketAddress.h:35
#define CPN_API
Definition: common.h:36
the server for the remote context.