/Users/ericb/Desktop/NATIVEPRINTDLG01/extensions/source/scanner/sane.hxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: sane.hxx,v $
00006  *
00007  *  $Revision: 1.6 $
00008  *
00009  *  last change: $Author: ihi $ $Date: 2008/01/14 15:03:13 $
00010  *
00011  *  The Contents of this file are made available subject to
00012  *  the terms of GNU Lesser General Public License Version 2.1.
00013  *
00014  *
00015  *    GNU Lesser General Public License Version 2.1
00016  *    =============================================
00017  *    Copyright 2005 by Sun Microsystems, Inc.
00018  *    901 San Antonio Road, Palo Alto, CA 94303, USA
00019  *
00020  *    This library is free software; you can redistribute it and/or
00021  *    modify it under the terms of the GNU Lesser General Public
00022  *    License version 2.1, as published by the Free Software Foundation.
00023  *
00024  *    This library is distributed in the hope that it will be useful,
00025  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027  *    Lesser General Public License for more details.
00028  *
00029  *    You should have received a copy of the GNU Lesser General Public
00030  *    License along with this library; if not, write to the Free Software
00031  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00032  *    MA  02111-1307  USA
00033  *
00034  ************************************************************************/
00035 #ifndef _SANE_HXX
00036 #define _SANE_HXX
00037 
00038 #include <osl/thread.h>
00039 #include <osl/module.h>
00040 #include <tools/string.hxx>
00041 #include <vcl/bitmap.hxx>
00042 #include <sane/sane.h>
00043 #include <scanner.hxx>
00044 
00045 // ---------------------
00046 // - BitmapTransporter -
00047 // ---------------------
00048 
00049 class BitmapTransporter : public OWeakObject, AWT::XBitmap
00050 {
00051         SvMemoryStream                                          m_aStream;
00052         vos::OMutex                                                     m_aProtector;
00053                                                                                 
00054 public:                                                                 
00055                                                                                 
00056                                                                                 BitmapTransporter();
00057         virtual                                                         ~BitmapTransporter();
00058                                                                                 
00059                                                                                 
00060         // XInterface                                           
00061         virtual ANY SAL_CALL                            queryInterface( const Type & rType ) throw( RuntimeException );
00062     virtual void SAL_CALL                               acquire() throw() { OWeakObject::acquire(); }
00063     virtual void SAL_CALL                               release() throw() { OWeakObject::release(); }
00064 
00065         virtual AWT::Size SAL_CALL                      getSize() throw();
00066         virtual SEQ( sal_Int8 ) SAL_CALL        getDIB() throw();
00067         virtual SEQ( sal_Int8 ) SAL_CALL        getMaskDIB() throw() { return SEQ( sal_Int8 )(); }
00068 
00069         // Misc
00070         void                                                            lock() { m_aProtector.acquire(); }
00071         void                                                            unlock() { m_aProtector.release(); }
00072         SvMemoryStream&                                         getStream() { return m_aStream; }
00073 };
00074 
00075 // --------
00076 // - Sane -
00077 // --------
00078 
00079 class Sane
00080 {
00081 private:
00082         static int                              nRefCount;
00083         static oslModule        pSaneLib;
00084         
00085         static SANE_Status              (*p_init)( SANE_Int*,
00086                                                                            SANE_Auth_Callback );
00087         static void                             (*p_exit)();
00088         static SANE_Status              (*p_get_devices)( const SANE_Device***,
00089                                                                                           SANE_Bool );
00090         static SANE_Status              (*p_open)( SANE_String_Const, SANE_Handle );
00091         static void                             (*p_close)( SANE_Handle );
00092         static const SANE_Option_Descriptor* (*p_get_option_descriptor)(
00093                 SANE_Handle, SANE_Int );
00094         static SANE_Status              (*p_control_option)( SANE_Handle, SANE_Int,
00095                                                                                                  SANE_Action, void*,
00096                                                                                                  SANE_Int* );
00097         static SANE_Status              (*p_get_parameters)( SANE_Handle,
00098                                                                                                  SANE_Parameters* );
00099         static SANE_Status              (*p_start)( SANE_Handle );
00100         static SANE_Status              (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
00101                                                                            SANE_Int* );
00102         static void                             (*p_cancel)( SANE_Handle );
00103         static SANE_Status              (*p_set_io_mode)( SANE_Handle, SANE_Bool );
00104         static SANE_Status              (*p_get_select_fd)( SANE_Handle, SANE_Int* );
00105         static const SANE_String_Const (*p_strstatus)( SANE_Status );
00106 
00107         static SANE_Int                         nVersion;
00108         static SANE_Device**            ppDevices;
00109         static int                                      nDevices;
00110 
00111         const SANE_Option_Descriptor**  mppOptions;
00112         int                                                             mnOptions;
00113         int                                                             mnDevice;
00114         SANE_Handle                                             maHandle;
00115 
00116         Link                                            maReloadOptionsLink;
00117 
00118         inline oslGenericFunction
00119                     LoadSymbol( const char* );
00120         void                    Init();
00121         void                    DeInit();
00122         void                    Stop();
00123 
00124         SANE_Status ControlOption( int, SANE_Action, void* );
00125 
00126         BOOL CheckConsistency( const char*, BOOL bInit = FALSE );
00127 
00128 public:
00129         Sane();
00130         ~Sane();
00131 
00132         static BOOL                     IsSane()
00133                 { return pSaneLib ? TRUE : FALSE; }
00134         BOOL                    IsOpen()
00135                 { return maHandle ? TRUE : FALSE; }
00136         static int                              CountDevices()
00137                 { return nDevices; }
00138         static String                   GetName( int n )
00139                 { return String( ppDevices[n]->name ? ppDevices[n]->name : "", osl_getThreadTextEncoding() ); }
00140         static String                   GetVendor( int n )
00141                 { return String( ppDevices[n]->vendor ? ppDevices[n]->vendor : "", osl_getThreadTextEncoding() ); }
00142         static String                   GetModel( int n )
00143                 { return String( ppDevices[n]->model ? ppDevices[n]->model : "", osl_getThreadTextEncoding() ); }
00144         static String                   GetType( int n )
00145                 { return String( ppDevices[n]->type ? ppDevices[n]->type : "", osl_getThreadTextEncoding() ); }
00146 
00147         String                  GetOptionName( int n )
00148                 { return String( mppOptions[n]->name ? (char*)mppOptions[n]->name : "", osl_getThreadTextEncoding() ); }
00149         String                  GetOptionTitle( int n )
00150                 { return String( mppOptions[n]->title ? (char*)mppOptions[n]->title : "", osl_getThreadTextEncoding() ); }
00151         SANE_Value_Type GetOptionType( int n )
00152                 { return mppOptions[n]->type; }
00153         SANE_Unit               GetOptionUnit( int n )
00154                 { return mppOptions[n]->unit; }
00155         String                  GetOptionUnitName( int n );
00156         SANE_Int                GetOptionCap( int n )
00157                 { return mppOptions[n]->cap; }
00158         SANE_Constraint_Type GetOptionConstraintType( int n )
00159                 { return mppOptions[n]->constraint_type; }
00160         const char**    GetStringConstraint( int n )
00161                 { return (const char**)mppOptions[n]->constraint.string_list; }
00162         int                             GetRange( int, double*& );
00163 
00164         inline int              GetOptionElements( int n );
00165         int                             GetOptionByName( const char* );
00166         BOOL                    GetOptionValue( int, BOOL& );
00167         BOOL                    GetOptionValue( int, ByteString& );
00168         BOOL                    GetOptionValue( int, double&, int nElement = 0 );
00169         BOOL                    GetOptionValue( int, double* );
00170 
00171         BOOL                    SetOptionValue( int, BOOL );
00172         BOOL                    SetOptionValue( int, const String& );
00173         BOOL                    SetOptionValue( int, double, int nElement = 0 );
00174         BOOL                    SetOptionValue( int, double* );
00175 
00176         BOOL                    ActivateButtonOption( int );
00177 
00178         int                             CountOptions() { return mnOptions; }
00179         int                             GetDeviceNumber() { return mnDevice; }
00180         
00181         BOOL                    Open( const char* );
00182         BOOL                    Open( int );
00183         void                    Close();
00184         void                    ReloadDevices();
00185         void                    ReloadOptions();
00186 
00187         BOOL                    Start( BitmapTransporter& );
00188 
00189         inline Link             SetReloadOptionsHdl( const Link& rLink );
00190 };
00191 
00192 inline int Sane::GetOptionElements( int n )
00193 {
00194         if( mppOptions[n]->type == SANE_TYPE_FIXED ||
00195                 mppOptions[n]->type == SANE_TYPE_INT )
00196         {
00197                 return mppOptions[n]->size/sizeof( SANE_Word );
00198         }
00199         return 1;
00200 }
00201 
00202 inline Link     Sane::SetReloadOptionsHdl( const Link& rLink )
00203 {
00204         Link aRet = maReloadOptionsLink;
00205         maReloadOptionsLink = rLink;
00206         return aRet;
00207 }
00208 
00209 #endif

Generated on Thu Feb 28 17:53:26 2008 for AquaScanner by  doxygen 1.5.1