~ubuntu-branches/ubuntu/vivid/mygui/vivid

« back to all changes in this revision

Viewing changes to MyGUIEngine/src/MyGUI_DynLibManager.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard, Bret Curtis, Scott Howard
  • Date: 2014-09-18 17:57:48 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140918175748-dd8va78mvpw1jbes
Tags: 3.2.1-1
[ Bret Curtis ]
* Updated license for majority of files from LGPL to Expat (MIT)

[ Scott Howard ]
* New upstream release
* Updated patch to add build option for system GLEW libraries
* All patches accepted upstream except shared_libraries.patch
* Bumped SONAME due to dropped symbols, updated *.symbols and package
  names
* Updated license of debian/* to Expat with permission of all authors
* Don't install Doxygen autogenerated md5 and map files (thanks
  lintian)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*!
2
 
        @file
3
 
        @author         Denis Koronchik
4
 
        @date           09/2007
5
 
*/
6
 
/*
7
 
        This file is part of MyGUI.
8
 
 
9
 
        MyGUI is free software: you can redistribute it and/or modify
10
 
        it under the terms of the GNU Lesser General Public License as published by
11
 
        the Free Software Foundation, either version 3 of the License, or
12
 
        (at your option) any later version.
13
 
 
14
 
        MyGUI is distributed in the hope that it will be useful,
15
 
        but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
        GNU Lesser General Public License for more details.
18
 
 
19
 
        You should have received a copy of the GNU Lesser General Public License
20
 
        along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
21
 
*/
22
 
#include "MyGUI_Precompiled.h"
23
 
#include "MyGUI_DynLibManager.h"
24
 
#include "MyGUI_Gui.h"
25
 
#include "MyGUI_WidgetManager.h"
26
 
 
27
 
namespace MyGUI
28
 
{
29
 
 
30
 
        template <> DynLibManager* Singleton<DynLibManager>::msInstance = nullptr;
31
 
        template <> const char* Singleton<DynLibManager>::mClassTypeName("DynLibManager");
32
 
 
33
 
        DynLibManager::DynLibManager() :
34
 
                mIsInitialise(false)
35
 
        {
36
 
        }
37
 
 
38
 
        void DynLibManager::initialise()
39
 
        {
40
 
                MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
41
 
                MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
42
 
 
43
 
                Gui::getInstance().eventFrameStart += newDelegate(this, &DynLibManager::notifyEventFrameStart);
44
 
 
45
 
                MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
46
 
                mIsInitialise = true;
47
 
        }
48
 
 
49
 
        void DynLibManager::shutdown()
50
 
        {
51
 
                MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
52
 
                MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
53
 
 
54
 
                unloadAll();
55
 
 
56
 
                Gui::getInstance().eventFrameStart -= newDelegate(this, &DynLibManager::notifyEventFrameStart);
57
 
                _unloadDelayDynLibs();
58
 
 
59
 
                MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
60
 
                mIsInitialise = false;
61
 
        }
62
 
 
63
 
        DynLib* DynLibManager::load(const std::string& fileName)
64
 
        {
65
 
                StringDynLibMap::iterator it = mLibsMap.find(fileName);
66
 
 
67
 
                if (it != mLibsMap.end())
68
 
                {
69
 
                        return it->second;
70
 
                }
71
 
 
72
 
                DynLib* pLib = new DynLib(fileName);
73
 
                if (!pLib->load())
74
 
                {
75
 
                        delete pLib;
76
 
                        return 0;
77
 
                }
78
 
 
79
 
                mLibsMap[fileName] = pLib;
80
 
                return pLib;
81
 
        }
82
 
 
83
 
        void DynLibManager::unload(DynLib* library)
84
 
        {
85
 
                StringDynLibMap::iterator it = mLibsMap.find(library->getName());
86
 
 
87
 
                if (it != mLibsMap.end())
88
 
                        mLibsMap.erase(it);
89
 
 
90
 
                mDelayDynLib.push_back(library);
91
 
        }
92
 
 
93
 
        void DynLibManager::unloadAll()
94
 
        {
95
 
                // unload and delete resources
96
 
                for (StringDynLibMap::iterator it = mLibsMap.begin(); it != mLibsMap.end(); ++it)
97
 
                {
98
 
                        mDelayDynLib.push_back(it->second);
99
 
                }
100
 
                // Empty the list
101
 
                mLibsMap.clear();
102
 
        }
103
 
 
104
 
        void DynLibManager::notifyEventFrameStart(float _time)
105
 
        {
106
 
                _unloadDelayDynLibs();
107
 
        }
108
 
 
109
 
        void DynLibManager::_unloadDelayDynLibs()
110
 
        {
111
 
                if (!mDelayDynLib.empty())
112
 
                {
113
 
                        WidgetManager* manager = WidgetManager::getInstancePtr();
114
 
                        if (manager != nullptr)
115
 
                                manager->_deleteDelayWidgets();
116
 
 
117
 
                        for (VectorDynLib::iterator entry = mDelayDynLib.begin(); entry != mDelayDynLib.end(); ++entry)
118
 
                        {
119
 
                                (*entry)->unload();
120
 
                                delete (*entry);
121
 
                        }
122
 
                        mDelayDynLib.clear();
123
 
                }
124
 
        }
125
 
 
126
 
} // namespace MyGUI
 
