source: trunk/src/tools/qlibrary_pm.cpp@ 127

Last change on this file since 127 was 8, checked in by dmik, 20 years ago

Transferred Qt for OS/2 version 3.3.1-rc5 sources from the CVS

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/****************************************************************************
2** $Id: qlibrary_pm.cpp 8 2005-11-16 19:36:46Z dmik $
3**
4** Implementation of QLibraryPrivate class for Win32
5**
6** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
7** Copyright (C) 2004 Norman ASA. Initial OS/2 Port.
8** Copyright (C) 2005 netlabs.org. Further OS/2 Development.
9**
10** This file is part of the tools module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include <qmap.h>
39#include <private/qlibrary_p.h>
40
41#ifdef QT_THREAD_SUPPORT
42# include <private/qmutexpool_p.h>
43#endif // QT_THREAD_SUPPORT
44
45#ifndef QT_H
46#include "qfile.h"
47#endif // QT_H
48
49#ifndef QT_NO_LIBRARY
50
51struct LibInstance {
52 LibInstance() { module = 0; refCount = 0; }
53 HMODULE module;
54 int refCount;
55};
56
57static QMap<QString, LibInstance*> *map = 0;
58/*
59 The platform dependent implementations of
60 - loadLibrary
61 - freeLibrary
62 - resolveSymbol
63
64 It's not too hard to guess what the functions do.
65*/
66
67#include "qt_os2.h"
68
69bool QLibraryPrivate::loadLibrary()
70{
71 if ( pHnd )
72 return TRUE;
73
74#ifdef QT_THREAD_SUPPORT
75 // protect map creation/access
76 QMutexLocker locker( qt_global_mutexpool ?
77 qt_global_mutexpool->get( &map ) : 0 );
78#endif // QT_THREAD_SUPPORT
79
80 if ( !map )
81 map = new QMap<QString, LibInstance*>;
82
83 QString filename = library->library();
84 if ( map->find(filename) != map->end() ) {
85 LibInstance *lib = (*map)[filename];
86 lib->refCount++;
87 pHnd = lib->module;
88 }
89 else {
90 APIRET rc = 0;
91 char errModule [256];
92 if ( (rc = DosLoadModule(
93 errModule, sizeof(errModule),
94 QFile::encodeName( filename ).data(), &pHnd
95 ))) {
96 pHnd = 0;
97#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
98 qSystemWarning( QString("Failed to load library %1 (reason: %2)!")
99 .arg( filename ).arg( errModule ), rc
100 );
101#endif
102 }
103 if ( pHnd ) {
104 LibInstance *lib = new LibInstance;
105 lib->module = pHnd;
106 lib->refCount++;
107 map->insert( filename, lib );
108 }
109 }
110 return pHnd != 0;
111}
112
113bool QLibraryPrivate::freeLibrary()
114{
115 if ( !pHnd )
116 return TRUE;
117
118#ifdef QT_THREAD_SUPPORT
119 // protect map access
120 QMutexLocker locker( qt_global_mutexpool ?
121 qt_global_mutexpool->get( &map ) : 0 );
122#endif // QT_THREAD_SUPPORT
123
124 bool ok = FALSE;
125 QMap<QString, LibInstance*>::iterator it;
126 for ( it = map->begin(); it != map->end(); ++it ) {
127 LibInstance *lib = *it;
128 if ( lib->module == pHnd ) {
129 lib->refCount--;
130 if ( lib->refCount == 0 ) {
131 ok = DosFreeModule( pHnd ) == 0;
132 if ( ok ) {
133 map->remove( it );
134 if ( map->count() == 0 ) {
135 delete map;
136 map = 0;
137 }
138 }
139 delete lib;
140 } else
141 ok = TRUE;
142 break;
143 }
144 }
145 if ( ok )
146 pHnd = 0;
147#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
148 else
149 qSystemWarning( "Failed to unload library!" );
150#endif
151 return ok;
152}
153
154void* QLibraryPrivate::resolveSymbol( const char* f )
155{
156 if ( !pHnd )
157 return 0;
158
159 void* address;
160 if ( DosQueryProcAddr( pHnd, 0, f, (PFN*) &address) ) address = 0;
161#if defined(QT_DEBUG_COMPONENT)
162 if ( !address )
163 qSystemWarning( QString("Couldn't resolve symbol \"%1\"").arg( f ) );
164#endif
165
166 return address;
167}
168
169#endif //QT_NO_LIBRARY
Note: See TracBrowser for help on using the repository browser.