1 package org.wcb.autohome;
2 /***
3 * Copyright (C) 1999 Walter Bogaardt
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 *
19 * Project: Home Automation Interface
20 * Filename: $Id: AutoHomeDaemonSession.java,v 1.17 2004/07/22 03:17:54 wbogaardt Exp $
21 * Abstract: Centralized backend for various components to send events to
22 * Serial port output.
23 */
24
25
26 import org.wcb.autohome.interfaces.X10DeviceConstants;
27 import org.wcb.autohome.interfaces.IDeviceRemote;
28
29
30 import org.wcb.autohome.exceptions.HomeException;
31 import org.wcb.common.UIDefaultsLoader;
32
33 public class AutoHomeDaemonSession
34 extends AutoHomeSession implements X10DeviceConstants
35 {
36
37 private static AutoHomeDaemonSession singleton = null;
38 private static String sServletPath;
39 private UIDefaultsLoader PROPERTY_LOADER;
40
41 /***
42 * This class provides a single point of reference for the application
43 * and the X10 API this class is primarily written to work with a non
44 * user interface.
45 */
46 private AutoHomeDaemonSession(){
47 }
48
49 /***
50 * returns a singleton value of the AutoHomeDaemonSession
51 * @return AutoHomeDaemonSession instance
52 */
53 public static AutoHomeDaemonSession getInstance() {
54 if (null==singleton) singleton = new AutoHomeDaemonSession();
55 return singleton;
56 }
57
58 /***
59 * Used by the command line application, but this will be deprecated because of
60 * web interface will be an improvement.
61 * @deprecated
62 * @return Interface of file system.
63 */
64 public IDeviceRemote getDeviceFactory(){
65 return deviceFactory;
66 }
67
68 /***
69 * Loads the last settings from the file properties
70 * file loader. These settings are the file name,
71 * serial port, baud, bit, and X10 device type information.
72 * @param sFilename file name to load can be null
73 * @param sDirectory directory path to load HAConfig.ini and jhome.prop files.
74 */
75 public void loadLastSettings(String sFilename, String sDirectory) {
76 sServletPath = sDirectory;
77 PROPERTY_LOADER = new UIDefaultsLoader(null, sDirectory);
78 super.loadStandAloneService(sDirectory);
79
80 if (super.getSerialPort() != null && !super.getSerialPort().getPort().equalsIgnoreCase("NO PORTS FOUND"))
81 {
82 try
83 {
84 if(! super.isX10GatwayConnected())
85 {
86 super.connectPortToDevice(getX10GatewayType());
87 }
88 }
89 catch (HomeException err)
90 {
91 this.printMessage(err.toString());
92 }
93 }
94
95 if (sFilename == null)
96 {
97 if (PROPERTY_LOADER.getProperty(LAST_FILE) != null && !PROPERTY_LOADER.getProperty(LAST_FILE).equals(""))
98 {
99 this.printMessage("Loading last file opened " + PROPERTY_LOADER.getProperty(LAST_FILE));
100 super.loadX10File(PROPERTY_LOADER.getProperty(LAST_FILE));
101 }
102 }
103 else
104 {
105 this.printMessage("Loaded " + sFilename);
106 super.loadX10File(sFilename);
107 }
108 }
109
110 /***
111 * Saves the file path and name and stores it in the jhome.prop file
112 * then it calls parent class to save the actual .x10 serialized file.
113 * @param sFullfilename full path and file name of the saved file.
114 * @throws HomeException
115 */
116 public void saveFile(String sFullfilename) throws HomeException{
117 PROPERTY_LOADER.setProperty(LAST_FILE, sFullfilename);
118 super.saveFile(sFullfilename);
119 PROPERTY_LOADER.saveProperties();
120 }
121
122 /***
123 * For servlets web application need to set reference to servlet context;
124 * @param sPath Servlet context path.
125 */
126 public void setServletPath(String sPath){
127 sServletPath = sPath;
128 }
129
130 /***
131 * For servlets web based applications need to get reference to servlet context;
132 * @return Servlet context path.
133 */
134 public String getServletPath(){
135 return sServletPath;
136 }
137
138 /***
139 * simple method to print messages to gui or console
140 * @param messages prints a system.out or speaks the text.
141 */
142 public void printMessage(String messages) {
143 showMessage(messages);
144 }
145 }
146
147
148
149
150
151
152
153
154
155
156