00001 //////////////////////////////////////////////////////////////////////////////// 00002 /*! \file CommFactory.h 00003 * \brief Declares the classes that know how to set up the comm network. 00004 * \author $Author: rsharo $ 00005 * \version $Revision: 1.1 $ 00006 * \date $Date: 2004/04/07 13:45:04 $ 00007 */////////////////////////////////////////////////////////////////////////////// 00008 #ifndef COMM_FACTORY_H 00009 #define COMM_FACTORY_H 00010 00011 class SystemProperties; 00012 class ACE_Reactor; 00013 class AddressServer; 00014 class AddressClient; 00015 class MessageServer; 00016 00017 #include "Comm/ReactorThread.h" 00018 00019 // 00020 // This interface class defines the methods of a communication factory. 00021 // A communication factory knows how to construct and configure 00022 // the components necessary to communicate using the 00023 // MessageClient/MessageServer scheme. 00024 class CommFactory 00025 { 00026 protected: 00027 // 00028 // Constructs a CommFactory. Since this is an abstract 00029 // base class, this method is protected. 00030 CommFactory() {} 00031 00032 public: 00033 // 00034 // Destroys a CommFactory. This is a virtual 00035 // destructor that does nothing by itself. 00036 virtual ~CommFactory() {} 00037 00038 // 00039 // Provides access to a functional AddressServer. 00040 // The server should already be initialized and ready for use. 00041 // Returns a pointer to an AddressServer, or NULL 00042 // if none is available. 00043 virtual AddressServer *GetAddressServer() = 0; 00044 00045 // 00046 // Provides access to a functional AddressClient. 00047 // The client should already be initialized and ready for use. 00048 // Returns a pointer to an AddressClient, or NULL 00049 // if none is available. 00050 virtual AddressClient *GetAddressClient() = 0; 00051 00052 // 00053 // Provides access to a functional MessageServer. 00054 // The server should already be initialized and ready for use. 00055 // Returns a pointer to an MessageServer, or NULL 00056 // if none is available. 00057 virtual MessageServer *GetMessageServer() = 0; 00058 00059 // 00060 // Provides access to a functional reactor. 00061 // The reactor should already be initialized and ready for use. 00062 // Returns a pointer to a reactor, or NULL 00063 // if none is available. 00064 virtual ACE_Reactor * GetReactor() = 0; 00065 }; 00066 00067 00068 // 00069 // A CommFactory that can be configured from a SystemProperties object. 00070 // A SystemProperties object can either be read from a configuration file 00071 // or populated programmatically. 00072 // This class reads all the information needed to configure a Comm 00073 // setup from a SystemProperties object. Default values are substituted 00074 // for anything not specified in the properties. 00075 // 00076 // The following is a sample INI-style property file that sets all 00077 // configuration fields to their default values. To use this file, Open 00078 // would be called with the section name "MyServer\\Comm". 00079 // 00080 // ############################################################################## 00081 // # Comm configuration file for MyServer 00082 // ############################################################################## 00083 // [MyServer\Comm] 00084 // 00085 // #----------------------------------------------------------------------------- 00086 // # The following fields specify where to find the address server. 00087 // # The host field is either a multicast IP address or "DEFAULT" 00088 // # The port field is either an IP port number or "DEFAULT" 00089 // # The timeout field says how many seconds we're willing to wait 00090 // # to talk with the address server before giving up and calling it an error. 00091 // # A timeout of zero mean "wait forever" 00092 // #----------------------------------------------------------------------------- 00093 // AddrServerHost = DEFAULT 00094 // AddrServerPort = DEFAULT 00095 // AddrServerTimeout = 0 00096 // 00097 // #----------------------------------------------------------------------------- 00098 // # Fields to create/configure an address server in this process. 00099 // # 00100 // # You should have exactly one address server running on the network at any 00101 // # time. 00102 // # 00103 // # AddrServerAutoDetect tells the factory to look on the network for a 00104 // # server if it doesn't find one in 5 attempts (takes 5 seconds), it will 00105 // # spawn its own. 00106 // # 00107 // # SpawnAddrServer tells the factory to spawn an address server. Use this 00108 // # if you always start the applications in a specific order. If 00109 // # AddrServerAutoDetect is enabled, it supercedes any setting to 00110 // # SpawnAddrServer. Note that only one process on the network should have 00111 // # this field set to true. 00112 // # 00113 // # Normally loopback will be enabled for this application. If its disabled 00114 // # then the process will only be able to function as a standalone address 00115 // # server -- message clients won't work. 00116 // # 00117 // # The time to live (AddrServerTTL) field decides whether the address 00118 // # server can talk through network routers. A value of one means it can't. 00119 // # For each value higher, the address server can talk through one router. 00120 // # Unless your project spans several subnets, leave this value at one. 00121 // # 00122 // # The AddrServerInterface field determines which ethernet adapter the 00123 // # address server will listen on. If your computer has multiple network 00124 // # ports, this should be set to the one you share with other processes in 00125 // # this application. If you want to bridge multiple adapters, leave this 00126 // # field as "". On Windoze machines, an interface is specified by its 00127 // # network address, for example, "192.168.0.1". 00128 // # On linux/unix flavors, its specified as the device name, 00129 // # for example, "eth1". 00130 // #----------------------------------------------------------------------------- 00131 // AddrServerAutoDetect = TRUE 00132 // SpawnAddrServer = FALSE 00133 // AddrServerLoopback = TRUE 00134 // AddrServerTTL = 1 00135 // AddrServerInterface = "" 00136 00137 // #----------------------------------------------------------------------------- 00138 // # Fields to determine how Comm handles messages. 00139 // # 00140 // # NumReactorThreads determines how many threads to allocate to Comm. You 00141 // # need at least 1 thread if you don't create a local address server, and 00142 // # you at least 2 if you do. If you're auto-detecting, you should be sure 00143 // # to budget that extra thread... 00144 // #----------------------------------------------------------------------------- 00145 // NumReactorThreads = 2 00146 // 00147 // ############################################################################## 00148 // # End MyServer\Comm 00149 // ############################################################################## 00150 class PropertyBasedCommFactory : public CommFactory 00151 { 00152 public: 00153 // 00154 // Default constructor for a PropertyBasedCommFactory. 00155 // The factory will not be useful until Open() is called. 00156 PropertyBasedCommFactory(); 00157 00158 // 00159 // Constructor for a PropertyBasedCommFactory. 00160 // Constructs the factory and configures its components. 00161 // Note that this constructor can't return an error code on 00162 // failure. If there's any chance that configuration will fail, 00163 // the default constructor should instead be used with an explicit 00164 // call to Open(). 00165 PropertyBasedCommFactory(SystemProperties &props, const char *mySection); 00166 00167 // 00168 // Destroys the CommFactory and all its components. 00169 // If Close() has not already been called, it will be called 00170 // from the destructor. 00171 virtual ~PropertyBasedCommFactory(); 00172 00173 // 00174 // Configures the factory's components for comm. The specified 00175 // section of the system properties will be read to determine 00176 // how comm should be configured. If the specified section is not found, 00177 // a default configuration will be used (with a logged warning). 00178 // Returns 0 on success or -1 on failure. 00179 virtual int Open(SystemProperties &props, const char *mySection); 00180 00181 // 00182 // Closes down the factory's comm components. Message clients 00183 // will no longer be able to send/receive messages. 00184 // Returns 0 on success or -1 on failure. 00185 int Close(); 00186 00187 // 00188 // Returns the factory's address server. 00189 // Returns a pointer to the factory's address server, or NULL 00190 // if no local address server was constructed. 00191 virtual AddressServer *GetAddressServer() { return m_pAddressServer; } 00192 00193 // 00194 // Returns the factory's address client. 00195 // Returns a pointer to the factory's address client, or NULL 00196 // if no address client is available. 00197 virtual AddressClient *GetAddressClient() { return m_pAddressClient; } 00198 00199 // 00200 // Returns the factory's message server. Message clients will typically 00201 // get the message server using this method and register themselves 00202 // with the returned object. Returns a pointer to the factory's message 00203 // server, or NULL if no message server is available. 00204 virtual MessageServer *GetMessageServer() { return m_pMessageServer; } 00205 00206 // 00207 // Provides access to a the factory's reactor. 00208 // Returns a pointer to the reactor, or NULL if no reactor is available. 00209 virtual ACE_Reactor * GetReactor() { return m_pReactor; } 00210 00211 protected: 00212 ACE_Reactor * m_pReactor; 00213 ReactorThread * m_pReactorThread; 00214 AddressClient * m_pAddressClient; 00215 AddressServer * m_pAddressServer; 00216 MessageServer * m_pMessageServer; 00217 }; 00218 00219 00220 #endif // COMM_FACTORY_H 00221