ofproto: Fix memory leak reported by valgrind.
[cascardo/ovs.git] / lib / db-ctl-base.h
index aff242b..bada320 100644 (file)
@@ -33,8 +33,6 @@ struct table;
  * (structs, commands and functions).  To utilize this module, user must
  * define the following:
  *
- * - the 'cmd_show_tables'.  (See 'struct cmd_show_table' for more info).
- *
  * - the command syntaxes for each command.  (See 'struct ctl_command_syntax'
  *   for more info)  and regiters them using ctl_register_commands().
  *
@@ -47,8 +45,10 @@ struct table;
 #define ovs_fatal please_use_ctl_fatal_instead_of_ovs_fatal
 
 struct ctl_table_class;
+struct cmd_show_table;
 void ctl_init(const struct ctl_table_class *tables,
-             void (*ctl_exit_func)(int status));
+              const struct cmd_show_table *cmd_show_tables,
+              void (*ctl_exit_func)(int status));
 char *ctl_default_db(void);
 OVS_NO_RETURN void ctl_fatal(const char *, ...) OVS_PRINTF_FORMAT(1, 2);
 
@@ -148,6 +148,17 @@ struct ctl_command *ctl_parse_commands(int argc, char *argv[],
                                        struct shash *local_options,
                                        size_t *n_commandsp);
 
+/* Sometimes, it is desirable to print the table with weak reference to
+ * rows in a 'cmd_show_table' table.  In that case, the 'weak_ref_table'
+ * should be used and user must define all variables. */
+struct weak_ref_table {
+    const struct ovsdb_idl_table_class *table;
+    const struct ovsdb_idl_column *name_column;
+    /* This colum must be a weak reference to the owning
+     * 'struct cmd_show_table''s table row. */
+    const struct ovsdb_idl_column *wref_column;
+};
+
 /* This struct is for organizing the 'show' command output where:
  *
  * - 'table' is the table to show.
@@ -157,24 +168,19 @@ struct ctl_command *ctl_parse_commands(int argc, char *argv[],
  *
  * - 'columns[]' allows user to specify the print of additional columns
  *   in 'table'.
+ *
+ * - if 'wref_table' is populated, print 'wref_table.name_column' for
+ *   each row in table 'wref_table.table' that has a reference to 'table'
+ *   in 'wref_table.wref_column'.  Every field must be populated.
+ *
  * */
 struct cmd_show_table {
     const struct ovsdb_idl_table_class *table;
     const struct ovsdb_idl_column *name_column;
     const struct ovsdb_idl_column *columns[3]; /* Seems like a good number. */
+    const struct weak_ref_table wref_table;
 };
 
-/* This array defines the 'show' command output format.  User can check the
- * definition in utilities/ovs-vsctl.c as reference.
- *
- * Particularly, if an element in 'columns[]' represents a reference to
- * another table, the referred table must also be defined as an entry in
- * in 'cmd_show_tables[]'.
- *
- * The definition must end with an all-NULL entry.
- * */
-extern struct cmd_show_table cmd_show_tables[];
-
 \f
 /* The base context struct for conducting the common database
  * operations (commands listed in 'db_ctl_commands').  User should