// 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; }
int zfl_config_test (Bool verbose) { // We create a config of this structure: // // root // type = zqueue // frontend // option // hwm = 1000 // swap = 25000000 # 25MB // subscribe = #2 // bind = tcp://eth0:5555 // backend // bind = tcp://eth0:5556 // zfl_config_t *root, *type, *frontend, *option, *hwm, *swap, *subscribe, *bind, *backend; printf (" * zfl_config: "); // Left is first child, next is next sibling root = zfl_config_new ("root", NULL); type = zfl_config_new ("type", root); zfl_config_set_string (type, "zqueue"); frontend = zfl_config_new ("frontend", root); option = zfl_config_new ("option", frontend); hwm = zfl_config_new ("hwm", option); zfl_config_set_string (hwm, "1000"); swap = zfl_config_new ("swap", option); zfl_config_set_string (swap, "25000000"); subscribe = zfl_config_new ("subscribe", option); zfl_config_set_printf (subscribe, "#%d", 2); bind = zfl_config_new ("bind", frontend); zfl_config_set_string (bind, "tcp://eth0:5555"); backend = zfl_config_new ("backend", root); bind = zfl_config_new ("bind", backend); zfl_config_set_string (bind, "tcp://eth0:5556"); if (verbose) { puts (""); zfl_config_save (root, "-"); } zfl_config_destroy (&root); assert (root == NULL); // Test loading from a JSON file zfl_config_t *config; config = zfl_config_load ("zfl_config_test.json"); assert (config); zfl_config_destroy (&config); // Test loading from a ZPL file config = zfl_config_load ("zfl_config_test.txt"); assert (config); zfl_config_destroy (&config); printf ("OK\n"); return 0; }