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