TEMPLATE MAGIC FOR GREAT JUSTICE
[invirt/third/libt4.git] / lock_server.cc
index be0c1c9..0f82080 100644 (file)
@@ -1,46 +1,37 @@
-// the lock server implementation
-
-#include "lock_server.h"
-#include <sstream>
+#include "rpc/rpc.h"
+#include <arpa/inet.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
-#include <arpa/inet.h>
-#include "lock.h"
+#include "lock_server_cache_rsm.h"
+#include "paxos.h"
+#include "rsm.h"
 
-lock_server::lock_server():
-    nacquire (0)
-{
-}
+// Main loop of lock_server
 
-// caller must hold lock_lock
-mutex &
-lock_server::get_lock(lock_protocol::lockid_t lid) {
-    lock ml(lock_lock);
-    // by the semantics of std::map, this will create
-    // the mutex if it doesn't already exist
-    mutex &l = locks[lid];
-    return l;
-}
+char tprintf_thread_prefix = 's';
 
-lock_protocol::status
-lock_server::stat(int clt, lock_protocol::lockid_t lid, int &r)
+int
+main(int argc, char *argv[])
 {
-    lock_protocol::status ret = lock_protocol::OK;
-    printf("stat request from clt %d\n", clt);
-    r = nacquire;
-    return ret;
-}
+    setvbuf(stdout, NULL, _IONBF, 0);
+    setvbuf(stderr, NULL, _IONBF, 0);
 
-lock_protocol::status
-lock_server::acquire(int clt, lock_protocol::lockid_t lid, int &r)
-{
-    get_lock(lid).lock();
-    return lock_protocol::OK;
-}
+    srandom(getpid());
 
-lock_protocol::status
-lock_server::release(int clt, lock_protocol::lockid_t lid, int &r)
-{
-    get_lock(lid).unlock();
-    return lock_protocol::OK;
+    if(argc != 3){
+        fprintf(stderr, "Usage: %s [master:]port [me:]port\n", argv[0]);
+        exit(1);
+    }
+
+    rsm rsm(argv[1], argv[2]);
+    lock_server_cache_rsm ls(&rsm);
+    rsm.set_state_transfer(&ls);
+
+    rsm.reg(lock_protocol::acquire, &lock_server_cache_rsm::acquire, &ls);
+    rsm.reg(lock_protocol::release, &lock_server_cache_rsm::release, &ls);
+    rsm.reg(lock_protocol::stat, &lock_server_cache_rsm::stat, &ls);
+
+    while(1)
+        sleep(1000);
 }