// MyPBX - an example jtapi program for accessing the PBX in Upson Hall
// Donna Bergmark - CS 519 - October 1998
// 
// All this program does is access the PBX, get a provider, get and print
// the list of services, and then shut down.

import javax.telephony.*;
import com.lucent.jtapi.tsapi.*;

public class MyPBX {

   public static void main (String args[]) {

      System.out.println ("About to create a JtapiPeer");
      try {
	 // get Lucent's implementation of the JtapiPeer object
	 JtapiPeer jtapiPeer = JtapiPeerFactory.getJtapiPeer 
	    ("com.lucent.jtapi.tsapi.TsapiPeer");
	 System.out.println ("Got one! its name is " +
	    jtapiPeer.getName() );

         // We got our jtapiPeer.  Now create a provider.
	 try {
	 Provider provider = 
	    jtapiPeer.getProvider("LUCENT#G3_SWITCH#CSTA#VADA;" 
	      + "login=Administrator;" + "passwd=NT!");
	 System.out.println("Got a provider! It's name is " 
	      + provider.getName() );

	 // Wait for the provider to enter the ready state
	 while (provider.getState() != Provider.IN_SERVICE)
	 {
	    try{ Thread.sleep(1000);}
	    catch (Exception e){}
	    System.out.print(".");
	 }
	 System.out.println("Provider is in service");
	 provider.shutdown();  // This takes a minute or so
	 }
	 catch (PlatformException e) {System.out.println(e);}
      }
      catch (JtapiPeerUnavailableException e) {
	 System.out.println (e);
      }
      System.out.println ("That's it for now.");
      System.exit(0);

   } // end main
}
