bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / scanner / sane.hxx
blob27d8711b530a224afaf9066947ed40b5edc3eb69
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 <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;
36 public:
38 BitmapTransporter();
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 >(); }
45 // Misc
46 void lock() { m_aProtector.acquire(); }
47 void unlock() { m_aProtector.release(); }
48 SvMemoryStream& getStream() { return m_aStream; }
52 class Sane
54 private:
55 static int nRefCount;
56 static oslModule pSaneLib;
58 static SANE_Status (*p_init)( SANE_Int*,
59 SANE_Auth_Callback );
60 static void (*p_exit)();
61 static SANE_Status (*p_get_devices)( const SANE_Device***,
62 SANE_Bool );
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,
68 SANE_Action, void*,
69 SANE_Int* );
70 static SANE_Status (*p_get_parameters)( SANE_Handle,
71 SANE_Parameters* );
72 static SANE_Status (*p_start)( SANE_Handle );
73 static SANE_Status (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
74 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;
82 static int nDevices;
84 std::unique_ptr<const SANE_Option_Descriptor*[]> mppOptions;
85 int mnOptions;
86 int mnDevice;
87 SANE_Handle maHandle;
89 Link<Sane&,void> maReloadOptionsLink;
91 static inline oslGenericFunction
92 LoadSymbol( const char* );
93 static void Init();
94 static void DeInit();
96 SANE_Status ControlOption( int, SANE_Action, void* );
98 bool CheckConsistency( const char*, bool bInit = false );
100 public:
101 Sane();
102 ~Sane();
104 static bool IsSane()
105 { return pSaneLib != nullptr; }
106 bool IsOpen()
107 { return maHandle != nullptr; }
108 static int CountDevices()
109 { return nDevices; }
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* );
154 bool Open( int );
155 void Close();
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 );
172 return 1;
176 inline Link<Sane&,void> Sane::SetReloadOptionsHdl( const Link<Sane&,void>& rLink )
178 Link<Sane&,void> aRet = maReloadOptionsLink;
179 maReloadOptionsLink = rLink;
180 return aRet;
183 #endif // INCLUDED_EXTENSIONS_SOURCE_SCANNER_SANE_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */