GizmoDistribution

gzDistRouterEngine.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzDistRouterEngine.h
00003 // Module       : gzRemoteDistribution
00004 // Description  : Router application for routing distribution messages between
00005 //                different kinds of communication transports.
00006 // Author       : Christian Andersson
00007 // Product      : GizmoDistribution 2.1.1
00008 //      
00009 // Copyright © 2004 - Saab Training Systems AB, Sweden
00010 //          
00011 // NOTE:    GizmoDistribution is a toolkit used for implementing distributed 
00012 //          objects and events in C++
00013 //
00014 //
00015 // Revision History...
00016 //
00017 // Who  Date    Description
00018 //
00019 // CAN  040811  Created file
00020 //
00021 //*****************************************************************************
00022 #ifndef __GZ_DIST_ROUTER_ENGINE_H__
00023 #define __GZ_DIST_ROUTER_ENGINE_H__
00024 
00030 // Includes
00031 #include "gzBaseLibrary.h"
00032 #include "gzDistBase.h"
00033 #include "gzDistSerializeMemory.h"
00034 #include "gzDistRemoteChannel.h"
00035 
00036 // Forward declarations
00037 class gzDistTransportInterface;
00038 
00039 //----------------------------- gzDistRouterTransportQueueInfo ----------------------------
00040 
00041 class gzDistRouterTransportQueueInfo
00042 {
00043     public:
00044         gzDistRouterTransportQueueInfo() : inQueue(0), outQueue(0), inAccum(0), outAccum(0) {}
00045         ~gzDistRouterTransportQueueInfo(){}
00046 
00047         gzUInt inQueue;
00048         gzUInt inAccum;
00049         gzUInt outQueue;
00050         gzUInt outAccum;
00051 };
00052 
00053 //----------------------------- gzDistRouterBuffer ----------------------------
00054 
00055 // Internal
00056 class gzDistRouterBuffer : public gzDistThreadSafeReference
00057 {
00058     public:
00059         gzDistRouterBuffer();
00060         virtual ~gzDistRouterBuffer();
00061 
00062         // The data buffer.
00063         gzUByte data[GZ_DIST_MESSAGE_BUFFER_SIZE * GZ_DIST_MAX_CODED_BUFFER_FACTOR];
00064 
00065         gzUInt length;
00066 };
00067 
00068 //--------------------------- gzDistRouterTransport ---------------------------
00069 
00070 // Internal
00071 class gzDistRouterTransport : public gzThread
00072 {
00073     public:
00074         gzDistRouterTransport(gzDistTransportInterface* transport);
00075 
00076         virtual ~gzDistRouterTransport();
00077 
00078         // Get a message from m_inMessages.
00079         gzBool getMessage(gzDistRouterBufferPtr& message);
00080 
00081         // Put a message in m_outMessages.
00082         // If the message queue is greater than queueLimit, the messages not be inserted.
00083         // queueLimit = 0 is unlimited queue size.
00084         gzBool addMessage(gzDistRouterBuffer* message, gzUInt queueLimit);
00085 
00086         // Get the transport.
00087         gzDistTransportInterface* getTransportInterface();
00088 
00089         gzDistRouterTransportQueueInfo getQueueInfo();
00090 
00091     protected:
00092 
00093         // Virtual function from gzThread.
00094         gzVoid process();
00095 
00096     private:
00097 
00098         // Put a message in m_inMessages.
00099         gzVoid addInMessage(gzDistRouterBuffer* message);
00100 
00101         // Get a message from m_outMessages.
00102         gzBool getOutMessage(gzDistRouterBufferPtr& message);
00103 
00104         // Clear m_outMessages.
00105         gzVoid clearOutMessages();
00106 
00107         // Mutex for m_inMessages.
00108         gzMutex m_inMessageLocker;
00109 
00110         // Mutex for m_outMessages.
00111         gzMutex m_outMessageLocker;
00112 
00113         // Messages received from m_transport.
00114         gzRefList<gzDistRouterBuffer> m_inMessages;
00115         
00116         // Messges from router.
00117         gzRefList<gzDistRouterBuffer> m_outMessages;
00118 
00119         // The transport.
00120         gzDistTransportInterface* m_transport;
00121 
00122         gzUInt m_inMessagesAccum;
00123 
00124         gzUInt m_outMessagesAccum;
00125 
00126         // True while running.
00127         gzBool m_run;
00128 };
00129 
00130 
00131 //---------------------------- gzDistRouterEngine ---------------------------
00132 
00134 
00137 class gzDistRouterEngine : public gzThread
00138 {
00139     public:
00140 
00142         GZ_REMOTE_EXPORT gzDistRouterEngine();
00143 
00145         GZ_REMOTE_EXPORT virtual ~gzDistRouterEngine();
00146 
00148         GZ_REMOTE_EXPORT gzBool addTransport(gzDistTransportInterface* transportInterface);
00149 
00151         GZ_REMOTE_EXPORT gzBool removeTransport(gzDistTransportInterface* transportInterface);
00152 
00154         GZ_REMOTE_EXPORT gzBool hasTransport(gzDistTransportInterface* transportInterface);
00155 
00157         GZ_REMOTE_EXPORT gzBool hasTransports();
00158 
00160         GZ_REMOTE_EXPORT gzULong getPPS(gzBool reset);
00161 
00163         GZ_REMOTE_EXPORT gzULong getRoutedBytes(gzBool reset);
00164 
00166         GZ_REMOTE_EXPORT gzVoid routeAllData(gzBool route);
00167 
00169         GZ_REMOTE_EXPORT gzDistRouterTransportQueueInfo getMessageQueueInfo(gzDistTransportInterface* transportInterface);
00170 
00172         GZ_REMOTE_EXPORT gzVoid setQueueLimit(gzUInt limit);        
00173 
00174     protected:
00175 
00176         // Virtual function from gzThread.
00177         gzVoid process();
00178 
00179     private:
00180 
00181         // Locker for m_transportList.
00182         gzMutex m_processLocker;
00183 
00184         // All transports.
00185         gzList<gzDistRouterTransport> m_transportList;
00186         
00187         // Message counter.
00188         gzULong m_messages;
00189 
00190         // Total number of routed bytes.
00191         gzULong m_routedBytes;
00192 
00193         // True while running.
00194         gzBool m_run;
00195 
00196         // Tells if the engine should route all messages
00197         // or only GizmoDistribution messages.
00198         gzBool m_routeGizmoDistOnly;
00199 
00200         gzDistProtocolMessageHeader m_messageHeader;
00201 
00202         gzUInt m_queueLimit;
00203 };
00204 
00205 #endif

Documentation for GizmoDistribution generated at Wed Feb 20 11:59:21 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond