Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_EXTENSIONS_SOURCE_SCANNER_SANE_HXX
20 : #define INCLUDED_EXTENSIONS_SOURCE_SCANNER_SANE_HXX
21 :
22 : #include <osl/thread.h>
23 : #include <osl/module.h>
24 : #include <vcl/bitmap.hxx>
25 : #include <sane/sane.h>
26 : #include <scanner.hxx>
27 :
28 :
29 : // - BitmapTransporter -
30 :
31 :
32 : class BitmapTransporter : public OWeakObject, css::awt::XBitmap
33 : {
34 : SvMemoryStream m_aStream;
35 : osl::Mutex m_aProtector;
36 :
37 : public:
38 :
39 : BitmapTransporter();
40 : virtual ~BitmapTransporter();
41 :
42 :
43 : // XInterface
44 : virtual Any SAL_CALL queryInterface( const Type & rType ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
45 0 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE { OWeakObject::acquire(); }
46 0 : virtual void SAL_CALL release() throw() SAL_OVERRIDE { OWeakObject::release(); }
47 :
48 : virtual css::awt::Size SAL_CALL getSize() throw(std::exception) SAL_OVERRIDE;
49 : virtual Sequence< sal_Int8 > SAL_CALL getDIB() throw(std::exception) SAL_OVERRIDE;
50 0 : virtual Sequence< sal_Int8 > SAL_CALL getMaskDIB() throw(std::exception) SAL_OVERRIDE { return Sequence< sal_Int8 >(); }
51 :
52 : // Misc
53 0 : void lock() { m_aProtector.acquire(); }
54 0 : void unlock() { m_aProtector.release(); }
55 0 : SvMemoryStream& getStream() { return m_aStream; }
56 : };
57 :
58 :
59 : // - Sane -
60 :
61 :
62 : class Sane
63 : {
64 : private:
65 : static int nRefCount;
66 : static oslModule pSaneLib;
67 :
68 : static SANE_Status (*p_init)( SANE_Int*,
69 : SANE_Auth_Callback );
70 : static void (*p_exit)();
71 : static SANE_Status (*p_get_devices)( const SANE_Device***,
72 : SANE_Bool );
73 : static SANE_Status (*p_open)( SANE_String_Const, SANE_Handle );
74 : static void (*p_close)( SANE_Handle );
75 : static const SANE_Option_Descriptor* (*p_get_option_descriptor)(
76 : SANE_Handle, SANE_Int );
77 : static SANE_Status (*p_control_option)( SANE_Handle, SANE_Int,
78 : SANE_Action, void*,
79 : SANE_Int* );
80 : static SANE_Status (*p_get_parameters)( SANE_Handle,
81 : SANE_Parameters* );
82 : static SANE_Status (*p_start)( SANE_Handle );
83 : static SANE_Status (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
84 : SANE_Int* );
85 : static void (*p_cancel)( SANE_Handle );
86 : static SANE_Status (*p_set_io_mode)( SANE_Handle, SANE_Bool );
87 : static SANE_Status (*p_get_select_fd)( SANE_Handle, SANE_Int* );
88 : static SANE_String_Const (*p_strstatus)( SANE_Status );
89 :
90 : static SANE_Int nVersion;
91 : static SANE_Device** ppDevices;
92 : static int nDevices;
93 :
94 : const SANE_Option_Descriptor** mppOptions;
95 : int mnOptions;
96 : int mnDevice;
97 : SANE_Handle maHandle;
98 :
99 : Link maReloadOptionsLink;
100 :
101 : inline oslGenericFunction
102 : LoadSymbol( const char* );
103 : void Init();
104 : void DeInit();
105 :
106 : SANE_Status ControlOption( int, SANE_Action, void* );
107 :
108 : bool CheckConsistency( const char*, bool bInit = false );
109 :
110 : public:
111 : Sane();
112 : ~Sane();
113 :
114 0 : static bool IsSane()
115 0 : { return pSaneLib ? sal_True : sal_False; }
116 0 : bool IsOpen()
117 0 : { return maHandle ? sal_True : sal_False; }
118 0 : static int CountDevices()
119 0 : { return nDevices; }
120 0 : static OUString GetName( int n )
121 0 : { return ppDevices[n]->name ? OUString( ppDevices[n]->name, strlen(ppDevices[n]->name), osl_getThreadTextEncoding() ) : OUString(); }
122 0 : static OUString GetVendor( int n )
123 0 : { return ppDevices[n]->vendor ? OUString( ppDevices[n]->vendor, strlen(ppDevices[n]->vendor), osl_getThreadTextEncoding() ) : OUString(); }
124 0 : static OUString GetModel( int n )
125 0 : { return ppDevices[n]->model ? OUString( ppDevices[n]->model, strlen(ppDevices[n]->model), osl_getThreadTextEncoding() ) : OUString(); }
126 0 : static OUString GetType( int n )
127 0 : { return ppDevices[n]->type ? OUString( ppDevices[n]->type, strlen(ppDevices[n]->type), osl_getThreadTextEncoding() ) : OUString(); }
128 :
129 0 : OUString GetOptionName( int n )
130 0 : { return mppOptions[n]->name ? OUString( (char*)mppOptions[n]->name, strlen((char*)mppOptions[n]->name), osl_getThreadTextEncoding() ) : OUString(); }
131 0 : OUString GetOptionTitle( int n )
132 0 : { return mppOptions[n]->title ? OUString( (char*)mppOptions[n]->title, strlen((char*)mppOptions[n]->title), osl_getThreadTextEncoding() ) : OUString(); }
133 0 : SANE_Value_Type GetOptionType( int n )
134 0 : { return mppOptions[n]->type; }
135 0 : SANE_Unit GetOptionUnit( int n )
136 0 : { return mppOptions[n]->unit; }
137 : OUString GetOptionUnitName( int n );
138 0 : SANE_Int GetOptionCap( int n )
139 0 : { return mppOptions[n]->cap; }
140 0 : SANE_Constraint_Type GetOptionConstraintType( int n )
141 0 : { return mppOptions[n]->constraint_type; }
142 0 : const char** GetStringConstraint( int n )
143 0 : { return (const char**)mppOptions[n]->constraint.string_list; }
144 : int GetRange( int, double*& );
145 :
146 : inline int GetOptionElements( int n );
147 : int GetOptionByName( const char* );
148 : bool GetOptionValue( int, bool& );
149 : bool GetOptionValue( int, OString& );
150 : bool GetOptionValue( int, double&, int nElement = 0 );
151 : bool GetOptionValue( int, double* );
152 :
153 : bool SetOptionValue( int, bool );
154 : bool SetOptionValue( int, const OUString& );
155 : bool SetOptionValue( int, double, int nElement = 0 );
156 : bool SetOptionValue( int, double* );
157 :
158 : bool ActivateButtonOption( int );
159 :
160 0 : int CountOptions() { return mnOptions; }
161 0 : int GetDeviceNumber() { return mnDevice; }
162 :
163 : bool Open( const char* );
164 : bool Open( int );
165 : void Close();
166 : void ReloadDevices();
167 : void ReloadOptions();
168 :
169 : bool Start( BitmapTransporter& );
170 :
171 : inline Link SetReloadOptionsHdl( const Link& rLink );
172 : };
173 :
174 0 : inline int Sane::GetOptionElements( int n )
175 : {
176 0 : if( mppOptions[n]->type == SANE_TYPE_FIXED ||
177 0 : mppOptions[n]->type == SANE_TYPE_INT )
178 : {
179 0 : return mppOptions[n]->size/sizeof( SANE_Word );
180 : }
181 0 : return 1;
182 : }
183 :
184 0 : inline Link Sane::SetReloadOptionsHdl( const Link& rLink )
185 : {
186 0 : Link aRet = maReloadOptionsLink;
187 0 : maReloadOptionsLink = rLink;
188 0 : return aRet;
189 : }
190 :
191 : #endif
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|