OctopOS  0.6.0
Data communication bus for SPACE HAUC
tentacle.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_TENTACLE_H_
10 #define INCLUDE_TENTACLE_H_
11 
12 #include <string.h>
13 #include <sys/types.h>
14 #include <sys/time.h>
15 #include <time.h>
16 #include <unistd.h>
17 
18 #include <exception>
19 #include <iostream>
20 #include <cstdlib>
21 #include <string>
22 #include <utility>
23 #include <mutex> // NOLINT
24 
25 #include "utility.h" // NOLINT
26 
31 class tentacle {
33  friend class octopOS;
34 
35  private:
37  static std::mutex id_lock;
38 
40  static void initRand(ushort* rand_seed);
41 
42  protected:
44  static int message_que;
45 
47  static intptr_t* shared_data;
48 
50  enum role_t {SUBSCRIBER, PUBLISHER }; // PROTECT ME SQUIRE
51 
57  static long getTempId(role_t role); // NOLINT
58 
59  public:
65  explicit tentacle(key_t msg_key);
66 
77  static std::pair<long, std::string> read(long type, bool block = true, // NOLINT
78  bool under = false);
79 
86  bool write(long type, std::string data); // NOLINT
87 
94  bool write(std::pair<long, std::string> pair); // NOLINT
95 };
96 
97 // Size-invariant string data type for publishing
98 class OctoString {
99  private:
100  char buf[MSGLEN - 1];
101 
102  public:
103  OctoString() {}
104  explicit OctoString(const std::string &value) {
105  if (value.size() > (MSGLEN - 2)) {
106  throw std::range_error("Given string is too large to publish.");
107  }
108  strcpy(buf, value.c_str()); // NOLINT - complains about strcpy?
109  }
110  OctoString& operator=(const std::string &other) {
111  strcpy(buf, other.c_str()); // NOLINT - complains about strcpy?
112  return *this;
113  }
114  OctoString& operator=(const OctoString &other) {
115  strcpy(buf, other.buf); // NOLINT - complains about strcpy?
116  return *this;
117  }
118  std::string get() {
119  return std::string(buf);
120  }
121 
122  operator std::string() {
123  return std::string(buf);
124  }
125 };
126 
127 #endif // INCLUDE_TENTACLE_H_
static long getTempId(role_t role)
Definition: tentacle.cpp:72
Definition: tentacle.h:31
Definition: octopos.h:34
tentacle(key_t msg_key)
Definition: tentacle.cpp:11
bool write(long type, std::string data)
Definition: tentacle.cpp:50
static std::pair< long, std::string > read(long type, bool block=true, bool under=false)
Definition: tentacle.cpp:28
Definition: tentacle.h:98
role_t
Definition: tentacle.h:50
static intptr_t * shared_data
Definition: tentacle.h:47
static int message_que
Definition: tentacle.h:44