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