GizmoDistribution

gzDistClientThreadPool.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzDistClientThreadPool.h
00003 // Module       : gzDistribution
00004 // Description  : Definition of a gzDistClientThreadPool
00005 // Author       : Christian Andersson   
00006 // Product      : GizmoDistribution 2.1.1
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 // CAN  040130  Created file    
00019 //
00020 //*****************************************************************************
00021 #ifndef __GZ_DIST_CLIENT_THREAD_POOL_H__
00022 #define __GZ_DIST_CLIENT_THREAD_POOL_H__
00023 
00029 // Includes
00030 #include "gzDistBase.h"
00031 
00032 // Forward declaration
00033 class gzDistClientThread;
00034 class gzDistClientInterface;
00035 
00036 // ---------------------------- gzDistThread -------------------------------
00037 // Pure virtual super class for all kind of threads in pool.
00038 class gzDistThreadInterface
00039 {
00040     public:
00041         gzDistThreadInterface() : m_threadId(0){}
00042         virtual ~gzDistThreadInterface() {}
00043 
00044         gzVoid trigger();
00045 
00046         gzULong getThreadId();
00047 
00048     protected:
00049 
00050         // Used for optimized response.
00051         gzDistTrigger m_trigger;
00052 
00053         // The thread id.
00054         gzULong m_threadId;
00055 };
00056 
00057 //-------------------------- gzDistClientThreadPool ---------------------------
00058 
00059 // Client thread pool that manages client threads
00060 class gzDistClientThreadPool : public gzDistThreadInterface
00061 {
00062     public:
00063 
00064         gzDistClientThreadPool();
00065         ~gzDistClientThreadPool();
00066 
00067         gzDistThreadInterface* registerClient(gzDistClientInterface* client, gzULong poolId, gzULong threadId);
00068         gzBool unregisterClient(gzDistClientInterface* client, gzULong poolId, gzULong threadId);
00069         gzVoid shutDown();
00070 
00071         // Returns TRUE if there are working threads or clients registered.
00072         gzBool isActive();
00073 
00074         gzBool processCustomThreadClients(gzBool waitForTrigger);
00075 
00076         gzULong getCustomThreadId();
00077 
00078         // Process the pool for the calling thread.
00079         gzBool processPool();
00080 
00081     protected:      
00082 
00083     private:
00084 
00085         gzDistClientThread* getThreadPool(gzULong poolId);
00086 
00087         gzDistClientThread* getThreadPoolByThread(gzULong threadId);
00088 
00089     // Members:
00090 
00091         gzList<gzDistClientThread> m_threadPool;
00092 
00093         // List of custom clients
00094         gzList<gzDistClientInterface> m_customClients;
00095         
00096         // Mutex for m_customClients
00097         gzMutex m_customClientsLocker;
00098 
00099         // Tell the thread reset the iterator to avoid working with destroied data.
00100         gzBool m_doReset;
00101 };
00102 
00103 
00104 //--------------------------- gzDistClientThread ------------------------------
00105 
00106 // Client thread
00107 class gzDistClientThread : public gzThread, public gzDistThreadInterface
00108 {
00109     public:
00110 
00111         gzDistClientThread(gzULong poolId);
00112         virtual ~gzDistClientThread();
00113         
00114         // Add a client to this pool.
00115         gzBool addClient(gzDistClientInterface* client);
00116 
00117         // Add a client to this pool outside mutex.
00118         gzBool addClientUnlocked(gzDistClientInterface* client);
00119 
00120         // Remove a client from this pool.
00121         gzBool removeClient(gzDistClientInterface* client);
00122 
00123         // Remove a client from this pool outside mutex.
00124         gzBool removeClientUnlocked(gzDistClientInterface* client);
00125 
00126         // Get the number of clients in this pool
00127         gzUInt getClients();
00128 
00129         // Run the thread.
00130         gzVoid activate();
00131 
00132         // Stop the thread.
00133         gzVoid terminate();
00134 
00135         gzULong getPoolId();
00136 
00137         gzULong getPoolThreadId();
00138 
00139         gzVoid singleProcess();
00140 
00141     protected:
00142         
00143         gzVoid process();
00144 
00145     private:
00146 
00147         gzList<gzDistClientInterface> m_clients;
00148         gzMutex m_clientsLocker;
00149 
00150         // The id of the pool.
00151         const gzULong m_poolId;
00152 
00153         // Tells if the thread is running.
00154         gzBool m_running;
00155 
00156         // Tell the thread reset the iterator to avoid working with destroied data.
00157         gzBool m_doReset;
00158 };
00159 
00160 
00161 #endif

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