|
22 | 22 | #include "../../Body/JsonNodeField.h" |
23 | 23 |
|
24 | 24 | #include "../../Endpoint/LeafResource.h" |
| 25 | +#include "../../Endpoint/LeafListResource.h" |
25 | 26 | #include "../../Endpoint/ListResource.h" |
26 | 27 | #include "../../Endpoint/ParentResource.h" |
27 | 28 | #include "../../Endpoint/Service.h" |
28 | 29 |
|
29 | 30 | #include "LeafResource.h" |
| 31 | +#include "LeafListResource.h" |
30 | 32 |
|
31 | 33 | #include "polycubed_core.h" |
32 | 34 |
|
@@ -56,7 +58,7 @@ bool ConcreteFactory::IsBaseModel( |
56 | 58 | tree_names_.pop(); |
57 | 59 | auto leaf = tree_names_.front(); |
58 | 60 |
|
59 | | - if (leaf == "uuid" || leaf == "status" || leaf == "peer") { |
| 61 | + if (leaf == "uuid" || leaf == "status" || leaf == "peer" || leaf == "tcubes") { |
60 | 62 | return true; |
61 | 63 | } |
62 | 64 | } |
@@ -228,8 +230,42 @@ std::unique_ptr<Endpoint::LeafListResource> ConcreteFactory::RestLeafList( |
228 | 230 | const std::vector<Body::JsonNodeField> &node_fields, bool configuration, |
229 | 231 | bool init_only_config, bool mandatory, Types::Scalar type, |
230 | 232 | std::vector<std::string> &&default_value) const { |
231 | | - throw std::invalid_argument( |
232 | | - "Yang case leaf-list not supported in base datamodel"); |
| 233 | + std::function<Response(const std::string &, const ListKeyValues &keys)> |
| 234 | + read_handler_; |
| 235 | + std::function<Response(const std::string &, const nlohmann::json &, |
| 236 | + const ListKeyValues &, Endpoint::Operation)> |
| 237 | + replace_handler_; |
| 238 | + |
| 239 | + // TODO: I need to capture this variable inside the lambda functions, |
| 240 | + // capturing "this" for me is not working |
| 241 | + auto local_core = this->core_; |
| 242 | + |
| 243 | + auto tree_names_ = tree_names; |
| 244 | + tree_names_.pop(); |
| 245 | + |
| 246 | + if (tree_names_.size() == 2) { |
| 247 | + if (tree_names_.front() != "ports") { |
| 248 | + throw std::runtime_error("unknown element found in base datamodel"); |
| 249 | + } |
| 250 | + |
| 251 | + tree_names_.pop(); |
| 252 | + auto leaf = tree_names_.front(); |
| 253 | + if (leaf == "tcubes") { |
| 254 | + read_handler_ = [local_core](const std::string &cube_name, |
| 255 | + const ListKeyValues &keys) -> Response { |
| 256 | + return local_core->base_model()->get_port_tcubes(cube_name, |
| 257 | + keys[0].value); |
| 258 | + }; |
| 259 | + } else { |
| 260 | + throw std::runtime_error("unknown element found in base datamodel: " + |
| 261 | + leaf); |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + return std::make_unique<LeafListResource>( |
| 266 | + std::move(read_handler_), std::move(replace_handler_), name, description, |
| 267 | + cli_example, rest_endpoint, parent, configuration, init_only_config, |
| 268 | + core_, std::move(value_field), node_fields, mandatory, type, std::move(default_value)); |
233 | 269 | } |
234 | 270 |
|
235 | 271 | std::unique_ptr<Endpoint::ListResource> ConcreteFactory::RestList( |
|
0 commit comments