home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextLibrary / Frameworks / NEXTIME.framework / Versions / A / Headers / NTClock.h < prev    next >
Encoding:
Text File  |  1995-08-30  |  4.3 KB  |  152 lines

  1. /*
  2.  *    NTClock.h
  3.  *     Copyright 1991, NeXT Computer, Inc.
  4.  *    
  5.  *    25Sept91 mpaque Created.
  6.  *    20Dec93    mpaque    Revised to meet NEXTIME requirements.
  7.  */
  8. #import <Foundation/NSObject.h>
  9.  
  10. typedef enum
  11. {
  12.     NTTimeDirectionReverse = -1,
  13.     NTTimeDirectionForward = 1
  14. }
  15. NTTimeDirection;
  16.  
  17. @protocol NTClock <NSObject>
  18. //
  19. // The alarm function schedules a callback.  The method to be called
  20. // should be declared in the form:
  21. //
  22. //    method: (id) sender: (double)time;
  23. //
  24. // The perform: method returns nil if the argument selector or objects
  25. // are invalid.  The method must be implemented in a subclass.
  26. //
  27. - (void)performSelector:(SEL)aSelector object:anObject atTime:(double)time;
  28. - (void)cancelPerform;        // Cancel delayed perform
  29. - (void)disablePerform;        // Inhibit delayed perform
  30. - (void)enablePerform;        // Re-enable inhibited delayed perform
  31.  
  32. - (BOOL)isReversable;        // Can clock direction be reversed?
  33. - (BOOL)scalesWhenResized;        // Can the clock be scaled out of realtime?
  34. - (BOOL)isSettable;        // Can the clock be set?
  35. - (BOOL)isStoppable;        // Can the clock be stopped?
  36.  
  37. //
  38. // These set operations return NO if the operation is not permitted
  39. //
  40. - (NTTimeDirection) timeDirection;
  41. - (BOOL)setTimeScale: (double) scale;
  42. - (double) timeScale;
  43. - (BOOL)setTimeOffset: (double) offset;
  44. - (double) timeOffset;
  45. - (BOOL)setCurrentTime: (double) seconds;
  46. - (double) currentTime;
  47. - (BOOL)stop;
  48. - (BOOL)isStopped;        // Returns YES if clock is stopped
  49. - (void)run;
  50.  
  51. // Forward and inverse transforms of time values
  52. - (double)baseTimeFromClockTime:(double)time;
  53. - (double)clockTimeFromBaseTime:(double)time;
  54. - (double)baseIntervalFromClockInterval:(double)interval;
  55. - (double)clockIntervalFromBaseInterval:(double)interval;
  56.  
  57. // clock delegate interface
  58. - (void)setDelegate:(id)delegate;
  59. - delegate;
  60.  
  61. // Slaving a clock to a master clock
  62. - (void)setMasterClock:(id <NTClock>)master;
  63. - (id <NTClock>)masterClock;
  64.  
  65. // The setMasterClock: method causes a slaved clock to generate the following
  66. // messages to the old and new master clocks:
  67. - (void)removeSlaveClock:(id <NTClock>)slave;
  68. - (void)addSlaveClock:(id <NTClock>)slave;
  69.  
  70. // Messages sent to slaved clocks
  71. // The 'sender' is the (id <NTClock>) object generating the message.
  72. - (void)masterDidSetCurrentTime: sender;
  73. - (void)masterDidChangeDirection: sender;
  74. - (void)masterDidStop: sender;
  75. - (void)masterWillStart: sender;
  76. - (void)masterDidStart: sender;
  77. @end
  78.  
  79. //
  80. // FIXME: Perhaps I need a 'clockIsRunning:' callout to indicate that the
  81. // clock is actually running?  Then again, this can be done by scheduling an
  82. // alarm for the currentTime value.
  83. //
  84. @protocol NTClockDelegate <NSObject>
  85. // All clock delegates should conform to this protocol
  86. // The 'sender' is the (id <NTClock>) object generating the message.
  87. - (void)clockDidSetCurrentTime: sender;
  88. - (void)clockDidChangeDirection: sender;
  89. - (void)clockDidStop: sender;
  90. - (void)clockWillStart: sender;
  91. - (void)clockDidStart: sender;
  92. @end
  93.  
  94. //
  95. // Prototype for callback func.  We call the address of the user's method
  96. // implementation directly, so we can properly pass the (double)
  97. // currentTime value.  The perform:: mechanism won't pass anything
  98. // wider than an (id).  The alarmMethod should be a selector for a 
  99. // method declared in the form:
  100. //
  101. //    - alarmMethod:(id)sender: (double)currentTime;
  102. //
  103. // where 'sender' is the clock instance generating the alarm callback,
  104. // and currentTime is the current time in the sending clock's frame
  105. // of reference.
  106. //
  107. typedef id (*NTIMPalarm)(id, SEL, id, double);
  108.  
  109. @class NSMutableArray;
  110.  
  111. @interface NTClock : NSObject <NTClock>
  112. {
  113.     // Capabilities flags
  114.     BOOL            isReversable;
  115.     BOOL            isScalable;
  116.     BOOL            isSettable;
  117.     BOOL            isStoppable;
  118.  
  119.     BOOL            isStopped;
  120.  
  121.     // Current alarm event information
  122.     BOOL            alarmSet;    // True if set, not delivered
  123.     double            alarmTime;
  124.     id            alarmInstance;
  125.     SEL            alarmMethod;
  126.     NTIMPalarm        alarmFunc;
  127.  
  128.     // current direction, NTTimeDirectionForward or
  129.     // NTTimeDirectionReverse, set by sign of timeScale and
  130.     // master clock direction, if a master clock is set.
  131.     NTTimeDirection        timeDirection;
  132.  
  133.     // Time scaling factor.  The sign sets direction
  134.     double            timeScale;
  135.     double            timeOffset;
  136.     // The clock's idea of the current time
  137.     double            currentTime;
  138.         
  139.     NSMutableArray *    slaveClocks;
  140.     id <NTClock>        masterClock;
  141.     id            delegate;
  142. }
  143.  
  144. /* Class methods */
  145. + (void)initialize;            // Class setup
  146.  
  147. /* Instance methods */
  148. - init;                // Initialize instance
  149.  
  150. @end
  151.  
  152.