|
| 1 | +From 22b41e7ed8268b94ccc139138e2037c390a3a616 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Bed=C5=99ich=20Schindler?= < [email protected]> |
| 3 | +Date: Thu, 10 Jul 2025 15:00:45 +0200 |
| 4 | +Subject: [PATCH] Implement `SchemaNode::actionRpcs()` |
| 5 | +MIME-Version: 1.0 |
| 6 | +Content-Type: text/plain; charset=UTF-8 |
| 7 | +Content-Transfer-Encoding: 8bit |
| 8 | +Organization: Wires |
| 9 | + |
| 10 | +This function allows to access list of actions |
| 11 | +within schema node. |
| 12 | + |
| 13 | +It is implemented same as `Module::actionRpcs` |
| 14 | +to follow same approach, so there is no need to use |
| 15 | +collections. |
| 16 | + |
| 17 | +Change-Id: Ie99908cfdd334433fd9ae6f1a909f196e61139fd |
| 18 | +Signed-off-by: Jan Kundrát < [email protected]> |
| 19 | +Signed-off-by: Mattias Walström < [email protected]> |
| 20 | +--- |
| 21 | + include/libyang-cpp/SchemaNode.hpp | 1 + |
| 22 | + src/SchemaNode.cpp | 12 ++++++++++++ |
| 23 | + tests/example_schema.hpp | 28 ++++++++++++++++++++++++++++ |
| 24 | + tests/schema_node.cpp | 21 +++++++++++++++++++++ |
| 25 | + 4 files changed, 62 insertions(+) |
| 26 | + |
| 27 | +diff --git a/include/libyang-cpp/SchemaNode.hpp b/include/libyang-cpp/SchemaNode.hpp |
| 28 | +index 0f1a4c4..9f49fd7 100644 |
| 29 | +--- a/include/libyang-cpp/SchemaNode.hpp |
| 30 | ++++ b/include/libyang-cpp/SchemaNode.hpp |
| 31 | +@@ -79,6 +79,7 @@ public: |
| 32 | + Collection<SchemaNode, IterationType::Sibling> siblings() const; |
| 33 | + Collection<SchemaNode, IterationType::Sibling> immediateChildren() const; |
| 34 | + std::vector<ExtensionInstance> extensionInstances() const; |
| 35 | ++ std::vector<SchemaNode> actionRpcs() const; |
| 36 | + |
| 37 | + std::vector<When> when() const; |
| 38 | + |
| 39 | +diff --git a/src/SchemaNode.cpp b/src/SchemaNode.cpp |
| 40 | +index 26b5099..ce24203 100644 |
| 41 | +--- a/src/SchemaNode.cpp |
| 42 | ++++ b/src/SchemaNode.cpp |
| 43 | +@@ -117,6 +117,18 @@ Collection<SchemaNode, IterationType::Sibling> SchemaNode::immediateChildren() c |
| 44 | + return c ? c->siblings() : Collection<SchemaNode, IterationType::Sibling>{nullptr, nullptr}; |
| 45 | + } |
| 46 | + |
| 47 | ++/** |
| 48 | ++ * @brief Returns a collection of action nodes (not RPC nodes) as SchemaNode |
| 49 | ++ */ |
| 50 | ++std::vector<SchemaNode> SchemaNode::actionRpcs() const |
| 51 | ++{ |
| 52 | ++ std::vector<SchemaNode> res; |
| 53 | ++ for (auto action = reinterpret_cast<const struct lysc_node*>(lysc_node_actions(m_node)); action; action = action->next) { |
| 54 | ++ res.emplace_back(SchemaNode{action, m_ctx}); |
| 55 | ++ } |
| 56 | ++ return res; |
| 57 | ++} |
| 58 | ++ |
| 59 | + /** |
| 60 | + * Returns the YANG description of the node. |
| 61 | + * |
| 62 | +diff --git a/tests/example_schema.hpp b/tests/example_schema.hpp |
| 63 | +index 0d8acb9..02d3d74 100644 |
| 64 | +--- a/tests/example_schema.hpp |
| 65 | ++++ b/tests/example_schema.hpp |
| 66 | +@@ -214,6 +214,34 @@ module example-schema { |
| 67 | + } |
| 68 | + |
| 69 | + container bigTree { |
| 70 | ++ action firstAction { |
| 71 | ++ input { |
| 72 | ++ leaf inputLeaf1 { |
| 73 | ++ type string; |
| 74 | ++ } |
| 75 | ++ } |
| 76 | ++ |
| 77 | ++ output { |
| 78 | ++ leaf outputLeaf1 { |
| 79 | ++ type string; |
| 80 | ++ } |
| 81 | ++ } |
| 82 | ++ } |
| 83 | ++ |
| 84 | ++ action secondAction { |
| 85 | ++ input { |
| 86 | ++ leaf inputLeaf2 { |
| 87 | ++ type string; |
| 88 | ++ } |
| 89 | ++ } |
| 90 | ++ |
| 91 | ++ output { |
| 92 | ++ leaf outputLeaf2 { |
| 93 | ++ type string; |
| 94 | ++ } |
| 95 | ++ } |
| 96 | ++ } |
| 97 | ++ |
| 98 | + container one { |
| 99 | + leaf myLeaf { |
| 100 | + type string; |
| 101 | +diff --git a/tests/schema_node.cpp b/tests/schema_node.cpp |
| 102 | +index 0001377..65ef462 100644 |
| 103 | +--- a/tests/schema_node.cpp |
| 104 | ++++ b/tests/schema_node.cpp |
| 105 | +@@ -544,6 +544,27 @@ TEST_CASE("SchemaNode") |
| 106 | + REQUIRE(elem.extensionInstances()[2].argument() == "last-modified"); |
| 107 | + } |
| 108 | + |
| 109 | ++ DOCTEST_SUBCASE("SchemaNode::actionRpcs") |
| 110 | ++ { |
| 111 | ++ DOCTEST_SUBCASE("no actions") |
| 112 | ++ { |
| 113 | ++ auto actions = ctx->findPath("/example-schema:presenceContainer").actionRpcs(); |
| 114 | ++ REQUIRE(actions.size() == 0); |
| 115 | ++ } |
| 116 | ++ |
| 117 | ++ DOCTEST_SUBCASE("two actions") |
| 118 | ++ { |
| 119 | ++ auto actions = ctx->findPath("/example-schema:bigTree").actionRpcs(); |
| 120 | ++ REQUIRE(actions.size() == 2); |
| 121 | ++ REQUIRE(actions[0].asActionRpc().name() == "firstAction"); |
| 122 | ++ REQUIRE(actions[0].asActionRpc().input().child()->name() == "inputLeaf1"); |
| 123 | ++ REQUIRE(actions[0].asActionRpc().output().child()->name() == "outputLeaf1"); |
| 124 | ++ REQUIRE(actions[1].asActionRpc().name() == "secondAction"); |
| 125 | ++ REQUIRE(actions[1].asActionRpc().input().child()->name() == "inputLeaf2"); |
| 126 | ++ REQUIRE(actions[1].asActionRpc().output().child()->name() == "outputLeaf2"); |
| 127 | ++ } |
| 128 | ++ } |
| 129 | ++ |
| 130 | + DOCTEST_SUBCASE("SchemaNode::operator==") |
| 131 | + { |
| 132 | + auto a = ctx->findPath("/type_module:leafString"); |
| 133 | +-- |
| 134 | +2.43.0 |
| 135 | + |
0 commit comments