.# 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!! * * TO CHANGE THIS, EDIT scripts/sockopts.gsl * * AND RUN ./generate in models/. * **************************************************** ------------------------------------------------------------------------- Copyright (c) 1991-2013 iMatix Corporation Copyright other contributors as noted in the AUTHORS file. This file is part of CZMQ, the high-level C binding for 0MQ: http://czmq.zeromq.org. This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL- ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . ========================================================================= */ #ifndef __ZSOCKOPT_H_INCLUDED__ #define __ZSOCKOPT_H_INCLUDED__ #ifdef __cplusplus extern "C" { #endif // @interface .for version #if (ZMQ_VERSION_MAJOR == $(major)) // Get socket options . for option . if defined (.minor) # if (ZMQ_VERSION_MINOR == $(minor)) . endif . if mode = "rw" | mode = "r" CZMQ_EXPORT $(ctype) zsocket_$(name) (void *zocket); . endif . if defined (.minor) # endif . endif . endfor // Set socket options . for option . 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 . for header $(string.trim(.):) . endfor #endif .endfor // Self test of this class int zsockopt_test (bool verbose); // @end #ifdef __cplusplus } #endif #endif .output "../src/zsockopt.c" /* ========================================================================= zsockopt - get/set 0MQ socket options **************************************************** * GENERATED SOURCE CODE, DO NOT EDIT!! * * TO CHANGE THIS, EDIT scripts/sockopts.gsl * * AND RUN ./generate in models/. * **************************************************** ------------------------------------------------------------------------- Copyright (c) 1991-2013 iMatix Corporation Copyright other contributors as noted in the AUTHORS file. This file is part of CZMQ, the high-level C binding for 0MQ: http://czmq.zeromq.org. This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL- ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . ========================================================================= */ /* @header The zsockopt class provides access to the 0MQ getsockopt/setsockopt API. @discuss This class is generated, using the GSL code generator. See the sockopts XML file, which provides the metadata, and the sockopts.gsl template, which does the work. @end */ #include "../include/czmq.h" .for version #if (ZMQ_VERSION_MAJOR == $(major)) . for option . if defined (.minor) # if (ZMQ_VERSION_MINOR == $(minor)) . endif . if mode = "rw" | mode = "w" // -------------------------------------------------------------------------- // Set socket ZMQ_$(NAME) value // *** 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 . .open = "&& " . endif . if last() . .close = ") {" . else . .close = "" . endif $(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 . if ctype = "int" . if type = "uint64" uint64_t value = $(name); int rc = zmq_setsockopt (zocket, ZMQ_$(NAME), &value, sizeof (uint64_t)); . elsif type = "int64" int64_t value = $(name); int rc = zmq_setsockopt (zocket, ZMQ_$(NAME), &value, sizeof (int64_t)); . elsif type = "uint32" uint32_t value = $(name); int rc = zmq_setsockopt (zocket, ZMQ_$(NAME), &value, sizeof (uint32_t)); . else 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 || 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" int64_t $(name); size_t option_len = sizeof (int64_t); zmq_getsockopt (zocket, ZMQ_$(NAME), &$(name), &option_len); . elsif type = "uint32" uint32_t $(name); size_t option_len = sizeof (uint32_t); 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 = "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) # endif . endif . endfor . for source $(string.trim(.):) . endfor #endif .endfor // -------------------------------------------------------------------------- // Selftest // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START *** int zsockopt_test (bool verbose) { printf (" * zsockopt: "); // @selftest zctx_t *ctx = zctx_new (); assert (ctx); void *zocket; .for version #if (ZMQ_VERSION_MAJOR == $(major)) . for option . if defined (.minor) # if (ZMQ_VERSION_MINOR == $(minor)) . endif . 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_value?'test':)"); . endif . endif . if mode = "rw" | mode = "r" . 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 $(string.trim(.):) . endfor #endif .endfor zctx_destroy (&ctx); // @end printf ("OK\\n"); return 0; }