User's Guide
Reference Manual
Release Notes
PDF
Top

cosTime
User's Guide
Version 1.2

Expand All
Contract All

Chapters

- The cosTime Application
  - Top of chapter
  - Content Overview
  - Brief Description of the User's Guide
- Introduction to cosTime
  - Top of chapter
  - Overview
- Installing cosTime
  - Top of chapter
  - Installation Process
- cosTime Examples
  - Top of chapter
  - A Tutorial on How to Create a Simple Service

# 4 cosTime Examples

### 4.1 A Tutorial on How to Create a Simple Service

#### Initiate the Application

To use the complete cosTime application Time and Timer Event Services must be installed. The application is then started by using cosTime:start(). To get access to Time Service or Timer Event Service, use start_time_service/2 or start_timerevent_service/1.

The Time Service are global, i.e., there may only exist one instance per Orber domain.

The Timer Event Service is locally registered, i.e., there may only exist one instance per node.

Note

The Time and Timer Event Service use the time base 15 october 1582 00:00. Performing operations using other time bases will not yield correct result. Furthermore, time and inaccuracy must be expressed in 100 nano seconds.

#### How to Run Everything

Below is a short transcript on how to run cosTime.

    %% Start Mnesia and Orber
    mnesia:delete_schema([node()]),
    mnesia:create_schema([node()]),
    orber:install([node()]),
    mnesia:start(),
    orber:start(),

    %% Install Time Service in the IFR.
    cosTime:install_time(),

    %% Install Timer Event Service in the IFR. Which, require
    %% the Time Service and cosEvent or cosNotification
    %% application to be installed.
    cosNotification:install(),
    cosTime:install_timerevent(),

    %% Now start the application and necessary services.
    cosTime:start(),
    %% Tdf == Time displacement factor
    %% Inaccuracy measured in 100 nano seconds
    TS=cosTime:start_time_service(TDF, Inaccuracy),
    TES=cosTime:start_timerevent_service(TS),

    %% Access a cosNotification Proxy Push Consumer. How this is
    %% done is implementation specific.
    ProxyPushConsumer = ....

    %% How we construct the event is also implementation specific.
    AnyEvent = ....

    %% Create a new relative universal time.
    %% Time measured in 100 nano seconds.
    UTO='CosTime_TimeService':
          new_universal_time(TS, Time, Inaccuracy, TDF),
    EH='CosTimerEvent_TimerEventService':
          register(TES, ProxyPushConsumer, AnyEvent),

    %% If we want to trigger one event Time*10^-7 seconds from now:
    'CosTimerEvent_TimerEventHandler':set_timer(EH, 'TTRelative', UTO),

    %% If we want to trigger an event every Time*10^-7 seconds, starting
    %% Time*10^-7 seconds from now:
    'CosTimerEvent_TimerEventHandler':set_timer(EH, 'TTPeriodic', UTO),

    %% If we want to use absolute time we must retrieve such an object.
    %% One way is to convert the one we got, UTO, by using:
    UTO2='CosTime_UTO':absolute_time(UTO),
    %% If any other way is used, the correct time base MUST be used, i.e.,
    %% 15 october 1582 00:00.
    'CosTimerEvent_TimerEventHandler':set_timer(EH, 'TTAbsolute', UTO2),