OSDN Git Service

[dennco] The update for the implementation of plugin functionality.
[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_plugin = DNPluginManager::instance()->getPlugin(pluginName);
34     if (!d_plugin)
35     {
36         std::string message = std::string("Failed to initialize cell '").append(location).append("#").append(name);
37         message.append("'\nLoading the specified plugin : '").append(pluginName).append("' failed");
38         dnNotifyError("Initialization failed", message);
39     }
40 }
41
42 DNPluginOutputCell::~DNPluginOutputCell()
43 {
44 }
45
46 bool DNPluginOutputCell::doTick(float time)
47 {
48     (void)time;
49
50     float value = 0.0;
51
52     for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
53        value += it->second->getValue();
54     }
55
56     mAxon->setValue(value);
57     if (d_plugin && d_plugin->getIsValid())
58     {
59         bool isReady = d_plugin->getIsReady();
60         if (isReady && (d_outputValue != value ||!d_wasReady))
61         {
62             d_outputValue = value;
63             d_plugin->setValueToPlugin(d_valueName.c_str(), value);
64         }
65         d_wasReady = isReady;
66     }
67     return true;
68 }
69
70 bool DNPluginOutputCell::doInit()
71 {
72     return true;
73 }
74
75 bool DNPluginOutputCell::doDestroy()
76 {
77     return true;
78 }
79
80 void DNPluginOutputCell::setValue(float value)
81 {
82     (void)value;
83 }