001 // RealtimeClock.java, created by cata 002 // Copyright (C) 2001 Catalin Francu <cata@mit.edu> 003 // Licensed under the terms of the GNU GPL; see COPYING for details. 004 005 package javax.realtime; 006 007 /** <code>RealtimeClock</code> implements a real-time clock. */ 008 public class RealtimeClock extends Clock { 009 010 private RelativeTime resolution; 011 012 /** Create an instance of <code>RealtimeClock</code>. */ 013 public RealtimeClock() { 014 this(1, 0); 015 } 016 017 /** Create an instance of <code>RealtimeClock</code> using given parameters. */ 018 public RealtimeClock(long millis, int nanos) { 019 super(); 020 resolution = new RelativeTime(millis, nanos); 021 } 022 023 /** Return the resolution of this <code>RealtimeClock</code> instance. */ 024 public RelativeTime getResolution() { 025 return new RelativeTime(resolution); 026 } 027 028 /** Sets the resolution of this <code>RealtimeClock</code> instance. */ 029 public void setResolution(RelativeTime res) { 030 resolution.set(res); 031 } 032 033 protected static native long getTimeInC(); 034 035 /** Returns the time in an <code>AbstractTime</code>. */ 036 public void getTime(AbsoluteTime time) { 037 long micros = getTimeInC(); 038 time.set(micros / 1000, (int)((micros % 1000) * 1000)); 039 } 040 }