Psyllid  v1.12.4
Project 8 Data Acquisisition Software
stream_manager.hh
Go to the documentation of this file.
1 /*
2  * stream_manager.hh
3  *
4  * Created on: Jan 5, 2017
5  * Author: obla999
6  */
7 
8 #ifndef PSYLLID_STREAM_MANAGER_HH_
9 #define PSYLLID_STREAM_MANAGER_HH_
10 
11 #include "locked_resource.hh"
12 
13 #include "diptera.hh"
14 
15 #include "hub.hh"
16 
17 #include "param.hh"
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 
23 namespace psyllid
24 {
44 
45  class node_binding;
46  // the node_binding is owned by this map; the node is not
47  typedef std::map< std::string, std::pair< node_binding*, midge::node* > > active_node_bindings;
48 
49  class node_builder;
50 
52  {
53  public:
55  {
56  scarab::param_node f_device_config;
57 
58  typedef std::map< std::string, node_builder* > nodes_t;
59  typedef std::set< std::string > connections_t;
60 
61  nodes_t f_nodes;
62  connections_t f_connections;
63 
64  //std::string f_run_string;
65  };
66 
67  typedef std::shared_ptr< midge::diptera > midge_ptr_t;
68 
69  public:
71  virtual ~stream_manager();
72 
73  bool initialize( const scarab::param_node& a_config );
74 
75  public:
76  bool add_stream( const std::string& a_name, const scarab::param_node& a_node );
77  const stream_template* get_stream( const std::string& a_name ) const;
78  void remove_stream( const std::string& a_name );
79 
80  bool configure_node( const std::string& a_stream_name, const std::string& a_node_name, const scarab::param_node& a_config );
81  bool dump_node_config( const std::string& a_stream_name, const std::string& a_node_name, scarab::param_node& a_config ) const;
82 
83  public:
84  void reset_midge(); // throws psyllid::error in the event of an error configuring midge
85  bool must_reset_midge() const;
86 
87  midge_package get_midge();
88  void return_midge( midge_package&& a_midge );
89 
90  active_node_bindings* get_node_bindings();
91 
92  std::string get_node_run_str() const;
93 
94  bool is_in_use() const;
95 
96  public:
97  dripline::reply_ptr_t handle_add_stream_request( const dripline::request_ptr_t a_request );
98  dripline::reply_ptr_t handle_remove_stream_request( const dripline::request_ptr_t a_request );
99 
100  dripline::reply_ptr_t handle_configure_node_request( const dripline::request_ptr_t a_request );
101  dripline::reply_ptr_t handle_dump_config_node_request( const dripline::request_ptr_t a_request );
102  dripline::reply_ptr_t handle_get_stream_list_request( const dripline::request_ptr_t a_request );
103  dripline::reply_ptr_t handle_get_stream_node_list_request( const dripline::request_ptr_t a_request );
104 
105  private:
106  void _add_stream( const std::string& a_name, const scarab::param_node& a_node );
107  void _add_stream( const std::string& a_name, const std::string& a_type, const scarab::param_node& a_node );
108  void _remove_stream( const std::string& a_name );
109 
110  void _configure_node( const std::string& a_stream_name, const std::string& a_node_name, const scarab::param_node& a_config );
111  void _dump_node_config( const std::string& a_stream_name, const std::string& a_node_name, scarab::param_node& a_config ) const;
112 
113  void clear_node_bindings();
114 
115  typedef std::map< std::string, stream_template > streams_t;
116  streams_t f_streams;
117 
118  mutable std::mutex f_manager_mutex;
119 
120  midge_ptr_t f_midge;
121  active_node_bindings f_node_bindings;
123  mutable std::mutex f_midge_mutex;
124  };
125 
126 
127  inline const stream_manager::stream_template* stream_manager::get_stream( const std::string& a_name ) const
128  {
129  std::unique_lock< std::mutex > t_lock( f_manager_mutex );
130  streams_t::const_iterator t_stream = f_streams.find( a_name );
131  if( t_stream == f_streams.end() ) return nullptr;
132  return &(t_stream->second);
133  }
134 
136  {
137  std::unique_lock< std::mutex > t_lock( f_manager_mutex );
138  return f_must_reset_midge;
139  }
140 
141  inline active_node_bindings* stream_manager::get_node_bindings()
142  {
143  return &f_node_bindings;
144  }
145 
146 
147 } /* namespace psyllid */
148 
149 #endif /* PSYLLID_STREAM_MANAGER_HH_ */
active_node_bindings f_node_bindings
void remove_stream(const std::string &a_name)
std::string get_node_run_str() const
bool dump_node_config(const std::string &a_stream_name, const std::string &a_node_name, scarab::param_node &a_config) const
active_node_bindings * get_node_bindings()
dripline::reply_ptr_t handle_dump_config_node_request(const dripline::request_ptr_t a_request)
const stream_template * get_stream(const std::string &a_name) const
dripline::reply_ptr_t handle_get_stream_list_request(const dripline::request_ptr_t a_request)
bool configure_node(const std::string &a_stream_name, const std::string &a_node_name, const scarab::param_node &a_config)
void _add_stream(const std::string &a_name, const scarab::param_node &a_node)
midge_package get_midge()
dripline::reply_ptr_t handle_add_stream_request(const dripline::request_ptr_t a_request)
dripline::reply_ptr_t handle_configure_node_request(const dripline::request_ptr_t a_request)
Holds node configuration and can be used to create node classes and node binding classes.
std::map< std::string, std::pair< node_binding *, midge::node *> > active_node_bindings
void _remove_stream(const std::string &a_name)
void _dump_node_config(const std::string &a_stream_name, const std::string &a_node_name, scarab::param_node &a_config) const
void _configure_node(const std::string &a_stream_name, const std::string &a_node_name, const scarab::param_node &a_config)
Manages one or multiple sets of midge-nodes.
void return_midge(midge_package &&a_midge)
locked_resource< midge::diptera, stream_manager > midge_package
dripline::reply_ptr_t handle_get_stream_node_list_request(const dripline::request_ptr_t a_request)
std::shared_ptr< midge::diptera > midge_ptr_t
std::map< std::string, node_builder *> nodes_t
bool initialize(const scarab::param_node &a_config)
std::map< std::string, stream_template > streams_t
dripline::reply_ptr_t handle_remove_stream_request(const dripline::request_ptr_t a_request)
bool add_stream(const std::string &a_name, const scarab::param_node &a_node)
Allows access to midge nodes.
Definition: node_builder.hh:38