Пример #1
0
void fl_set_working_dir(const gchar *dir)
{
	gchar *aux;

	if (dir == NULL || strcmp(working_dir->str, dir) == 0)
		return;

	/* set the new working_dir */
	g_string_assign(working_dir, dir);
	expand_dir(working_dir);

	aux = str_filename_to_utf8(working_dir->str, NULL);
	if (aux == NULL) {
		/* if we can't convert to UTF-8, leave it as is
		   (let Gtk do the complaining...) */
		g_string_assign(working_dir_utf8, dir);
	}
	else {
		g_string_assign(working_dir_utf8, aux);
		free(aux);
	}
	
	gtk_entry_set_text(ent_wd, working_dir_utf8->str);
	
	/* update the directory mru list */
	mru_add(dir_mru, working_dir_utf8->str);

	gtk_combo_box_text_remove_all(combo_wd);
	g_list_foreach(GLIST(dir_mru->list), glist_2_combo, combo_wd);

	if (check_working_dir())
		load_file_list();
	else
		clear_file_list();
}
Пример #2
0
void fl_set_working_dir_utf8(const gchar *dir)
{
	gchar *aux;

	if (dir == NULL || strcmp(working_dir_utf8->str, dir) == 0)
		return;

	/* set the new working_dir */
	g_string_assign(working_dir_utf8, dir);

	aux = str_filename_from_utf8(working_dir_utf8->str, NULL);
	if (aux == NULL) {
		/* if we can't convert from UTF-8, leave it as is
		   (loading from the filesystem will just fail) */
		g_string_assign(working_dir, dir);
	}
	else {
		g_string_assign(working_dir, aux);
		free(aux);
	}
	
	if (expand_dir(working_dir)) {
		// need to reflect back to utf
		aux = str_filename_to_utf8(working_dir->str, NULL);
		if (aux != NULL)
			g_string_assign(working_dir_utf8, aux);
		free(aux);
	}
	
	gtk_entry_set_text(ent_wd, working_dir_utf8->str);
	
	/* update the directory mru list */
	mru_add(dir_mru, working_dir_utf8->str);
	gtk_combo_box_text_remove_all(combo_wd);
	g_list_foreach(GLIST(dir_mru->list), glist_2_combo, combo_wd);


	if (check_working_dir())
		load_file_list();
	else
		clear_file_list();
}
Пример #3
0
void cb_wd_changed(GObject *obj, gpointer user_data)
{
	GList *iter;
	const char *new_text = gtk_entry_get_text(ent_wd);

	/* 
	   Problem: GtkCombo doesn't have a signal to indicate the user has
	   selected something, and the underlying GtkList's "selection-changed" 
	   signal is useless as usual (it fires way too many times for no 
	   apparent reason)
	   Solution: Compare the entry text with our MRU list. If there is a 
	   match, that's /probably/ because the user selected something from 
	   the dropdown.
	*/
	for (iter = GLIST(dir_mru->list); iter; iter = g_list_next(iter)) {
		if (strcmp(iter->data, new_text) == 0) {
			fl_set_working_dir_utf8(new_text);
			break;
		}
	}
}
Пример #4
0
void dispatch_request(Router *r, Message *m)
{
    Registrar *reg;
    InputInterface *iface;
    MessagePattern *mp;
    GLIST(InputInterface) *tool_list;
    GLIST_ITERATOR(InputInterface) iface_itr;
    int request_processed=0;
    
    reg=r->registrar_ptr;
    pthread_mutex_lock(&r->bindings_mutex);
    
    tool_list=&(r->comm_bindings[m->senderid].pattern_bindings[m->pattern_id]);
    iface_itr=Glist_itr_begin(tool_list);
    
    while (iface_itr)
    {
        iface=Glist_itr_at(iface_itr);
        mp=&(reg->active_tools[iface->toolid].input_pattern[iface->pattern_id]);
        request_processed=(*mp->req_fptr)(m,mp->pattern)? 0 /*ERROR*/ : 1 /*SUCCESS*/;
        /* Only first successful reply is enough. */
        if(request_processed)
            break;
        iface_itr=Glist_itr_next(iface_itr);
    }
    pthread_mutex_unlock(&r->bindings_mutex);
    if (! request_processed)
    {
        /* request was not processed successfully, therefore, there won't
        be corresponding reply. Send pre-defined REQUEST_FAILURE_NO_REPLY 
        to sender of the reqeust.*/
        request_failure_reply(m->senderid, m->reqrepid);
    }
    else
    {
        /* A proper reply shall be sent therefore, keep the entry
        in the request_tool_list to be deleted later upon arrival of
        corresponding reply. */
    }
}
Пример #5
0
void dispatch_reply (Router *r, Message *m)
{
    RequestTool rt = { { 0 } }, *rtptr=0;
    Registrar *reg = 0;
    InputInterface *iface=0;
    MessagePattern *mp=0;
    GLIST(InputInterface) *tool_list=0;
    GLIST_ITERATOR(InputInterface) iface_itr=0;
    
    reg=r->registrar_ptr;
    pthread_mutex_lock(&r->bindings_mutex);
    
    rt.reqrepid=m->reqrepid;
    rtptr=Glist_search(&r->request_tool_list,&rt,(void *)compare_reqrepid_func);
    if (!rtptr)
    {
        fprintf(stderr,"message_router.c: dispatch: A REPLY for no corresopnding REQUEST\n");
        /* TODO take proper error handling steps */
    }
    else
    {
        tool_list=&(r->comm_bindings[m->senderid].pattern_bindings[m->pattern_id]);
        iface_itr=Glist_itr_begin(tool_list);
        
        while (iface_itr)
        {
            iface=Glist_itr_at(iface_itr);
            if (rtptr->toolid == iface->toolid)
            {
                mp=&(reg->active_tools[iface->toolid].input_pattern[iface->pattern_id]);
                (*mp->rep_fptr)(m, mp->pattern);
                Glist_eraseptr(&r->request_tool_list,rtptr,(void *)del_request_tool_func);
                iface_itr=0;
            }
            iface_itr=Glist_itr_next(iface_itr);
        }
    }
    pthread_mutex_unlock(&r->bindings_mutex);
}
Пример #6
0
void dispatch_notification (Router *r, Message *m)
{
    Registrar *reg=0;
    InputInterface *iface=0;
    MessagePattern *mp=0;
    GLIST(InputInterface) *tool_list=0;
    GLIST_ITERATOR(InputInterface) iface_itr=0;

    reg=r->registrar_ptr;
    pthread_mutex_lock(&r->bindings_mutex);
    
    tool_list=&(r->comm_bindings[m->senderid].pattern_bindings[m->pattern_id]);
    iface_itr=Glist_itr_begin(tool_list);
    while (iface_itr)
    {
        iface=Glist_itr_at(iface_itr);
        mp=&(reg->active_tools[iface->toolid].input_pattern[iface->pattern_id]);
        (*mp->not_fptr)(m, mp->pattern);
        iface_itr=Glist_itr_next(iface_itr);
    }
    pthread_mutex_unlock(&r->bindings_mutex);
}
Пример #7
0
int send_message(Router *router, Message *m)
{
    int ret=0;
    assert(router && m);

    if(REQUEST == m->type)
    {
        GLIST(InputInterface) * iface_list;
        pthread_mutex_lock(&router->bindings_mutex);    
        iface_list=&(router->comm_bindings[m->senderid].pattern_bindings[m->pattern_id]);
        if (Glist_empty(iface_list))
        {
            /* There is no tool to honor this request so I do not accept this reqeust */
            ret=1; /* ERROR */
        }
        else
        {
            RequestTool rt;
            rt.toolid=m->senderid;
            rt.reqrepid=m->reqrepid;
            Glist_add(&router->request_tool_list, &rt, sizeof(RequestTool),
                      (void *)requesttool_copyfunc);
            ret=0;
        }        
        pthread_mutex_unlock(&router->bindings_mutex);
    }
    
    if(0 == ret)
    {    
        if (SYNC_MODE == m->mode)
            ret=send_sync_message(router, m);
        else
            ret=mqueue_add(&router->mqueue, m)? 0 /* SUCCESS */ : 1 /* ERROR */;
    }
    return ret;
}