Re: gthreads and file operations



the sample code is:

#include "myheader.h"

int main(int argc, char ** argv)
{
    GThread *l_th1, *l_th2;
    g_thread_init(NULL);
    gdk_threads_init();
    gtk_init(&argc,&argv);
    initCommandParser();
    initCurrentManager();
    initWindowManager();
    l_th1 = g_thread_create(_gtkthread,NULL,TRUE,NULL);
    l_th2 = g_thread_create(gnomeProxy,NULL,TRUE,NULL);
    g_thread_join(l_th1);
    g_thread_join(l_th2);
    return 0;
}

void * _gtkthread(gpointer a_data)
{
    gdk_threads_enter();
    g_signal_connect(G_OBJECT(curScreen), "window-opened",
G_CALLBACK(windowOpenedHandler), NULL);
    g_signal_connect(G_OBJECT(curScreen), "window-stacking-changed",
G_CALLBACK(windowStackingChangedHandler), NULL);
    g_signal_connect(G_OBJECT(curScreen), "active-window-changed",
G_CALLBACK(activeWindowChangedHandler), NULL);
    gtk_main();
    gdk_threads_leave();
    return NULL;
}

void * gnomeProxy(gpointer data){
    ....
gdk_threads_enter();
// couple of nested function calls and then i call prepareGrammar() in one
of those calls
prepareGrammar();
gdk_threads_leave();
    ....
}

void prepareGrammar()
{
    FILE *fp;
    if(grammar==FALSE)
    {
        fp = fopen("grammar1.gram", "w");
        grammar=TRUE;
    }
    else {
        fp = fopen("grammar2.gram", "w");
        grammar=FALSE;
    }
    fprintf(fp,"(");
    writeGrammer(getCurrentAccessibleFrame(SPI_getDesktop(0)), fp);
    fseek(fp, -1, 2);
    fprintf(fp, ")");
    fclose(fp);
}

void writeGrammer(Accessible * application, FILE * fp)
{
    glong c, i;
    AccessibleStateSet * state;
    if(application!=NULL)
    {
        if(Accessible_getName(application)!=NULL)
        {
            state=Accessible_getStateSet(application);
            if(state!=NULL)
                if(AccessibleStateSet_contains(state, SPI_STATE_SHOWING))
                {
                    if(Accessible_isAction(application))
                    {
                        if(g_strcmp0(Accessible_getName(application),
"")!=0)
                            g_fprintf(fp, "%s |",
Accessible_getName(application));
                    }
                }
        }
        state=Accessible_getStateSet(application);
        if(state!=NULL)
            if(AccessibleStateSet_contains(state, SPI_STATE_SHOWING))
            {
                c=Accessible_getChildCount(application);
                for(i=0; i<c; i++)
                {
                    writeGrammer(Accessible_getChildAtIndex(application, i),
fp);
                }
            }
    }
}


On Tue, Apr 13, 2010 at 1:06 AM, Thomas Stover <thomas wsinnovations com>wrote:

On Tue, 13 Apr 2010 01:01:15 +0530, Nischal Rao <rao nischal gmail com>
wrote:

Is the
threads part of the code I had sent earlier correct?

I haven't seen the code yet. It could be me, but the mailing list software
probably scrubs attachments. Most folks just post as inline text.

--
www.thomasstover.com




-- 
regards,
Nischal E Rao
blogs.sun.com/nischal

Join RVCE OSUM at http://osum.sun.com/group/rvceosum



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]