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 <vcl/bitmap.hxx>
25 #include <sane/sane.h>
26 #include <scanner.hxx>
29 // - BitmapTransporter -
32 class BitmapTransporter
: public OWeakObject
, css::awt::XBitmap
34 SvMemoryStream m_aStream
;
35 osl::Mutex m_aProtector
;
40 virtual ~BitmapTransporter();
44 virtual Any SAL_CALL
queryInterface( const Type
& rType
) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
45 virtual void SAL_CALL
acquire() throw() SAL_OVERRIDE
{ OWeakObject::acquire(); }
46 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
{ OWeakObject::release(); }
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 virtual Sequence
< sal_Int8
> SAL_CALL
getMaskDIB() throw(std::exception
) SAL_OVERRIDE
{ return Sequence
< sal_Int8
>(); }
53 void lock() { m_aProtector
.acquire(); }
54 void unlock() { m_aProtector
.release(); }
55 SvMemoryStream
& getStream() { return m_aStream
; }
66 static oslModule pSaneLib
;
68 static SANE_Status (*p_init
)( SANE_Int
*,
70 static void (*p_exit
)();
71 static SANE_Status (*p_get_devices
)( const SANE_Device
***,
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
,
80 static SANE_Status (*p_get_parameters
)( SANE_Handle
,
82 static SANE_Status (*p_start
)( SANE_Handle
);
83 static SANE_Status (*p_read
)( SANE_Handle
, SANE_Byte
*, 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
);
90 static SANE_Int nVersion
;
91 static SANE_Device
** ppDevices
;
94 const SANE_Option_Descriptor
** mppOptions
;
99 Link
<> maReloadOptionsLink
;
101 static inline oslGenericFunction
102 LoadSymbol( const char* );
104 static void DeInit();
106 SANE_Status
ControlOption( int, SANE_Action
, void* );
108 bool CheckConsistency( const char*, bool bInit
= false );
115 { return pSaneLib
!= nullptr; }
117 { return maHandle
!= nullptr; }
118 static int CountDevices()
120 static OUString
GetName( int n
)
121 { return ppDevices
[n
]->name
? OUString( ppDevices
[n
]->name
, strlen(ppDevices
[n
]->name
), osl_getThreadTextEncoding() ) : OUString(); }
122 static OUString
GetVendor( int n
)
123 { return ppDevices
[n
]->vendor
? OUString( ppDevices
[n
]->vendor
, strlen(ppDevices
[n
]->vendor
), osl_getThreadTextEncoding() ) : OUString(); }
124 static OUString
GetModel( int n
)
125 { return ppDevices
[n
]->model
? OUString( ppDevices
[n
]->model
, strlen(ppDevices
[n
]->model
), osl_getThreadTextEncoding() ) : OUString(); }
126 static OUString
GetType( int n
)
127 { return ppDevices
[n
]->type
? OUString( ppDevices
[n
]->type
, strlen(ppDevices
[n
]->type
), osl_getThreadTextEncoding() ) : OUString(); }
129 OUString
GetOptionName( int n
)
130 { return mppOptions
[n
]->name
? OUString( mppOptions
[n
]->name
, strlen(mppOptions
[n
]->name
), osl_getThreadTextEncoding() ) : OUString(); }
131 OUString
GetOptionTitle( int n
)
132 { return mppOptions
[n
]->title
? OUString( mppOptions
[n
]->title
, strlen(mppOptions
[n
]->title
), osl_getThreadTextEncoding() ) : OUString(); }
133 SANE_Value_Type
GetOptionType( int n
)
134 { return mppOptions
[n
]->type
; }
135 SANE_Unit
GetOptionUnit( int n
)
136 { return mppOptions
[n
]->unit
; }
137 OUString
GetOptionUnitName( int n
);
138 SANE_Int
GetOptionCap( int n
)
139 { return mppOptions
[n
]->cap
; }
140 SANE_Constraint_Type
GetOptionConstraintType( int n
)
141 { return mppOptions
[n
]->constraint_type
; }
142 const char** GetStringConstraint( int n
)
143 { return const_cast<const char**>(mppOptions
[n
]->constraint
.string_list
); }
144 int GetRange( int, double*& );
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* );
153 bool SetOptionValue( int, bool );
154 bool SetOptionValue( int, const OUString
& );
155 bool SetOptionValue( int, double, int nElement
= 0 );
156 bool SetOptionValue( int, double* );
158 bool ActivateButtonOption( int );
160 int CountOptions() { return mnOptions
; }
161 int GetDeviceNumber() { return mnDevice
; }
163 bool Open( const char* );
166 void ReloadDevices();
167 void ReloadOptions();
169 bool Start( BitmapTransporter
& );
171 inline Link
<> SetReloadOptionsHdl( const Link
<>& rLink
);
174 inline int Sane::GetOptionElements( int n
)
176 if( mppOptions
[n
]->type
== SANE_TYPE_FIXED
||
177 mppOptions
[n
]->type
== SANE_TYPE_INT
)
179 return mppOptions
[n
]->size
/sizeof( SANE_Word
);
184 inline Link
<> Sane::SetReloadOptionsHdl( const Link
<>& rLink
)
186 Link
<> aRet
= maReloadOptionsLink
;
187 maReloadOptionsLink
= rLink
;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */