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

IDEA::SharedTimingService Class Reference
[TimingService]

This class is responsible for maintaining all the data that is shared among all the AgentTimingService instances in different processes. More...

#include <SharedTimingService.hh>

List of all members.

Public Types

enum  Action {
  UNINITIALIZED = 0, WAKEUP_DELETE, CANCEL_DELETE, INSERT,
  CHECK_WARPING
}

Public Methods

 SharedTimingService (int tscale, bool warp, const Time &offset)
 Constructor.

 ~SharedTimingService ()
 Destructor.

void synchronize (const Time &time, int ts)
 Sets the start date of the invoking timing service to time and sets the timescale to ts.

int registerAgent (const std::string &aName)
 Registers an agent to the invoking shared timing-service. Returns the internal identifier used to identify the agent in the invoking shared-memory. Returns 0 if the agent can not be registered.

void unregisterAgent (int aId)
 NOT IMPLEMENTED.

void setTimer (int agentId, const Time &time)
 Will populate the local data-structure with the necesarry data and release the server-semaphore of the invoking instance.

void cancelTimer (int agentId, const Time &time)
 Will populate the local data-structure with the necesarry data and release the server-semaphore of the invoking instance.

Time getCurrentTime ()
 Returns the current (simulated) time.

Time getElapsedTime () const
 Returns the elapsed time since the pivot date of the invoking timing service.

const TimegetPivotDate () const
 Returns the pivot date of the invoking timing service.

void setAgentActive (int agentId)
 Will increment the counter of active agents by one.

void setAgentNotActive (int agentId)
 Will decrement the counter of active agents by one.

void incrementTransitMessages (int agentId, int numOfMsgs)
 Increments the number of messages by numOfMsgs that have been send out by agentId.

void decrementTransitMessages (int agentId, int numOfMsgs)
 Decrements the number of messages by numOfMsgs that have been send out by agentId.

Time getRelativeTime (const Time &tym) const
int getTimeScale () const
 Returns the time-scale used by the invoking timing-service instance.

int getTransitMessageCount ()
 Returns the number of messages in transit (see SharedTimingService::incrementTransitMessages).

int getActiveAgentCount ()
 Returns the number of active agents (see SharedTimingService::setAgentActive).

const SharedTimingService::ActiongetAction () const
 Returns the action that would be executed by the TimingService main thread if it would be able to acquire the server-semaphore.

int getActionRequesterId () const
 Returns the identifier of the agent from which the current server-action is coming from.

const TimegetActionTime () const
 Returns the time associated with the next action.

const bool isWarpingEnabled ()
 Returns true if warping is enabled otherwise false.

char * getRegisteredAgentName (int agentId)
 Will return the name of agent used when registering agent agentId.

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)
 Activates the main-thread of the invoking instance.

ThreadSemaphoregetWakeupHandlerSemaphore ()
 Returns ...

ProcessSemaphoregetServerSemaphore ()
 Returns ...

ProcessSemaphoregetServerDoneSemaphore ()
 Returns ...

void setScaleDate (const Time &scaleDate)
bool warp (const Time &nextEvent)
 Will determine if it can warp if the next event is at time nextEvent. Returns true if the agent warped otherwise returns false.

const TimegetMinimumWarp () const
 Returns the minimum warp. The minimum warp is the amount of time we at least must be able to warp (time we warp to minus current time) before we consider warping. The time we warp possibly warp to is next event minust the warp-padding obviously this must be in the future.

const TimegetWarpPadding () const
 Returns the warp padding. The warp padding is the amount of time between the time we warp to and the next event.

void setMinimumWarp (const Time &t)
void setWarpPadding (const Time &t)

Static Public Methods

SharedTimingService * findInstance ()
void setSharedMemoryPoolName (const std::string &name)
 Sets the shared-memory-pool-name to name.

std::string & getSharedMemoryPoolName ()
 Returns the memory-pool-name used for shared memory.


Private Methods

Time getNow () const
 Returns the current wall-time.

void initializePivotDate ()
 Initializes the pivot date of the invoking timing service to the current time of the machine.

 SharedTimingService ()
 SharedTimingService (const SharedTimingService &)
SharedTimingService & operator= (const SharedTimingService &)
void requestWarpCheck (int agentId)
 Will check if the invoking timing-service can warp (if enabled) and if so will warp.

int svc ()
 Main thread function.


