1*2e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2e2212a7SAndrew Rist  * distributed with this work for additional information
6*2e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
9*2e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2e2212a7SAndrew Rist  *
11*2e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2e2212a7SAndrew Rist  *
13*2e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2e2212a7SAndrew Rist  * software distributed under the License is distributed on an
15*2e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2e2212a7SAndrew Rist  * specific language governing permissions and limitations
18*2e2212a7SAndrew Rist  * under the License.
19*2e2212a7SAndrew Rist  *
20*2e2212a7SAndrew Rist  *************************************************************/
21*2e2212a7SAndrew Rist 
22*2e2212a7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _DBAUI_ODBC_CONFIG_HXX_
25cdf0e10cSrcweir #define _DBAUI_ODBC_CONFIG_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "commontypes.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #if defined(WNT) || defined (UNX) || defined (OS2)
30cdf0e10cSrcweir #define HAVE_ODBC_SUPPORT
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #if ( defined(WNT) || defined (OS2) ) && defined(HAVE_ODBC_SUPPORT)
34cdf0e10cSrcweir #define HAVE_ODBC_ADMINISTRATION
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <tools/link.hxx>
38cdf0e10cSrcweir #include <osl/module.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <memory>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //.........................................................................
43cdf0e10cSrcweir namespace dbaui
44cdf0e10cSrcweir {
45cdf0e10cSrcweir //.........................................................................
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //=========================================================================
48cdf0e10cSrcweir //= OOdbcLibWrapper
49cdf0e10cSrcweir //=========================================================================
50cdf0e10cSrcweir /** base for helper classes wrapping functionality from an ODBC library
51cdf0e10cSrcweir */
52cdf0e10cSrcweir class OOdbcLibWrapper
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	oslModule			m_pOdbcLib;		// the library handle
55cdf0e10cSrcweir 	::rtl::OUString		m_sLibPath;		// the path to the library
56cdf0e10cSrcweir 
57cdf0e10cSrcweir public:
58cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
isLoaded() const59cdf0e10cSrcweir 	sal_Bool	isLoaded() const { return NULL != m_pOdbcLib; }
60cdf0e10cSrcweir #else
61cdf0e10cSrcweir 	sal_Bool	isLoaded() const { return sal_False; }
62cdf0e10cSrcweir #endif
getLibraryName() const63cdf0e10cSrcweir 	::rtl::OUString getLibraryName() const { return m_sLibPath; }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir protected:
66cdf0e10cSrcweir #ifndef HAVE_ODBC_SUPPORT
OOdbcLibWrapper()67cdf0e10cSrcweir 	OOdbcLibWrapper() : m_pOdbcLib(NULL) { }
68cdf0e10cSrcweir #else
69cdf0e10cSrcweir 	OOdbcLibWrapper();
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir 	~OOdbcLibWrapper();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	oslGenericFunction  loadSymbol(const sal_Char* _pFunctionName);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	/// load the lib
76cdf0e10cSrcweir 	sal_Bool	load(const sal_Char* _pLibPath);
77cdf0e10cSrcweir 	/// unload the lib
78cdf0e10cSrcweir 	void		unload();
79cdf0e10cSrcweir };
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //=========================================================================
82cdf0e10cSrcweir //= OOdbcEnumeration
83cdf0e10cSrcweir //=========================================================================
84cdf0e10cSrcweir struct OdbcTypesImpl;
85cdf0e10cSrcweir class OOdbcEnumeration : public OOdbcLibWrapper
86cdf0e10cSrcweir {
87cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
88cdf0e10cSrcweir 	// entry points for ODBC administration
89cdf0e10cSrcweir 	oslGenericFunction  m_pAllocHandle;
90cdf0e10cSrcweir 	oslGenericFunction  m_pFreeHandle;
91cdf0e10cSrcweir 	oslGenericFunction  m_pSetEnvAttr;
92cdf0e10cSrcweir 	oslGenericFunction  m_pDataSources;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir #endif
95cdf0e10cSrcweir 	OdbcTypesImpl*	m_pImpl;
96cdf0e10cSrcweir 		// needed because we can't have a member of type SQLHANDLE: this would require us to include the respective
97cdf0e10cSrcweir 		// ODBC file, which would lead to a lot of conflicts with other includes
98cdf0e10cSrcweir 
99cdf0e10cSrcweir public:
100cdf0e10cSrcweir 	OOdbcEnumeration();
101cdf0e10cSrcweir 	~OOdbcEnumeration();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	void		getDatasourceNames(StringBag& _rNames);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir protected:
106cdf0e10cSrcweir 	/// ensure that an ODBC environment is allocated
107cdf0e10cSrcweir 	sal_Bool	allocEnv();
108cdf0e10cSrcweir 	/// free any allocated ODBC environment
109cdf0e10cSrcweir 	void		freeEnv();
110cdf0e10cSrcweir };
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //=========================================================================
113cdf0e10cSrcweir //= OOdbcManagement
114cdf0e10cSrcweir //=========================================================================
115cdf0e10cSrcweir #ifdef HAVE_ODBC_ADMINISTRATION
116cdf0e10cSrcweir class ProcessTerminationWait;
117cdf0e10cSrcweir class OOdbcManagement
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     ::std::auto_ptr< ProcessTerminationWait >   m_pProcessWait;
120cdf0e10cSrcweir     Link                                        m_aAsyncFinishCallback;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir public:
123cdf0e10cSrcweir 	OOdbcManagement( const Link& _rAsyncFinishCallback );
124cdf0e10cSrcweir     ~OOdbcManagement();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	bool    manageDataSources_async();
127cdf0e10cSrcweir     bool    isRunning() const;
128cdf0e10cSrcweir };
129cdf0e10cSrcweir #endif
130cdf0e10cSrcweir 
131cdf0e10cSrcweir //.........................................................................
132cdf0e10cSrcweir }	// namespace dbaui
133cdf0e10cSrcweir //.........................................................................
134cdf0e10cSrcweir 
135cdf0e10cSrcweir #endif // _DBAUI_ODBC_CONFIG_HXX_
136cdf0e10cSrcweir 
137