示例#1
0
static void
format_icanhaz_command (client_t *self, server_t *server)
{
    fmq_msg_path_set (server->request, self->sub->path);                      
    //  If client app wants full resync, send cache to server                 
    if (atoi (fmq_config_resolve (self->config, "client/resync", "0")) == 1) {
        fmq_msg_options_insert (server->request, "RESYNC", "1");              
        fmq_msg_cache_set (server->request, sub_cache (self->sub));           
    }                                                                         
}
示例#2
0
static void
get_next_subscription (client_t *self)
{
    sub_t *sub = (sub_t *) zlist_next (self->subs); 
    if (sub) {                                      
        fmq_msg_path_set (self->request, sub->path);
        self->next_event = ok_event;                
    }                                               
    else                                            
        self->next_event = finished_event;          
}
示例#3
0
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);
    }
}
示例#4
0
static void
control_message (client_t *self)
{
    zmsg_t *msg = zmsg_recv (self->pipe);
    char *method = zmsg_popstr (msg);
    if (streq (method, "SUBSCRIBE")) {
        char *path = zmsg_popstr (msg);
        //  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;                     
        }                                                           
        free (path);
    }
    else
    if (streq (method, "CONNECT")) {
        char *endpoint = zmsg_popstr (msg);
        client_restart (self, endpoint);
        free (endpoint);
    }
    else
    if (streq (method, "CONFIG")) {
        char *config_file = zmsg_popstr (msg);
        fmq_config_destroy (&self->config);
        self->config = fmq_config_load (config_file);
        if (self->config)
            client_apply_config (self);
        else {
            printf ("E: cannot load config file '%s'\n", config_file);
            self->config = fmq_config_new ("root", NULL);
        }
        free (config_file);
    }
    else
    if (streq (method, "SETOPTION")) {
        char *path = zmsg_popstr (msg);
        char *value = zmsg_popstr (msg);
        fmq_config_path_set (self->config, path, value);
        free (path);
        free (value);
    }
    else
    if (streq (method, "STOP")) {
        zstr_send (self->pipe, "OK");
        self->stopped = true;
    }
    free (method);
    zmsg_destroy (&msg);

    if (self->next_event)
        client_execute (self, self->next_event);
}