// Apply configuration tree: // * apply client configuration // * print any echo items in top-level sections // * apply sections that match methods static void client_apply_config (client_t *self) { // Apply echo commands and class methods fmq_config_t *section = fmq_config_child (self->config); while (section) { fmq_config_t *entry = fmq_config_child (section); while (entry) { if (streq (fmq_config_name (entry), "echo")) zclock_log (fmq_config_value (entry)); entry = fmq_config_next (entry); } if (streq (fmq_config_name (section), "subscribe")) { char *path = fmq_config_resolve (section, "path", "?"); // Store subscription along with any previous ones // Check we don't already have a subscription for this path self->sub = (sub_t *) zlist_first (self->subs); while (self->sub) { if (streq (path, self->sub->path)) return; self->sub = (sub_t *) zlist_next (self->subs); } // Subscription path must start with '/' // We'll do better error handling later assert (*path == '/'); // New subscription, store it for later replay char *inbox = fmq_config_resolve (self->config, "client/inbox", ".inbox"); self->sub = sub_new (self, inbox, path); zlist_append (self->subs, self->sub); } else if (streq (fmq_config_name (section), "set_inbox")) { char *path = fmq_config_resolve (section, "path", "?"); fmq_config_path_set (self->config, "client/inbox", path); } else if (streq (fmq_config_name (section), "set_resync")) { long enabled = atoi (fmq_config_resolve (section, "enabled", "")); // Request resynchronization from server fmq_config_path_set (self->config, "client/resync", enabled? "1" :"0"); } section = fmq_config_next (section); } client_config_self (self); }
static void client_apply_config (client_t *self) { // Get standard client configuration self->heartbeat = atoi ( fmq_config_resolve (self->config, "client/heartbeat", "1")) * 1000; // Apply echo commands and class methods fmq_config_t *section = fmq_config_child (self->config); while (section) { fmq_config_t *entry = fmq_config_child (section); while (entry) { if (streq (fmq_config_name (entry), "echo")) puts (fmq_config_value (entry)); entry = fmq_config_next (entry); } if (streq (fmq_config_name (section), "subscribe")) { char *path = fmq_config_resolve (section, "path", "?"); // Store subscription along with any previous ones // Check we don't already have a subscription for this path sub_t *sub = (sub_t *) zlist_first (self->subs); while (sub) { if (streq (path, sub->path)) return; sub = (sub_t *) zlist_next (self->subs); } // Subscription path must start with '/' // We'll do better error handling later assert (*path == '/'); // New subscription, so store it for later replay sub = sub_new (self, path); zlist_append (self->subs, sub); // If we're connected, then also send to server if (self->connected) { fmq_msg_path_set (self->request, path); self->next_event = subscribe_event; } } section = fmq_config_next (section); } }