int zfl_device_test (Bool verbose) { printf (" * zfl_device: "); // Create a new device from the ZPL test file zfl_device_t *device = zfl_device_new ("zfl_device_test.txt"); assert (device); // Look for device that does not exist void *socket = zfl_device_socket (device, "nosuch", "socket", ZMQ_SUB); assert (socket == NULL); zmq_close (socket); // Look for existing device, configure it char *main_device = zfl_device_locate (device, 0); assert (*main_device); assert (streq (main_device, "main")); char *type = zfl_device_property (device, main_device, "type"); assert (*type); assert (streq (type, "zmq_queue")); char *endpoint = zfl_device_property (device, main_device, "frontend/endpoint"); assert (*endpoint); assert (streq (endpoint, "valid-endpoint")); // Configure two sockets void *frontend = zfl_device_socket (device, main_device, "frontend", ZMQ_SUB); assert (frontend); zmq_close (frontend); void *backend = zfl_device_socket (device, main_device, "backend", ZMQ_PUB); assert (backend); zmq_close (backend); zfl_device_destroy (&device); assert (device == NULL); printf ("OK\n"); return 0; }
// Starts a device as configured by a JSON or text config file // static void s_start_configured_device (char *filename) { // Create and configure a zfl_device object zfl_device_t *device = zfl_device_new (filename); if (!device) { printf ("E: '%s' can't be read, or has invalid syntax\n", filename); exit (EXIT_FAILURE); } // Find first device char *main_device = zfl_device_locate (device, 0); if (!*main_device) { printf ("E: No device specified, please read http://rfc.zeromq.org/spec:5\n"); exit (EXIT_FAILURE); } // Process device type char *type = zfl_device_property (device, main_device, "type"); int device_type; // 0MQ defined type int frontend_type; // Socket types depending int backend_type; // on the device type s_parse_device_type (type, &device_type, &frontend_type, &backend_type); // Create and configure sockets void *frontend = zfl_device_socket (device, main_device, "frontend", frontend_type); assert (frontend); void *backend = zfl_device_socket (device, main_device, "backend", backend_type); assert (backend); // Start the device now if (zfl_device_verbose (device)) printf ("I: Starting device...\n"); // Will not actually ever return zmq_device (device_type, frontend, backend); zfl_device_destroy (&device); }