ext/czmq/scripts/sockopts.gsl in rbczmq-1.7.1 vs ext/czmq/scripts/sockopts.gsl in rbczmq-1.7.2
- old
+ new
@@ -1,19 +1,34 @@
-.output "../include/zsockopt.h"
-.for version
-. for option
-. if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
-. option.ctype = "int"
-. option.ctype_const = "int"
-. elsif type = "blob"
-. option.ctype = "char *" # Enforce C strings
-. option.ctype_const = "const char *"
-. else
-. echo "E: unknown type: $(type)"
-. endif
-. endfor
-.endfor
+.# This is a code generator built using the iMatix GSL code generation
+.# language. See https://github.com/imatix/gsl for details. This script
+.# is licensed under MIT/X11.
+.#
+.template 0
+ output "../include/zsockopt.h"
+ for version
+ # Expand any macros
+ for include
+ for options.macro where name = include.name
+ for . as child
+ copy child to version
+ endfor
+ endfor
+ endfor
+ # Preprocess options
+ for option
+ if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
+ option.ctype = "int"
+ option.ctype_const = "int"
+ elsif type = "string" | type = "key"
+ option.ctype = "char *" # Enforce C strings
+ option.ctype_const = "const char *"
+ else
+ echo "E: unknown type: $(type)"
+ endif
+ endfor
+ endfor
+.endtemplate
/* =========================================================================
zsockopt - get/set 0MQ socket options
****************************************************
* GENERATED SOURCE CODE, DO NOT EDIT!! *
@@ -70,10 +85,13 @@
. if defined (.minor)
# if (ZMQ_VERSION_MINOR == $(minor))
. endif
. if mode = "rw" | mode = "w"
CZMQ_EXPORT void zsocket_set_$(name) (void *zocket, $(ctype_const) $(name));
+. if type = "key"
+CZMQ_EXPORT void zsocket_set_$(name)_bin (void *zocket, const byte *$(name));
+. endif
. endif
. if defined (.minor)
# endif
. endif
. endfor
@@ -86,31 +104,10 @@
.endfor
// Self test of this class
int zsockopt_test (bool verbose);
// @end
-.for version
-// Deprecated function names
-#if (ZMQ_VERSION_MAJOR == $(major))
-. for option
-. if defined (.minor)
-# if (ZMQ_VERSION_MINOR == $(minor))
-. endif
-. if mode = "rw" | mode = "r"
-#define zsockopt_$(name) zsocket_$(name)
-. endif
-. if mode = "rw" | mode = "w"
-#define zsockopt_set_$(name) zsocket_set_$(name)
-. endif
-. if defined (.minor)
-# endif
-. endif
-. endfor
-#endif
-
-.endfor
-
#ifdef __cplusplus
}
#endif
#endif
@@ -169,11 +166,16 @@
// *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
void
zsocket_set_$(name) (void *zocket, $(ctype_const) $(name))
{
+. if style = "macro"
# if defined (ZMQ_$(NAME))
+. endif
+. if defined (.ifdef)
+# if defined ($(ifdef:))
+. endif
. if count (restrict)
. for restrict
. if first()
. .open = "if ("
. else
@@ -182,11 +184,11 @@
. if last()
. .close = ") {"
. else
. .close = ""
. endif
- $(open)zsockopt_type (zocket) != ZMQ_$(TYPE)$(close)
+ $(open)zsocket_type (zocket) != ZMQ_$(TYPE)$(close)
. endfor
printf ("ZMQ_$(NAME) is not valid on %s sockets\\n", zsocket_type_str (zocket));
assert (false);
}
. endif
@@ -204,25 +206,59 @@
int rc = zmq_setsockopt (zocket, ZMQ_$(NAME), &$(name), sizeof (int));
. endif
. else
int rc = zmq_setsockopt (zocket, ZMQ_$(NAME), $(name), strlen ($(name)));
. endif
- assert (rc == 0 || errno == ETERM);
+ assert (rc == 0 || zmq_errno () == ETERM);
+. if defined (.ifdef)
+# endif
+. endif
+. if style = "macro"
# endif
+. endif
}
+.# Generate additional set_xxx_bin method
+.if type = "key"
+// --------------------------------------------------------------------------
+// Set socket ZMQ_$(NAME) value from 32-octet binary
+// *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
+
+void
+zsocket_set_$(name)_bin (void *zocket, const byte *$(name))
+{
+. if style = "macro"
+# if defined (ZMQ_$(NAME))
+. endif
+. if defined (.ifdef)
+# if defined ($(ifdef:))
+. endif
+ int rc = zmq_setsockopt (zocket, ZMQ_$(NAME), $(name), 32);
+ assert (rc == 0 || zmq_errno () == ETERM);
+. if defined (.ifdef)
+# endif
+. endif
+. if style = "macro"
+# endif
+. endif
+}
+
+
+.endif
. endif
. if mode = "rw" | mode = "r"
// --------------------------------------------------------------------------
// Return socket ZMQ_$(NAME) value
// *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
$(ctype)
zsocket_$(name) (void *zocket)
{
+. if style = "macro"
# if defined (ZMQ_$(NAME))
+. endif
. if type = "uint64"
uint64_t $(name);
size_t option_len = sizeof (uint64_t);
zmq_getsockopt (zocket, ZMQ_$(NAME), &$(name), &option_len);
. elsif type = "int64"
@@ -235,21 +271,29 @@
zmq_getsockopt (zocket, ZMQ_$(NAME), &$(name), &option_len);
. elsif type = "int"
int $(name);
size_t option_len = sizeof (int);
zmq_getsockopt (zocket, ZMQ_$(NAME), &$(name), &option_len);
-. elsif type = "blob"
+. elsif type = "string" | type = "key"
size_t option_len = 255;
char *$(name) = (char *) zmalloc (option_len);
zmq_getsockopt (zocket, ZMQ_$(NAME), $(name), &option_len);
. endif
. if type = "int"
return $(name);
. else
return ($(ctype)) $(name);
. endif
+. if style = "macro"
+# else
+. if type = "string" | type = "key"
+ return NULL;
+. else
+ return 0;
+. endif
# endif
+. endif
}
. endif
. if defined (.minor)
@@ -280,33 +324,43 @@
#if (ZMQ_VERSION_MAJOR == $(major))
. for option
. if defined (.minor)
# if (ZMQ_VERSION_MINOR == $(minor))
. endif
-# if defined (ZMQ_$(NAME))
+. if style = "macro"
+# if defined (ZMQ_$(NAME))
+. endif
+. if defined (.ifdef)
+# if defined ($(ifdef:))
+. endif
zocket = zsocket_new (ctx, ZMQ_$(TEST));
assert (zocket);
. if mode = "rw" | mode = "w"
. if ctype = "int"
zsocket_set_$(name) (zocket, 1);
. if mode = "rw"
assert (zsocket_$(name) (zocket) == 1);
. endif
. else
- zsocket_set_$(name) (zocket, "test");
+ zsocket_set_$(name) (zocket, "$(test_value?'test':)");
. endif
. endif
. if mode = "rw" | mode = "r"
-. if type = "blob"
+. if type = "string" | type = "key"
char *$(name) = zsocket_$(name) (zocket);
assert ($(name));
free ($(name));
. else
zsocket_$(name) (zocket);
. endif
. endif
zsocket_destroy (ctx, zocket);
+. if defined (.ifdef)
# endif
+. endif
+. if style = "macro"
+# endif
+. endif
. if defined (.minor)
# endif
. endif
. endfor
. for selftest