OSDN Git Service

[dennco] updated the plugin feature implementation.
[dennco/dennco.git] / Source / layer3 / dnpluginoutputcell.cpp
1 //  Copyright (c) 2012 Dennco Project
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 //
17 //  Created by tkawata on 1/17/2013.
18 //
19 #include "dnpluginoutputcell.h"
20
21 #include "dnplugin.h"
22 #include "dnpluginmanager.h"
23 #include "TKReceptor.h"
24 #include "TKAxon.h"
25 #include "DNUtils.h"
26
27 #include <limits>
28
29 DNPluginOutputCell::DNPluginOutputCell(TKContainer *container, std::string location, std::string name, std::string pluginName, std::string valueName)
30     : DNCellInterfaceable(container, location, name, false, true),
31       d_plugin(NULL), d_valueName(valueName), d_outputValue(std::numeric_limits<float>::quiet_NaN()), d_wasReady(false)
32 {
33     d_valueIterator = mReceptors.end();
34     d_forceUpdateIterator = mReceptors.end();
35
36     d_plugin = DNPluginManager::instance()->getPlugin(pluginName);
37     if (!d_plugin)
38     {
39         std::string message = std::string("Failed to initialize cell '").append(location).append("#").append(name);
40         message.append("'\nLoading the specified plugin : '").append(pluginName).append("' failed");
41         dnNotifyError("Initialization failed", message);
42     }
43 }
44
45 DNPluginOutputCell::~DNPluginOutputCell()
46 {
47 }
48
49 bool DNPluginOutputCell::doTick(float time)
50 {
51     (void)time;
52
53     float value = 0.0;
54     if (d_valueIterator != mReceptors.end())
55     {
56         value = d_valueIterator->second->getValue();
57     }
58     else
59     {
60         d_valueIterator = mReceptors.find("value");
61     }
62
63     bool forceUpdate = false;
64     if (d_forceUpdateIterator != mReceptors.end())
65     {
66         forceUpdate = d_forceUpdateIterator->second->getValue() > 0;
67     }
68     else
69     {
70         d_forceUpdateIterator = mReceptors.find("forceUpdate");
71     }
72
73     mAxon->setValue(value);
74     if (d_plugin && d_plugin->getIsValid())
75     {
76         bool isReady = d_plugin->getIsReady();
77         if (isReady && (value != d_outputValue || forceUpdate))
78         {
79             d_outputValue = value;
80             d_plugin->setValueToPlugin(d_valueName.c_str(), value);
81         }
82         d_wasReady = isReady;
83     }
84     return true;
85 }
86
87 bool DNPluginOutputCell::doInit()
88 {
89     return true;
90 }
91
92 bool DNPluginOutputCell::doDestroy()
93 {
94     return true;
95 }
96
97 void DNPluginOutputCell::setValue(float value)
98 {
99     (void)value;
100 }