Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

GlobalObjects.cpp

Go to the documentation of this file.
00001 #include "headers.h"
00002 
00003 GlobalObjects* GlobalObjects::m_globalObjects = NULL;
00004 
00005 GlobalObjects*
00006 GlobalObjects::instance() {
00007     if (m_globalObjects == NULL) {
00008         // Note: it is absolutely necessary that this is a two-stage process, because some of the
00009         // objects in "init" require globalObjects to exist!
00010         m_globalObjects = new GlobalObjects();
00011         m_globalObjects->init();
00012     }
00013     return m_globalObjects;
00014 } // fn instance
00015 
00016 
00017 void
00018 GlobalObjects::destroy() {
00019     if (m_globalObjects != NULL) {
00020         m_globalObjects->destroyImpl();
00021         delete m_globalObjects;
00022         m_globalObjects = NULL;
00023     }
00024 } // fn destroy
00025 
00026 
00031 void
00032 GlobalObjects::destroyImpl() {
00033     // save current configuration
00034     m_config->save();
00035     m_catcher->save();
00036 
00037     delete m_transportLayer;
00038     m_transportLayer = NULL;
00039     
00040     delete m_catcher;
00041     m_catcher = NULL;
00042     
00043     delete m_config;
00044     m_config = NULL;
00045     
00046     delete m_interfaces;
00047     m_interfaces = NULL;
00048     
00049     delete m_webServer;
00050     m_webServer = NULL;
00051     
00052     delete m_proxy;
00053     m_proxy = NULL;
00054 
00055     // if I put this at the beginning of this function, it doesnt work - there is a seg fault somewhere.
00056     // but putting it here seems to be ok - I dont know why!
00057     //ThreadSpawningTimer::destroy();
00058     
00059     delete m_httpTestProcessor;
00060     m_httpTestProcessor = NULL;
00061     
00062 #ifdef TEST
00063     delete m_cli;
00064     m_cli = NULL;
00065 #endif
00066 } // fn destroyImpl
00067 
00068 
00071 GlobalObjects::GlobalObjects() {
00072     m_config = NULL;
00073     m_catcher = NULL;    
00074     m_transportLayer = NULL;
00075     m_networkLayer = NULL;
00076     m_interfaces = NULL;
00077     m_webServer = NULL;
00078     m_proxy = NULL;
00079     m_httpTestProcessor = NULL;
00080 #ifdef TEST
00081     m_cli = NULL;
00082 #endif
00083 } // ctor
00084 
00085 
00086 void
00087 GlobalObjects::init() {
00088     // initialize the debug file
00089     stringstream debugFilename;
00090         const int BUFSIZE = 128;
00091     char theTime[BUFSIZE];
00092     time_t now = time(NULL);
00093     struct tm *tp = gmtime(&now);
00094     strftime(theTime, BUFSIZE, "%Y_%m_%d_%H_%M_%S", tp);
00095 
00096     debugFilename << "debug_" << theTime << ".out";
00097     debugSetFile(debugFilename.str().c_str());
00098 
00099     //ThreadSpawningTimer::instance();
00100     m_interfaces = new Interfaces();
00101     
00102     m_config = new Config();
00103     m_config->load();
00104 
00105     m_catcher = new Catcher();
00106     m_catcher->load();
00107 
00108     m_transportLayer = new TransportLayer();
00109 
00110     m_networkLayer = m_transportLayer->getNetworkLayer();
00111 
00112     m_webServer = new WebServer();
00113 
00114     m_proxy = new ProxyCommandProcessor();
00115     m_proxy->setParser(new ProxyParser(m_proxy));
00116     m_proxy->addCommand(new ProxyRequestCommand());
00117 #ifndef RELEASE
00118     m_proxy->startThread();
00119 #endif
00120 
00121     m_httpTestProcessor = new HttpTestCommandProcessor();
00122     m_httpTestProcessor->setParser(new HttpTestInterfaceParser(m_httpTestProcessor));
00123     initializeCommands(m_httpTestProcessor, m_httpTestProcessor);
00124     m_httpTestProcessor->startThread();
00125 
00126 #ifdef TEST
00127     m_cli = new FileHandleCommandProcessor();
00128     m_cli->setParser(new CliParser(m_cli));
00129     initializeCommands(m_cli, m_httpTestProcessor);
00130 #endif
00131 } // fn init
00132 
00133 
00134 
00135 GlobalObjects::~GlobalObjects() {
00136 } // dtor
00137 
00138 
00139 void 
00140 GlobalObjects::initializeCommands(CommandProcessor* cp, HttpTestCommandProcessor* htcp) {
00141 #ifdef TEST
00142     //cp->addCommand(new ClientTestCommand());
00143     cp->addCommand(new HttpTestProcessorCommand(htcp));
00144     cp->addCommand(new TransportLayerCommand());
00145     cp->addCommand(new ServiceTableCommand());
00146     cp->addCommand(new ServiceEntryCommand());
00147     cp->addCommand(new SarCommand());
00148     cp->addCommand(new WindowPositionCommand());
00149     cp->addCommand(new TpPacketCommand());
00150     cp->addCommand(new NetworkLayerCommand());
00151     cp->addCommand(new VirtualCircuitTableCommand());
00152     cp->addCommand(new LiveBroadcastTableCommand());
00153     cp->addCommand(new PriorityPacketQueueCommand());
00154     cp->addCommand(new NpPacketCommand(NpPacket::Connect));
00155     cp->addCommand(new NpPacketCommand(NpPacket::Established));
00156     cp->addCommand(new NpPacketCommand(NpPacket::Fin));
00157     cp->addCommand(new NpPacketCommand(NpPacket::Discovery));
00158     cp->addCommand(new NpPacketCommand(NpPacket::ImHere));
00159     cp->addCommand(new NpPacketCommand(NpPacket::Ping));
00160     cp->addCommand(new NpPacketCommand(NpPacket::Pong));
00161     cp->addCommand(new LinkLayerCommand());
00162     cp->addCommand(new NodeCommand());
00163     cp->addCommand(new SocketAddressCommand());
00164     cp->addCommand(new ConfigureCommand());
00165     cp->addCommand(new CatcherCommand());
00166     cp->addCommand(new ExitCommand());
00167     cp->addCommand(new InterfaceCommand());
00168     cp->addCommand(new ThreadMessageQueueCommand());
00169     cp->addCommand(new CertCommand());
00170     cp->addCommand(new DesCommand());
00171     cp->addCommand(new RsaCommand());
00172     cp->addCommand(new WebServerCommand());
00173     cp->addCommand(new HelpCommand(cp));
00174     // add more commands here
00175 
00176     if (dynamic_cast<FileHandleCommandProcessor*>(cp) != NULL) {
00177         cp->addCommand(new TimerCommand());
00178         cp->addCommand(new NullCommand());
00179     }
00180 
00181     if (dynamic_cast<HttpTestCommandProcessor*>(cp) != NULL) { 
00182         cp->addCommand(new HttpTestPageCommand(htcp));
00183     }
00184 #endif
00185     if (dynamic_cast<HttpTestCommandProcessor*>(cp) != NULL) { 
00186         cp->addCommand(new SummaryScreenCommand());
00187         cp->addCommand(new BasicConfigurationCommand());
00188         cp->addCommand(new AdvancedConfigurationCommand());
00189         cp->addCommand(new NodeManagerCommand());
00190         cp->addCommand(new ConnectionManagerCommand());
00191     }
00192 } // fn initializeCommands
00193 
00194 
00195 
00196 #ifdef TEST
00197 
00198 FileHandleCommandProcessor*
00199 GlobalObjects::getCli() {
00200     if (m_cli == NULL) {
00201         debug(DEBUG_ERR, "Global CLI object not initialized!");
00202     }
00203     return m_cli;
00204 } // fn getCli
00205 
00206 #endif
00207 
00208 HttpTestCommandProcessor*
00209 GlobalObjects::getHttpTestCommandProcessor() {
00210     if (m_httpTestProcessor == NULL) {
00211         debug(DEBUG_ERR, "Global Proxy object not initialized!");
00212     }
00213     return m_httpTestProcessor;
00214 } // fn getHttpTestCommandProcessor
00215 
00216 
00217 ProxyCommandProcessor*
00218 GlobalObjects::getProxyCommandProcessor() {
00219     if (m_proxy == NULL) {
00220         debug(DEBUG_ERR, "Global Proxy object not initialized!");
00221     }
00222     return m_proxy;
00223 } // fn getProxy
00224 
00225 
00226 Config*
00227 GlobalObjects::getConfig() {
00228     if (m_config == NULL) {
00229         debug(DEBUG_ERR, "Global Config object not initialized!");
00230     }
00231     return m_config;
00232 } // fn getConfig
00233 
00234 
00235 Catcher*
00236 GlobalObjects::getCatcher() {
00237     if (m_catcher == NULL) {
00238         debug(DEBUG_ERR, "Global Catcher object not initialized!");
00239     }
00240     return m_catcher;
00241 } // fn getCatcher
00242 
00243 
00244 NetworkLayer*
00245 GlobalObjects::getNetworkLayer() {
00246     if (m_networkLayer == NULL) {
00247         debug(DEBUG_ERR, "Global NetworkLayer object not initialized!");
00248     }
00249     return m_networkLayer;
00250 } // fn getNetworkLayer
00251 
00252 
00253 Interfaces*
00254 GlobalObjects::getInterfaces() {
00255     if (m_interfaces == NULL) {
00256         debug(DEBUG_ERR, "Global Interfaces object not initialized!");
00257     }
00258     return m_interfaces;
00259 } // fn getInterfaces
00260 
00261 
00262 TransportLayer*
00263 GlobalObjects::getTransportLayer() {
00264     if (m_transportLayer == NULL) {
00265         debug(DEBUG_ERR, "Global transport layer object not initialized!");
00266     }
00267     return m_transportLayer;
00268 } // fn getTransportLayer
00269 
00270 
00271 ServiceTable*
00272 GlobalObjects::getServiceTable() {
00273     if (m_transportLayer->getServiceTable() == NULL) {
00274         debug(DEBUG_ERR, "GLobal service table object not initialized.");
00275     }
00276     return m_transportLayer->getServiceTable();
00277 } // fn getServiceTable
00278 
00279 
00280 void
00281 GlobalObjects::setConfig(Config* config) {
00282     m_config = config;
00283 } // fn setConfig
00284 
00285 
00286 void
00287 GlobalObjects::setCatcher(Catcher* catcher) {
00288     m_catcher = catcher;
00289 } // fn setCatcher
00290 
00291 
00292 void
00293 GlobalObjects::setNetworkLayer(NetworkLayer* networkLayer) {
00294     m_networkLayer = networkLayer;
00295 } // fn setNetworkLayer
00296 
00297 
00298 void
00299 GlobalObjects::setInterfaces(Interfaces* interfaces) {
00300     m_interfaces = interfaces;
00301 } // fn setInterfaces
00302 

Generated at Thu Jul 11 13:31:50 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001