| 1 | package tmcsim.cadsimulator.managers; |
|---|
| 2 | |
|---|
| 3 | import java.io.FileInputStream; |
|---|
| 4 | import java.rmi.RemoteException; |
|---|
| 5 | import java.util.Properties; |
|---|
| 6 | import java.util.logging.Level; |
|---|
| 7 | import java.util.logging.Logger; |
|---|
| 8 | |
|---|
| 9 | import tmcsim.cadsimulator.stillimagecontrol.ATMSCommunicator; |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * ATMSManager is a CAD Simulator Manager used to handle all |
|---|
| 13 | * communication between the CAD Simulator and the ATMS server. |
|---|
| 14 | * Upon construction, the ATMSCommunicator is initialized with |
|---|
| 15 | * information from the properties file. This Object is used |
|---|
| 16 | * to perform the specific communication functions to send and |
|---|
| 17 | * receive data to/from the ATMS server. Methods in this |
|---|
| 18 | * Manager allow for the current ATMS server time to be queried |
|---|
| 19 | * and still images to be updated for display to ATMS clients. |
|---|
| 20 | * |
|---|
| 21 | * @author Matthew Cechini |
|---|
| 22 | * @version |
|---|
| 23 | */ |
|---|
| 24 | public class ATMSManager { |
|---|
| 25 | |
|---|
| 26 | /** Error Logger. */ |
|---|
| 27 | private static Logger atmsLogger = Logger.getLogger("tmcsim.cadsimulator.managers"); |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * Enumeration containing property names for Properties parsing. |
|---|
| 31 | * @author Matthew Cechini |
|---|
| 32 | */ |
|---|
| 33 | private static enum ATMS_PROPERTIES { |
|---|
| 34 | /** */ |
|---|
| 35 | ATMS_HOST ("ATMSHost"), |
|---|
| 36 | /** */ |
|---|
| 37 | USERNAME ("Username"), |
|---|
| 38 | /** */ |
|---|
| 39 | PASSWORD ("Password"), |
|---|
| 40 | /** */ |
|---|
| 41 | IMAGE_DIR ("ImageDir"); |
|---|
| 42 | |
|---|
| 43 | public String name; |
|---|
| 44 | |
|---|
| 45 | private ATMS_PROPERTIES(String n) { |
|---|
| 46 | name = n; |
|---|
| 47 | } |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | /** ATMSCommunicator Object used for communication to the ATMS server. */ |
|---|
| 51 | private ATMSCommunicator theATMSCommunicator; |
|---|
| 52 | |
|---|
| 53 | /** Properties Object. */ |
|---|
| 54 | private Properties atmsProperties = null; |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * Constructor. Loads the Properties file and initializes the |
|---|
| 59 | * ATMSCommunicator with the parsed data. |
|---|
| 60 | * |
|---|
| 61 | * @param propertiesFile Target file path of properties file. |
|---|
| 62 | */ |
|---|
| 63 | public ATMSManager(String propertiesFile) { |
|---|
| 64 | |
|---|
| 65 | try { |
|---|
| 66 | atmsProperties = new Properties(); |
|---|
| 67 | atmsProperties.load(new FileInputStream(propertiesFile)); |
|---|
| 68 | |
|---|
| 69 | theATMSCommunicator = new ATMSCommunicator( |
|---|
| 70 | atmsProperties.getProperty(ATMS_PROPERTIES.ATMS_HOST.name), |
|---|
| 71 | atmsProperties.getProperty(ATMS_PROPERTIES.USERNAME.name), |
|---|
| 72 | atmsProperties.getProperty(ATMS_PROPERTIES.PASSWORD.name), |
|---|
| 73 | atmsProperties.getProperty(ATMS_PROPERTIES.IMAGE_DIR.name)); |
|---|
| 74 | |
|---|
| 75 | } |
|---|
| 76 | catch (Exception e) { |
|---|
| 77 | atmsLogger.logp(Level.SEVERE, "ATMSManager", "Constructor", |
|---|
| 78 | "Exception in parsing properties file.", e); |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * Returns the current ATMS server time as the number of seconds since Jan 1, 1970. |
|---|
| 85 | * |
|---|
| 86 | * @return Current time in seconds. |
|---|
| 87 | * @throws Exception if an exception occurs communicating to the ATMS server. |
|---|
| 88 | */ |
|---|
| 89 | public long getCurrentTime() throws Exception { |
|---|
| 90 | return theATMSCommunicator.getCurrentTime(); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | /** |
|---|
| 94 | * Show a new image for an ATMS camera. The ATMS camera files are named |
|---|
| 95 | * <ATMS_Camera_ID>.xpm. If a camera file exists, delete it. Then copy |
|---|
| 96 | * the parameter file name to <ATMS_Camera_ID>.xpm. If the camera ID or |
|---|
| 97 | * new file does not exist, throw an exception. |
|---|
| 98 | * |
|---|
| 99 | * @param ATMS_cameraID ATMS indexed camera ID. |
|---|
| 100 | * @param fileName Filename to show. |
|---|
| 101 | * @throws RemoteException if an exception occurs communicating to the ATMS server. |
|---|
| 102 | */ |
|---|
| 103 | public void showImage(Integer ATMS_cameraID, String fileName) throws RemoteException { |
|---|
| 104 | theATMSCommunicator.showImage(ATMS_cameraID, fileName); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | } |
|---|