1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.2 -->
<HTML>
<HEAD>
<TITLE>cosTime Examples</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif"></A>
</CENTER>
<A NAME="4"><!-- Empty --></A>
<H2>4 cosTime Examples</H2>
<A NAME="4.1"><!-- Empty --></A>
<H3>4.1 A Tutorial on How to Create a Simple Service</H3>
<A NAME="4.1.1"><!-- Empty --></A>
<H4>4.1.1 Initiate the Application</H4>
<P> To use the complete cosTime application Time and Timer Event Services
must be installed. The application is then started by using
<CODE>cosTime:start()</CODE>. To get access to Time Service or Timer Event Service,
use <CODE>start_time_service/2</CODE> or <CODE>start_timerevent_service/1.</CODE>
<P> The Time Service are global, i.e., there may only exist one instance per
Orber domain.
<P> The Timer Event Service is locally registered, i.e., there may only exist
one instance per node.
<P>
<TABLE CELLPADDING=4>
<TR>
<TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
<TD>
<P>The Time and Timer Event Service use the time base
<STRONG>15 october 1582 00:00</STRONG>. Performing operations using other time
bases will not yield correct result. Furthermore, time and inaccuracy
must be expressed in 100 nano seconds. </TD>
</TR>
</TABLE>
<A NAME="4.1.2"><!-- Empty --></A>
<H4>4.1.2 How to Run Everything</H4>
<P> Below is a short transcript on how to run cosTime.
<PRE>
%% 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),
</PRE>
<CENTER>
<HR>
<SMALL>
Copyright © 1991-2004
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|