// file: $ISIP_IFC/util/demo/isip_comm_client_speech_recognition/SpeechRecognitionMainServer.java
// version: $Id: SpeakerVerificationMainServer.java 10572 2006-06-26 21:54:34Z rei5 $ 
//

// import necessary java libraries
//

// none

// import galaxy libraries
// 
import galaxy.server.MainServer;
import galaxy.server.ServerArgParser;

/**
 * This class is derived from the MainServer class and ui frame is
 * added.
 */
public class SpeakerVerificationMainServer extends MainServer {
    
    //-------------------------------------------------------------------------
    //
    // public constants
    //
    //-------------------------------------------------------------------------
    
    /**
     * The String represents the server name
     */
    public static String SERVER_NAME = "speaker_verification"; 

    //------------------------------------------------------------------------
    //
    // protected data
    //
    //-----------------------------------------------------------------------
    
    /**
     * Speaker Verification UI frame
     */
    protected SpeakerVerificationUIFrame speaker_verification_frame_d;


    //-------------------------------------------------------------------------
    //
    // public methods
    //
    //-------------------------------------------------------------------------

    /**
     * Constructor for this class. <P>
     *
     * The object of the SpeechRecognitionMainServer is intialized using
     * the constructor of the MainServer class.
     *
     * @param args args arguments, usually from the command line.
     */
    public SpeakerVerificationMainServer(String[] args) {
	
	// call the super class constructor
	//
	super(SERVER_NAME, args);
	
	// set the file name in which the server class name located
	//
	serverClassName = "SpeakerVerificationServer";

	// create speaker verification parser
	//
	SpeakerVerificationArgParser parser = new 
	    SpeakerVerificationArgParser(args);

	// get the speech analysis port number
	//
	int client_port = parser.getClientPort();

        System.out.println("This is client's port number    " + 
			   client_port); //speaker_verification_port);
	
	// get the process manager port number
	//
	int demo_manager_port = parser.getDemoManagerPort();

	System.out.println("This is demo manager's port number    " + 
			   demo_manager_port);
 
	// get the process manager ip address
	//
	String demo_manager_ip_address = parser.getDemoManagerIPAddress();

	System.out.println("This is demo manager's ip address    " + 
			   demo_manager_ip_address); 

	// get the hub ip address
	//
	String hub_ip_address = parser.getHubIPAddress();

	System.out.println("This is hub's ip address    " + 
			   hub_ip_address); 


	// get the mode of the client
	//
	String server_mode = parser.getMode();
	boolean mode;

	// check for null pointer and choose method of execution
	//
	if (server_mode != null && server_mode.equalsIgnoreCase("server")) 
	    mode = true;
	else 
	    mode = false;

	// create a new ui frame using the port numbers and ip address
	//
	speaker_verification_frame_d = 
	    new SpeakerVerificationUIFrame(client_port,
					 demo_manager_port, 
					 demo_manager_ip_address,
					 mode);

	// get the hub port from the connection manager because this is set
	// on the server side
	//
	int hub_port = 
	    speaker_verification_frame_d.getConnectionManager().getHubPort();

	System.err.println("Connecting to the hub at IP[" + hub_ip_address +
			   "] and port[" + hub_port + "]");

	// finally connect to the hub
	//
	// if mode == false then the client connects to the hub
	// if mode == true then the hub connects connects to the client
	//
	if (mode == false) {
	    setActsAsHubClient(true);
	    contactHub(hub_ip_address, hub_port, "speaker_verify_ID",
		   -1);
	}
	else {
	    System.err.println("PROBLEM! CLIENT IS CURRENTLY NOT CODED TO " +
			       "ALLOW THE HUB TO CONNECT TO IT. SET MODE " +
			       "SO CLIENT IS IN SERVER MODE");
	    System.err.println("PROBLEM! CLIENT IS CURRENTLY NOT CODED TO " +
			       "ALLOW THE HUB TO CONNECT TO IT. SET MODE " +
			       "SO CLIENT IS IN SERVER MODE");
	}
    }
    

    //-------------------------------------------------------------------------
    //
    // class-specific public methods:
    //  set methods
    //
    //-------------------------------------------------------------------------


    //-------------------------------------------------------------------------
    //
    // class-specific public methods:
    //  get methods
    //
    //-------------------------------------------------------------------------
    /**
     * Used to return the Object of the SpeechRecognitionUIFrame which is
     * created in the class' constructor.  
     *
     * @return a SpeechRecognitionUIFrame instance is returned.
     */
    public SpeakerVerificationUIFrame getSpeakerVerificationUIFrame() {
	return speaker_verification_frame_d;
    }

    //-------------------------------------------------------------------------
    //
    // main diagnostic method for this class
    //
    //-------------------------------------------------------------------------
    
    /**
     * Diagnostic method for this class.
     *
     * @param args arguments from the command line.
     */    
    public static void main(String[] args) {
	new SpeakerVerificationMainServer(args)
	    .speaker_verification_frame_d.setVisible(true);    
    }
}
