From: hackbard Date: Wed, 3 Nov 2004 18:09:39 +0000 (+0000) Subject: added nlsop_gui.c (not finished yet) + fixes to server and client code X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fnlsop.git;a=commitdiff_plain;h=b49c96b3def8a0907e366eac36be249f08e49799 added nlsop_gui.c (not finished yet) + fixes to server and client code --- diff --git a/nlsop_client.c b/nlsop_client.c index c314299..6467827 100644 --- a/nlsop_client.c +++ b/nlsop_client.c @@ -49,6 +49,8 @@ #include "network.h" #include "event.h" +#include "nlsop_general.h" + #define MAKE_AMORPH(N) *(N)|=AMORPH #define MAKE_CRYST(N) *(N)&=~AMORPH @@ -417,9 +419,6 @@ int get_data_and_calc(t_event *event,void *allineed) { int i,j; int resave; int c_step; -#define DC_QUIT (1<<0) -#define DC_OK (1<<1) -#define DC_END (1<<2) unsigned char data[256]; t_net *net; diff --git a/nlsop_gui.c b/nlsop_gui.c new file mode 100644 index 0000000..7949c55 --- /dev/null +++ b/nlsop_gui.c @@ -0,0 +1,216 @@ +/* + * nlsop gui code + * + * author: frank zirkelbach (frank.zirkelbach@physik.uni-augsburg.de) + * + * this program tries helping to understand the amorphous depuration + * and recrystallization of SiCx while ion implantation at temperatures + * below 400 degree celsius. + * hopefully the program will simulate the stabilization of the + * selforganizing lamella structure in the observed behaviour. + * + * refs: + * - J. K. N. Lindner. Habil.Schrift, Universitaet Augsburg. + * - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg. + * + * Copyright (C) 2004 Frank Zirkelbach + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "nlsop.h" +#include "dfbapi.h" +#include "random.h" + +#include "network.h" +#include "event.h" +#include "display.h" + +#include "nlsop_general.h" + +#define LOGFILE "~/.nlsop_logfile" + +int usage(char *prog) +{ + puts("usage:"); + printf("%s -i -p -l \n",prog); + return 1; +} + +/* + * gui internal functions + */ + +int display_new_line(t_display *display,char *text) { + + return 1; +} + +int send_and_wait_for_answer(t_net *net,t_display *display) { + + return 1; +} + +int send_job(t_net *net,t_input *input,t_display *display) { + + return 1; +} + +int get_command(t_event *event,void *allineed) { + + t_net *net; + t_display *display; + t_input *input; + + unsigned char data[64]; + + net=(t_net *)allineed; + display=(t_display *)(allineed+sizeof(t_net)); + input=(t_input *)(allineed+sizeof(t_net)+sizeof(t_display)); + + switch(input->content[0]) { + case GUI_INFO: + send_and_wait_for_answer(net,display); + break; + case GUI_ADDJOB: + send_job(net,input,display) + break; + case GUI_QUIT: + /* stop everything */ + event_math(0,event,READ,REMOVE); + network_shutdown(net); + display_shutdown(display); + input_shutdown(input); + event_shutdown(event); + return 2; + default: + display_new_line(display,"unknown gui command"); + break; + } + + return 1; +} + +/* + * main program + */ + +int main(int argc,char **argv) +{ + + char server_ip[16]; + char logfile[64]; + int port; + + t_net net; + t_event event; + t_display display; + t_input input; + + unsigned char data; + int i; + + int fd; + + void *allyouneed; + + /* default values */ + strcpy(logfile,LOGFILE); + strcpy(server_ip,""); + port=1025; + + /* parse/check argv */ + for(i=1;iac,job->size*sizeof(unsigned char)); if(ret==N_ERROR) printf("FATAL: getting ac status failed\n"); - ret=network_receice_chan(net,channel,job->cc,job->size*sizeof(int)); + ret=network_receive_chan(net,channel,(unsigned char *)job->cc, + job->size*sizeof(int)); if(ret==N_ERROR) printf("FATAL: getting cc failed\n"); - ret=network_receive_chan(net,channel,&(job->step),sizeof(int)); + ret=network_receive_chan(net,channel,(unsigned char *)&(job->step), + sizeof(int)); if(ret==N_ERROR) printf("FATAL: getting step number failed\n"); if(dc!=DC_QUIT) { - snprintf(filename,"nlsop_b%f_c%f_s%f_ds%d_dr%f_Z%c__%d_of_%d.save", - job->info->b,job->info->c,job->info->s, - job->info->diff_rate,job->info->dr_ac, - job->info->z_diff?'y':'n', - job->step,job->info->steps); + snprintf(filename,128,"nlsop_b%f_c%f_s%f_ds%d_dr%f_Z%c__%d_of_%d.save", + job->info.b,job->info.c,job->info.s, + job->info.diff_rate,job->info.dr_ac, + job->info.z_diff?'y':'n', + job->step,job->info.steps); if((fd=open(filename,O_WRONLY|O_CREAT))<0) { printf("FATAL: unable to open file %s\n",filename); return -1; } + memset(&d3l,0,sizeof(d3_lattice)); + d3l.max_x=job->x; + d3l.max_y=job->y; + d3l.max_z=job->z; + if(write(fd,&d3l,sizeof(d3_lattice))info),sizeof(info))ac,job->size*sizeof(unsigned char)); + if(retsize*sizeof(unsigned char)) { + printf("FATAL: write of a/c states failed\n"); + return -1; + } + + ret=write(fd,job->cc,job->size*sizeof(int)); + if(retsize*sizeof(int)) { + printf("FATAL: write of c.-conc. failed\n"); + return -1; + } + close(fd); } return 1; } -int handle_node(net,event,c_list,g_list,job) { +int add_job(t_net *net,int chan,t_list *jl) { + + t_job job; + + job.channel=-1; + job.status=IN_QUEUE; + job.progress=0; + + network_receive_chan(net,chan,(unsigned char *)&(job.x),sizeof(int)); + network_receive_chan(net,chan,(unsigned char *)&(job.y),sizeof(int)); + network_receive_chan(net,chan,(unsigned char *)&(job.z),sizeof(int)); + network_receive_chan(net,chan,(unsigned char *)&(job.info),sizeof(info)); + + job.size=job.x*job.y*job.z; + + job.ac=(unsigned char *)malloc(job.size*sizeof(unsigned char)); + if(job.ac==NULL) { + printf("unable to malloc a/c memory\n"); + return -1; + } + + job.cc=(int *)malloc(job.size*sizeof(int)); + if(job.cc==NULL) { + printf("unable to malloc cc memory\n"); + return -1; + } + + job.step=0; + + list_add_element(jl,&job,sizeof(t_job)); + + return 1; +} + +int send_status(t_net *net,int chan,t_list *jl) { + + unsigned char data; + int count; + int i; + + data=GUI_INFO; + count=list_count(jl); + + network_send_chan(net,chan,&data,sizeof(unsigned char)); + network_send_chan(net,chan,(unsigned char *)&count,sizeof(int)); + + list_reset(jl); + for(i=0;icurrent->data,sizeof(t_job)); + list_next(jl); + } + + return 1; +} + +int handle_node(t_net *net,t_event *event, + t_list *c_list,t_list *g_list,t_list *job) { int i; unsigned char data; @@ -186,7 +248,6 @@ int handle_node(net,event,c_list,g_list,job) { if(data==DC_END) { save_job(net,i,j,DC_END); /* reset client */ - c->channel=i; c->status=IDLE; /* delete job entry */ list_del_current(job); @@ -212,7 +273,21 @@ int handle_node(net,event,c_list,g_list,job) { else if(list_search_data(g_list,&i,sizeof(int))==L_SUCCESS) { /* its a gui */ - + if(data==GUI_ADDJOB) add_job(net,i,job); + + else if(data==GUI_INFO) send_status(net,i,job); + + else if(data==GUI_QUIT) { + printf("disconnecting gui on channel %d\n",i); + event_math(net->connection[i].fd,event,READ,REMOVE); + network_close(net,i); + list_del_current(g_list); + } + + else { + printf("unknown gui command\n"); + return -1; + } } else { @@ -226,6 +301,69 @@ int handle_node(net,event,c_list,g_list,job) { return 1; } +int distribute_jobs(t_event *event,void *allineed) { + + t_net *net; + t_list *c_list,*g_list,*job; + int count_j,count_c; + t_job *j; + t_client *c; + unsigned char data; + d3_lattice d3l; + + net=(t_net *)allineed; + c_list=(t_list *)(allineed+sizeof(t_net)); + g_list=(t_list *)(allineed+sizeof(t_net)+sizeof(t_list)); + job=(t_list *)(allineed+sizeof(t_net)+2*sizeof(t_list)); + + count_j=list_count(job); + count_c=list_count(c_list); + + list_reset(job); + list_reset(c_list); + while((count_c!=0)&&(count_j!=0)) { + j=(t_job *)job->current->data; + c=(t_client *)c_list->current->data; + while(c->status!=IDLE) { + list_next(c_list); + c=(t_client *)c_list->current->data; + } + while(j->status!=IN_QUEUE) { + list_next(job); + j=(t_job *)job->current->data; + } + + /* direct current job to current client */ + if(j->step==0) data=NLSOP_NJOB; + else data=NLSOP_CJOB; + + c->status=WORK; + j->channel=c->channel; + j->status=IN_WORK; + + d3l.max_x=j->x; + d3l.max_y=j->y; + d3l.max_z=j->z; + + network_send_chan(net,c->channel,&data,sizeof(unsigned char)); + network_send_chan(net,c->channel,(unsigned char *)&d3l,sizeof(d3_lattice)); + network_send_chan(net,c->channel,(unsigned char *)&(j->info),sizeof(info)); + + if(data==NLSOP_CJOB) { + network_send_chan(net,c->channel,j->ac,j->size*sizeof(unsigned char)); + network_send_chan(net,c->channel,(unsigned char *)&(j->cc), + j->size*sizeof(int)); + } + + --count_c; + --count_j; + list_next(c_list); + list_next(job); + } + + return 1; +} + int parse_incoming(t_event *event,void *allineed) { t_net *net; @@ -237,7 +375,7 @@ int parse_incoming(t_event *event,void *allineed) { job=(t_list *)(allineed+sizeof(t_net)+2*sizeof(t_list)); /* decide what to do */ - if(FD_ISSET(net->l.fd,&(event->rfds))) { + if(FD_ISSET(net->l_fd,&(event->rfds))) { /* new node */ printf("new node ...\n"); add_node(net,event,c_list,g_list); @@ -269,9 +407,9 @@ int main(int argc,char **argv) /* tzzz ... */ allyouneed=malloc(sizeof(t_net)+3*sizeof(t_list)); memcpy(allyouneed,&net,sizeof(t_net)); - memcpy(allyouneed+sizeof(t_net),&c_list,sizeof(list)); - memcpy(allyouneed+sizeof(t_net)+sizeof(t_list),&g_list,sizeof(list)); - memcpy(allyouneed+sizeof(t_net)+2*sizeof(t_list),&job,sizeof(list)); + memcpy(allyouneed+sizeof(t_net),&c_list,sizeof(t_list)); + memcpy(allyouneed+sizeof(t_net)+sizeof(t_list),&g_list,sizeof(t_list)); + memcpy(allyouneed+sizeof(t_net)+2*sizeof(t_list),&job,sizeof(t_list)); /* default values */ port=1025; @@ -281,7 +419,8 @@ int main(int argc,char **argv) /* event init */ event_init(&event,1); - event_set_timeout(&event,0,0); + /* 10 sec event timeout - distributing jobs */ + event_set_timeout(&event,10,0); /* connect to server */ network_init(&net,1); @@ -293,7 +432,7 @@ int main(int argc,char **argv) /* wait for events :) */ event_math(net.l_fd,&event,READ,ADD); - event_start(&event,allyouneed,parse_incoming,NULL); + event_start(&event,allyouneed,parse_incoming,distribute_jobs); return 1; }