update credits
[LibreOffice.git] / extensions / source / scanner / sane.hxx
blob06a7dc8f0e4c6adc69a8b3cdd0e90c44591d248c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _SANE_HXX
20 #define _SANE_HXX
22 #include <osl/thread.h>
23 #include <osl/module.h>
24 #include <tools/string.hxx>
25 #include <vcl/bitmap.hxx>
26 #include <sane/sane.h>
27 #include <scanner.hxx>
29 // ---------------------
30 // - BitmapTransporter -
31 // ---------------------
33 class BitmapTransporter : public OWeakObject, css::awt::XBitmap
35 SvMemoryStream m_aStream;
36 osl::Mutex m_aProtector;
38 public:
40 BitmapTransporter();
41 virtual ~BitmapTransporter();
44 // XInterface
45 virtual Any SAL_CALL queryInterface( const Type & rType ) throw( RuntimeException );
46 virtual void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
47 virtual void SAL_CALL release() throw() { OWeakObject::release(); }
49 virtual css::awt::Size SAL_CALL getSize() throw();
50 virtual Sequence< sal_Int8 > SAL_CALL getDIB() throw();
51 virtual Sequence< sal_Int8 > SAL_CALL getMaskDIB() throw() { return Sequence< sal_Int8 >(); }
53 // Misc
54 void lock() { m_aProtector.acquire(); }
55 void unlock() { m_aProtector.release(); }
56 SvMemoryStream& getStream() { return m_aStream; }
59 // --------
60 // - Sane -
61 // --------
63 class Sane
65 private:
66 static int nRefCount;
67 static oslModule pSaneLib;
69 static SANE_Status (*p_init)( SANE_Int*,
70 SANE_Auth_Callback );
71 static void (*p_exit)();
72 static SANE_Status (*p_get_devices)( const SANE_Device***,
73 SANE_Bool );
74 static SANE_Status (*p_open)( SANE_String_Const, SANE_Handle );
75 static void (*p_close)( SANE_Handle );
76 static const SANE_Option_Descriptor* (*p_get_option_descriptor)(
77 SANE_Handle, SANE_Int );
78 static SANE_Status (*p_control_option)( SANE_Handle, SANE_Int,
79 SANE_Action, void*,
80 SANE_Int* );
81 static SANE_Status (*p_get_parameters)( SANE_Handle,
82 SANE_Parameters* );
83 static SANE_Status (*p_start)( SANE_Handle );
84 static SANE_Status (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
85 SANE_Int* );
86 static void (*p_cancel)( SANE_Handle );
87 static SANE_Status (*p_set_io_mode)( SANE_Handle, SANE_Bool );
88 static SANE_Status (*p_get_select_fd)( SANE_Handle, SANE_Int* );
89 static SANE_String_Const (*p_strstatus)( SANE_Status );
91 static SANE_Int nVersion;
92 static SANE_Device** ppDevices;
93 static int nDevices;
95 const SANE_Option_Descriptor** mppOptions;
96 int mnOptions;
97 int mnDevice;
98 SANE_Handle maHandle;
100 Link maReloadOptionsLink;
102 inline oslGenericFunction
103 LoadSymbol( const char* );
104 void Init();
105 void DeInit();
107 SANE_Status ControlOption( int, SANE_Action, void* );
109 sal_Bool CheckConsistency( const char*, sal_Bool bInit = sal_False );
111 public:
112 Sane();
113 ~Sane();
115 static sal_Bool IsSane()
116 { return pSaneLib ? sal_True : sal_False; }
117 sal_Bool IsOpen()
118 { return maHandle ? sal_True : sal_False; }
119 static int CountDevices()
120 { return nDevices; }
121 static String GetName( int n )
122 { return String( ppDevices[n]->name ? ppDevices[n]->name : "", osl_getThreadTextEncoding() ); }
123 static String GetVendor( int n )
124 { return String( ppDevices[n]->vendor ? ppDevices[n]->vendor : "", osl_getThreadTextEncoding() ); }
125 static String GetModel( int n )
126 { return String( ppDevices[n]->model ? ppDevices[n]->model : "", osl_getThreadTextEncoding() ); }
127 static String GetType( int n )
128 { return String( ppDevices[n]->type ? ppDevices[n]->type : "", osl_getThreadTextEncoding() ); }
130 String GetOptionName( int n )
131 { return String( mppOptions[n]->name ? (char*)mppOptions[n]->name : "", osl_getThreadTextEncoding() ); }
132 String GetOptionTitle( int n )
133 { return String( mppOptions[n]->title ? (char*)mppOptions[n]->title : "", osl_getThreadTextEncoding() ); }
134 SANE_Value_Type GetOptionType( int n )
135 { return mppOptions[n]->type; }
136 SANE_Unit GetOptionUnit( int n )
137 { return mppOptions[n]->unit; }
138 String GetOptionUnitName( int n );
139 SANE_Int GetOptionCap( int n )
140 { return mppOptions[n]->cap; }
141 SANE_Constraint_Type GetOptionConstraintType( int n )
142 { return mppOptions[n]->constraint_type; }
143 const char** GetStringConstraint( int n )
144 { return (const char**)mppOptions[n]->constraint.string_list; }
145 int GetRange( int, double*& );
147 inline int GetOptionElements( int n );
148 int GetOptionByName( const char* );
149 sal_Bool GetOptionValue( int, sal_Bool& );
150 sal_Bool GetOptionValue( int, OString& );
151 sal_Bool GetOptionValue( int, double&, int nElement = 0 );
152 sal_Bool GetOptionValue( int, double* );
154 sal_Bool SetOptionValue( int, sal_Bool );
155 sal_Bool SetOptionValue( int, const String& );
156 sal_Bool SetOptionValue( int, double, int nElement = 0 );
157 sal_Bool SetOptionValue( int, double* );
159 sal_Bool ActivateButtonOption( int );
161 int CountOptions() { return mnOptions; }
162 int GetDeviceNumber() { return mnDevice; }
164 sal_Bool Open( const char* );
165 sal_Bool Open( int );
166 void Close();
167 void ReloadDevices();
168 void ReloadOptions();
170 sal_Bool Start( BitmapTransporter& );
172 inline Link SetReloadOptionsHdl( const Link& rLink );
175 inline int Sane::GetOptionElements( int n )
177 if( mppOptions[n]->type == SANE_TYPE_FIXED ||
178 mppOptions[n]->type == SANE_TYPE_INT )
180 return mppOptions[n]->size/sizeof( SANE_Word );
182 return 1;
185 inline Link Sane::SetReloadOptionsHdl( const Link& rLink )
187 Link aRet = maReloadOptionsLink;
188 maReloadOptionsLink = rLink;
189 return aRet;
192 #endif
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */