xref: /trunk/main/extensions/source/scanner/sane.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*46dbaceeSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*46dbaceeSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*46dbaceeSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*46dbaceeSAndrew Rist  * distributed with this work for additional information
6*46dbaceeSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*46dbaceeSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*46dbaceeSAndrew Rist  * "License"); you may not use this file except in compliance
9*46dbaceeSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*46dbaceeSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*46dbaceeSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*46dbaceeSAndrew Rist  * software distributed under the License is distributed on an
15*46dbaceeSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*46dbaceeSAndrew Rist  * KIND, either express or implied.  See the License for the
17*46dbaceeSAndrew Rist  * specific language governing permissions and limitations
18*46dbaceeSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*46dbaceeSAndrew Rist  *************************************************************/
21*46dbaceeSAndrew Rist 
22*46dbaceeSAndrew Rist 
23cdf0e10cSrcweir #ifndef _SANE_HXX
24cdf0e10cSrcweir #define _SANE_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <osl/thread.h>
27cdf0e10cSrcweir #include <osl/module.h>
28cdf0e10cSrcweir #include <tools/string.hxx>
29cdf0e10cSrcweir #include <vcl/bitmap.hxx>
30cdf0e10cSrcweir #include <sane/sane.h>
31cdf0e10cSrcweir #include <scanner.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // ---------------------
34cdf0e10cSrcweir // - BitmapTransporter -
35cdf0e10cSrcweir // ---------------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class BitmapTransporter : public OWeakObject, AWT::XBitmap
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     SvMemoryStream                      m_aStream;
40cdf0e10cSrcweir     vos::OMutex                         m_aProtector;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir public:
43cdf0e10cSrcweir 
44cdf0e10cSrcweir                                         BitmapTransporter();
45cdf0e10cSrcweir     virtual                             ~BitmapTransporter();
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     // XInterface
49cdf0e10cSrcweir     virtual ANY SAL_CALL                queryInterface( const Type & rType ) throw( RuntimeException );
acquire()50cdf0e10cSrcweir     virtual void SAL_CALL               acquire() throw() { OWeakObject::acquire(); }
release()51cdf0e10cSrcweir     virtual void SAL_CALL               release() throw() { OWeakObject::release(); }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     virtual AWT::Size SAL_CALL          getSize() throw();
54cdf0e10cSrcweir     virtual SEQ( sal_Int8 ) SAL_CALL    getDIB() throw();
SEQ(sal_Int8)55cdf0e10cSrcweir     virtual SEQ( sal_Int8 ) SAL_CALL    getMaskDIB() throw() { return SEQ( sal_Int8 )(); }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     // Misc
lock()58cdf0e10cSrcweir     void                                lock() { m_aProtector.acquire(); }
unlock()59cdf0e10cSrcweir     void                                unlock() { m_aProtector.release(); }
getStream()60cdf0e10cSrcweir     SvMemoryStream&                     getStream() { return m_aStream; }
61cdf0e10cSrcweir };
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // --------
64cdf0e10cSrcweir // - Sane -
65cdf0e10cSrcweir // --------
66cdf0e10cSrcweir 
67cdf0e10cSrcweir class Sane
68cdf0e10cSrcweir {
69cdf0e10cSrcweir private:
70cdf0e10cSrcweir     static int              nRefCount;
71cdf0e10cSrcweir     static oslModule        pSaneLib;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     static SANE_Status      (*p_init)( SANE_Int*,
74cdf0e10cSrcweir                                        SANE_Auth_Callback );
75cdf0e10cSrcweir     static void             (*p_exit)();
76cdf0e10cSrcweir     static SANE_Status      (*p_get_devices)( const SANE_Device***,
77cdf0e10cSrcweir                                               SANE_Bool );
78cdf0e10cSrcweir     static SANE_Status      (*p_open)( SANE_String_Const, SANE_Handle );
79cdf0e10cSrcweir     static void             (*p_close)( SANE_Handle );
80cdf0e10cSrcweir     static const SANE_Option_Descriptor* (*p_get_option_descriptor)(
81cdf0e10cSrcweir         SANE_Handle, SANE_Int );
82cdf0e10cSrcweir     static SANE_Status      (*p_control_option)( SANE_Handle, SANE_Int,
83cdf0e10cSrcweir                                                  SANE_Action, void*,
84cdf0e10cSrcweir                                                  SANE_Int* );
85cdf0e10cSrcweir     static SANE_Status      (*p_get_parameters)( SANE_Handle,
86cdf0e10cSrcweir                                                  SANE_Parameters* );
87cdf0e10cSrcweir     static SANE_Status      (*p_start)( SANE_Handle );
88cdf0e10cSrcweir     static SANE_Status      (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
89cdf0e10cSrcweir                                        SANE_Int* );
90cdf0e10cSrcweir     static void             (*p_cancel)( SANE_Handle );
91cdf0e10cSrcweir     static SANE_Status      (*p_set_io_mode)( SANE_Handle, SANE_Bool );
92cdf0e10cSrcweir     static SANE_Status      (*p_get_select_fd)( SANE_Handle, SANE_Int* );
93cdf0e10cSrcweir     static SANE_String_Const (*p_strstatus)( SANE_Status );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     static SANE_Int             nVersion;
96cdf0e10cSrcweir     static SANE_Device**        ppDevices;
97cdf0e10cSrcweir     static int                  nDevices;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     const SANE_Option_Descriptor**  mppOptions;
100cdf0e10cSrcweir     int                             mnOptions;
101cdf0e10cSrcweir     int                             mnDevice;
102cdf0e10cSrcweir     SANE_Handle                     maHandle;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     Link                        maReloadOptionsLink;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     inline oslGenericFunction
107cdf0e10cSrcweir                     LoadSymbol( const char* );
108cdf0e10cSrcweir     void            Init();
109cdf0e10cSrcweir     void            DeInit();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     SANE_Status ControlOption( int, SANE_Action, void* );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     sal_Bool CheckConsistency( const char*, sal_Bool bInit = sal_False );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir public:
116cdf0e10cSrcweir     Sane();
117cdf0e10cSrcweir     ~Sane();
118cdf0e10cSrcweir 
IsSane()119cdf0e10cSrcweir     static sal_Bool         IsSane()
120cdf0e10cSrcweir         { return pSaneLib ? sal_True : sal_False; }
IsOpen()121cdf0e10cSrcweir     sal_Bool            IsOpen()
122cdf0e10cSrcweir         { return maHandle ? sal_True : sal_False; }
CountDevices()123cdf0e10cSrcweir     static int              CountDevices()
124cdf0e10cSrcweir         { return nDevices; }
GetName(int n)125cdf0e10cSrcweir     static String           GetName( int n )
126cdf0e10cSrcweir         { return String( ppDevices[n]->name ? ppDevices[n]->name : "", osl_getThreadTextEncoding() ); }
GetVendor(int n)127cdf0e10cSrcweir     static String           GetVendor( int n )
128cdf0e10cSrcweir         { return String( ppDevices[n]->vendor ? ppDevices[n]->vendor : "", osl_getThreadTextEncoding() ); }
GetModel(int n)129cdf0e10cSrcweir     static String           GetModel( int n )
130cdf0e10cSrcweir         { return String( ppDevices[n]->model ? ppDevices[n]->model : "", osl_getThreadTextEncoding() ); }
GetType(int n)131cdf0e10cSrcweir     static String           GetType( int n )
132cdf0e10cSrcweir         { return String( ppDevices[n]->type ? ppDevices[n]->type : "", osl_getThreadTextEncoding() ); }
133cdf0e10cSrcweir 
GetOptionName(int n)134cdf0e10cSrcweir     String          GetOptionName( int n )
135cdf0e10cSrcweir         { return String( mppOptions[n]->name ? (char*)mppOptions[n]->name : "", osl_getThreadTextEncoding() ); }
GetOptionTitle(int n)136cdf0e10cSrcweir     String          GetOptionTitle( int n )
137cdf0e10cSrcweir         { return String( mppOptions[n]->title ? (char*)mppOptions[n]->title : "", osl_getThreadTextEncoding() ); }
GetOptionType(int n)138cdf0e10cSrcweir     SANE_Value_Type GetOptionType( int n )
139cdf0e10cSrcweir         { return mppOptions[n]->type; }
GetOptionUnit(int n)140cdf0e10cSrcweir     SANE_Unit       GetOptionUnit( int n )
141cdf0e10cSrcweir         { return mppOptions[n]->unit; }
142cdf0e10cSrcweir     String          GetOptionUnitName( int n );
GetOptionCap(int n)143cdf0e10cSrcweir     SANE_Int        GetOptionCap( int n )
144cdf0e10cSrcweir         { return mppOptions[n]->cap; }
GetOptionConstraintType(int n)145cdf0e10cSrcweir     SANE_Constraint_Type GetOptionConstraintType( int n )
146cdf0e10cSrcweir         { return mppOptions[n]->constraint_type; }
GetStringConstraint(int n)147cdf0e10cSrcweir     const char**    GetStringConstraint( int n )
148cdf0e10cSrcweir         { return (const char**)mppOptions[n]->constraint.string_list; }
149cdf0e10cSrcweir     int             GetRange( int, double*& );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     inline int      GetOptionElements( int n );
152cdf0e10cSrcweir     int             GetOptionByName( const char* );
153cdf0e10cSrcweir     sal_Bool            GetOptionValue( int, sal_Bool& );
154cdf0e10cSrcweir     sal_Bool            GetOptionValue( int, ByteString& );
155cdf0e10cSrcweir     sal_Bool            GetOptionValue( int, double&, int nElement = 0 );
156cdf0e10cSrcweir     sal_Bool            GetOptionValue( int, double* );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     sal_Bool            SetOptionValue( int, sal_Bool );
159cdf0e10cSrcweir     sal_Bool            SetOptionValue( int, const String& );
160cdf0e10cSrcweir     sal_Bool            SetOptionValue( int, double, int nElement = 0 );
161cdf0e10cSrcweir     sal_Bool            SetOptionValue( int, double* );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     sal_Bool            ActivateButtonOption( int );
164cdf0e10cSrcweir 
CountOptions()165cdf0e10cSrcweir     int             CountOptions() { return mnOptions; }
GetDeviceNumber()166cdf0e10cSrcweir     int             GetDeviceNumber() { return mnDevice; }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     sal_Bool            Open( const char* );
169cdf0e10cSrcweir     sal_Bool            Open( int );
170cdf0e10cSrcweir     void            Close();
171cdf0e10cSrcweir     void            ReloadDevices();
172cdf0e10cSrcweir     void            ReloadOptions();
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     sal_Bool            Start( BitmapTransporter& );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     inline Link     SetReloadOptionsHdl( const Link& rLink );
177cdf0e10cSrcweir };
178cdf0e10cSrcweir 
GetOptionElements(int n)179cdf0e10cSrcweir inline int Sane::GetOptionElements( int n )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     if( mppOptions[n]->type == SANE_TYPE_FIXED ||
182cdf0e10cSrcweir         mppOptions[n]->type == SANE_TYPE_INT )
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         return mppOptions[n]->size/sizeof( SANE_Word );
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir     return 1;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
SetReloadOptionsHdl(const Link & rLink)189cdf0e10cSrcweir inline Link Sane::SetReloadOptionsHdl( const Link& rLink )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     Link aRet = maReloadOptionsLink;
192cdf0e10cSrcweir     maReloadOptionsLink = rLink;
193cdf0e10cSrcweir     return aRet;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir #endif
197