Skip to content

Commit 2d1e8d1

Browse files
committed
use new NodeList and PathList in SuperNode
1 parent 00a9e92 commit 2d1e8d1

19 files changed

Lines changed: 258 additions & 121 deletions

include/villas/mapping.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <villas/stats.hpp>
2929
#include <villas/common.hpp>
30+
#include <villas/node_list.hpp>
3031

3132
#define RE_MAPPING_INDEX "[a-zA-Z0-9_]+"
3233
#define RE_MAPPING_RANGE "(" RE_MAPPING_INDEX ")(?:-(" RE_MAPPING_INDEX "))?"
@@ -99,7 +100,7 @@ struct mapping_entry {
99100
};
100101
};
101102

102-
int mapping_entry_prepare(struct mapping_entry *me, struct vlist *nodes);
103+
int mapping_entry_prepare(struct mapping_entry *me, villas::node::NodeList &nodes);
103104

104105
int mapping_entry_update(const struct mapping_entry *me, struct sample *remapped, const struct sample *original);
105106

@@ -115,6 +116,6 @@ int mapping_entry_to_str(const struct mapping_entry *me, unsigned index, char **
115116

116117
int mapping_list_parse(struct vlist *ml, json_t *json);
117118

118-
int mapping_list_prepare(struct vlist *ml, struct vlist *nodes);
119+
int mapping_list_prepare(struct vlist *ml, villas::node::NodeList &nodes);
119120

120121
int mapping_list_remap(const struct vlist *ml, struct sample *remapped, const struct sample *original);

include/villas/node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <uuid/uuid.h>
3535

3636
#include <villas/node_type.h>
37+
#include <villas/node_list.hpp>
3738
#include <villas/node_direction.h>
3839
#include <villas/sample.h>
3940
#include <villas/list.h>
@@ -121,7 +122,7 @@ int node_parse(struct vnode *n, json_t *json, const uuid_t sn_uuid);
121122
* @param nodes The nodes will be added to this list.
122123
* @param all This list contains all valid nodes.
123124
*/
124-
int node_list_parse(struct vlist *list, json_t *json, struct vlist *all);
125+
int node_list_parse(struct vlist *list, json_t *json, villas::node::NodeList &all);
125126

126127
/** Parse the list of signal definitions. */
127128
int node_parse_signals(struct vlist *list, json_t *json);

include/villas/node_list.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/** Node list
2+
*
3+
* @file
4+
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
5+
* @copyright 2014-2021, Institute for Automation of Complex Power Systems, EONERC
6+
* @license GNU General Public License (version 3)
7+
*
8+
* VILLASnode
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
24+
#pragma once
25+
26+
#include <uuid/uuid.h>
27+
28+
#include <list>
29+
#include <string>
30+
31+
/* Forward declarations */
32+
struct vnode;
33+
34+
namespace villas {
35+
namespace node {
36+
37+
class NodeList : public std::list<struct vnode *> {
38+
39+
public:
40+
/** Lookup a node from the list based on its name */
41+
struct vnode * lookup(const std::string &name);
42+
43+
/** Lookup a node from the list based on its UUID */
44+
struct vnode * lookup(const uuid_t &uuid);
45+
};
46+
47+
} /* namespace node */
48+
} /* namespace villas */

include/villas/node_type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include <jansson.h>
3030

31-
#include <villas/list.h>
31+
#include <villas/node_list.hpp>
3232
#include <villas/common.hpp>
3333
#include <villas/memory.h>
3434
#include <villas/log.hpp>
@@ -58,7 +58,7 @@ struct vnode_type {
5858

5959
enum State state; /**< State of this node-type. */
6060

61-
struct vlist instances; /**< A list of all existing nodes of this type. */
61+
villas::node::NodeList instances; /**< A list of all existing nodes of this type. */
6262

6363
size_t size; /**< Size of private data bock. @see node::_vd */
6464
size_t pool_size;

include/villas/path.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <villas/common.hpp>
4242
#include <villas/mapping.h>
4343
#include <villas/task.hpp>
44+
#include <villas/node_list.hpp>
4445

4546
#include <villas/log.hpp>
4647

@@ -104,7 +105,7 @@ struct vpath {
104105
/** Initialize internal data structures. */
105106
int path_init(struct vpath *p) __attribute__ ((warn_unused_result));
106107

107-
int path_prepare(struct vpath *p, struct vlist *nodes);
108+
int path_prepare(struct vpath *p, villas::node::NodeList &nodes);
108109

109110
/** Check if path configuration is proper. */
110111
void path_check(struct vpath *p);
@@ -158,9 +159,9 @@ int path_reverse(struct vpath *p, struct vpath *r);
158159
* @retval 0 Success. Everything went well.
159160
* @retval <0 Error. Something went wrong.
160161
*/
161-
int path_parse(struct vpath *p, json_t *json, struct vlist *nodes, const uuid_t sn_uuid);
162+
int path_parse(struct vpath *p, json_t *json, villas::node::NodeList &nodes, const uuid_t sn_uuid);
162163

163-
void path_parse_mask(struct vpath *p, json_t *json_mask, struct vlist *nodes);
164+
void path_parse_mask(struct vpath *p, json_t *json_mask, villas::node::NodeList &nodes);
164165

165166
bool path_is_simple(const struct vpath *p);
166167

include/villas/path_list.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/** Node list
2+
*
3+
* @file
4+
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
5+
* @copyright 2014-2021, Institute for Automation of Complex Power Systems, EONERC
6+
* @license GNU General Public License (version 3)
7+
*
8+
* VILLASnode
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
24+
#pragma once
25+
26+
#include <uuid/uuid.h>
27+
28+
#include <list>
29+
#include <string>
30+
31+
/* Forward declarations */
32+
struct vpath;
33+
34+
namespace villas {
35+
namespace node {
36+
37+
class PathList : public std::list<struct vpath *> {
38+
39+
public:
40+
/** Lookup a path from the list based on its UUID */
41+
struct vpath * lookup(const uuid_t &uuid);
42+
};
43+
44+
} /* namespace node */
45+
} /* namespace villas */

include/villas/super_node.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ extern "C" {
3333

3434
#include <fstream>
3535

36-
#include <villas/list.h>
3736
#include <villas/api.hpp>
3837
#include <villas/web.hpp>
3938
#include <villas/log.hpp>
4039
#include <villas/config.hpp>
4140
#include <villas/node.h>
41+
#include <villas/node_list.hpp>
42+
#include <villas/path_list.hpp>
4243
#include <villas/task.hpp>
4344
#include <villas/common.hpp>
4445
#include <villas/kernel/if.hpp>
@@ -59,8 +60,8 @@ class SuperNode {
5960

6061
Logger logger;
6162

62-
struct vlist nodes;
63-
struct vlist paths;
63+
NodeList nodes;
64+
PathList paths;
6465
std::list<kernel::Interface *> interfaces;
6566

6667
#ifdef WITH_API
@@ -137,17 +138,17 @@ class SuperNode {
137138

138139
struct vnode * getNode(const std::string &name)
139140
{
140-
return vlist_lookup_name<struct vnode>(&nodes, name);
141+
return nodes.lookup(name);
141142
}
142143

143-
struct vlist * getNodes()
144+
NodeList & getNodes()
144145
{
145-
return &nodes;
146+
return nodes;
146147
}
147148

148-
struct vlist * getPaths()
149+
PathList & getPaths()
149150
{
150-
return &paths;
151+
return paths;
151152
}
152153

153154
std::list<kernel::Interface *> & getInterfaces()

lib/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ set(LIB_SRC
5757
node_direction.cpp
5858
node_type.cpp
5959
node.cpp
60+
node_list.cpp
6061
path_destination.cpp
6162
path_source.cpp
6263
path.cpp
64+
path_list.cpp
6365
pool.cpp
6466
queue_signalled.cpp
6567
queue.cpp

lib/api/node_request.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ NodeRequest::prepare()
3030
{
3131
int ret;
3232

33-
auto *nodes = session->getSuperNode()->getNodes();
33+
auto &nodes = session->getSuperNode()->getNodes();
3434

3535
uuid_t uuid;
3636
ret = uuid_parse(matches[1].c_str(), uuid);
3737
if (ret) {
38-
node = vlist_lookup_name<struct vnode>(nodes, matches[1]);
38+
node = nodes.lookup(matches[1]);
3939
if (!node)
4040
throw BadRequest("Unknown node", "{ s: s }",
4141
"node", matches[1].c_str()
4242
);
4343
}
4444
else {
45-
node = vlist_lookup_uuid<struct vnode>(nodes, uuid);
45+
node = nodes.lookup(uuid);
4646
if (!node)
4747
throw BadRequest("No node found with with matching UUID", "{ s: s }",
4848
"uuid", matches[1].c_str()

lib/api/path_request.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ PathRequest::prepare()
3838
"uuid", matches[1].c_str()
3939
);
4040

41-
auto *paths = session->getSuperNode()->getPaths();
42-
path = vlist_lookup_uuid<struct vpath>(paths, uuid);
41+
auto paths = session->getSuperNode()->getPaths();
42+
path = paths.lookup(uuid);
4343
if (!path)
4444
throw BadRequest("No path found with with matching UUID", "{ s: s }",
4545
"uuid", matches[1].c_str()

0 commit comments

Comments
 (0)