// ************************************************************************ // $Id: HighResolutionClock.java 561 2005-07-11 20:09:17Z mdeters $ // ************************************************************************ // // jRate // // Copyright (C) 2001-2005 by Angelo Corsaro. // // All Rights Reserved. // // Permission to use, copy, modify, and distribute this software and // its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appear in all copies and // that both that copyright notice and this permission notice appear // in supporting documentation. I don't make any representations // about the suitability of this software for any purpose. It is // provided "as is" without express or implied warranty. // // // ************************************************************************* // // ************************************************************************* package javax.realtime; /** * This class provide an high resolution clock. The resolution is the * same as the clock speed at which the processor is running, on * Pentium processors. * * @author Angelo Corsaro * @version 1.0 */ public class HighResolutionClock extends Clock { private static HighResolutionClock theIntance; static { theIntance = new HighResolutionClock(); } public HighResolutionClock() {} public static HighResolutionClock instance() { return theIntance; } /** * Return the resolution of the clock -- the interval between ticks. * * @return A RelativeTime object representing the resolution of this. */ public RelativeTime getResolution() { return HighResolutionClock.getResolutionImpl(); } private static native RelativeTime getResolutionImpl(); /** * Set the resolution of this. For some hardwhere clocks setting * resolution impossible and if called on those nothing happens.

* * Implementation Note: If the requested resolution * overceeds the one obtainable by the underlying hardware this * method guarantees that the finest resolution possible is set. * * @param resolution The new resolution of this. */ public void setResolution(RelativeTime resolution) { HighResolutionClock.setResolutionImpl(); } private static native void setResolutionImpl(); /** * Return the current time in an existing object. The time * represented by the given AbsoluteTime is changed some time * between the invocation of the method and the return of the * method. * * @param time The AbsoluteTime object which will have its * time changed. */ public void getTime(AbsoluteTime time) { HighResolutionClock.getTimeImpl(time); } private static native void getTimeImpl(AbsoluteTime time); public long getClockTickCount() { return HighResolutionClock.getClockTickCountImpl(); } private static native long getClockTickCountImpl(); public RelativeTime clockTickToTime(long clockTicks) { RelativeTime time = new RelativeTime(); this.clockTickToTime(clockTicks, time); return time; } public native void clockTickToTime(long clockTicks, RelativeTime time); // -- jRate Specific Methods -- TimerImpl createPeriodicTimerImpl(PeriodicTimer timer) { // TODO: Implement Me!!! return null; } TimerImpl createOneShotTimerImpl(OneShotTimer timer) { // TODO: Implement Me!!! return null; } /** * Creates a PeriodicTimerImpl with the given timing * characteristics. * * @param timer a aPeriodicTimer value representing * the owner ot this timer implementation. * @param start a HighResolutionTime value representing the * time at which the timer will first expire (if it's a relative time, it * represents time from now). * @param interval a RelativeTime value representing * the period of the timer * @return a PeriodicTimerImpl value */ PeriodicTimerImpl createPeriodicTimerImpl(PeriodicTimer timer, HighResolutionTime start, RelativeTime interval) { return null; } /** * Creates a OneShotTimerImpl with the given timing * characteristics. * * @param timer a OneShotTimer value representing * the owner ot this timer implementation. * @param time a HighResolutionTime value representing the * time at which the timer will expire (if it's a relative time, it * represents time from now). * @return a PeriodicTimerImpl value */ OneShotTimerImpl createOneShotTimerImpl(OneShotTimer timer, HighResolutionTime time) { return null; } }