Component index
Section index

Component uithread


Search

	/*
	    The following example grab the information produced by a process and
	    fill a table (editrecord). One uithread is used to collect the data
	    and a PRIVATE_MESSAGE is used to signal the editrecord thread.
	
	    This sample also show how one thread may ask another to end using
	    PRIVATE_MESSAGE.
	*/
	
	<mod>
	static void sample_uithread_popen()
	{
	    glocal SSTRINGS data;
	    glocal PRIVATE_MESSAGE samples,ending;
	    dialog_clear();
	
	    <call uithread>();
	    <f thread1>
	        <call walkpopen>("/tmp/x output 100",1,true);
	        <f wait>
	            /*
	                We are using diagui_sync() to make sure the other dialog
	                are still alive.
	            */
	            int ret = diagui_sync (pop,timeout,true);
	            if (dialog_testmessage(glocal.ending)){
	                end = true;
	                pop.kill();
	            }
	            return ret;
	        </f>
	        <f oneline>
	            glocal.data.add (new SSTRING(line));
	            dialog_sendmessage (glocal.samples);
	        </f>
	        </call>
	    </f>
	    <f thread2>
	        <call editrecords>("Some records","",help_nil);
	        <f head>
	            waitfor (glocal.samples);
	            newf_head ("column1\tcolumn2\tcolumn3");
	            setvsize (10);
	        </f>
	        <f load>
	            for (int i=0; i<glocal.data.getnb(); i++){
	                const char *s = glocal.data.getitem(i)->get();
	                char tmp[strlen(s)+1];
	                strcpy (tmp,s);
	                char *pt = tmp;
	                while (*pt != '\0'){
	                    if (*pt == ' ') *pt = '\t';
	                    pt++;
	                }
	                SSTRING word;
	                pt = str_copyword (word,tmp);
	                new_menuitem (word.get(),pt);
	            }
	        </f>
	        <f editone>
	            printf ("Line %d was selected\n",no);
	        </f>
	        </call>
	        dialog_sendmessage (glocal.ending);
	    </f>
	    </call>
	}
	</mod>