Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _SANE_HXX
29 : : #define _SANE_HXX
30 : :
31 : : #include <osl/thread.h>
32 : : #include <osl/module.h>
33 : : #include <tools/string.hxx>
34 : : #include <vcl/bitmap.hxx>
35 : : #include <sane/sane.h>
36 : : #include <scanner.hxx>
37 : :
38 : : // ---------------------
39 : : // - BitmapTransporter -
40 : : // ---------------------
41 : :
42 : : class BitmapTransporter : public OWeakObject, AWT::XBitmap
43 : : {
44 : : SvMemoryStream m_aStream;
45 : : osl::Mutex m_aProtector;
46 : :
47 : : public:
48 : :
49 : : BitmapTransporter();
50 : : virtual ~BitmapTransporter();
51 : :
52 : :
53 : : // XInterface
54 : : virtual ANY SAL_CALL queryInterface( const Type & rType ) throw( RuntimeException );
55 : 0 : virtual void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
56 : 0 : virtual void SAL_CALL release() throw() { OWeakObject::release(); }
57 : :
58 : : virtual AWT::Size SAL_CALL getSize() throw();
59 : : virtual SEQ( sal_Int8 ) SAL_CALL getDIB() throw();
60 : 0 : virtual SEQ( sal_Int8 ) SAL_CALL getMaskDIB() throw() { return SEQ( sal_Int8 )(); }
61 : :
62 : : // Misc
63 : 0 : void lock() { m_aProtector.acquire(); }
64 : 0 : void unlock() { m_aProtector.release(); }
65 : 0 : SvMemoryStream& getStream() { return m_aStream; }
66 : : };
67 : :
68 : : // --------
69 : : // - Sane -
70 : : // --------
71 : :
72 : : class Sane
73 : : {
74 : : private:
75 : : static int nRefCount;
76 : : static oslModule pSaneLib;
77 : :
78 : : static SANE_Status (*p_init)( SANE_Int*,
79 : : SANE_Auth_Callback );
80 : : static void (*p_exit)();
81 : : static SANE_Status (*p_get_devices)( const SANE_Device***,
82 : : SANE_Bool );
83 : : static SANE_Status (*p_open)( SANE_String_Const, SANE_Handle );
84 : : static void (*p_close)( SANE_Handle );
85 : : static const SANE_Option_Descriptor* (*p_get_option_descriptor)(
86 : : SANE_Handle, SANE_Int );
87 : : static SANE_Status (*p_control_option)( SANE_Handle, SANE_Int,
88 : : SANE_Action, void*,
89 : : SANE_Int* );
90 : : static SANE_Status (*p_get_parameters)( SANE_Handle,
91 : : SANE_Parameters* );
92 : : static SANE_Status (*p_start)( SANE_Handle );
93 : : static SANE_Status (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
94 : : SANE_Int* );
95 : : static void (*p_cancel)( SANE_Handle );
96 : : static SANE_Status (*p_set_io_mode)( SANE_Handle, SANE_Bool );
97 : : static SANE_Status (*p_get_select_fd)( SANE_Handle, SANE_Int* );
98 : : static SANE_String_Const (*p_strstatus)( SANE_Status );
99 : :
100 : : static SANE_Int nVersion;
101 : : static SANE_Device** ppDevices;
102 : : static int nDevices;
103 : :
104 : : const SANE_Option_Descriptor** mppOptions;
105 : : int mnOptions;
106 : : int mnDevice;
107 : : SANE_Handle maHandle;
108 : :
109 : : Link maReloadOptionsLink;
110 : :
111 : : inline oslGenericFunction
112 : : LoadSymbol( const char* );
113 : : void Init();
114 : : void DeInit();
115 : :
116 : : SANE_Status ControlOption( int, SANE_Action, void* );
117 : :
118 : : sal_Bool CheckConsistency( const char*, sal_Bool bInit = sal_False );
119 : :
120 : : public:
121 : : Sane();
122 : : ~Sane();
123 : :
124 : 0 : static sal_Bool IsSane()
125 [ # # ]: 0 : { return pSaneLib ? sal_True : sal_False; }
126 : 0 : sal_Bool IsOpen()
127 [ # # ]: 0 : { return maHandle ? sal_True : sal_False; }
128 : 0 : static int CountDevices()
129 : 0 : { return nDevices; }
130 : 0 : static String GetName( int n )
131 [ # # ]: 0 : { return String( ppDevices[n]->name ? ppDevices[n]->name : "", osl_getThreadTextEncoding() ); }
132 : 0 : static String GetVendor( int n )
133 [ # # ]: 0 : { return String( ppDevices[n]->vendor ? ppDevices[n]->vendor : "", osl_getThreadTextEncoding() ); }
134 : 0 : static String GetModel( int n )
135 [ # # ]: 0 : { return String( ppDevices[n]->model ? ppDevices[n]->model : "", osl_getThreadTextEncoding() ); }
136 : 0 : static String GetType( int n )
137 [ # # ]: 0 : { return String( ppDevices[n]->type ? ppDevices[n]->type : "", osl_getThreadTextEncoding() ); }
138 : :
139 : 0 : String GetOptionName( int n )
140 [ # # ]: 0 : { return String( mppOptions[n]->name ? (char*)mppOptions[n]->name : "", osl_getThreadTextEncoding() ); }
141 : 0 : String GetOptionTitle( int n )
142 [ # # ]: 0 : { return String( mppOptions[n]->title ? (char*)mppOptions[n]->title : "", osl_getThreadTextEncoding() ); }
143 : 0 : SANE_Value_Type GetOptionType( int n )
144 : 0 : { return mppOptions[n]->type; }
145 : 0 : SANE_Unit GetOptionUnit( int n )
146 : 0 : { return mppOptions[n]->unit; }
147 : : String GetOptionUnitName( int n );
148 : 0 : SANE_Int GetOptionCap( int n )
149 : 0 : { return mppOptions[n]->cap; }
150 : 0 : SANE_Constraint_Type GetOptionConstraintType( int n )
151 : 0 : { return mppOptions[n]->constraint_type; }
152 : 0 : const char** GetStringConstraint( int n )
153 : 0 : { return (const char**)mppOptions[n]->constraint.string_list; }
154 : : int GetRange( int, double*& );
155 : :
156 : : inline int GetOptionElements( int n );
157 : : int GetOptionByName( const char* );
158 : : sal_Bool GetOptionValue( int, sal_Bool& );
159 : : sal_Bool GetOptionValue( int, rtl::OString& );
160 : : sal_Bool GetOptionValue( int, double&, int nElement = 0 );
161 : : sal_Bool GetOptionValue( int, double* );
162 : :
163 : : sal_Bool SetOptionValue( int, sal_Bool );
164 : : sal_Bool SetOptionValue( int, const String& );
165 : : sal_Bool SetOptionValue( int, double, int nElement = 0 );
166 : : sal_Bool SetOptionValue( int, double* );
167 : :
168 : : sal_Bool ActivateButtonOption( int );
169 : :
170 : 0 : int CountOptions() { return mnOptions; }
171 : 0 : int GetDeviceNumber() { return mnDevice; }
172 : :
173 : : sal_Bool Open( const char* );
174 : : sal_Bool Open( int );
175 : : void Close();
176 : : void ReloadDevices();
177 : : void ReloadOptions();
178 : :
179 : : sal_Bool Start( BitmapTransporter& );
180 : :
181 : : inline Link SetReloadOptionsHdl( const Link& rLink );
182 : : };
183 : :
184 : 0 : inline int Sane::GetOptionElements( int n )
185 : : {
186 [ # # ][ # # ]: 0 : if( mppOptions[n]->type == SANE_TYPE_FIXED ||
187 : 0 : mppOptions[n]->type == SANE_TYPE_INT )
188 : : {
189 : 0 : return mppOptions[n]->size/sizeof( SANE_Word );
190 : : }
191 : 0 : return 1;
192 : : }
193 : :
194 : 0 : inline Link Sane::SetReloadOptionsHdl( const Link& rLink )
195 : : {
196 : 0 : Link aRet = maReloadOptionsLink;
197 : 0 : maReloadOptionsLink = rLink;
198 : 0 : return aRet;
199 : : }
200 : :
201 : : #endif
202 : :
203 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|