Static Private Methods

SharedTimingService * constructInstance (int tscale=1, bool warp=false, const Time &offset=Time::getZero())
void releaseInstance ()
SharedMemoryAllocatorgetAllocator ()

Private Attributes

ThreadSemaphore m_WakeupHandlerSemaphore
 Semaphore to signal that a timer has gone off in the reactor.

ProcessSemaphore m_ServerSemaphore
 Semaphore used to communicate that a client process has a request for the server.

ProcessSemaphore m_ServerDoneSemaphore
 Used to communicate the completion of a server request by the server thread to a client process.

ProcessMutex m_TimingServiceMutex
ProcessMutex m_TimeBaseMutex
char m_RegisteredAgentNames [16][256]
 Has all the names of a registered agent. The char* name is also the name of the process semaphore that will be released when a wakeup call arrive.

int m_AgentIdCounter
 A counter that increments everytime an agent registers.

Time m_LastWarpedToTime
 The amount of time the invoking timing service has warped since startup.

Time m_ScaleDate
 The scale date represents the date as of which we scale time with the time scale.

Time m_PivotDate
 Pivot date for all time representations.

int m_TimeScale
 Ratio of real time to sim time.

double m_InverseTimeScale
 Ratio of sim time to real time.

int m_ActiveAgentCounter
 Keeps count of number of active agents.

const bool m_WarpingEnabled
 Keeps count of the number of as yet undelivered messagess. Used to avoid warping while there is are messages in transit.

int m_TransitMessageCounter
Action m_ServerAction
 Requested action.

int m_ServerActionRequester
 Id of requesting agent.

Time m_ServerActionTime
 Time to insert/cancel.

Time m_MinimumWarp
Time m_WarpPadding
bool m_WakeupHandlerThreadDone

Static Private Attributes

std::string s_SharedMemoryPoolName = "TIMING_SERVICE"

Friends

class TimingService
class MetaTimingService


Detailed Description

This class is responsible for maintaining all the data that is shared among all the AgentTimingService instances in different processes.

class SharedTimingService


Member Enumeration Documentation

enum IDEA::SharedTimingService::Action
 

Enumeration values:
UNINITIALIZED 
WAKEUP_DELETE 
CANCEL_DELETE 
INSERT 
CHECK_WARPING 


Constructor & Destructor Documentation

IDEA::SharedTimingService::SharedTimingService int    tscale,
bool    warp,
const Time   offset
 

Constructor.

Creates a SharedTimingService instance with timescale equal to tscale and enable warping if warp is true and starts at time offset.

IDEA::SharedTimingService::~SharedTimingService  
 

Destructor.

IDEA::SharedTimingService::SharedTimingService   [private]
 

Default constructor, not implemented by design

IDEA::SharedTimingService::SharedTimingService const SharedTimingService &    [private]
 

Copy constructor, not implemented by design


Member Function Documentation

int IDEA::SharedTimingService::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
 

Activates the main-thread of the invoking instance.

The parameter n_threads is ignored and always at-most one thread will be spawned.

void IDEA::SharedTimingService::cancelTimer int    agentId,
const Time   time
 

Will populate the local data-structure with the necesarry data and release the server-semaphore of the invoking instance.

The TimingService maint thread (see TimingService::svc) will try to acquire the released semaphore and process this next event.

Will print an error if the agentId is not in the valid range (valid if larger than 0 and lower than number of registered number of agents) and ignore the invocation.

SharedTimingService * IDEA::SharedTimingService::constructInstance int    tscale = 1,
bool    warp = false,
const Time   offset = Time::getZero()
[static, private]
 

void IDEA::SharedTimingService::decrementTransitMessages int    agentId,
int    numOfMsgs
 

Decrements the number of messages by numOfMsgs that have been send out by agentId.

The counter is used to decide if timing-service can or can not warp. If the active-counter reaches zero from a non-zero state the invoking instance will check if warping can be executed.

Will print an error if the agentId is not in the valid range (valid if larger than 0 and lower than number of registered number of agents) or if the counter becomes negative and ignore the invocation.

Todo:
Use this, actual use has not been implemented yet...

SharedTimingService * IDEA::SharedTimingService::findInstance   [static]
 

const SharedTimingService::Action & IDEA::SharedTimingService::getAction  
 

Returns the action that would be executed by the TimingService main thread if it would be able to acquire the server-semaphore.

