Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/module/Plugin.cc @ 11014

Last change on this file since 11014 was 11014, checked in by landauf, 9 years ago

moved code for loading/unloading a plugin into separate functions

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "Plugin.h"
30
31#include "ModuleInstance.h"
32#include "util/Output.h"
33#include "core/Core.h"
34
35namespace orxonox
36{
37    Plugin::Plugin(const std::string& name, const std::string& libraryName) : name_(name), libraryName_(libraryName)
38    {
39        this->referenceCounter_ = 0;
40        this->moduleInstance_ = NULL;
41    }
42
43    Plugin::~Plugin()
44    {
45        if (this->moduleInstance_ != NULL)
46            this->unload();
47    }
48
49    void Plugin::reference()
50    {
51        this->referenceCounter_++;
52        if (this->referenceCounter_ == 1) // increased from 0 to 1 -> load plugin
53            this->load();
54        else
55            orxout(internal_info) << "Increased reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
56    }
57
58    void Plugin::dereference()
59    {
60        if (this->referenceCounter_ == 0)
61        {
62            orxout(internal_warning) << "Tried to dereference plugin " << this->name_ << " more often than it was referenced" << endl;
63            return;
64        }
65
66        this->referenceCounter_--;
67        if (this->referenceCounter_ == 0) // reduced from 1 to 0 -> load plugin
68            this->unload();
69        else
70            orxout(internal_info) << "Reduced reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
71    }
72
73    void Plugin::load()
74    {
75        orxout(internal_info) << "Loading plugin " << this->name_ << "..." << endl;
76        this->moduleInstance_ = new ModuleInstance(this->libraryName_);
77        Core::getInstance().loadModule(this->moduleInstance_);
78    }
79
80    void Plugin::unload()
81    {
82        orxout(internal_info) << "Unloading plugin " << this->name_ << "..." << endl;
83        Core::getInstance().unloadModule(this->moduleInstance_);
84        delete this->moduleInstance_;
85        this->moduleInstance_ = NULL;
86    }
87}
Note: See TracBrowser for help on using the repository browser.