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