bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / scanner / sane.hxx
blob06687028a5e8a7c45939522b6c9afe672477dcd3
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 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;
37 public:
39 BitmapTransporter();
40 virtual ~BitmapTransporter();
43 // XInterface
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 >(); }
52 // Misc
53 void lock() { m_aProtector.acquire(); }
54 void unlock() { m_aProtector.release(); }
55 SvMemoryStream& getStream() { return m_aStream; }
59 // - Sane -
62 class Sane
64 private:
65 static int nRefCount;
66 static oslModule pSaneLib;
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 );
90 static SANE_Int nVersion;
91 static SANE_Device** ppDevices;
92 static int nDevices;
94 const SANE_Option_Descriptor** mppOptions;
95 int mnOptions;
96 int mnDevice;
97 SANE_Handle maHandle;
99 Link<> maReloadOptionsLink;
101 static inline oslGenericFunction
102 LoadSymbol( const char* );
103 static void Init();
104 static void DeInit();
106 SANE_Status ControlOption( int, SANE_Action, void* );
108 bool CheckConsistency( const char*, bool bInit = false );
110 public:
111 Sane();
112 ~Sane();
114 static bool IsSane()
115 { return pSaneLib != nullptr; }
116 bool IsOpen()
117 { return maHandle != nullptr; }
118 static int CountDevices()
119 { return nDevices; }
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* );
164 bool Open( int );
165 void Close();
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 );
181 return 1;
184 inline Link<> Sane::SetReloadOptionsHdl( const Link<>& rLink )
186 Link<> aRet = maReloadOptionsLink;
187 maReloadOptionsLink = rLink;
188 return aRet;
191 #endif
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */