Destroy default wxWebSession in module

This commit is contained in:
Tobias Taschner
2018-11-03 12:32:42 +01:00
parent f04094e4ec
commit 7577c95aab
2 changed files with 35 additions and 0 deletions

View File

@@ -234,6 +234,8 @@ public:
static wxWebSession& GetDefault();
static void DestroyDefault();
static wxWebSession* New(const wxString& backend = wxWebSessionBackendDefault);
static void RegisterFactory(const wxString& backend, wxSharedPtr<wxWebSessionFactory> factory);

View File

@@ -18,6 +18,7 @@
#include "wx/webrequest.h"
#include "wx/mstream.h"
#include "wx/module.h"
#include "wx/uri.h"
#include "wx/filefn.h"
#include "wx/filename.h"
@@ -403,6 +404,11 @@ wxWebSession& wxWebSession::GetDefault()
return *ms_defaultSession;
}
void wxWebSession::DestroyDefault()
{
ms_defaultSession.reset();
}
// static
wxWebSession* wxWebSession::New(const wxString& backend)
{
@@ -449,4 +455,31 @@ bool wxWebSession::IsBackendAvailable(const wxString& backend)
return factory != ms_factoryMap.end();
}
// ----------------------------------------------------------------------------
// Module ensuring all global/singleton objects are destroyed on shutdown.
// ----------------------------------------------------------------------------
class WebRequestModule : public wxModule
{
public:
WebRequestModule()
{
}
virtual bool OnInit() wxOVERRIDE
{
return true;
}
virtual void OnExit() wxOVERRIDE
{
wxWebSession::DestroyDefault();
}
private:
wxDECLARE_DYNAMIC_CLASS(WebRequestModule);
};
wxIMPLEMENT_DYNAMIC_CLASS(WebRequestModule, wxModule);
#endif // wxUSE_WEBREQUEST