source: tags/arb_5.1/DBSERVER/db_server.cxx

Last change on this file was 5390, checked in by westram, 16 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1#define TIMEOUT 1000*60*2
2/* every 2 minutes save */
3#define LOOPS 30
4/* wait 1 hour till kill myself */
5
6#include <stdio.h>
7#include <string.h>
8#include <arbdb.h>
9#include <servercntrl.h>
10
11int main(int argc,char **argv)
12{
13    struct arb_params *params;
14    GBDATA            *gb_extern;
15    GBDATA            *gb_main;
16    GB_ERROR           error;
17    int                timer;
18    int                last_update = 0;
19    int                clock;
20
21    if (argc <=1 || strcmp(argv[1], "--help") == 0) {
22        printf("Syntax of the arb_db_server:\n");
23        printf("        arb_db_server [-D]database [-Tsocketid]\n");
24        return -1;
25    }
26
27    params = arb_trace_argv(&argc,argv);
28    if (!params->tcp) {
29        static char arg[] = ":";
30        params->tcp = arg;
31    }
32
33    if (argc==2){
34        params->db_server = (char *)strdup(argv[1]);
35        argc--;
36    }
37
38    //
39
40    gb_extern = GB_open(params->tcp,"rwc");
41    if (gb_extern) {
42        GB_close(gb_extern);
43        return -1;
44    }
45    printf("Loading '%s'...\n", params->db_server);
46    gb_main = GB_open(params->db_server,"rw");
47    if (!gb_main) {
48        printf("Error: File %s not found\n",params->db_server);
49        return -1;
50    }
51    error = GBCMS_open(params->tcp, TIMEOUT,gb_main);
52    if (error) {
53        printf("Cannot start your arb_db_server: %s\n",error);
54        return (-1);
55    }
56
57    printf("Database is saved after every transaction (one . one save)\n");
58
59    for (timer = LOOPS;timer>0;timer--) { /* the server ends */
60        GB_begin_transaction(gb_main);
61        clock = GB_read_clock(gb_main);
62        if (GB_read_clients(gb_main) >0) {
63            timer = LOOPS;
64        }
65        GB_commit_transaction(gb_main);
66        if (clock>last_update) {
67            last_update = clock;
68            printf("."); fflush(stdout);
69            GB_save(gb_main,0,"b");
70            timer = LOOPS;
71        }
72        GBCMS_accept_calls(gb_main,GB_FALSE);
73    }
74    return(0);
75}
76
77extern "C" {
78    int aisc_open(void) { return 0; }
79    int aisc_close(void) { return 0;}
80}
Note: See TracBrowser for help on using the repository browser.