// Starts a device as configured by a full ZDCF config file // static void s_start_configured_device (char *filename) { FILE *file; // JSON config file stream if (streq (filename, "-")) file = stdin; // "-" means read from stdin else { file = fopen (filename, "rb"); if (!file) { printf ("E: '%s' doesn't exist or can't be read\n", filename); exit (EXIT_FAILURE); } } // Load config data into blob zfl_blob_t *blob = zfl_blob_new (); assert (blob); zfl_blob_load (blob, file); fclose (file); // Create a new config from the blob data zfl_config_t *config = zfl_config_new (zfl_blob_data (blob)); assert (config); // Find first device char *device = zfl_config_device (config, 0); if (!*device) { printf ("E: No device specified, please read http://rfc.zeromq.org/spec:3\n"); exit (EXIT_FAILURE); } // Process device type char *type = zfl_config_device_type (config, device); 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_config_socket (config, device, "frontend", frontend_type); assert (frontend); void *backend = zfl_config_socket (config, device, "backend", backend_type); assert (backend); // Start the device now if (zfl_config_verbose (config)) printf ("I: Starting device...\n"); // Will not actually ever return zmq_device (device_type, frontend, backend); zfl_config_destroy (&config); }
int zfl_config_test (Bool verbose) { printf (" * zfl_config: "); // Create a new config from the ZPL test file zfl_config_t *config = zfl_config_new ( zfl_tree_zpl_file ("zfl_config_test.txt")); assert (config); // Test unknown device void *socket = zfl_config_socket (config, "nosuch", "socket", ZMQ_SUB); assert (socket == NULL); zmq_close (socket); // Find real device char *device = zfl_config_device (config, 0); assert (*device); assert (streq (device, "main")); char *type = zfl_config_device_type (config, device); assert (*type); assert (streq (type, "zqueue")); // Configure two sockets void *frontend = zfl_config_socket (config, device, "frontend", ZMQ_SUB); assert (frontend); zmq_close (frontend); void *backend = zfl_config_socket (config, device, "backend", ZMQ_PUB); assert (backend); zmq_close (backend); zfl_config_destroy (&config); assert (config == NULL); printf ("OK\n"); return 0; }