source: tags/initial/PROBE/PT_main.cxx

Last change on this file was 2, checked in by oldcode, 24 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <string.h>
5#include <sys/stat.h>
6#include <PT_server.h>
7#include <PT_server_prototypes.h>
8#include "probe.h"
9#include "pt_prototypes.h"
10#include <arbdbt.h>
11#include <servercntrl.h>
12#include <server.h>
13#include <client.h>
14#include <struct_man.h>
15#define MAX_TRY 10
16#define TIME_OUT 1000*60*60*24
17
18struct probe_struct_global psg;
19char *pt_error_buffer = new char[1024];
20ulong physical_memory = 0;
21       
22/*****************************************************************************
23                Communication
24*******************************************************************************/ 
25char *pt_init_main_struct(PT_main *main, char *filename)
26{
27    main = main;
28    probe_read_data_base(filename);
29    GB_begin_transaction(psg.gb_main);
30    psg.alignment_name = GBT_get_default_alignment(psg.gb_main);
31    GB_commit_transaction(psg.gb_main);
32    probe_read_alignments();
33    PT_build_species_hash();
34    return 0;
35}
36PT_main *aisc_main;     /* muss so heissen */
37
38extern "C" int server_shutdown(PT_main *pm,aisc_string passwd){
39    /** passwdcheck **/
40    pm = pm;
41    if( strcmp(passwd, "47@#34543df43%&3667gh") ) return 1;
42    printf("\nI got the shutdown message.\n");
43    /** shoot clients **/
44    aisc_broadcast(psg.com_so, 0,
45                   "SERVER UPDATE BY ADMINISTRATOR!\nYou'll get the latest version. Your screen information will be lost, sorry!");
46    /** shutdown **/
47    aisc_server_shutdown(psg.com_so);
48    exit(0);
49    return 0;
50}
51extern "C" int broadcast(PT_main *main, int dummy )
52{
53    aisc_broadcast(psg.com_so, main->m_type, main->m_text);
54    dummy = dummy;
55    return 0;
56}
57
58void PT_init_psg(){
59    memset((char *)&psg,0,sizeof(psg));
60    int i;
61    for (i=0;i<256;i++){
62        psg.complement[i] = PT_complement(i);
63    }
64}
65
66extern int aisc_core_on_error;
67
68int main(int argc, char **argv)
69{
70    int i;
71    struct Hs_struct *so;
72    char *name;
73    char *error;
74    char *aname,*tname;
75    const char *suffix;
76    struct stat s_source,s_dest;
77    int build_flag;
78    struct arb_params *params;
79    char        *command_flag;
80    params = arb_trace_argv(&argc,argv);
81    PT_init_psg();
82    GB_install_pid(0);          /* not arb_clean able */
83    aisc_core_on_error = 0;
84    physical_memory = GB_get_physical_memory();
85    /***** try to open com with any other pb server ******/
86    if ((argc>2) || ((argc<2)&&!params->db_server)) {
87        printf("Syntax: %s [-look/-build/-kill/-QUERY] -Dfile.arb -TSocketid\n",argv[0]);
88        exit (-1);
89    }
90    if (argc==2) {
91        command_flag = argv[1];
92    }
93    else {
94        static char flag[] = "-boot";
95        command_flag = flag;
96    }
97    if (!(name = params->tcp)) {
98        if( !(name=(char *)GBS_read_arb_tcp("ARB_PT_SERVER")) ){
99            GB_print_error();
100            exit(-1);
101        }
102    }
103    aisc_main = create_PT_main();
104    aname = params->db_server;
105    suffix = ".pt";
106    tname = (char *)calloc(sizeof(char),strlen(aname)+strlen(suffix)+1);
107    sprintf(tname,"%s%s",aname,suffix);
108    if (!strcmp(command_flag, "-build")) {      /* build command */
109        if (( error = pt_init_main_struct(aisc_main, params->db_server) ))
110        {
111            printf("PT_SERVER: Gave up:\nERROR: %s\n", error);
112            exit(0);
113        }
114        enter_stage_1_build_tree(aisc_main,tname);
115        exit(0);
116    }
117    if (!strcmp(command_flag, "-QUERY")) {
118        if (( error = pt_init_main_struct(aisc_main, params->db_server) ))
119        {
120            printf("PT_SERVER: Gave up:\nERROR: %s\n", error);
121            exit(0);
122        }
123        enter_stage_3_load_tree(aisc_main,tname);                       /* now stage 3 */
124        PT_debug_tree();
125        exit(0);
126    }
127    psg.link = (aisc_com *) aisc_open(name, &psg.main, AISC_MAGIC_NUMBER);
128    if (psg.link) {
129        if (!strcmp(command_flag, "-look"))
130            exit(0);    /* already another serther */
131        printf("There is another activ server. I try to kill him...\n");
132        aisc_nput(psg.link, PT_MAIN, psg.main,
133                  MAIN_SHUTDOWN, "47@#34543df43%&3667gh",
134                  NULL);
135        aisc_close(psg.link); psg.link = 0;
136    }
137    if (!strcmp(command_flag, "-kill")) {
138        exit(0);
139    }
140    printf("\n TUM POS_TREE SERVER (Oliver Strunk) V 1.0 (C) 1993 \ninitializing:\n");
141    printf("open connection...\n");
142    sleep(1);
143    for (i = 0, so = 0; (i < MAX_TRY) && (!so); i++) {
144        so = open_aisc_server(name, TIME_OUT,0);
145        if (!so)
146            sleep(10);
147    }
148    if (!so) {
149        printf("PT_SERVER: Gave up on opening the communication socket!\n");
150        exit(0);
151    }
152    psg.com_so = so;
153    /**** init server main struct ****/
154    printf("Init internal structs...\n");
155    /****** all ok: main'loop' ********/
156    if (stat(aname,&s_source)) {
157        aisc_server_shutdown(so);
158        printf("PT_SERVER error while stat source %s\n",aname);
159        exit(-1);
160    }
161    build_flag = 0;
162    if (stat(tname,&s_dest)) {
163        build_flag = 1;
164    }else{
165        if ( (s_source.st_mtime>s_dest.st_mtime) || (s_dest.st_size == 0)) {
166            printf("PT_SERVER: Source %s has been modified more recently than %s\n",aname,tname);
167            build_flag = 1;
168        }
169    }
170    if (build_flag) {
171        char buf[256];
172        sprintf(buf,"%s -build -D%s",argv[0],params->db_server);
173        system(buf);
174    }
175
176    if (( error = pt_init_main_struct(aisc_main, params->db_server) ))
177    {
178        aisc_server_shutdown(so);
179        printf("PT_SERVER: Gave up:\nERROR: %s\n", error);
180        exit(0);
181    }
182    enter_stage_3_load_tree(aisc_main,tname);
183    printf("ok, server is running.\n");
184    aisc_accept_calls(so);
185    aisc_server_shutdown(so);
186       
187    return 0;           // never reached
188}
Note: See TracBrowser for help on using the repository browser.