Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

/home/pauldt/projects/IDEA/IDEA-ALL/IDEA-DEV/TimingService/Includes/SharedTimingService.hh

Go to the documentation of this file.
00001 // -*- Mode: c++ -*-
00002 //     File: $Source: /home/cvs/ISG-Repository/IDEA-DEV/TimingService/Includes/SharedTimingService.hh,v $
00003 //      Tag: $Name: DR_01_11_06 $
00004 //      CVS: $Id: SharedTimingService.hh,v 1.5 2005/07/15 22:24:40 rijsman Exp $
00005 //     Info: $CVSROOT/IDEA-DEV/COPYRIGHT
00006 
00007 #ifndef SHARED_TIMING_SERVICE_H
00008 #define SHARED_TIMING_SERVICE_H
00009 
00010 #include <ace/Shared_Memory_MM.h>
00011 #include <ace/Malloc.h>
00012 #include "ace/PI_Malloc.h"
00013 #include "ace/Auto_Ptr.h"
00014 
00015 #include "ThreadTools.hh"
00016 #include "TimeBasics.hh"
00017 
00018 #define MAX_NO_OF_AGENTS 16
00019 #define MAX_AGENT_NAME_LENGTH 256
00020 
00021 namespace IDEA
00022 {
00026   typedef ACE_Malloc_T< ACE_SHARED_MEMORY_POOL, ProcessMutex, ACE_PI_Control_Block  >  SharedMemoryAllocator;
00027 
00036   class SharedTimingService:
00037     public ACE_Task_Base
00038   {
00039     friend class TimingService;
00040     friend class MetaTimingService;
00041   public:
00042     enum Action
00043       {
00044         UNINITIALIZED = 0,
00045         WAKEUP_DELETE, // was DUE_TO_WAKEUP
00046         CANCEL_DELETE, // was DUE_TO_CANCEL
00047         INSERT,        // was DUE_TO_INSERT
00048         CHECK_WARPING
00049       };
00050 
00057     SharedTimingService( int tscale, bool warp, const Time& offset );
00061     ~SharedTimingService();
00067     void synchronize( const Time& time, int ts );
00071     static SharedTimingService* findInstance();
00078     int registerAgent( const std::string& aName );   
00082     void unregisterAgent(int aId);
00093     void setTimer( int agentId, const Time& time);
00104     void cancelTimer( int agentId, const Time& time);
00108     Time getCurrentTime(); 
00112     Time getElapsedTime() const;
00116     const Time& getPivotDate() const;
00126     void setAgentActive( int agentId);
00136     void setAgentNotActive( int agentId);
00148     void incrementTransitMessages( int agentId, int numOfMsgs);
00160     void decrementTransitMessages( int agentId, int numOfMsgs);
00164     Time getRelativeTime(const Time & tym) const;
00168     int getTimeScale() const;
00172     int getTransitMessageCount();
00176     int getActiveAgentCount();
00181     const SharedTimingService::Action& getAction() const;
00185     int getActionRequesterId() const;
00189     const Time& getActionTime() const;
00193     const bool isWarpingEnabled();
00197     char* getRegisteredAgentName( int agentId);
00201     static void setSharedMemoryPoolName( const std::string& name );
00205     static std::string& getSharedMemoryPoolName();
00211     int activate(long flags=THR_NEW_LWP|THR_JOINABLE|THR_INHERIT_SCHED, int n_threads=1, int force_active=0, long priority=ACE_DEFAULT_THREAD_PRIORITY, int grp_id=-1, ACE_Task_Base *task=0, ACE_hthread_t thread_handles[]=0, void *stack[]=0, size_t stack_size[]=0, ACE_thread_t thread_ids[]=0); 
00215     ThreadSemaphore& getWakeupHandlerSemaphore() { return  m_WakeupHandlerSemaphore; }
00219     ProcessSemaphore& getServerSemaphore() { return m_ServerSemaphore; }
00223     ProcessSemaphore& getServerDoneSemaphore() { return m_ServerDoneSemaphore; }
00227     void setScaleDate( const Time& scaleDate );
00232     bool warp( const Time& nextEvent );
00238     const Time& getMinimumWarp() const;
00243     const Time& getWarpPadding() const;
00247     void setMinimumWarp( const Time& t );
00251     void setWarpPadding( const Time& t );
00252   private:
00256     Time getNow() const;
00260     void initializePivotDate();
00264     static SharedTimingService* constructInstance( int tscale = 1, bool warp = false, const Time& offset= Time::getZero() );
00268     static void releaseInstance();
00272     static SharedMemoryAllocator* getAllocator();
00276     SharedTimingService();                          
00280     SharedTimingService(const SharedTimingService &); // copy constructor
00284     SharedTimingService & operator=(const SharedTimingService &); // assignment operator
00288     void requestWarpCheck( int agentId );
00292     int svc();
00296     static std::string s_SharedMemoryPoolName;
00300     ThreadSemaphore m_WakeupHandlerSemaphore;
00304 
00305     ProcessSemaphore m_ServerSemaphore;
00309     ProcessSemaphore m_ServerDoneSemaphore;
00313     ProcessMutex m_TimingServiceMutex;
00317     ProcessMutex m_TimeBaseMutex;
00321     char m_RegisteredAgentNames[MAX_NO_OF_AGENTS][MAX_AGENT_NAME_LENGTH];
00325     int m_AgentIdCounter;
00329     Time m_LastWarpedToTime;   
00335     Time m_ScaleDate; 
00339     Time m_PivotDate;   
00343     int m_TimeScale;        
00347     double m_InverseTimeScale; 
00351     int m_ActiveAgentCounter;  
00355     const bool m_WarpingEnabled;    
00359     int m_TransitMessageCounter; 
00363     Action m_ServerAction; 
00367     int m_ServerActionRequester;  
00371     Time m_ServerActionTime;          
00375     Time m_MinimumWarp;
00379     Time m_WarpPadding;
00383     bool m_WakeupHandlerThreadDone;
00384   };
00385 
00386 }
00387 
00388 
00389 
00390 #endif // SHARED_TIMING_SERVICE_H

Contact information
© IDEA
Generated on Fri Feb 3 17:09:42 2006 for IDEA.