OctopOS  0.6.0
Data communication bus for SPACE HAUC
octopos.h
Go to the documentation of this file.
1 // Copyright 2017 Space HAUC Command and Data Handling
2 // This file is part of octopOS which is released under AGPLv3.
3 // See file LICENSE.txt or go to <http://www.gnu.org/licenses/> for full
4 // license details.
5 
9 #ifndef INCLUDE_OCTOPOS_H_
10 #define INCLUDE_OCTOPOS_H_
11 
12 #include <signal.h>
13 
14 #include <unordered_map>
15 #include <mutex> // NOLINT
16 #include <string>
17 #include <vector>
18 #include <tuple>
19 #include <sstream>
20 #include <iterator>
21 #include <memory>
22 #include <utility>
23 
24 #include "utility.h" // NOLINT
25 #include "tentacle.h" // NOLINT
26 
27 
34 class octopOS {
35  public:
40  static octopOS& getInstance();
41 
43  octopOS(octopOS const&) = delete;
44 
46  void operator=(octopOS const &) = delete;
47 
52  ~octopOS();
53 
64  std::pair<unsigned, key_t> create_new_topic
65  (std::string name, unsigned size);
66 
78  static void* listen_for_child(void* tentacle_index_dynamic);
79 
86  bool propagate_to_subscribers(std::string name);
87 
100  std::pair<unsigned, key_t> subscribe_to_topic(std::string name,
101  unsigned tentacle, octopOS_id_t subscriber_id, long size = -1); // NOLINT
102 
108  static void sig_handler(int sig);
109 
110  private:
117  static long get_id(tentacle::role_t role); // NOLINT
118 
122  void topic_reader_in();
123 
127  void topic_reader_out();
128 
132  void topic_writer_in();
133 
137  void topic_writer_out();
138 
140  static int shmid;
142  static int tentacle_ids[NUMMODULES];
144  static std::vector<int> semids;
146  static std::vector<tentacle*> tentacles;
149  static intptr_t *shared_ptr, *shared_end_ptr;
150 
162  static std::unordered_map<std::string,
163  std::tuple<unsigned,
164  key_t,
165  std::vector<std::pair<octopOS_id_t, unsigned>>
166  >
167  > topic_data;
168 
170  static std::mutex topic_data_rdlock, topic_data_rdtry,
171  topic_data_wrlock, topic_data_lock;
173  static unsigned topic_data_readers, topic_data_writers;
174 
179  octopOS();
180 };
181 
182 #endif // INCLUDE_OCTOPOS_H_
const unsigned NUMMODULES
Definition: utility.h:30
static void sig_handler(int sig)
Definition: octopos.cpp:28
static void * listen_for_child(void *tentacle_index_dynamic)
Definition: octopos.cpp:153
static octopOS & getInstance()
Definition: octopos.cpp:22
~octopOS()
Definition: octopos.cpp:315
Definition: tentacle.h:31
void operator=(octopOS const &)=delete
Definition: octopos.h:34
bool propagate_to_subscribers(std::string name)
Definition: octopos.cpp:210
std::pair< unsigned, key_t > create_new_topic(std::string name, unsigned size)
Definition: octopos.cpp:118
role_t
Definition: tentacle.h:50
long octopOS_id_t
Definition: utility.h:47
std::pair< unsigned, key_t > subscribe_to_topic(std::string name, unsigned tentacle, octopOS_id_t subscriber_id, long size=-1)
Definition: octopos.cpp:231