int IDEA::SharedTimingService::getActionRequesterId  
 

Returns the identifier of the agent from which the current server-action is coming from.

const Time & IDEA::SharedTimingService::getActionTime  
 

Returns the time associated with the next action.

int IDEA::SharedTimingService::getActiveAgentCount  
 

Returns the number of active agents (see SharedTimingService::setAgentActive).

SharedMemoryAllocator * IDEA::SharedTimingService::getAllocator   [static, private]
 

Time IDEA::SharedTimingService::getCurrentTime  
 

Returns the current (simulated) time.

Time IDEA::SharedTimingService::getElapsedTime  
 

Returns the elapsed time since the pivot date of the invoking timing service.

const Time & IDEA::SharedTimingService::getMinimumWarp  
 

Returns the minimum warp. The minimum warp is the amount of time we at least must be able to warp (time we warp to minus current time) before we consider warping. The time we warp possibly warp to is next event minust the warp-padding obviously this must be in the future.

Time IDEA::SharedTimingService::getNow   [private]
 

Returns the current wall-time.

const Time & IDEA::SharedTimingService::getPivotDate  
 

Returns the pivot date of the invoking timing service.

char * IDEA::SharedTimingService::getRegisteredAgentName int    agentId
 

Will return the name of agent used when registering agent agentId.

Time IDEA::SharedTimingService::getRelativeTime const Time   tym const
 

ProcessSemaphore& IDEA::SharedTimingService::getServerDoneSemaphore   [inline]
 

Returns ...

ProcessSemaphore& IDEA::SharedTimingService::getServerSemaphore   [inline]
 

Returns ...

std::string & IDEA::SharedTimingService::getSharedMemoryPoolName   [static]
 

Returns the memory-pool-name used for shared memory.

int IDEA::SharedTimingService::getTimeScale  
 

Returns the time-scale used by the invoking timing-service instance.

int IDEA::SharedTimingService::getTransitMessageCount  
 

Returns the number of messages in transit (see SharedTimingService::incrementTransitMessages).

ThreadSemaphore& IDEA::SharedTimingService::getWakeupHandlerSemaphore   [inline]
 

Returns ...

const Time & IDEA::SharedTimingService::getWarpPadding  
 

Returns the warp padding. The warp padding is the amount of time between the time we warp to and the next event.

void IDEA::SharedTimingService::incrementTransitMessages int    agentId,
int    numOfMsgs
 

Increments the number of messages by numOfMsgs that have been send out by agentId.

The counter is used to decide if timing-service can or can not warp. If the active-counter reaches zero from a non-zero state the invoking instance will check if warping can be executed.

Will print an error if the agentId is not in the valid range (valid if larger than 0 and lower than number of registered number of agents) or if the counter becomes negative and ignore the invocation.

Todo:
Use this, actual use has not been implemented yet...

void IDEA::SharedTimingService::initializePivotDate   [private]
 

Initializes the pivot date of the invoking timing service to the current time of the machine.

const bool IDEA::SharedTimingService::isWarpingEnabled  
 

Returns true if warping is enabled otherwise false.

SharedTimingService& IDEA::SharedTimingService::operator= const SharedTimingService &    [private]
 

Assignment operator, not implemented by design

int IDEA::SharedTimingService::registerAgent const std::string &    aName
 

Registers an agent to the invoking shared timing-service. Returns the internal identifier used to identify the agent in the invoking shared-memory. Returns 0 if the agent can not be registered.

One can only register MAX_NO_OF_AGENTS agents.

void IDEA::SharedTimingService::releaseInstance   [static, private]
 

void IDEA::SharedTimingService::requestWarpCheck int    agentId [private]
 

Will check if the invoking timing-service can warp (if enabled) and if so will warp.

void IDEA::SharedTimingService::setAgentActive int    agentId
 

Will increment the counter of active agents by one.

The active agent counter is used to decide if timing-service can or can not warp. If the active-counter reaches zero from a non-zero state the invoking instance will check if warping can be executed (see SharedTimingService::setAgentNotActve).

Will print an error if the agentId is not in the valid range (valid if larger than 0 and lower than number of registered number of agents) and ignore the invocation.

void IDEA::SharedTimingService::setAgentNotActive int    agentId
 

Will decrement the counter of active agents by one.

