GCC Code Coverage Report


Directory: ./
File: demos/set_data.cpp
Date: 2022-06-30 06:29:57
Exec Total Coverage
Lines: 0 95 0.0%
Branches: 0 206 0.0%

Line Branch Exec Source
1 /**
2 * @file set_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 set the data into a shared memory. This
10 * memory is read from the counter part of this app: get_data
11 */
12
13 #include <signal.h>
14 #include <unistd.h>
15 #include <iostream>
16 #include <vector>
17 #include "shared_memory/shared_memory.hpp"
18
19 static bool RUNNING = true;
20
21 // the shared memory does not keep track of what
22 // segment and objects it created (to be realtime compatible),
23 // so cleaning has to be "manual"
24
25 void cleaning_memory(int)
26 {
27 RUNNING = false;
28 shared_memory::clear_shared_memory("main_memory");
29 }
30
31 int main()
32 {
33 cleaning_memory(0);
34 RUNNING = true;
35
36 // cleaning on ctrl+c
37 struct sigaction cleaning;
38 cleaning.sa_handler = cleaning_memory;
39 sigemptyset(&cleaning.sa_mask);
40 cleaning.sa_flags = 0;
41 sigaction(SIGINT, &cleaning, nullptr);
42
43 double d1 = 0.0;
44 double d2 = 0.0;
45
46 double v1[2];
47
48 std::vector<double> v2(2, 0.0);
49
50 Eigen::VectorXd v3 = Eigen::VectorXd(4);
51
52 std::map<int, double> m1;
53 m1[0] = d1;
54 m1[1] = d2;
55
56 std::map<std::string, double> m2;
57 m2["value_1"] = d1;
58 m2["value_2"] = d2;
59
60 std::map<std::string, std::vector<double>> m3;
61 m3["value_1"] = std::vector<double>(2, 0.0);
62 m3["value_2"] = std::vector<double>(2, 0.0);
63
64 std::map<std::string, Eigen::VectorXd> m4;
65 m4["value_1"] = Eigen::VectorXd(4);
66 m4["value_2"] = Eigen::VectorXd(4);
67
68 const std::string s1("my string");
69
70 unsigned count = 0;
71 while (RUNNING)
72 {
73 d1 += 0.01;
74 d2 += 0.001;
75
76 int offset = 0;
77 v1[0] = (d1 + offset);
78 ++offset;
79 v1[1] = (d1 + offset);
80 ++offset;
81
82 v2[0] = (d1 + offset);
83 ++offset;
84 v2[1] = (d1 + offset);
85 ++offset;
86
87 v3[0] = (d1 + offset);
88 ++offset;
89 v3[1] = (d1 + offset);
90 ++offset;
91 v3[2] = (d1 + offset);
92 ++offset;
93 v3[3] = (d1 + offset);
94 ++offset;
95
96 m1[0] = (d1 + offset);
97 ++offset;
98 m1[1] = (d1 + offset);
99 ++offset;
100
101 m2["value_1"] = (d1 + offset);
102 ++offset;
103 m2["value_2"] = (d1 + offset);
104 ++offset;
105
106 m3["value_1"][0] = (d1 + offset);
107 ++offset;
108 m3["value_2"][0] = (d1 + offset);
109 ++offset;
110
111 m3["value_1"][1] = (d1 + offset);
112 ++offset;
113 m3["value_2"][1] = (d1 + offset);
114 ++offset;
115
116 m4["value_1"][0] = (d1 + offset);
117 ++offset;
118 m4["value_1"][1] = (d1 + offset);
119 ++offset;
120 m4["value_1"][2] = (d1 + offset);
121 ++offset;
122 m4["value_1"][3] = (d1 + offset);
123 ++offset;
124 m4["value_2"][0] = (d1 + offset);
125 ++offset;
126 m4["value_2"][1] = (d1 + offset);
127 ++offset;
128 m4["value_2"][2] = (d1 + offset);
129 ++offset;
130 m4["value_2"][3] = (d1 + offset);
131 ++offset;
132
133 shared_memory::set("main_memory", "d1", d1);
134 shared_memory::set("main_memory", "d2", d2);
135 shared_memory::set("main_memory", "v1", v1, 2);
136 shared_memory::set("main_memory", "v2", v2);
137 shared_memory::set("main_memory", "v3", v3);
138 shared_memory::set("main_memory", "m1", m1);
139 shared_memory::set("main_memory", "m2", m2);
140 shared_memory::set("main_memory", "m3", m3);
141 shared_memory::set("main_memory", "m4", m4);
142 shared_memory::set("main_memory", "s1", s1);
143 // shared_memory::set("main_memory","protobuf_string",
144 // arguments.SerializeAsString());
145
146 ++count;
147 std::cout << ".";
148 if (count % 100 == 0)
149 {
150 std::cout << std::endl;
151 }
152 usleep(1000);
153 }
154 }
155