xref: /aoo42x/main/vcl/unx/generic/app/saltimer.cxx (revision c82f2877)
1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c82f2877SAndrew Rist  * distributed with this work for additional information
6*c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c82f2877SAndrew Rist  *
11*c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c82f2877SAndrew Rist  *
13*c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c82f2877SAndrew Rist  * specific language governing permissions and limitations
18*c82f2877SAndrew Rist  * under the License.
19*c82f2877SAndrew Rist  *
20*c82f2877SAndrew Rist  *************************************************************/
21*c82f2877SAndrew Rist 
22*c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir #include <sys/time.h>
29cdf0e10cSrcweir #include <sys/times.h>
30cdf0e10cSrcweir #include <time.h>
31cdf0e10cSrcweir #include <unistd.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <unx/salunx.h>
34cdf0e10cSrcweir #include <unx/saldata.hxx>
35cdf0e10cSrcweir #include <unx/saldisp.hxx>
36cdf0e10cSrcweir #include <unx/saltimer.h>
37cdf0e10cSrcweir #include <unx/salinst.h>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // -=-= SalData =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
40cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Timeout() const41cdf0e10cSrcweir void X11SalData::Timeout() const
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
44cdf0e10cSrcweir     if( pSVData->mpSalTimer )
45cdf0e10cSrcweir         pSVData->mpSalTimer->CallCallback();
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // -=-= SalXLib =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
49cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
StopTimer()50cdf0e10cSrcweir void SalXLib::StopTimer()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	m_aTimeout.tv_sec	= 0;
53cdf0e10cSrcweir 	m_aTimeout.tv_usec	= 0;
54cdf0e10cSrcweir 	m_nTimeoutMS		= 0;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
StartTimer(sal_uLong nMS)57cdf0e10cSrcweir void SalXLib::StartTimer( sal_uLong nMS )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	timeval Timeout (m_aTimeout); // previous timeout.
60cdf0e10cSrcweir 	gettimeofday (&m_aTimeout, 0);
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	m_nTimeoutMS  = nMS;
63cdf0e10cSrcweir 	m_aTimeout    += m_nTimeoutMS;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	if ((Timeout > m_aTimeout) || (Timeout.tv_sec == 0))
66cdf0e10cSrcweir 	{
67cdf0e10cSrcweir 		// Wakeup from previous timeout (or stopped timer).
68cdf0e10cSrcweir 		Wakeup();
69cdf0e10cSrcweir 	}
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // -=-= SalTimer -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
73cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
CreateSalTimer()74cdf0e10cSrcweir SalTimer* X11SalInstance::CreateSalTimer()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     return new X11SalTimer();
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
~X11SalTimer()79cdf0e10cSrcweir X11SalTimer::~X11SalTimer()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
Stop()83cdf0e10cSrcweir void X11SalTimer::Stop()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	GetX11SalData()->GetLib()->StopTimer();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
Start(sal_uLong nMS)88cdf0e10cSrcweir void X11SalTimer::Start( sal_uLong nMS )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	GetX11SalData()->GetLib()->StartTimer( nMS );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93