LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/scanner - sane.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 45 0.0 %
Date: 2012-12-27 Functions: 0 24 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : #ifndef _SANE_HXX
      20             : #define _SANE_HXX
      21             : 
      22             : #include <osl/thread.h>
      23             : #include <osl/module.h>
      24             : #include <tools/string.hxx>
      25             : #include <vcl/bitmap.hxx>
      26             : #include <sane/sane.h>
      27             : #include <scanner.hxx>
      28             : 
      29             : // ---------------------
      30             : // - BitmapTransporter -
      31             : // ---------------------
      32             : 
      33             : class BitmapTransporter : public OWeakObject, AWT::XBitmap
      34             : {
      35             :     SvMemoryStream                      m_aStream;
      36             :     osl::Mutex                          m_aProtector;
      37             : 
      38             : public:
      39             : 
      40             :                                         BitmapTransporter();
      41             :     virtual                             ~BitmapTransporter();
      42             : 
      43             : 
      44             :     // XInterface
      45             :     virtual ANY SAL_CALL                queryInterface( const Type & rType ) throw( RuntimeException );
      46           0 :     virtual void SAL_CALL               acquire() throw() { OWeakObject::acquire(); }
      47           0 :     virtual void SAL_CALL               release() throw() { OWeakObject::release(); }
      48             : 
      49             :     virtual AWT::Size SAL_CALL          getSize() throw();
      50             :     virtual SEQ( sal_Int8 ) SAL_CALL    getDIB() throw();
      51           0 :     virtual SEQ( sal_Int8 ) SAL_CALL    getMaskDIB() throw() { return SEQ( sal_Int8 )(); }
      52             : 
      53             :     // Misc
      54           0 :     void                                lock() { m_aProtector.acquire(); }
      55           0 :     void                                unlock() { m_aProtector.release(); }
      56           0 :     SvMemoryStream&                     getStream() { return m_aStream; }
      57             : };
      58             : 
      59             : // --------
      60             : // - Sane -
      61             : // --------
      62             : 
      63             : class Sane
      64             : {
      65             : private:
      66             :     static int              nRefCount;
      67             :     static oslModule        pSaneLib;
      68             : 
      69             :     static SANE_Status      (*p_init)( SANE_Int*,
      70             :                                        SANE_Auth_Callback );
      71             :     static void             (*p_exit)();
      72             :     static SANE_Status      (*p_get_devices)( const SANE_Device***,
      73             :                                               SANE_Bool );
      74             :     static SANE_Status      (*p_open)( SANE_String_Const, SANE_Handle );
      75             :     static void             (*p_close)( SANE_Handle );
      76             :     static const SANE_Option_Descriptor* (*p_get_option_descriptor)(
      77             :         SANE_Handle, SANE_Int );
      78             :     static SANE_Status      (*p_control_option)( SANE_Handle, SANE_Int,
      79             :                                                  SANE_Action, void*,
      80             :                                                  SANE_Int* );
      81             :     static SANE_Status      (*p_get_parameters)( SANE_Handle,
      82             :                                                  SANE_Parameters* );
      83             :     static SANE_Status      (*p_start)( SANE_Handle );
      84             :     static SANE_Status      (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
      85             :                                        SANE_Int* );
      86             :     static void             (*p_cancel)( SANE_Handle );
      87             :     static SANE_Status      (*p_set_io_mode)( SANE_Handle, SANE_Bool );
      88             :     static SANE_Status      (*p_get_select_fd)( SANE_Handle, SANE_Int* );
      89             :     static SANE_String_Const (*p_strstatus)( SANE_Status );
      90             : 
      91             :     static SANE_Int             nVersion;
      92             :     static SANE_Device**        ppDevices;
      93             :     static int                  nDevices;
      94             : 
      95             :     const SANE_Option_Descriptor**  mppOptions;
      96             :     int                             mnOptions;
      97             :     int                             mnDevice;
      98             :     SANE_Handle                     maHandle;
      99             : 
     100             :     Link                        maReloadOptionsLink;
     101             : 
     102             :     inline oslGenericFunction
     103             :                     LoadSymbol( const char* );
     104             :     void            Init();
     105             :     void            DeInit();
     106             : 
     107             :     SANE_Status ControlOption( int, SANE_Action, void* );
     108             : 
     109             :     sal_Bool CheckConsistency( const char*, sal_Bool bInit = sal_False );
     110             : 
     111             : public:
     112             :     Sane();
     113             :     ~Sane();
     114             : 
     115           0 :     static sal_Bool         IsSane()
     116           0 :         { return pSaneLib ? sal_True : sal_False; }
     117           0 :     sal_Bool            IsOpen()
     118           0 :         { return maHandle ? sal_True : sal_False; }
     119           0 :     static int              CountDevices()
     120           0 :         { return nDevices; }
     121           0 :     static String           GetName( int n )
     122           0 :         { return String( ppDevices[n]->name ? ppDevices[n]->name : "", osl_getThreadTextEncoding() ); }
     123           0 :     static String           GetVendor( int n )
     124           0 :         { return String( ppDevices[n]->vendor ? ppDevices[n]->vendor : "", osl_getThreadTextEncoding() ); }
     125           0 :     static String           GetModel( int n )
     126           0 :         { return String( ppDevices[n]->model ? ppDevices[n]->model : "", osl_getThreadTextEncoding() ); }
     127           0 :     static String           GetType( int n )
     128           0 :         { return String( ppDevices[n]->type ? ppDevices[n]->type : "", osl_getThreadTextEncoding() ); }
     129             : 
     130           0 :     String          GetOptionName( int n )
     131           0 :         { return String( mppOptions[n]->name ? (char*)mppOptions[n]->name : "", osl_getThreadTextEncoding() ); }
     132           0 :     String          GetOptionTitle( int n )
     133           0 :         { return String( mppOptions[n]->title ? (char*)mppOptions[n]->title : "", osl_getThreadTextEncoding() ); }
     134           0 :     SANE_Value_Type GetOptionType( int n )
     135           0 :         { return mppOptions[n]->type; }
     136           0 :     SANE_Unit       GetOptionUnit( int n )
     137           0 :         { return mppOptions[n]->unit; }
     138             :     String          GetOptionUnitName( int n );
     139           0 :     SANE_Int        GetOptionCap( int n )
     140           0 :         { return mppOptions[n]->cap; }
     141           0 :     SANE_Constraint_Type GetOptionConstraintType( int n )
     142           0 :         { return mppOptions[n]->constraint_type; }
     143           0 :     const char**    GetStringConstraint( int n )
     144           0 :         { return (const char**)mppOptions[n]->constraint.string_list; }
     145             :     int             GetRange( int, double*& );
     146             : 
     147             :     inline int      GetOptionElements( int n );
     148             :     int             GetOptionByName( const char* );
     149             :     sal_Bool            GetOptionValue( int, sal_Bool& );
     150             :     sal_Bool            GetOptionValue( int, rtl::OString& );
     151             :     sal_Bool            GetOptionValue( int, double&, int nElement = 0 );
     152             :     sal_Bool            GetOptionValue( int, double* );
     153             : 
     154             :     sal_Bool            SetOptionValue( int, sal_Bool );
     155             :     sal_Bool            SetOptionValue( int, const String& );
     156             :     sal_Bool            SetOptionValue( int, double, int nElement = 0 );
     157             :     sal_Bool            SetOptionValue( int, double* );
     158             : 
     159             :     sal_Bool            ActivateButtonOption( int );
     160             : 
     161           0 :     int             CountOptions() { return mnOptions; }
     162           0 :     int             GetDeviceNumber() { return mnDevice; }
     163             : 
     164             :     sal_Bool            Open( const char* );
     165             :     sal_Bool            Open( int );
     166             :     void            Close();
     167             :     void            ReloadDevices();
     168             :     void            ReloadOptions();
     169             : 
     170             :     sal_Bool            Start( BitmapTransporter& );
     171             : 
     172             :     inline Link     SetReloadOptionsHdl( const Link& rLink );
     173             : };
     174             : 
     175           0 : inline int Sane::GetOptionElements( int n )
     176             : {
     177           0 :     if( mppOptions[n]->type == SANE_TYPE_FIXED ||
     178           0 :         mppOptions[n]->type == SANE_TYPE_INT )
     179             :     {
     180           0 :         return mppOptions[n]->size/sizeof( SANE_Word );
     181             :     }
     182           0 :     return 1;
     183             : }
     184             : 
     185           0 : inline Link Sane::SetReloadOptionsHdl( const Link& rLink )
     186             : {
     187           0 :     Link aRet = maReloadOptionsLink;
     188           0 :     maReloadOptionsLink = rLink;
     189           0 :     return aRet;
     190             : }
     191             : 
     192             : #endif
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10