#ifndef lock_server_h
#define lock_server_h

#include "list.h"
#include "ihash.h"

struct lock_request 
{
  str lockname;
  struct sockaddr_in sin;
  tailq_entry<lock_request> llink;
};


struct lock_status 
{
  ihash_entry<lock_status> hlink;
  str lockname;
  lock_request *active_request;
  tailq<lock_request, &lock_request::llink> queue;
};


class LS {
public:
  LS();
  void attach(ptr<axprt> sx);

private:
  ptr<asrv> sxx;
  ptr<aclnt> c;
  ihash<const str, lock_status, &lock_status::lockname,
        &lock_status::hlink> locks;
    
  static void dispatch(LS *, svccb *);
  void acquire(svccb *sbp);
  void release(svccb *sbp);
  void grant_done(str name, bool *r, struct sockaddr_in *, clnt_stat err);
  void grant_lock(lock_status *lock, lock_request *req);
  void send_grant(str name, struct sockaddr_in sin);
  str hex(str s);
};

#endif
