On Tue, Mar 17, 2015 at 10:35:26AM -0400, Russell Bryant wrote:
> I started working on a new command line utility that used this shared
> code.  I wanted the ability to pass some data from common
> initialization code to all of the commands.  You can find a similar
> pattern in ovs-vsctl.
> 
> This patch updates the command handler to take a new struct,
> ovs_cmdl_context, instead of argc and argv directly.  It includes argc
> and argv, but also includes an opaque type (void *), where the user of
> this API can attach its custom data it wants passed along to command
> handlers.
> 
> This patch affected the ovstest sub-programs, as well.  The patch
> includes a bit of an odd hack to OVSTEST_REGISTER() to avoid making
> the main() function of the sub-programs take a ovs_cmdl_context.
> The test main() functions still receive argc and argv directly, as
> that seems more natural.  The test-subprograms themselves are able to
> make use of a context internally, though.
> 
> Signed-off-by: Russell Bryant <[email protected]>

Thanks!

I applied this to master.  I folded in one change to make the ##
operator do something useful (it didn't make a real difference because
OVSTEST_REGISTER is only used once per translation unit):

diff --git a/tests/ovstest.h b/tests/ovstest.h
index 082a0d7..ddd7f3e 100644
--- a/tests/ovstest.h
+++ b/tests/ovstest.h
@@ -76,12 +76,12 @@ void ovstest_register(const char *test_name, 
ovs_cmdl_handler f);
  */
 #define OVSTEST_REGISTER(name, function) \
     static void \
-    ovstest_wrapper_##function__(struct ovs_cmdl_context *ctx) \
+    ovstest_wrapper_##function##__(struct ovs_cmdl_context *ctx) \
     { \
         function(ctx->argc, ctx->argv); \
     } \
     OVS_CONSTRUCTOR(register_##function) { \
-        ovstest_register(name, ovstest_wrapper_##function__); \
+        ovstest_register(name, ovstest_wrapper_##function##__); \
     }
 
 #endif
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to