00001 /* 00002 * Squid.java 00003 * 00004 * Copyright (C) 2005 Project SQUID, http://www.cs.helsinki.fi/group/squid/ 00005 * 00006 * This file is part of Ikayaki. 00007 * 00008 * Ikayaki is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * Ikayaki is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with Ikayaki; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 package ikayaki.squid; 00024 00025 import ikayaki.Project; 00026 00027 import java.io.IOException; 00028 00035 public class Squid { 00036 00040 private static Squid instance; 00041 00045 private Project owner; 00046 00050 private Degausser degausser; 00051 00055 private Handler handler; 00056 00060 private Magnetometer magnetometer; 00061 00065 public static synchronized Squid instance() throws IOException { 00066 if (instance == null) instance = new Squid(); 00067 return instance; 00068 } 00069 00073 private Squid() throws IOException { 00074 owner = null; 00075 try { 00076 degausser = new Degausser(); 00077 } catch (SerialIOException ex) { 00078 System.err.println("Cannot create degausser: " + ex); 00079 throw new IOException("Cannot create degausser"); 00080 } 00081 try { 00082 handler = new Handler(); 00083 handler.setUp(); 00084 } catch (SerialIOException ex) { 00085 System.err.println("Cannot create handler: " + ex); 00086 throw new IOException("Cannot create handler"); 00087 } 00088 try { 00089 magnetometer = new Magnetometer(); 00090 } catch (SerialIOException ex) { 00091 System.err.println("Cannot create magnetometer: " + ex); 00092 throw new IOException("Cannot create magnetometer"); 00093 } 00094 } 00095 00101 public Degausser getDegausser() { 00102 return this.degausser; 00103 } 00104 00110 public Handler getHandler() { 00111 return this.handler; 00112 } 00113 00119 public Magnetometer getMagnetometer() { 00120 return this.magnetometer; 00121 } 00122 00131 public synchronized void updateSettings() { 00132 // TODO 00133 } 00134 00140 public synchronized boolean isOK() { 00141 if (this.degausser != null && this.handler != null && this.magnetometer != null) { 00142 if (this.degausser.isOK() && this.handler.isOK() && this.magnetometer.isOK()) { 00143 return true; 00144 } 00145 } 00146 return false; 00147 } 00148 00156 public synchronized boolean setOwner(Project owner) { 00157 if (this.owner == null || this.owner.getState() == Project.State.IDLE) { 00158 this.owner = owner; 00159 return true; 00160 } else { 00161 return false; 00162 } 00163 } 00164 00170 public synchronized Project getOwner() { 00171 return this.owner; 00172 } 00173 }