root/juggler/branches/2.2/modules/gadgeteer/gadget/AbstractNetworkManager.h
| Revision 20010, 6.0 kB (checked in by aronb, 1 year ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /*************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 2 | * |
| 3 | * VR Juggler is (C) Copyright 1998-2007 by Iowa State University |
| 4 | * |
| 5 | * Original Authors: |
| 6 | * Allen Bierbaum, Christopher Just, |
| 7 | * Patrick Hartling, Kevin Meinert, |
| 8 | * Carolina Cruz-Neira, Albert Baker |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Library General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Library General Public |
| 21 | * License along with this library; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 02111-1307, USA. |
| 24 | * |
| 25 | *************** <auto-copyright.pl END do not edit this line> ***************/ |
| 26 | |
| 27 | #ifndef _GADGET_ABSTRACT_NETWORK_MANAGER_H |
| 28 | #define _GADGET_ABSTRACT_NETWORK_MANAGER_H |
| 29 | |
| 30 | #include <gadget/gadgetConfig.h> |
| 31 | |
| 32 | #include <map> |
| 33 | |
| 34 | #include <vpr/IO/Socket/SocketStream.h> |
| 35 | #include <vpr/Util/GUID.h> |
| 36 | |
| 37 | #include <jccl/RTRC/ConfigElementHandler.h> |
| 38 | #include <jccl/Config/ConfigElementPtr.h> |
| 39 | |
| 40 | #include <gadget/Connector.h> |
| 41 | #include <gadget/Reactor.h> |
| 42 | |
| 43 | |
| 44 | namespace cluster |
| 45 | { |
| 46 | class Packet; |
| 47 | } |
| 48 | |
| 49 | namespace gadget |
| 50 | { |
| 51 | class Node; |
| 52 | class PacketHandler; |
| 53 | |
| 54 | /** \class AbstractNetworkManager AbstractNetworkManager.h gadget/AbstractNetworkManager.h |
| 55 | * |
| 56 | * Network abstraction. |
| 57 | */ |
| 58 | class GADGET_CLASS_API AbstractNetworkManager : public jccl::ConfigElementHandler |
| 59 | { |
| 60 | public: |
| 61 | /** |
| 62 | * Construct an empty representation of a network. |
| 63 | */ |
| 64 | AbstractNetworkManager(); |
| 65 | |
| 66 | /** |
| 67 | * Disconnect all nodes in network and release memory. |
| 68 | */ |
| 69 | virtual ~AbstractNetworkManager(); |
| 70 | |
| 71 | private: |
| 72 | AbstractNetworkManager(const AbstractNetworkManager& anm) |
| 73 | : jccl::ConfigElementHandler(anm) |
| 74 | {;} |
| 75 | void operator=(const AbstractNetworkManager&) |
| 76 | {;} |
| 77 | public: |
| 78 | |
| 79 | /** |
| 80 | * Process an incoming packet. |
| 81 | */ |
| 82 | void handlePacket(cluster::Packet* packet, Node* node); |
| 83 | |
| 84 | void updateNewConnections(); |
| 85 | |
| 86 | /** |
| 87 | * Creates a Node with the given parameters and adds |
| 88 | * this new node the std::map of Nodes. |
| 89 | * |
| 90 | * The caller of this method mustlock the Nodes list |
| 91 | * first by callinf lockNodes() |
| 92 | */ |
| 93 | bool addNode(const std::string& name, const std::string& host_name, |
| 94 | const vpr::Uint16& port, |
| 95 | vpr::SocketStream* socketStream = NULL); |
| 96 | |
| 97 | /** |
| 98 | * Adds the given Node to the std::map of Nodes |
| 99 | * |
| 100 | * The caller of this method mustlock the Nodes list |
| 101 | * first by callinf lockNodes() |
| 102 | */ |
| 103 | void addNode(Node* node); |
| 104 | |
| 105 | /** |
| 106 | * Removes the Node with the given hostname |
| 107 | */ |
| 108 | void removeNode(const std::string& nodeHostname); |
| 109 | |
| 110 | public: |
| 111 | /** |
| 112 | * Returns the Node with the given hostname |
| 113 | * If no Node with this hostname exists, NULL is returned. |
| 114 | */ |
| 115 | gadget::Node* getNodeByHostname(const std::string& host_name); |
| 116 | |
| 117 | /** |
| 118 | * Returns the Node with the given name |
| 119 | * If no Node with this name exists, NULL is returned. |
| 120 | */ |
| 121 | gadget::Node* getNodeByName(const std::string& node_name); |
| 122 | |
| 123 | /** |
| 124 | * Get the number of nodes in network. |
| 125 | */ |
| 126 | size_t getNumNodes() |
| 127 | { |
| 128 | return mNodes.size(); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Print out debug information about all nodes. |
| 133 | */ |
| 134 | void debugDumpNodes(int debug_level); |
| 135 | |
| 136 | Reactor& getReactor() |
| 137 | { |
| 138 | return mReactor; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Get an iterator to the beginning of the Nodes std::vector. |
| 143 | * The caller of this method must have locked the Nodes list. |
| 144 | */ |
| 145 | std::vector<gadget::Node*>::iterator getNodesBegin() |
| 146 | { |
| 147 | return mNodes.begin(); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Get an iterator to the end of the Nodes std::vector. |
| 152 | * The caller of this method must have locked the Nodes list. |
| 153 | */ |
| 154 | std::vector<gadget::Node*>::iterator getNodesEnd() |
| 155 | { |
| 156 | return mNodes.end(); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Return the number of Nodes in the Pending Nodes list. |
| 161 | */ |
| 162 | vpr::Uint16 getNumPendingNodes(); |
| 163 | |
| 164 | private: |
| 165 | /** |
| 166 | * Attempt to connect to all Nodes in the PendingNodes list. |
| 167 | */ |
| 168 | bool attemptPendingNodes(); |
| 169 | |
| 170 | public: |
| 171 | /** |
| 172 | * Kill the listen thread and the update thread |
| 173 | */ |
| 174 | void shutdown(); |
| 175 | |
| 176 | public: |
| 177 | /** |
| 178 | * Determine if the given jccl::ConfigElement is a cluster_node element. |
| 179 | */ |
| 180 | bool recognizeClusterMachineConfig(jccl::ConfigElementPtr element); |
| 181 | |
| 182 | /** |
| 183 | * Determine if we can handle the given jccl::ConfigElement. |
| 184 | */ |
| 185 | bool configCanHandle(jccl::ConfigElementPtr element); |
| 186 | |
| 187 | /** |
| 188 | * Configure the given jccl::ConfigElement because it was just added to |
| 189 | * the active configuration. |
| 190 | * |
| 191 | * @return true If we successfully configured the given cluster_node |
| 192 | * element. |
| 193 | * @return false If we failed to configure the given cluster_node element. |
| 194 | */ |
| 195 | bool configAdd(jccl::ConfigElementPtr element); |
| 196 | |
| 197 | /** |
| 198 | * Return the element type for cluster_node element that we configure |
| 199 | * here. |
| 200 | */ |
| 201 | static std::string getClusterNodeElementType(); |
| 202 | |
| 203 | /** |
| 204 | * Remove the given jccl::ConfigElement from the active configuration . |
| 205 | * |
| 206 | * @return true If we successfully removed the given cluster_node element. |
| 207 | * @return false If we failed to removed the given cluster_node element. |
| 208 | */ |
| 209 | bool configRemove(jccl::ConfigElementPtr element); |
| 210 | |
| 211 | /** |
| 212 | * Determine if the given hostname matches the local machine's hostname. |
| 213 | */ |
| 214 | static bool isLocalHost(const std::string& testHostName); |
| 215 | |
| 216 | PacketHandler* getHandlerByGUID(const vpr::GUID& handler_guid); |
| 217 | void addHandler(PacketHandler* new_handler); |
| 218 | |
| 219 | virtual bool attemptConnect(Node* node) = 0; |
| 220 | virtual void startListening(int listen_port, bool accept_anonymous) = 0; |
| 221 | |
| 222 | private: |
| 223 | std::vector<gadget::Node*> mNodes; /**< List of nodes in network. */ |
| 224 | |
| 225 | std::map<vpr::GUID, PacketHandler*> mHandlerMap; |
| 226 | Reactor mReactor; |
| 227 | }; |
| 228 | |
| 229 | } // end namespace gadget |
| 230 | |
| 231 | #endif |
Note: See TracBrowser for help on using the browser.
