xref: /aoo4110/main/vcl/unx/headless/svpinst.hxx (revision b1cdbd2c)
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 #ifndef _SVP_SALINST_HXX
25 #define _SVP_SALINST_HXX
26 
27 #include <vos/mutex.hxx>
28 #include <vos/thread.hxx>
29 
30 #include <salinst.hxx>
31 #include <salwtype.hxx>
32 #include <saltimer.hxx>
33 
34 #include <list>
35 
36 #include <time.h>  // timeval
37 
38 #define VIRTUAL_DESKTOP_WIDTH 1024
39 #define VIRTUAL_DESKTOP_HEIGHT 768
40 #define VIRTUAL_DESKTOP_DEPTH 24
41 
42 // -------------------------------------------------------------------------
43 // SalYieldMutex
44 // -------------------------------------------------------------------------
45 
46 class SvpSalYieldMutex : public vos::OMutex
47 {
48 protected:
49 	sal_uLong										mnCount;
50 	vos::OThread::TThreadIdentifier	mnThreadId;
51 
52 public:
53 												SvpSalYieldMutex();
54 
55 	virtual void								acquire();
56 	virtual void								release();
57 	virtual sal_Bool 							tryToAcquire();
58 
GetAcquireCount() const59 	sal_uLong										GetAcquireCount() const { return mnCount; }
GetThreadId() const60 	vos::OThread::TThreadIdentifier	GetThreadId() const { return mnThreadId; }
61 };
62 
63 // ---------------
64 // - SalTimer -
65 // ---------------
66 class SvpSalInstance;
67 class SvpSalTimer : public SalTimer
68 {
69     SvpSalInstance* m_pInstance;
70 public:
SvpSalTimer(SvpSalInstance * pInstance)71     SvpSalTimer( SvpSalInstance* pInstance ) : m_pInstance( pInstance ) {}
72     virtual ~SvpSalTimer();
73 
74     // overload all pure virtual methods
75 	virtual void Start( sal_uLong nMS );
76 	virtual void Stop();
77 };
78 
79 // ---------------
80 // - SalInstance -
81 // ---------------
82 class SvpSalFrame;
83 class SvpSalInstance : public SalInstance
84 {
85     timeval			    m_aTimeout;
86     sal_uLong               m_nTimeoutMS;
87 	int                 m_pTimeoutFDS[2];
88     SvpSalYieldMutex    m_aYieldMutex;
89 
90     // internal event queue
91     struct SalUserEvent
92     {
93         const SalFrame*		m_pFrame;
94         void*			    m_pData;
95         sal_uInt16		   m_nEvent;
96 
SalUserEventSvpSalInstance::SalUserEvent97         SalUserEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT )
98                 : m_pFrame( pFrame ),
99                   m_pData( pData ),
100                   m_nEvent( nEvent )
101         {}
102     };
103 
104     oslMutex        m_aEventGuard;
105     std::list< SalUserEvent > m_aUserEvents;
106 
107     std::list< SalFrame* > m_aFrames;
108 
109     bool isFrameAlive( const SalFrame* pFrame ) const;
110 
111 public:
112     static SvpSalInstance* s_pDefaultInstance;
113 
114     SvpSalInstance();
115     virtual ~SvpSalInstance();
116 
117     void PostEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
118     void CancelEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
119 
120     void StartTimer( sal_uLong nMS );
121     void StopTimer();
122     void Wakeup();
123 
registerFrame(SalFrame * pFrame)124     void registerFrame( SalFrame* pFrame ) { m_aFrames.push_back( pFrame ); }
125     void deregisterFrame( SalFrame* pFrame );
getFrames() const126     const std::list< SalFrame* >& getFrames() const { return m_aFrames; }
127 
128     bool            CheckTimeout( bool bExecuteTimers = true );
129 
130     // Frame
131     virtual SalFrame*      	CreateChildFrame( SystemParentData* pParent, sal_uLong nStyle );
132     virtual SalFrame*      	CreateFrame( SalFrame* pParent, sal_uLong nStyle );
133     virtual void			DestroyFrame( SalFrame* pFrame );
134 
135     // Object (System Child Window)
136     virtual SalObject*		CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, sal_Bool bShow = sal_True );
137     virtual void			DestroyObject( SalObject* pObject );
138 
139     // VirtualDevice
140     // nDX and nDY in Pixel
141     // nBitCount: 0 == Default(=as window) / 1 == Mono
142     // pData allows for using a system dependent graphics or device context
143     virtual SalVirtualDevice*	CreateVirtualDevice( SalGraphics* pGraphics,
144                                                      long nDX, long nDY,
145                                                      sal_uInt16 nBitCount, const SystemGraphicsData *pData = NULL );
146     virtual void				DestroyVirtualDevice( SalVirtualDevice* pDevice );
147 
148     // Printer
149     // pSetupData->mpDriverData can be 0
150     // pSetupData must be updatet with the current
151     // JobSetup
152     virtual SalInfoPrinter*	CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
153                                                ImplJobSetup* pSetupData );
154     virtual void			DestroyInfoPrinter( SalInfoPrinter* pPrinter );
155     virtual SalPrinter*		CreatePrinter( SalInfoPrinter* pInfoPrinter );
156     virtual void			DestroyPrinter( SalPrinter* pPrinter );
157 
158     virtual void			GetPrinterQueueInfo( ImplPrnQueueList* pList );
159     virtual void			GetPrinterQueueState( SalPrinterQueueInfo* pInfo );
160     virtual void			DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo );
161     virtual String          GetDefaultPrinter();
162 
163     // SalTimer
164     virtual SalTimer*		CreateSalTimer();
165     // SalI18NImeStatus
166     virtual SalI18NImeStatus*   CreateI18NImeStatus();
167     // SalSystem
168     virtual SalSystem*		CreateSalSystem();
169     // SalBitmap
170     virtual SalBitmap*		CreateSalBitmap();
171 
172     // YieldMutex
173     virtual vos::IMutex*	GetYieldMutex();
174     virtual sal_uLong			ReleaseYieldMutex();
175     virtual void			AcquireYieldMutex( sal_uLong nCount );
176     virtual bool            CheckYieldMutex();
177 
178 	// wait next event and dispatch
179     // must returned by UserEvent (SalFrame::PostEvent)
180     // and timer
181     virtual void			Yield( bool bWait, bool bHandleAllCurrentEvents );
182     virtual bool			AnyInput( sal_uInt16 nType );
183 
184     // may return NULL to disable session management
185     virtual SalSession*		CreateSalSession();
186 
187     virtual void*			GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes );
188 
189     virtual void            AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType);
190 };
191 
192 #endif // _SV_SALINST_HXX
193