The active agent counter is used to decide if timing-service can or can not warp. If the active-counter reaches zero from a non-zero state the invoking instance will check if warping can be executed (see SharedTimingService::setAgentNotActve).

Will print an error if the agentId is not in the valid range (valid if larger than 0 and lower than number of registered number of agents) or if the counter becomes negative and ignore the invocation.

void IDEA::SharedTimingService::setMinimumWarp const Time   t
 

void IDEA::SharedTimingService::setScaleDate const Time   scaleDate
 

void IDEA::SharedTimingService::setSharedMemoryPoolName const std::string &    name [static]
 

Sets the shared-memory-pool-name to name.

void IDEA::SharedTimingService::setTimer int    agentId,
const Time   time
 

Will populate the local data-structure with the necesarry data and release the server-semaphore of the invoking instance.

The TimingService maint thread (see TimingService::svc) will try to acquire the released semaphore and process this next event.

Will print an error if the aId is not in the valid range (valid if larger than 0 and lower than number of registered number of agents) and ignore the invocation.

void IDEA::SharedTimingService::setWarpPadding const Time   t
 

int IDEA::SharedTimingService::svc   [private]
 

Main thread function.

void IDEA::SharedTimingService::synchronize const Time   time,
int    ts
 

Sets the start date of the invoking timing service to time and sets the timescale to ts.

time needs to be later or equeal to getNow()

void IDEA::SharedTimingService::unregisterAgent int    aId
 

NOT IMPLEMENTED.

bool IDEA::SharedTimingService::warp const Time   nextEvent
 

Will determine if it can warp if the next event is at time nextEvent. Returns true if the agent warped otherwise returns false.


Friends And Related Function Documentation

friend class MetaTimingService [friend]
 

friend class TimingService [friend]
 


Member Data Documentation

int IDEA::SharedTimingService::m_ActiveAgentCounter [private]
 

Keeps count of number of active agents.

int IDEA::SharedTimingService::m_AgentIdCounter [private]
 

A counter that increments everytime an agent registers.

double IDEA::SharedTimingService::m_InverseTimeScale [private]
 

Ratio of sim time to real time.

Time IDEA::SharedTimingService::m_LastWarpedToTime [private]
 

The amount of time the invoking timing service has warped since startup.

Time IDEA::SharedTimingService::m_MinimumWarp [private]
 

Time IDEA::SharedTimingService::m_PivotDate [private]
 

Pivot date for all time representations.

char IDEA::SharedTimingService::m_RegisteredAgentNames[ 16 ][ 256 ] [private]
 

Has all the names of a registered agent. The char* name is also the name of the process semaphore that will be released when a wakeup call arrive.

Time IDEA::SharedTimingService::m_ScaleDate [private]
 

The scale date represents the date as of which we scale time with the time scale.

current-time = warped-time + ( wall-time - scale-date ) / scale

Action IDEA::SharedTimingService::m_ServerAction [private]
 

Requested action.

int IDEA::SharedTimingService::m_ServerActionRequester [private]
 

Id of requesting agent.

Time IDEA::SharedTimingService::m_ServerActionTime [private]
 

Time to insert/cancel.

ProcessSemaphore IDEA::SharedTimingService::m_ServerDoneSemaphore [private]
 

Used to communicate the completion of a server request by the server thread to a client process.

ProcessSemaphore IDEA::SharedTimingService::m_ServerSemaphore [private]
 

Semaphore used to communicate that a client process has a request for the server.

ProcessMutex IDEA::SharedTimingService::m_TimeBaseMutex [private]
 

int IDEA::SharedTimingService::m_TimeScale [private]
 

Ratio of real time to sim time.

ProcessMutex IDEA::SharedTimingService::m_TimingServiceMutex [private]
 

int IDEA::SharedTimingService::m_TransitMessageCounter [private]
 

ThreadSemaphore IDEA::SharedTimingService::m_WakeupHandlerSemaphore [private]
 

Semaphore to signal that a timer has gone off in the reactor.

bool IDEA::SharedTimingService::m_WakeupHandlerThreadDone [private]
 

const bool IDEA::SharedTimingService::m_WarpingEnabled [private]
 

Keeps count of the number of as yet undelivered messagess. Used to avoid warping while there is are messages in transit.

Time IDEA::SharedTimingService::m_WarpPadding [private]
 

std::string IDEA::SharedTimingService::s_SharedMemoryPoolName = "TIMING_SERVICE" [static, private]
 


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