1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_EXTENSIONS_SOURCE_SCANNER_SANE_HXX
20 #define INCLUDED_EXTENSIONS_SOURCE_SCANNER_SANE_HXX
22 #include <osl/thread.h>
23 #include <osl/module.h>
24 #include <tools/stream.hxx>
25 #include <tools/link.hxx>
26 #include <vcl/bitmap.hxx>
27 #include <sane/sane.h>
28 #include "scanner.hxx"
31 class BitmapTransporter
: public cppu::WeakImplHelper
<css::awt::XBitmap
>
33 SvMemoryStream m_aStream
;
34 osl::Mutex m_aProtector
;
39 virtual ~BitmapTransporter() override
;
41 virtual css::awt::Size SAL_CALL
getSize() override
;
42 virtual Sequence
< sal_Int8
> SAL_CALL
getDIB() override
;
43 virtual Sequence
< sal_Int8
> SAL_CALL
getMaskDIB() override
{ return Sequence
< sal_Int8
>(); }
46 void lock() { m_aProtector
.acquire(); }
47 void unlock() { m_aProtector
.release(); }
48 SvMemoryStream
& getStream() { return m_aStream
; }
56 static oslModule pSaneLib
;
58 static SANE_Status (*p_init
)( SANE_Int
*,
60 static void (*p_exit
)();
61 static SANE_Status (*p_get_devices
)( const SANE_Device
***,
63 static SANE_Status (*p_open
)( SANE_String_Const
, SANE_Handle
);
64 static void (*p_close
)( SANE_Handle
);
65 static const SANE_Option_Descriptor
* (*p_get_option_descriptor
)(
66 SANE_Handle
, SANE_Int
);
67 static SANE_Status (*p_control_option
)( SANE_Handle
, SANE_Int
,
70 static SANE_Status (*p_get_parameters
)( SANE_Handle
,
72 static SANE_Status (*p_start
)( SANE_Handle
);
73 static SANE_Status (*p_read
)( SANE_Handle
, SANE_Byte
*, SANE_Int
,
75 static void (*p_cancel
)( SANE_Handle
);
76 static SANE_Status (*p_set_io_mode
)( SANE_Handle
, SANE_Bool
);
77 static SANE_Status (*p_get_select_fd
)( SANE_Handle
, SANE_Int
* );
78 static SANE_String_Const (*p_strstatus
)( SANE_Status
);
80 static SANE_Int nVersion
;
81 static SANE_Device
** ppDevices
;
84 std::unique_ptr
<const SANE_Option_Descriptor
*[]> mppOptions
;
89 Link
<Sane
&,void> maReloadOptionsLink
;
91 static inline oslGenericFunction
92 LoadSymbol( const char* );
96 SANE_Status
ControlOption( int, SANE_Action
, void* );
98 bool CheckConsistency( const char*, bool bInit
= false );
105 { return pSaneLib
!= nullptr; }
107 { return maHandle
!= nullptr; }
108 static int CountDevices()
110 static OUString
GetName( int n
)
111 { return ppDevices
[n
]->name
? OUString( ppDevices
[n
]->name
, strlen(ppDevices
[n
]->name
), osl_getThreadTextEncoding() ) : OUString(); }
112 static OUString
GetVendor( int n
)
113 { return ppDevices
[n
]->vendor
? OUString( ppDevices
[n
]->vendor
, strlen(ppDevices
[n
]->vendor
), osl_getThreadTextEncoding() ) : OUString(); }
114 static OUString
GetModel( int n
)
115 { return ppDevices
[n
]->model
? OUString( ppDevices
[n
]->model
, strlen(ppDevices
[n
]->model
), osl_getThreadTextEncoding() ) : OUString(); }
116 static OUString
GetType( int n
)
117 { return ppDevices
[n
]->type
? OUString( ppDevices
[n
]->type
, strlen(ppDevices
[n
]->type
), osl_getThreadTextEncoding() ) : OUString(); }
119 OUString
GetOptionName( int n
)
120 { return mppOptions
[n
]->name
? OUString( mppOptions
[n
]->name
, strlen(mppOptions
[n
]->name
), osl_getThreadTextEncoding() ) : OUString(); }
121 OUString
GetOptionTitle( int n
)
122 { return mppOptions
[n
]->title
? OUString( mppOptions
[n
]->title
, strlen(mppOptions
[n
]->title
), osl_getThreadTextEncoding() ) : OUString(); }
123 SANE_Value_Type
GetOptionType( int n
)
124 { return mppOptions
[n
]->type
; }
125 SANE_Unit
GetOptionUnit( int n
)
126 { return mppOptions
[n
]->unit
; }
127 OUString
GetOptionUnitName( int n
);
128 SANE_Int
GetOptionCap( int n
)
129 { return mppOptions
[n
]->cap
; }
130 SANE_Constraint_Type
GetOptionConstraintType( int n
)
131 { return mppOptions
[n
]->constraint_type
; }
132 const char** GetStringConstraint( int n
)
133 { return const_cast<const char**>(mppOptions
[n
]->constraint
.string_list
); }
134 int GetRange( int, std::unique_ptr
<double[]>& );
136 inline int GetOptionElements( int n
);
137 int GetOptionByName( const char* );
138 bool GetOptionValue( int, bool& );
139 bool GetOptionValue( int, OString
& );
140 bool GetOptionValue( int, double&, int nElement
= 0 );
141 bool GetOptionValue( int, double* );
143 void SetOptionValue( int, bool );
144 void SetOptionValue( int, const OUString
& );
145 void SetOptionValue( int, double, int nElement
= 0 );
146 void SetOptionValue( int, double const * );
148 bool ActivateButtonOption( int );
150 int CountOptions() { return mnOptions
; }
151 int GetDeviceNumber() { return mnDevice
; }
153 bool Open( const char* );
156 void ReloadDevices();
157 void ReloadOptions();
159 bool Start( BitmapTransporter
& );
161 inline Link
<Sane
&,void> SetReloadOptionsHdl( const Link
<Sane
&,void>& rLink
);
165 inline int Sane::GetOptionElements( int n
)
167 if( mppOptions
[n
]->type
== SANE_TYPE_FIXED
||
168 mppOptions
[n
]->type
== SANE_TYPE_INT
)
170 return mppOptions
[n
]->size
/sizeof( SANE_Word
);
176 inline Link
<Sane
&,void> Sane::SetReloadOptionsHdl( const Link
<Sane
&,void>& rLink
)
178 Link
<Sane
&,void> aRet
= maReloadOptionsLink
;
179 maReloadOptionsLink
= rLink
;
183 #endif // INCLUDED_EXTENSIONS_SOURCE_SCANNER_SANE_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */