Major clean-ups. Migrating to C++11.
[invirt/third/libt4.git] / lock_smain.cc
1 #include "rpc/rpc.h"
2 #include <arpa/inet.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include "lock_server_cache_rsm.h"
7 #include "paxos.h"
8 #include "rsm.h"
9
10 // Main loop of lock_server
11
12 char tprintf_thread_prefix = 's';
13
14 int
15 main(int argc, char *argv[])
16 {
17     int count = 0;
18
19     setvbuf(stdout, NULL, _IONBF, 0);
20     setvbuf(stderr, NULL, _IONBF, 0);
21
22     srandom(getpid());
23
24     if(argc != 3){
25         fprintf(stderr, "Usage: %s [master:]port [me:]port\n", argv[0]);
26         exit(1);
27     }
28
29     char *count_env = getenv("RPC_COUNT");
30     if(count_env != NULL){
31         count = atoi(count_env);
32     }
33
34     rsm rsm(argv[1], argv[2]);
35     lock_server_cache_rsm ls(&rsm);
36     rsm.set_state_transfer((rsm_state_transfer *)&ls);
37     rsm.reg(lock_protocol::acquire, &ls, &lock_server_cache_rsm::acquire);
38     rsm.reg(lock_protocol::release, &ls, &lock_server_cache_rsm::release);
39     rsm.reg(lock_protocol::stat, &ls, &lock_server_cache_rsm::stat);
40
41     while(1)
42         sleep(1000);
43 }