added nlsop_gui.c (not finished yet) + fixes to server and client code
[physik/nlsop.git] / nlsop_gui.c
diff --git a/nlsop_gui.c b/nlsop_gui.c
new file mode 100644 (file)
index 0000000..7949c55
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#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 <ip> -p <port> -l <logfile>\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;i<argc;i++) {
+    if(argv[i][0]=='-') {
+      switch(argv[i][1]) {
+        case 'h':
+          usage(argv[0]);
+          return -1;
+        case 'i':
+          strncpy(server_ip,argv[++i],16);
+          break;
+        case 'p':
+          port=atoi(argv[++i]);
+          break;
+        case 'l':
+          strncpy(logfile,argv[++i],64);
+          break;
+        default:
+          usage(argv[0]);
+          return -1;
+      }
+    }
+  }
+  if(!strcmp(server_ip,"")) {
+    usage(argv[0]);
+    return -1;
+  }
+
+  if((fd=open(logfile,O_WRONLY,O_CREAT))<0) {
+    printf("unable to open file %s\n",logfile);
+    return -1;
+  }
+
+  allyouneed=malloc(sizeof(t_net)+sizeof(t_display)+sizeof(t_input));
+  memcpy(allyouneed,&net,sizeof(t_net));
+  memcpy(allyouneed+sizeof(t_net),&display,sizeof(t_display));
+  memcpy(allyouneed+sizeof(t_net)+sizeof(t_display),sizeof(t_input));
+
+  /* input init */
+  input_init(&input,fd);
+  input.mode=CONTENT_BUFFER|LINE_BUFFERED|INPUT_ECHO;
+  input_ios_init(&input);
+
+  /* event init */
+  event_init(&event,fd);
+  event_set_timeout(&event,0,0);
+
+  /* display init */
+  display_init(&display,fd);
+
+  /* user interaction */
+  event_math(0,&event,READ,ADD);
+
+  /* connect to server */
+  network_init(&net,fd);
+  network_set_connection_info(&net,0,server_ip,port);
+  if(network_connect(&net,0)==N_E_CONNECT) {
+    printf("unable to connect to server, aborting ...\n");
+    return -1;
+  }
+  network_select(&net,0);
+
+  /* tell server: i am a client, i may work for you */
+  data=NLSOP_GUI;
+  network_send(net.connection[0].fd,&data,1);
+
+  /* wait for job */
+  event_start(&event,allyouneed,get_command,NULL);
+
+  free(allyouneed);
+  close(fd);
+
+  return 1;
+}