]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
lib: Refactor CLI interface function names
[mirror_frr.git] / lib / command_graph.h
1 /*
2 * Graph data structure and companion routines for CLI backend.
3 *
4 * --
5 * Copyright (C) 2016 Cumulus Networks, Inc.
6 *
7 * This file is part of GNU Zebra.
8 *
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 * 02111-1307, USA.
23 */
24
25 #ifndef _ZEBRA_COMMAND_GRAPH_H
26 #define _ZEBRA_COMMAND_GRAPH_H
27
28 #include "command.h"
29
30 /**
31 * Types for graph nodes.
32 *
33 * The node type determines what kind of data the node can match (in the
34 * matching use case) or hold (in the argv use case).
35 */
36 enum graph_node_type
37 {
38 IPV4_GN, // IPV4 addresses
39 IPV4_PREFIX_GN, // IPV4 network prefixes
40 IPV6_GN, // IPV6 prefixes
41 IPV6_PREFIX_GN, // IPV6 network prefixes
42 WORD_GN, // words
43 RANGE_GN, // integer ranges
44 NUMBER_GN, // numbers
45 VARIABLE_GN, // almost anything
46 /* plumbing types */
47 SELECTOR_GN, // marks beginning of selector subgraph
48 OPTION_GN, // marks beginning of option subgraph
49 NUL_GN, // transparent node with various uses
50 START_GN, // first node in the graph (has no parents)
51 END_GN // leaf node in the graph, has pointer to cmd_element
52 };
53
54 /**
55 * Command graph node.
56 * Used for matching and passing arguments to vtysh commands.
57 */
58 struct graph_node
59 {
60 enum graph_node_type type; // data type this node matches or holds
61 vector children; // this node's children
62
63 char *text; // original format text
64 char *doc; // docstring for this node
65 long long value; // for NUMBER_GN
66 long long min, max; // for RANGE_GN
67
68 /* cmd_element struct pointer, only valid for END_GN */
69 struct cmd_element *element;
70
71 /* used for passing arguments to command functions */
72 char *arg;
73
74 /* refcount for node parents */
75 unsigned int refs;
76 };
77
78 /**
79 * Adds a node as a child of another node.
80 *
81 * @param[in] parent node
82 * @param[in] child node
83 * @return child node
84 */
85 struct graph_node *
86 graphnode_add_child (struct graph_node *parent, struct graph_node *child);
87
88 /**
89 * Creates a new node, initializes all fields to default values and sets the
90 * node type.
91 *
92 * @param[in] type node type
93 * @return pointer to the created node
94 */
95 struct graph_node *
96 graphnode_new (enum graph_node_type type);
97
98 /**
99 * Deletes a graph node without deleting its children.
100 *
101 * @param[out] node pointer to node to delete
102 */
103 void
104 graphnode_delete (struct graph_node *node);
105
106 /**
107 * Deletes a graph node and recursively deletes all its direct and indirect
108 * children.
109 *
110 * @param[out] node start node of graph to free
111 */
112 void
113 graphnode_delete_graph (struct graph_node *node);
114
115 #endif /* _ZEBRA_COMMAND_GRAPH_H */