<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css"> <title>Erlang -- cosTime Examples</title> </head> <body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container"> <script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript"> <!-- function getWinHeight() { var myHeight = 0; if( typeof( window.innerHeight ) == 'number' ) { //Non-IE myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myHeight = document.body.clientHeight; } return myHeight; } function setscrollpos() { var objf=document.getElementById('loadscrollpos'); document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2; } function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } addEvent(window, 'load', setscrollpos); //--></script><div id="leftnav"><div class="innertube"> <img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/cosTime-1.1.12.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>cosTime</strong><br><strong>User's Guide</strong><br><small>Version 1.1.12</small></p> <br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p> <ul class="flipMenu" imagepath="../../../../doc/js/flipmenu"> <li id="no" title="The cosTime Application" expanded="false">The cosTime Application<ul> <li><a href="ch_contents.html"> Top of chapter </a></li> <li title="Content Overview"><a href="ch_contents.html#id61319">Content Overview</a></li> <li title="Brief Description of the User's Guide"><a href="ch_contents.html#id61577">Brief Description of the User's Guide</a></li> </ul> </li> <li id="no" title="Introduction to cosTime" expanded="false">Introduction to cosTime<ul> <li><a href="ch_introduction.html"> Top of chapter </a></li> <li title="Overview"><a href="ch_introduction.html#id61588">Overview</a></li> </ul> </li> <li id="no" title="Installing cosTime" expanded="false">Installing cosTime<ul> <li><a href="ch_install.html"> Top of chapter </a></li> <li title="Installation Process "><a href="ch_install.html#id61845">Installation Process </a></li> </ul> </li> <li id="loadscrollpos" title="cosTime Examples" expanded="true">cosTime Examples<ul> <li><a href="ch_example.html"> Top of chapter </a></li> <li title="A Tutorial on How to Create a Simple Service"><a href="ch_example.html#id57341">A Tutorial on How to Create a Simple Service</a></li> </ul> </li> </ul> </div></div> <div id="content"> <div class="innertube"> <h1>4 cosTime Examples</h1> <h3><a name="id57341">4.1 A Tutorial on How to Create a Simple Service</a></h3> <h4>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 <span class="code">cosTime:start()</span>. To get access to Time Service or Timer Event Service, use <span class="code">start_time_service/2</span> or <span class="code">start_timerevent_service/1.</span></p> <p>The Time Service are global, i.e., there may only exist one instance per Orber domain.</p> <p>The Timer Event Service is locally registered, i.e., there may only exist one instance per node.</p> <div class="note"> <div class="label">Note</div> <div class="content"><p> <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.</p> </p></div> </div> <h4>How to Run Everything</h4> <p>Below is a short transcript on how to run cosTime. </p> <div class="example"><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></div> </div> <div class="footer"> <hr> <p>Copyright © 2000-2012 Ericsson AB. All Rights Reserved.</p> </div> </div> </div></body> </html>