2 Copyright © 1997-98, The AROS Development Team. All rights reserved.
5 Desc: Demo of new OOP system
14 #include "timerclass.h"
15 #include "sysdep/sysdep.h"
23 struct timeval start_time
;
24 struct timeval elapsed_time
;
27 /* Does dest - src => dest */
28 VOID
SubTime(struct timeval
*dest
, struct timeval
*src
)
30 /* Normalize the terms */
31 while(src
->tv_usec
> 999999)
34 src
->tv_usec
-= 1000000;
36 while(dest
->tv_usec
> 999999)
39 dest
->tv_usec
-= 1000000;
42 dest
->tv_usec
-= src
->tv_usec
;
43 dest
->tv_sec
-= src
->tv_sec
;
47 dest
->tv_usec
+= 1000000;
54 VOID
_Timer_Start(Class
*cl
, Object
*o
, Msg msg
)
56 struct TimerData
*data
;
57 EnterFunc(bug("Timer::Start(cl=%p, o=%p)\n", cl
, o
));
58 D(bug("data=%p\n", data
));
60 data
= INST_DATA(cl
, o
);
61 D(bug("data=%p\n", data
));
63 gettimeofday(&(data
->start_time
), NULL
);
65 ReturnVoid("Timer::Start");
68 VOID
_Timer_Stop(Class
*cl
, Object
*o
, Msg msg
)
70 struct TimerData
*data
= INST_DATA(cl
, o
);
71 gettimeofday(&(data
->elapsed_time
), NULL
);
73 SubTime(&(data
->elapsed_time
), &(data
->start_time
));
78 VOID
_Timer_PrintElapsed(Class
*cl
, Object
*o
, Msg msg
)
80 struct TimerData
*data
= INST_DATA(cl
, o
);
82 printf("%d secs and %d micros\n"
83 ,data
->elapsed_time
.tv_sec
84 ,data
->elapsed_time
.tv_usec
);
88 IPTR
_Timer_TestMethod(Class
*cl
, Msg msg
)
94 Class
*MakeTimerClass()
98 struct MethodDescr mdescr
[] =
100 { (IPTR (*)())_Timer_Start
, M_Timer_Start
},
101 { (IPTR (*)())_Timer_Stop
, M_Timer_Stop
},
102 { (IPTR (*)())_Timer_PrintElapsed
, M_Timer_PrintElapsed
},
103 { (IPTR (*)())_Timer_TestMethod
, M_Timer_TestMethod
},
106 struct InterfaceDescr ifdescr
[]=
108 { mdescr
, "Timer", 4},
113 #if (HASHED_IFS || HASHED_METHODS)
114 IPTR (*methods
[])() =
116 (IPTR (*)())_Timer_Start
,
117 (IPTR (*)())_Timer_Stop
,
118 (IPTR (*)())_Timer_PrintElapsed
,
119 (IPTR (*)())_Timer_TestMethod
,
122 struct InterfaceDescr ifdescr
[] =
124 { methods
, I_Timer
, 4},
132 cl
= MakeClass(TIMERCLASS
, ROOTCLASS
, ifdescr
, sizeof (struct TimerData
));
141 VOID
FreeTimerClass(Class
*cl
)