#include <stdio.h>
#include <rpc/rpc.h>
#include <unistd.h>
#include <sys/param.h>
#include "../commonIncludes/defn.h"
#include "../commonIncludes/Coordinator.h"

/*
    Boot strapping will initialize the data which is global for
    remote procedures.

    This is the client program which will call the server at this
    node itself.
*/

int main(int argc, char* argv[]) {
     CLIENT           *cl;
     char             server[MAXHOSTNAMELEN];
     int              numOfLocks;  
	 static struct timeval TIMEOUT = {25,0};

     if (gethostname(server, MAXHOSTNAMELEN)) {
        error("main: gethostname: couldn't get the name of host");
        error("main: Sorry can't boot up");
        return GET_HOST_NAME_FAIL;
     }

     if (argc == 1) {
         numOfLocks = 0;
     }
     else {
         numOfLocks  = atoi(argv[1]);
     }

     if ((cl = clnt_create(server, COORDINATOR, ADMINISTRATION, "tcp"))
                                            == NULL) {
        clnt_pcreateerror(server);
        return CLIENT_CONNECTION_FAIL;
     }

     remove_locks_6(&numOfLocks, cl);
	 if(clnt_call(cl,REMOVE_LOCKS,xdr_int,&numOfLocks,
				xdr_void,NULL,TIMEOUT) != RPC_SUCCESS) {
		   printf("Remove lock process : The process of removing the lock has FAILED");
	       clnt_perror(cl,server);
		   exit(CLIENT_CONNECTION_FAIL);
     }
     clnt_destroy(cl);
}

