//     $Id: ClientConnectStatus.java,v 3.2 1998/12/07 20:48:53 jpg3u Exp $    
 ////////////////////////////////////////////////////////////////////////////
 //
 // File: ClientConnectStatus.java
 //
 // Purpose: This object is passed from the Server RMI to the 
 //            Demon GUI to allow the display of the current
 //            connection status of each client.
 //
 //          This is a shared/helper class, and can used by several
 //          modules.  For that reason, we don't bother
 //          specifying the Invoking modules.
 //
 // Authors:
 //   rgb  Robert G. Bartholet rgb2u@virginia.edu
 //
 // Modifications:
 //
 //   12-NOV-1998  rgb  Initial creation
 //   16-NOV-1998  smg  Added automatic version header
 //   16-NOV-1998  rgb  Added thrown exceptions
 //                rgb  Added constructor to take num_clients
 //   17-NOV-1998  rgb  Fixed some compilation errors in signatures
 //                rgb  Added throws to signature of default constructor
 //   20-NOV-1998  jpg  Added copy constructor
 //   01-DEC-1998  rgb  Changed status from boolean to int
 //   07-DEC-1998  rgb  Changed status back to boolean, added Submited data
 //
 // To do:
 //
 ////////////////////////////////////////////////////////////////////////////
 public class ClientConnectStatus
 implements java.io.Serializable {
   public static final int MAXCLIENTS = 10;  // max number of users of system
   public static final int MINCLIENTS = 1;   // mininum number of users of system
   protected int num_clients;                // number of modules or users connecting to server
   // each array element is a client; true is connected, shanges submitted
   protected boolean connect_status[] = new boolean [MAXCLIENTS];
   protected boolean submit_status[] = new boolean [MAXCLIENTS];
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  ClientConnectStatus  [constructor]
   //
   // Purpose: This creates a new ClientConnectStatus object and 
   //            initializes the status array to all false.
   //   
   ///////////////////////////////////////////////////////////////////
   public ClientConnectStatus () throws BoundsException {
     int x;
     num_clients = 0;
     for (x = 0; x < MAXCLIENTS; x++) {
       SetClientConnStatus (x,false );      // can throw BoundsException
       SetClientSubStatus (x,false );      // can throw BoundsException
     }
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  ClientConnectStatus  [constructor]
   //
   // Purpose: This creates a new ClientConnectStatus object and 
   //            initializes the state of the source.
   //   
   ///////////////////////////////////////////////////////////////////
   public ClientConnectStatus (ClientConnectStatus source) throws BoundsException {
     int x;
     num_clients = source.GetNumClients();
     for (x = 0; x < source.GetNumClients(); x++) {
       SetClientConnStatus (x, source.GetClientConnStatus(x));
       SetClientSubStatus(x, source.GetClientSubStatus(x));      // can throw BoundsException
     }
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  ClientConnectStatus  [constructor]
   //
   // Purpose: This creates a new ClientConnectStatus object and 
   //            initializes the status array to size num_users, state false
   //   
   ///////////////////////////////////////////////////////////////////
   public ClientConnectStatus (int num_users) throws BoundsException {
     int x;
     if (num_users < MINCLIENTS || num_users > MAXCLIENTS) {
       throw new BoundsException ("ClientConnectStatus called with invalid argument");
     }
     num_clients = num_users;
     for (x = 0; x < MAXCLIENTS; x++) {
       SetClientConnStatus (x, false);       // can throw BoundsException
       SetClientSubStatus(x,false);
     }
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  SetClientConnStatus
   //
   // Purpose: This sets the connection status for a particular client.
   //   
   ///////////////////////////////////////////////////////////////////
   public void SetClientConnStatus (int index, boolean connect) throws BoundsException {
     if (index < MINCLIENTS - 1 || index > MAXCLIENTS - 1) {
       throw new BoundsException ("SetClientStatus called with invalid index");
     }
     connect_status[index] = connect;
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  SetClientSubStatus
   //
   // Purpose: This sets the submit status for a particular client.
   //   
   ///////////////////////////////////////////////////////////////////
   public void SetClientSubStatus (int index, boolean submit) throws BoundsException {
     if (index < MINCLIENTS - 1 || index > MAXCLIENTS - 1) {
       throw new BoundsException ("SetClientStatus called with invalid index");
     }
     submit_status[index] = submit;
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  SetNumClients
   //
   // Purpose: This sets the number of clients that will connect
   //            to the server
   //   
   ///////////////////////////////////////////////////////////////////
   public void SetNumClients (int num) throws BoundsException {
     if (num < MINCLIENTS || num > MAXCLIENTS) {
       throw new BoundsException ("SetNumClients called with invalid argument");
     }
     num_clients = num;
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  GetClientConnStatus
   //
   // Purpose: Returns the current status of a client; true is connected
   //   
   ///////////////////////////////////////////////////////////////////
   public boolean GetClientConnStatus (int index) throws BoundsException {
     if (index < MINCLIENTS - 1 || index > MAXCLIENTS - 1) {
       throw new BoundsException ("GetClientStatus called with invalid argument");
     }
     return connect_status[index];
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  GetClientSubStatus
   //
   // Purpose: Returns the current status of a client; true is connected
   //   
   ///////////////////////////////////////////////////////////////////
   public boolean GetClientSubStatus (int index) throws BoundsException {
     if (index < MINCLIENTS - 1 || index > MAXCLIENTS - 1) {
       throw new BoundsException ("GetClientStatus called with invalid argument");
     }
     return submit_status[index];
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  GetNumClients
   //
   // Purpose: Returns the number of clients that will connect to server
   //   
   ///////////////////////////////////////////////////////////////////
   public int GetNumClients () {
     return num_clients;
   }
 }