
"Hello World" for GizmoDistribution. Illustrates how to set up the distribution manager for local or global distribution.
The source code can also be found in the examples directory of the GizmoDistribution installation.
.
00001 //***************************************************************************** 00002 // File : main.cpp 00003 // Module : main 00004 // Description : main (example application) 00005 // Author : Anders Sandblad 00006 // Product : GizmoDistribution 00007 // 00008 // Copyright © 2004- Saab Training Systems AB, Sweden 00009 // 00010 // NOTE: GizmoDistribution is a toolkit used for implementing distributed 00011 // objects and events in C++ 00012 // 00013 // 00014 // Revision History... 00015 // 00016 // Who Date Description 00017 // 00018 // XAA 040423 Created file 00019 // 00020 //***************************************************************************** 00021 00022 // Includes 00023 #include "gzBaseLibrary.h" 00024 #include "gzDistLibrary.h" 00025 00026 // Use this define to enable global distribution 00027 //#define GLOBAL 00028 00029 00030 // Application entry point 00031 int main(int argc, char* argv[]) 00032 { 00033 // Setup default message receiver 00034 gzMessage::setMessageLevel(GZ_MESSAGE_NOTICE); 00035 00036 #ifndef GLOBAL 00037 00038 // Create the manager and start local distribution 00039 gzDistManagerPtr manager = gzDistManager::getManager(TRUE); 00040 manager->start(); 00041 00042 GZMESSAGE(GZ_MESSAGE_NOTICE, "Hello Local GizmoDistribution !!!"); 00043 00044 #else 00045 00046 // To enable global distribution you should 00047 // provide two channels (with different transports). 00048 // One channel is used for data distribution and 00049 // the other is used for server control messages. 00050 00051 // Create the manager 00052 gzDistManagerPtr manager = gzDistManager::getManager(TRUE); 00053 00054 // This is the simplest way to do it. It uses default parameters. 00055 // See GizmoDistribution online documentation for details. 00056 manager->start(gzDistCreateDefaultSessionChannel(), gzDistCreateDefaultServerChannel()); 00057 00058 /* *** Note: If you want to specify IP and ports, do as below: *** 00059 00060 // Setup session channel 00061 gzDistRemoteChannel* sessionChannel = new gzDistRemoteChannel; 00062 gzDistTransportUDP* sessionTransport = new gzDistTransportUDP; 00063 00064 ! // For multicast... \ 00065 ! sessionTransport->createMulticast(gzSocketAddress(gzHostAddress(234,56,78,90), 2345)); | 00066 ! | 00067 ! // ...or for broadcast | NOTE: Use only one of these! 00068 ! sessionTransport->createBroadcast(2345); | 00069 / 00070 sessionChannel->setTransport(sessionTransport); 00071 00072 // Setup server channel 00073 gzDistRemoteChannel* serverChannel = new gzDistRemoteChannel; 00074 gzDistTransportUDP* serverTransport = new gzDistTransportUDP; 00075 00076 ! // For multicast... \ 00077 ! serverTransport->createMulticast(gzSocketAddress(gzHostAddress(234,56,78,90), 5432)); | 00078 ! | 00079 ! // ...or for broadcast: | NOTE: Use only one of these! 00080 ! serverTransport->createBroadcast(5432); | 00081 / 00082 serverChannel->setTransport(serverTransport); 00083 00084 // Start manager for global distribution 00085 manager->start(sessionChannel, serverChannel); 00086 */ 00087 GZMESSAGE(GZ_MESSAGE_NOTICE, "Hello Global GizmoDistribution !!!"); 00088 00089 #endif 00090 00091 // run a while 00092 gzSleep(2 * GZ_SLEEP_SECOND); 00093 00094 // shut down and release manager 00095 manager->shutDown(); 00096 manager = NULL; 00097 00098 gzSleep(GZ_SLEEP_SECOND); 00099 00100 return 0; 00101 00102 } 00103