NEST  2.6.0,not_revisioned_source_dir@0
music_message_in_proxy.h
Go to the documentation of this file.
1 /*
2  * music_message_in_proxy.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST 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 NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef MUSIC_MESSAGE_IN_PROXY_H
24 #define MUSIC_MESSAGE_IN_PROXY_H
25 
26 #include "config.h"
27 #ifdef HAVE_MUSIC
28 
29 #include <vector>
30 #include <string>
31 #include "nest.h"
32 #include "node.h"
33 #include "communicator.h"
34 #include "arraydatum.h"
35 #include "dictutils.h"
36 
37 #include "mpi.h"
38 #include "music.hh"
39 
40 /*BeginDocumentation
41 
42 Name: music_message_in_proxy - A device which receives message strings from MUSIC.
43 
44 Description:
45 A music_message_in_proxy can be used to receive message strings from
46 remote MUSIC applications in NEST.
47 
48 It uses the MUSIC library to receive message strings from other
49 applications. The music_message_in_proxy represents an input port to
50 which MUSIC can connect a message source. The music_message_in_proxy
51 can queried using GetStatus to retrieve the messages.
52 
53 Parameters:
54 The following properties are available in the status dictionary:
55 
56 port_name - The name of the MUSIC input port to listen to (default:
57  message_in)
58 port_width - The width of the MUSIC input port
59 data - A sub-dictionary that contains the string messages
60  in the form of two arrays:
61  messages - The strings
62  message_times - The times the messages were sent (ms)
63 n_messages - The number of messages.
64 published - A bool indicating if the port has been already published
65  with MUSIC
66 
67 The parameter port_name can be set using SetStatus. The field n_messages
68 can be set to 0 to clear the data arrays.
69 
70 Examples:
71 /music_message_in_proxy Create /mmip Set
72 10 Simulate
73 mmip GetStatus /data get /messages get 0 get /command Set
74 (Executing command ') command join ('.) join =
75 command cvx exec
76 
77 Author: Jochen Martin Eppler
78 FirstVersion: July 2010
79 Availability: Only when compiled with MUSIC
80 
81 SeeAlso: music_event_out_proxy, music_event_in_proxy, music_cont_in_proxy
82 */
83 
84 namespace nest
85 {
86  class MsgHandler : public MUSIC::MessageHandler
87  {
89  std::vector<double> message_times;
90 
91  void operator()(double t, void* msg, size_t size)
92  {
93  message_times.push_back(t * 1000.0);
94  messages.push_back(std::string(static_cast<char*>(msg), size));
95  }
96 
97  public:
99  {
100  DictionaryDatum dict(new Dictionary);
101  (*dict)["messages"] = messages;
102  (*dict)["message_times"] = DoubleVectorDatum(new std::vector<double>(message_times));
103  (*d)["n_messages"] = messages.size();
104  (*d)["data"] = dict;
105  }
106 
107  void clear()
108  {
109  message_times.clear();
110  messages.clear();
111  }
112  };
113 
120  {
121 
122  public:
125 
126  bool has_proxies() const {return false;}
127  bool one_node_per_process() const {return true;}
128 
129  void get_status(DictionaryDatum &) const;
130  void set_status(const DictionaryDatum &);
131 
132  private:
133 
134  void init_state_(const Node&);
135  void init_buffers_();
136  void calibrate();
137 
138  void update(Time const &, const long_t, const long_t) {}
139 
140  // ------------------------------------------------------------
141  struct State_;
142 
143  struct Parameters_ {
144  std::string port_name_;
146 
147  Parameters_();
148  Parameters_(const Parameters_&);
149 
150  void get(DictionaryDatum&) const;
151 
155  void set(const DictionaryDatum&, State_&);
156  };
157 
158  // ------------------------------------------------------------
159 
160  struct State_ {
161  bool published_;
163 
164  State_();
165 
166  void get(DictionaryDatum&) const;
167  void set(const DictionaryDatum&, const Parameters_&);
168  };
169 
170  // ------------------------------------------------------------
171 
172  struct Buffers_ {
174  };
175 
176  // ------------------------------------------------------------
177 
178  struct Variables_ {
179  MUSIC::MessageInputPort *MP_;
180  };
181 
182  // ------------------------------------------------------------
183 
188  };
189 
190 inline
192 {
193  P_.get(d);
194  S_.get(d);
195 
197 }
198 
199 inline
201 {
202  Parameters_ ptmp = P_; // temporary copy in case of errors
203  ptmp.set(d, S_); // throws if BadProperty
204 
205  State_ stmp = S_;
206  stmp.set(d, P_); // throws if BadProperty
207 
208  long_t nm = 0;
209  if ( updateValue<long_t>(d, "n_messages", nm) )
210  {
211  if ( nm == 0 )
213  else
214  throw BadProperty("n_messaged can only be set to 0.");
215  }
216 
217  // if we get here, temporaries contain consistent set of properties
218  P_ = ptmp;
219  S_ = stmp;
220 }
221 
222 } // namespace
223 
224 #endif
225 
226 #endif /* #ifndef MUSIC_MESSAGE_IN_PROXY_H */
Definition: music_message_in_proxy.h:172
void get(DictionaryDatum &) const
Definition: music_message_in_proxy.cpp:60
void calibrate()
Re-calculate dependent parameters of the node.
Definition: music_message_in_proxy.cpp:116
void get(DictionaryDatum &) const
Store current values in dictionary.
Definition: music_message_in_proxy.cpp:75
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
Declarations for base class Node.
MsgHandler message_handler_
Definition: music_message_in_proxy.h:173
void set_status(const DictionaryDatum &)
Definition: music_message_in_proxy.h:200
void clear(void)
Definition: tokenarray.h:320
void push_back(const Token &t)
Definition: tokenarray.h:236
void init_buffers_()
Private function to initialize the buffers of a node.
Definition: music_message_in_proxy.cpp:113
ArrayDatum messages
The buffer for incoming message.
Definition: music_message_in_proxy.h:88
bool published_
indicates whether this node has been published already with MUSIC
Definition: music_message_in_proxy.h:161
int port_width_
the width of the MUSIC port
Definition: music_message_in_proxy.h:162
std::string port_name_
the name of MUSIC port to connect to
Definition: music_message_in_proxy.h:144
void operator()(double t, void *msg, size_t size)
Definition: music_message_in_proxy.h:91
std::vector< double > message_times
The buffer for incoming message.
Definition: music_message_in_proxy.h:89
void update(Time const &, const long_t, const long_t)
Bring the node from state $t$ to $t+n*dt$.
Definition: music_message_in_proxy.h:138
void init_state_(const Node &)
Private function to initialize the state of a node to model defaults.
Definition: music_message_in_proxy.cpp:106
A class that associates names and tokens.
Definition: dict.h:45
Buffers_ B_
Definition: music_message_in_proxy.h:186
Definition: nest_time.h:130
bool has_proxies() const
Returns true if the node has proxies on remote threads.
Definition: music_message_in_proxy.h:126
lockPTRDatum< std::vector< double >,&SLIInterpreter::DoubleVectortype > DoubleVectorDatum
Definition: arraydatum.h:93
Definition: music_message_in_proxy.h:178
void get_status(DictionaryDatum &d) const
Definition: music_message_in_proxy.h:98
Parameters_()
Sets default parameter values.
Definition: music_message_in_proxy.cpp:39
void set(const DictionaryDatum &, State_ &)
Set values from dicitonary.
Definition: music_message_in_proxy.cpp:66
void get_status(DictionaryDatum &) const
Definition: music_message_in_proxy.h:191
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition: exceptions.h:420
State_()
Sets default state value.
Definition: music_message_in_proxy.cpp:50
void set(const DictionaryDatum &, const Parameters_ &)
Set values from dicitonary.
Definition: music_message_in_proxy.cpp:81
size_t size(void) const
Return number of elements in the array.
Definition: tokenarray.h:142
Parameters_ P_
Definition: music_message_in_proxy.h:184
Variables_ V_
Definition: music_message_in_proxy.h:187
music_message_in_proxy()
Definition: music_message_in_proxy.cpp:89
MUSIC::MessageInputPort * MP_
The MUSIC cont port for input of data.
Definition: music_message_in_proxy.h:179
Default types used by the NEST kernel.
Definition: music_message_in_proxy.h:86
bool one_node_per_process() const
Returns true if the node exists only once per process, but does not have proxies on remote threads...
Definition: music_message_in_proxy.h:127
Definition: music_message_in_proxy.h:160
Base class for all NEST network objects.
Definition: node.h:96
void clear()
Definition: music_message_in_proxy.h:107
Emit spikes at times received from another application via a MUSIC port.
Definition: music_message_in_proxy.h:119
Definition: music_message_in_proxy.h:143
double acceptable_latency_
the acceptable latency of the port
Definition: music_message_in_proxy.h:145
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96
State_ S_
Definition: music_message_in_proxy.h:185