Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* @file get_data.cpp |
3 |
|
|
* @author Vincent Berenz |
4 |
|
|
* @license License BSD-3-Clause |
5 |
|
|
* @copyright Copyright (c) 2019, New York University and Max Planck |
6 |
|
|
* Gesellschaft. |
7 |
|
|
* @date 2019-05-22 |
8 |
|
|
* |
9 |
|
|
* @brief Create a small app that fetch the data from a shared memory. This |
10 |
|
|
* memory is filled with the counter part of this app: set_data |
11 |
|
|
*/ |
12 |
|
|
#include <signal.h> |
13 |
|
|
#include <unistd.h> |
14 |
|
|
#include <iostream> |
15 |
|
|
#include <vector> |
16 |
|
|
#include "shared_memory/shared_memory.hpp" |
17 |
|
|
|
18 |
|
|
static bool RUNNING = true; |
19 |
|
|
|
20 |
|
✗ |
void exiting_memory(int) |
21 |
|
|
{ |
22 |
|
✗ |
RUNNING = false; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
✗ |
int main() |
26 |
|
|
{ |
27 |
|
|
// exiting on ctrl+c |
28 |
|
|
struct sigaction exiting; |
29 |
|
✗ |
exiting.sa_handler = exiting_memory; |
30 |
|
✗ |
sigemptyset(&exiting.sa_mask); |
31 |
|
✗ |
exiting.sa_flags = 0; |
32 |
|
✗ |
sigaction(SIGINT, &exiting, NULL); |
33 |
|
|
|
34 |
|
✗ |
double d1 = 0.0; |
35 |
|
✗ |
double d2 = 0.0; |
36 |
|
|
|
37 |
|
|
double v1[2]; |
38 |
|
✗ |
v1[0] = 0.0; |
39 |
|
✗ |
v1[1] = 0.0; |
40 |
|
|
|
41 |
|
✗ |
std::vector<double> v2(2); |
42 |
|
✗ |
v2[0] = 0.0; |
43 |
|
✗ |
v2[1] = 0.0; |
44 |
|
|
|
45 |
|
✗ |
Eigen::VectorXd v3(4); |
46 |
|
|
|
47 |
|
✗ |
std::map<int, double> m1; |
48 |
|
✗ |
m1[0] = d1; |
49 |
|
✗ |
m1[1] = d2; |
50 |
|
|
|
51 |
|
✗ |
std::map<std::string, double> m2; |
52 |
|
✗ |
m2["value_1"] = d1; |
53 |
|
✗ |
m2["value_2"] = d2; |
54 |
|
|
|
55 |
|
✗ |
std::map<std::string, std::vector<double>> m3; |
56 |
|
✗ |
m3["value_1"] = std::vector<double>(2, 0.0); |
57 |
|
✗ |
m3["value_2"] = std::vector<double>(2, 0.0); |
58 |
|
|
|
59 |
|
✗ |
std::map<std::string, Eigen::VectorXd> m4; |
60 |
|
✗ |
m4["value_1"] = Eigen::VectorXd(4); |
61 |
|
✗ |
m4["value_2"] = Eigen::VectorXd(4); |
62 |
|
|
|
63 |
|
✗ |
std::string s1; |
64 |
|
|
|
65 |
|
✗ |
while (RUNNING) |
66 |
|
|
{ |
67 |
|
✗ |
shared_memory::get("main_memory", "d1", d1); |
68 |
|
✗ |
shared_memory::get("main_memory", "d2", d2); |
69 |
|
✗ |
shared_memory::get("main_memory", "v1", v1, std::size_t{2}); |
70 |
|
✗ |
shared_memory::get("main_memory", "v2", v2); |
71 |
|
✗ |
shared_memory::get("main_memory", "v3", v3); |
72 |
|
✗ |
shared_memory::get("main_memory", "m1", m1); |
73 |
|
✗ |
shared_memory::get("main_memory", "m2", m2); |
74 |
|
✗ |
shared_memory::get("main_memory", "m3", m3); |
75 |
|
✗ |
shared_memory::get("main_memory", "m4", m4); |
76 |
|
✗ |
shared_memory::get("main_memory", "s1", s1); |
77 |
|
|
|
78 |
|
✗ |
std::cout << "values: "; |
79 |
|
✗ |
std::cout << "d1=" << d1 << " ; "; |
80 |
|
✗ |
std::cout << "d2=" << d2 << " ; "; |
81 |
|
✗ |
std::cout << "v1[0]=" << v1[0] << " ; "; |
82 |
|
✗ |
std::cout << "v1[1]=" << v1[1] << " ; "; |
83 |
|
✗ |
std::cout << "v2[0]=" << v2[0] << " ; "; |
84 |
|
✗ |
std::cout << "v2[1]=" << v2[1] << " ; "; |
85 |
|
✗ |
std::cout << "v3=" << v3.transpose() << " ; "; |
86 |
|
✗ |
std::cout << "m1[0]=" << m1[0] << " ; "; |
87 |
|
✗ |
std::cout << "m1[1]=" << m1[1] << " ; "; |
88 |
|
✗ |
std::cout << "m2[value1]=" << m2["value_1"] << " ; "; |
89 |
|
✗ |
std::cout << "m2[value2]=" << m2["value_2"] << " ; "; |
90 |
|
✗ |
std::cout << "m3[value1]=" << m3["value_1"][0] << " ; "; |
91 |
|
✗ |
std::cout << "m3[value2]=" << m3["value_2"][0] << " ; "; |
92 |
|
✗ |
std::cout << "m3[value1]=" << m3["value_1"][0] << " ; "; |
93 |
|
✗ |
std::cout << "m3[value2]=" << m3["value_2"][0] << " ; "; |
94 |
|
✗ |
std::cout << "m4[value1]=" << m4["value_1"].transpose() << " ; "; |
95 |
|
✗ |
std::cout << "m4[value2]=" << m4["value_2"].transpose() << " ; "; |
96 |
|
✗ |
std::cout << "s1=" << s1 << " ; "; |
97 |
|
✗ |
std::cout << std::endl; |
98 |
|
✗ |
usleep(10000); |
99 |
|
|
} |
100 |
|
|
} |
101 |
|
|
|