~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/archive/lts.h

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 /*
  2  * lts.h --
  3  *
  4  *      Logical Time System header file
  5  *
  6  * Copyright (c) 1997-2002 The Regents of the University of California.
  7  * All rights reserved.
  8  *
  9  * Redistribution and use in source and binary forms, with or without
 10  * modification, are permitted provided that the following conditions are met:
 11  *
 12  * A. Redistributions of source code must retain the above copyright notice,
 13  *    this list of conditions and the following disclaimer.
 14  * B. Redistributions in binary form must reproduce the above copyright notice,
 15  *    this list of conditions and the following disclaimer in the documentation
 16  *    and/or other materials provided with the distribution.
 17  * C. Neither the names of the copyright holders nor the names of its
 18  *    contributors may be used to endorse or promote products derived from this
 19  *    software without specific prior written permission.
 20  *
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 22  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  * @(#) $Header: /usr/mash/src/repository/mash/mash-1/archive/lts.h,v 1.9 2002/02/03 03:09:26 lim Exp $
 34  */
 35 
 36 
 37 #ifndef MASH_LTS_H
 38 #define MASH_LTS_H
 39 
 40 
 41 #include <tclcl.h>
 42 #include <timer.h>
 43 #include <misc/all-types.h>
 44 #include <misc/linkedlist.h>
 45 
 46 #ifndef WIN32
 47 #include <sys/time.h>
 48 #else
 49 #include <time.h>
 50 #endif
 51 
 52 /*
 53  * different types of LTS triggers
 54  */
 55 #define LTS_SPEED     0x0001
 56 #define LTS_REFERENCE 0x0002
 57 class LTS;
 58 
 59 class LTSTimer : private Timer {
 60 public:
 61         LTSTimer() : lts_(NULL) { }
 62         virtual ~LTSTimer() { }
 63 
 64         void sched(timeval logical);
 65         void sched_system(timeval system);
 66         void cancel() { Timer::cancel(); }
 67         LTS* LTS_() { return lts_; }
 68         void LTS_(LTS *lts) { lts_ = lts; }
 69 
 70 protected:
 71         virtual void timeout()=0;
 72         LTS *lts_;
 73 };
 74 
 75 
 76 class LTSTrigger {
 77 public:
 78         LTSTrigger(u_int32_t triggerType) : lts_(NULL), type_(triggerType) { }
 79         virtual ~LTSTrigger() { }
 80 
 81         u_int32_t type() { return type_; }
 82         LTS* LTS_() { return lts_; }
 83         void LTS_(LTS *lts) { lts_ = lts; }
 84 
 85 protected:
 86         virtual void callback(u_int32_t triggerType)=0;
 87         LTS *lts_;
 88         u_int32_t type_;
 89 
 90         friend class LTS;
 91 };
 92 
 93 
 94 class LTS : public TclObject {
 95 public:
 96         LTS();
 97         ~LTS() { }
 98 
 99         double Speed() { return speed_; }
100         void Speed(double newValue) {
101                 // must reset the logical to system mapping so there is no
102                 // sudden jump in logical time when the speed is changed!
103                 timeval system = NowSystem();
104                 SetReference(LogicalTimeOf(system), system);
105                 speed_ = newValue;
106         }
107 
108         timeval NowLogical() {
109                 return LogicalTimeOf(NowSystem());
110         }
111 
112         void    NowLogical(timeval logical) {
113                 SetReference(logical, NowSystem());
114         }
115 
116         virtual timeval NowSystem() {
117                 timeval tv;
118                 gettimeofday(&tv, NULL);
119                 return tv;
120         }
121 
122         void    SetReference(timeval logical, timeval system) {
123                 refLogical_ = logical;
124                 refSystem_  = system;
125         }
126 
127         Bool SetTrigger(LTSTrigger *trigger) {
128                 return triggers_.InsertAtTail(trigger);
129         }
130         void UnsetTrigger(LTSTrigger *trigger) {
131                 triggers_.Remove(trigger);
132         }
133 
134         void AdjustLogicalReference(double delta);
135 
136         int speed(int argc, const char *const *argv);
137         int now_logical(int argc, const char *const *argv);
138         int now_system (int argc, const char *const *argv);
139         int set_reference(int argc, const char *const *argv);
140 
141         void ActivateTriggers(u_int32_t triggerType);
142 private:
143         timeval LogicalTimeOf(timeval system);
144         timeval SystemTimeOf (timeval logical);
145 
146         double  speed_;
147         timeval refLogical_, refSystem_;
148 
149         List<LTSTrigger> triggers_;
150         friend class LTSTimer;
151 };
152 
153 
154 
155 #endif /* MASH_LTS_H */
156 
157 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.