1
/*
 
2
 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
 
3
 * Distributed under the MIT License
 
4
 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
 
5
 */
 
6
 
 
7
#include "MyGUI_Precompiled.h"
 
8
#include "MyGUI_DynLibManager.h"
 
9
#include "MyGUI_Gui.h"
 
10
#include "MyGUI_WidgetManager.h"
 
11
 
 
12
namespace MyGUI
 
13
{
 
14
 
 
15
        template <> DynLibManager* Singleton<DynLibManager>::msInstance = nullptr;
 
16
        template <> const char* Singleton<DynLibManager>::mClassTypeName = "DynLibManager";
 
17
 
 
18
        DynLibManager::DynLibManager() :
 
19
                mIsInitialise(false)
 
20
        {
 
21
        }
 
22
 
 
23
        void DynLibManager::initialise()
 
24
        {
 
25
                MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
 
26
                MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
 
27
 
 
28
                Gui::getInstance().eventFrameStart += newDelegate(this, &DynLibManager::notifyEventFrameStart);
 
29
 
 
30
                MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
 
31
                mIsInitialise = true;
 
32
        }
 
33
 
 
34
        void DynLibManager::shutdown()
 
35
        {
 
36
                MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
 
37
                MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
 
38
 
 
39
                unloadAll();
 
40
 
 
41
                Gui::getInstance().eventFrameStart -= newDelegate(this, &DynLibManager::notifyEventFrameStart);
 
42
                _unloadDelayDynLibs();
 
43
 
 
44
                MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
 
45
                mIsInitialise = false;
 
46
        }
 
47
 
 
48
        DynLib* DynLibManager::load(const std::string& fileName)
 
49
        {
 
50
                StringDynLibMap::iterator it = mLibsMap.find(fileName);
 
51
 
 
52
                if (it != mLibsMap.end())
 
53
                {
 
54
                        return it->second;
 
55
                }
 
56
 
 
57
                DynLib* pLib = new DynLib(fileName);
 
58
                if (!pLib->load())
 
59
                {
 
60
                        delete pLib;
 
61
                        return 0;
 
62
                }
 
63
 
 
64
                mLibsMap[fileName] = pLib;
 
65
                return pLib;
 
66
        }
 
67
 
 
68
        void DynLibManager::unload(DynLib* library)
 
69
        {
 
70
                StringDynLibMap::iterator it = mLibsMap.find(library->getName());
 
71
 
 
72
                if (it != mLibsMap.end())
 
73
                        mLibsMap.erase(it);
 
74
 
 
75
                mDelayDynLib.push_back(library);
 
76
        }
 
77
 
 
78
        void DynLibManager::unloadAll()
 
79
        {
 
80
                // unload and delete resources
 
81
                for (StringDynLibMap::iterator it = mLibsMap.begin(); it != mLibsMap.end(); ++it)
 
82
                {
 
83
                        mDelayDynLib.push_back(it->second);
 
84
                }
 
85
                // Empty the list
 
86
                mLibsMap.clear();
 
87
        }
 
88
 
 
89
        void DynLibManager::notifyEventFrameStart(float _time)
 
90
        {
 
91
                _unloadDelayDynLibs();
 
92
        }
 
93
 
 
94
        void DynLibManager::_unloadDelayDynLibs()
 
95
        {
 
96
                if (!mDelayDynLib.empty())
 
97
                {
 
98
                        WidgetManager* manager = WidgetManager::getInstancePtr();
 
99
                        if (manager != nullptr)
 
100
                                manager->_deleteDelayWidgets();
 
101
 
 
102
                        for (VectorDynLib::iterator entry = mDelayDynLib.begin(); entry != mDelayDynLib.end(); ++entry)
 
103
                        {
 
104
                                (*entry)->unload();
 
105
                                delete (*entry);
 
106
                        }
 
107
                        mDelayDynLib.clear();
 
108
                }
 
109
        }
 
110
 
 
111
} // namespace MyGUI