spore_test_node.h
1 /*
2  * This file is part of SPORE.
3  *
4  * Copyright (C) 2016, the SPORE team (see AUTHORS).
5  *
6  * SPORE is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * SPORE is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SPORE. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * For more information see: https://github.com/IGITUGraz/spore-nest-module
20  *
21  * File: spore_test_node.h
22  * Author: Kappel
23  *
24  * Created on November 9, 2016, 2:30 PM
25  */
26 
27 #ifndef SPORE_TEST_MODULE_H
28 #define SPORE_TEST_MODULE_H
29 
30 #include "dictutils.h"
31 
32 #include "tracing_node.h"
33 #include "spore_test_base.h"
34 #include "spore_names.h"
35 
36 namespace spore
37 {
38 
42 class SporeTestNode : public TracingNode
43 {
44 public:
45  SporeTestNode();
47 
48  void get_status(DictionaryDatum&) const;
49  void set_status(const DictionaryDatum&);
50 
55  using nest::Node::handle;
56  using nest::Node::handles_test_event;
57 
58  void handle(nest::SpikeEvent&);
59  nest::port handles_test_event(nest::SpikeEvent&, nest::rport);
60  nest::port send_test_event(nest::Node&, nest::rport, nest::synindex, bool);
61 
62 
63 protected:
64  void register_test(SporeTestBase* test);
65 
66 private:
67  void init_state_(const nest::Node& proto);
68  void init_buffers_();
69  void calibrate();
70 
71  void update(nest::Time const&, const long, const long);
72 
73  std::string test_name_;
74  double test_time_;
75 
76  std::map<std::string, SporeTestBase*> tests_;
77 };
78 
82 inline
83 nest::port SporeTestNode::send_test_event(nest::Node& target, nest::rport receptor_type, nest::synindex, bool)
84 {
85  nest::SpikeEvent e;
86  e.set_sender(*this);
87 
88  return target.handles_test_event(e, receptor_type);
89 }
90 
94 inline
95 nest::port SporeTestNode::handles_test_event(nest::SpikeEvent&, nest::rport receptor_type)
96 {
97  return 0;
98 }
99 
103 inline
104 void SporeTestNode::get_status(DictionaryDatum& d) const
105 {
106  def<std::string>(d, names::test_name, test_name_);
107  def<double>(d, names::test_time, test_time_);
108  if (not test_name_.empty())
109  {
110  const SporeTestBase* test = tests_.at(test_name_);
111  assert(test);
112  test->get_status(d);
113  }
114 }
115 
119 inline
120 void SporeTestNode::set_status(const DictionaryDatum &d)
121 {
122  std::string test_name;
123  if (updateValue<std::string>(d, names::test_name, test_name))
124  {
125  if (tests_.find(test_name) == tests_.end())
126  throw nest::BadParameter("test '" + test_name + "' does not exist!");
127 
128  test_name_ = test_name;
129  }
130 
131 
132  updateValue<double>(d, names::test_time, test_time_);
133 
134  if (not test_name_.empty())
135  {
136  tests_[test_name_]->set_status(d);
137  }
138 }
139 
140 }
141 
142 #endif
void handle(nest::SpikeEvent &)
Definition: spore_test_node.cpp:96
nest::port send_test_event(nest::Node &, nest::rport, nest::synindex, bool)
Definition: spore_test_node.h:83
~SporeTestNode()
Definition: spore_test_node.cpp:51
Base class to all nodes that record traces.
Definition: tracing_node.h:52
Base class to all tests.
Definition: spore_test_base.h:43
Node to test the SPORE module.
Definition: spore_test_node.h:42
void register_test(SporeTestBase *test)
Definition: spore_test_node.cpp:62
Global namespace holding all classes of the SPORE NEST module.
Definition: circular_buffer.h:31
void set_status(const DictionaryDatum &)
Definition: spore_test_node.h:120
SporeTestNode()
Definition: spore_test_node.cpp:40
void get_status(DictionaryDatum &) const
Definition: spore_test_node.h:104
nest::port handles_test_event(nest::SpikeEvent &, nest::rport)
Definition: spore_test_node.h:95