Adapted to recent changes of %build_linklib.
[AROS-Contrib.git] / FryingPan / framework / Generic / Timer.cpp
blobd92b566a185d0667652e926a2aee3fd236737b45
1 /*
2 * Amiga Generic Set - set of libraries and includes to ease sw development for all Amiga platforms
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "Timer.h"
21 #include <libclass/exec.h>
22 #include <devices/timer.h>
23 #include <exec/ports.h>
24 #include "LibrarySpool.h"
26 using namespace GenNS;
28 Timer::Timer()
30 issued = 0;
31 port = Exec->CreateMsgPort();
32 treq = (timerequest*)Exec->CreateIORequest(port, sizeof(timerequest));
33 Exec->OpenDevice("timer.device", UNIT_VBLANK, (IORequest*)treq, 0);
36 Timer::~Timer()
38 AbortRequest();
39 WaitRequest();
40 Exec->CloseDevice((IORequest*)treq);
41 Exec->DeleteIORequest((IORequest*)treq);
42 Exec->DeleteMsgPort(port);
45 void Timer::WaitRequest()
48 if (issued != 0)
50 Exec->WaitPort(port);
51 treq = (timerequest*)Exec->GetMsg(port);
52 issued = 0;
56 void Timer::AbortRequest()
58 if (issued != 0)
60 Exec->AbortIO((IORequest*)treq);
61 WaitRequest();
65 void Timer::AddRequest(unsigned long duration) // milliseconds ?
68 * don't initiate another request unless this one is finished.
70 if (issued != 0)
72 struct timerequest *tr = (struct timerequest*)Exec->GetMsg(port);
73 if (tr == 0)
74 return;
76 treq = tr;
77 issued = 0;
79 treq->tr_node.io_Command = TR_ADDREQUEST;
80 treq->tr_time.tv_secs = (duration/1000);
81 treq->tr_time.tv_micro = (duration % 1000) * 1000;
82 Exec->SendIO((IORequest*)treq);
83 issued = 1;
86 unsigned long Timer::GetSignals(void)
88 return 1<<port->mp_SigBit;