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 Inteface ALICE
20 * Filename: $Id: Main.java,v 1.7 2004/02/28 00:21:46 wbogaardt Exp $
21 * Abstract: Start up action servlet for web interface.
22 *
23 * $Log: Main.java,v $
24 * Revision 1.7 2004/02/28 00:21:46 wbogaardt
25 * fixed formating to be compliant with sun coding convention
26 *
27 * Revision 1.6 2004/01/15 21:05:17 wbogaardt
28 * major revamp of Modules and interfaces changes overall structure of how information is stored
29 *
30 * Revision 1.5 2003/12/24 20:24:17 wbogaardt
31 * Fixed display of console message on start up
32 *
33 * Revision 1.4 2003/12/16 22:08:33 wbogaardt
34 * refactored events daemon handeling
35 *
36 * Revision 1.3 2003/12/08 23:46:02 wbogaardt
37 * added javadoc comments and cleaned up Main class
38 *
39 *
40 */
41
42 import org.wcb.autohome.exceptions.HomeException;
43 import org.wcb.autohome.interfaces.IX10Events;
44 import org.wcb.autohome.interfaces.IX10Module;
45
46 import java.io.BufferedReader;
47 import java.io.InputStreamReader;
48 import java.io.IOException;
49 import java.util.Vector;
50
51 /***
52 * The main class to start the swing application
53 */
54 public class Main {
55
56 private HomeCenterPanel centerPanel;
57 private EventsHandler myHandle;
58
59 /***
60 * Main entry point for the alice swing application
61 * @param args Arguments can be -nosplash or -nogui
62 */
63 public static void main(String[] args) {
64 if (args.length > 0)
65 {
66 if (args[0].equals("-nosplash"))
67 {
68 new AliceFrame("nosplash");
69 }
70 else if (args[0].equals("-nogui"))
71 {
72
73 if (args.length > 1)
74 {
75 new Main(args[1]);
76
77 }
78 else
79 {
80 new Main(null);
81 }
82 }
83 else
84 {
85 printUsage();
86 }
87 }
88 else
89 {
90 new AliceFrame("splash");
91 }
92 }
93
94 /***
95 * Main runing part of application for console mode
96 * @param sArg1 The file name of the x10 file to run
97 */
98 public Main(String sArg1) {
99
100 if (sArg1 != null)
101 {
102 AutoHomeDaemonSession.getInstance().loadLastSettings(sArg1, System.getProperty("user.home"));
103 AutoHomeDaemonSession.getInstance().runEventsDaemon();
104
105 }
106 else
107 {
108 AutoHomeDaemonSession.getInstance().loadLastSettings(null, System.getProperty("user.home"));
109 AutoHomeDaemonSession.getInstance().runEventsDaemon();
110
111 }
112 listenToConsole();
113 }
114
115 /***
116 * While the application is running parse through the
117 * users input and act on those actions.
118 * If the application is exited then close off everything.
119 */
120 public void listenToConsole() {
121 String command;
122 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
123 while (true)
124 {
125 System.out.println("Cmd options -[list][exit]");
126 System.out.print("Alice Cmd> ");
127 command = "";
128 try
129 {
130 command = in.readLine();
131 }
132 catch (IOException ioe)
133 {
134 System.err.println("Failed reading command from prompt" + ioe);
135 }
136 if (command.startsWith("exit"))
137 {
138 myHandle.stop();
139 try
140 {
141 AutoHomeDaemonSession.getInstance().closeSerialPort();
142 }
143 catch (HomeException err)
144 {
145
146 }
147 System.exit(0);
148 }
149 else if (command.startsWith("list"))
150 {
151 printList(myHandle.getModel());
152 }
153 else
154 {
155 System.out.println("Not a recognized command");
156 }
157 }
158 }
159
160 /***
161 * This prints a list of available events from the
162 * save file.
163 * @param model list of events to run
164 */
165 public void printList(Vector model) {
166 IX10Events event;
167 for (int i = 0; i < model.size(); i++)
168 {
169 event = (IX10Events) model.elementAt(i);
170 IX10Module iEventModule = event.getModule();
171 System.out.println(iEventModule.getFullDeviceCode() + "\t" + iEventModule.getType() + "\t"
172 + event.getAction() + "\t " + event.getTime());
173 }
174 }
175
176 /***
177 * Prints the usage of this command line start
178 */
179 public static void printUsage() {
180 System.out.println("Usage: java or jre -cp autohome.jar org.wcb.autohome.Main [-nosplash -nogui][filename]");
181 System.out.println(" ");
182 System.out.println("Where -nosplash doesn't display splash screen");
183 System.out.println(" -nogui Starts Alice in console automatically running saved events");
184 System.out.println(" filename Following enter the .x10 file that you want events");
185 System.out.println(" run from. You must include the entire directory and");
186 System.out.println(" file name location.(i.e. /home/myfile.x10)");
187 System.out.println(" ");
188 }
189 }
190
191
192