23#include <osl/thread.hxx>
29#include <com/sun/star/scanner/ScannerException.hpp>
33 SAL_INFO(
"extensions.scanner",
"BitmapTransporter");
39 SAL_INFO(
"extensions.scanner",
"~BitmapTransporter");
58 aRet.Width = aRet.Height = 0;
87 osl::Mutex m_aProtector;
91 SaneHolder() : m_nError(ScanError_ScanErrorNone), m_bBusy(false) {}
94 typedef std::vector< std::shared_ptr<SaneHolder> > sanevec;
101 allSanes() : mnRefCount(0) {}
106 void allSanes::acquire()
111 void allSanes::release()
120 struct theSaneProtector :
public rtl::Static<osl::Mutex, theSaneProtector> {};
121 struct theSanes :
public rtl::Static<allSanes, theSanes> {};
123class ScannerThread :
public osl::Thread
125 std::shared_ptr<SaneHolder> m_pHolder;
130 virtual void SAL_CALL
run()
override;
131 virtual void SAL_CALL onTerminated()
override {
delete this; }
133 ScannerThread( std::shared_ptr<SaneHolder> pHolder,
136 virtual ~ScannerThread()
override;
141ScannerThread::ScannerThread(std::shared_ptr<SaneHolder> pHolder,
146 SAL_INFO(
"extensions.scanner",
"ScannerThread");
150ScannerThread::~ScannerThread()
152 SAL_INFO(
"extensions.scanner",
"~ScannerThread");
156void ScannerThread::run()
158 osl_setThreadName(
"ScannerThread");
160 osl::MutexGuard aGuard( m_pHolder->m_aProtector );
163 m_pHolder->m_xBitmap = pTransporter;
165 m_pHolder->m_bBusy =
true;
166 if( m_pHolder->m_aSane.IsOpen() )
168 int nOption = m_pHolder->m_aSane.GetOptionByName(
"preview" );
170 m_pHolder->m_aSane.SetOptionValue( nOption,
false );
172 m_pHolder->m_nError =
173 m_pHolder->m_aSane.Start( *pTransporter ) ?
174 ScanError_ScanErrorNone : ScanError_ScanCanceled;
177 m_pHolder->m_nError = ScanError_ScannerNotAvailable;
181 m_xListener->disposing( css::lang::EventObject(xXInterface) );
182 m_pHolder->m_bBusy =
false;
188 osl::MutexGuard aGuard( theSaneProtector::get() );
189 theSanes::get().acquire();
195 osl::MutexGuard aGuard( theSaneProtector::get() );
196 theSanes::get().release();
203 aRet.Width = aRet.Height = 0;
216 osl::MutexGuard aGuard( theSaneProtector::get() );
217 sanevec &rSanes = theSanes::get().m_aSanes;
221 auto pSaneHolder = std::make_shared<SaneHolder>();
223 rSanes.push_back( pSaneHolder );
242 osl::MutexGuard aGuard( theSaneProtector::get() );
243 sanevec &rSanes = theSanes::get().m_aSanes;
245 SAL_INFO(
"extensions.scanner",
"ScannerManager::configureScanner");
247 if( scanner_context.InternalData < 0 ||
o3tl::make_unsigned(scanner_context.InternalData) >= rSanes.size() )
248 throw ScannerException(
249 "Scanner does not exist",
251 ScanError_InvalidContext
254 std::shared_ptr<SaneHolder> pHolder = rSanes[scanner_context.InternalData];
255 if( pHolder->m_bBusy )
256 throw ScannerException(
259 ScanError_ScanInProgress
262 pHolder->m_bBusy =
true;
266 pHolder->m_bBusy =
false;
278 osl::MutexGuard aGuard( theSaneProtector::get() );
279 sanevec &rSanes = theSanes::get().m_aSanes;
281 SAL_INFO(
"extensions.scanner",
"ScannerManager::startScan");
283 if( scanner_context.InternalData < 0 ||
o3tl::make_unsigned(scanner_context.InternalData) >= rSanes.size() )
284 throw ScannerException(
285 "Scanner does not exist",
287 ScanError_InvalidContext
289 std::shared_ptr<SaneHolder> pHolder = rSanes[scanner_context.InternalData];
290 if( pHolder->m_bBusy )
291 throw ScannerException(
294 ScanError_ScanInProgress
296 pHolder->m_bBusy =
true;
298 ScannerThread* pThread =
new ScannerThread( pHolder, listener,
this );
305 osl::MutexGuard aGuard( theSaneProtector::get() );
306 sanevec &rSanes = theSanes::get().m_aSanes;
308 if( scanner_context.InternalData < 0 ||
o3tl::make_unsigned(scanner_context.InternalData) >= rSanes.size() )
309 throw ScannerException(
310 "Scanner does not exist",
312 ScanError_InvalidContext
315 std::shared_ptr<SaneHolder> pHolder = rSanes[scanner_context.InternalData];
317 return pHolder->m_nError;
323 osl::MutexGuard aGuard( theSaneProtector::get() );
324 sanevec &rSanes = theSanes::get().m_aSanes;
326 if( scanner_context.InternalData < 0 ||
o3tl::make_unsigned(scanner_context.InternalData) >= rSanes.size() )
327 throw ScannerException(
328 "Scanner does not exist",
330 ScanError_InvalidContext
332 std::shared_ptr<SaneHolder> pHolder = rSanes[scanner_context.InternalData];
334 osl::MutexGuard aProtGuard( pHolder->m_aProtector );
337 pHolder->m_xBitmap.clear();
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
virtual css::awt::Size SAL_CALL getSize() override
virtual Sequence< sal_Int8 > SAL_CALL getDIB() override
virtual ~BitmapTransporter() override
virtual short run() override
virtual Sequence< sal_Int8 > SAL_CALL getDIB() override
virtual css::awt::Size SAL_CALL getSize() override
virtual Sequence< ScannerContext > SAL_CALL getAvailableScanners() override
static void AcquireData()
virtual ScanError SAL_CALL getError(const ScannerContext &scanner_context) override
css::uno::Reference< css::awt::XWindow > mxDialogParent
virtual void SAL_CALL startScan(const ScannerContext &scanner_context, const Reference< css::lang::XEventListener > &rxListener) override
virtual Reference< css::awt::XBitmap > SAL_CALL getBitmap(const ScannerContext &scanner_context) override
virtual sal_Bool SAL_CALL configureScannerAndScan(ScannerContext &scanner_context, const Reference< css::lang::XEventListener > &rxListener) override
virtual sal_uInt64 TellEnd() override
sal_uInt64 Seek(sal_uInt64 nPos)
SvStream & ReadInt32(sal_Int32 &rInt32)
std::size_t ReadBytes(void *pData, std::size_t nSize)
#define SAL_INFO(area, stream)
def run(arg=None, arg2=-1)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)