1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dynamic library management
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dynlib.h"
16 #include <wx/dynlib.h>
17 #include <wx/filefn.h>
19 #include <wx/string.h>
21 // ---------------------------------------------------------------------------
22 // System dependent include
23 // ---------------------------------------------------------------------------
29 // ---------------------------------------------------------------------------
31 // ---------------------------------------------------------------------------
33 wxLibraries wxTheLibraries
;
35 // ---------------------------------------------------------------------------
36 // wxLibrary (one instance per dynamic library
37 // ---------------------------------------------------------------------------
39 wxLibrary::wxLibrary(void *handle
)
41 typedef wxClassLibrary
*(*t_get_list
)(void);
46 get_list
= (t_get_list
)GetSymbol("GetClassList");
47 m_liblist
= (*get_list
)();
50 wxLibrary::~wxLibrary()
53 typedef void (*t_free_list
)(wxClassLibrary
*);
54 t_free_list free_list
;
56 free_list
= (t_free_list
) GetSymbol("FreeClassList");
57 if (free_list
!= NULL
)
66 wxObject
*wxLibrary::CreateObject(const wxString
& name
)
68 return m_liblist
->CreateObject(name
);
71 void *wxLibrary::GetSymbol(const wxString
& symbname
)
74 return dlsym(m_handle
, symbname
.GetData());
78 // ---------------------------------------------------------------------------
79 // wxLibraries (only one instance should normally exist)
80 // ---------------------------------------------------------------------------
82 wxLibraries::wxLibraries()
86 wxLibraries::~wxLibraries()
88 wxNode
*node
= m_loaded
.First();
91 wxLibrary
*lib
= (wxLibrary
*)node
->Data();
98 wxLibrary
*wxLibraries::LoadLibrary(const wxString
& name
)
100 wxString lib_name
= name
;
104 if ( (node
= m_loaded
.Find(name
.GetData())) )
105 return ((wxLibrary
*)node
->Data());
108 lib_name
.Prepend("./lib");
111 printf("lib_name = %s\n", WXSTRINGCAST lib_name
);
113 void *handle
= dlopen(lib_name
.GetData(), RTLD_LAZY
);
115 printf("handle = %x\n", handle
);
116 lib
= new wxLibrary(handle
);
124 m_loaded
.Append(name
.GetData(), lib
);
128 wxObject
*wxLibraries::CreateObject(const wxString
& path
)
130 wxNode
*node
= m_loaded
.First();
134 obj
= ((wxLibrary
*)node
->Data())->CreateObject(path
);
143 // ---------------------------------------------------------------------------
144 // wxClassLibrary (this class is used to access the internal class)
145 // ---------------------------------------------------------------------------
147 wxClassLibrary::wxClassLibrary(void)
151 wxClassLibrary::~wxClassLibrary(void)
155 for (i
=0;i
<m_list
.Count();i
++)
159 void wxClassLibrary::RegisterClass(wxClassInfo
*class_info
,
160 const wxString
& path
)
162 wxClassLibInfo
*info
= new wxClassLibInfo
;
164 info
->class_info
= class_info
;
169 void wxClassLibrary::UnregisterClass(wxClassInfo
*class_info
)
173 while (i
< m_list
.Count()) {
174 if (m_list
[i
]->class_info
== class_info
) {
183 bool wxClassLibrary::CreateObjects(const wxString
& path
,
184 wxArrayClassInfo
& objs
)
186 wxClassLibInfo
*info
;
189 while (i
< m_list
.Count()) {
191 if (wxMatchWild(path
, info
->path
))
192 objs
.Add(info
->class_info
);
198 bool wxClassLibrary::FetchInfos(const wxString
& path
,
199 wxArrayClassLibInfo
& infos
)
201 wxClassLibInfo
*info
;
204 while (i
< m_list
.Count()) {
206 if (wxMatchWild(path
, info
->path
)) {
207 wxClassLibInfo
*inf
= new wxClassLibInfo
;
216 wxObject
*wxClassLibrary::CreateObject(const wxString
& path
)
218 wxClassLibInfo
*info
;
221 while (i
< m_list
.Count()) {
223 if (wxMatchWild(path
, info
->path
))
224 return info
->class_info
->CreateObject();