Update of /cvsroot/magicmap/magicmapclient/src/net/sf/magicmap/client/controller In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12081/src/net/sf/magicmap/client/controller Modified Files: Controller.java ServerPoller.java ServerManager.java PollHandler.java Added Files: VirtualServerManager.java SOAPServerManager.java Log Message: + Client is usable without server Index: PollHandler.java =================================================================== RCS file: /cvsroot/magicmap/magicmapclient/src/net/sf/magicmap/client/controller/PollHandler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PollHandler.java 12 Feb 2005 16:00:28 -0000 1.2 --- PollHandler.java 11 May 2005 10:51:27 -0000 1.3 *************** *** 9,12 **** --- 9,13 ---- import javax.swing.SwingUtilities; + import net.sf.magicmap.client.interfaces.ServerPollerListener; import net.sf.magicmap.client.model.node.AccessPointNode; *************** *** 266,291 **** // Alle momentan gesehenen AccessPoints merken ArrayList seenAps = client.getSeenAccessPoints(); ! for (int i = 0; i < sr.length; i++){ ! SimpleScanResultDTO r = sr[i]; ! String mac = r.getMacAP(); ! // Gibt es ggf. einen AP mit der Mac-Adresse? ! AccessPointNode ap = nodeModel.findAccessPoint(mac); ! if (ap == null){ ! // Nein ! ap = new AccessPointNode(nodeModel); ! ap.setMacAddress(mac); ! nodeModel.addNode(ap); ! //ap.setName(mac); ! } else{ ! // AccessPoint nur aktualisieren? ! if (seenAps.remove(ap)){ ! // Nur Signallevel aktualisieren ! client.setSignalLevelForAcessPoint(ap, r.getSignalLevel().doubleValue()); } else{ ! // Neu ! client.seesAccessPoint(ap, r.getSignalLevel().doubleValue()); } } } // Alle APs aus seenAps werden demzufolge nicht mehr gesehen und // dies teilen wir unserem Modell mit --- 267,298 ---- // Alle momentan gesehenen AccessPoints merken ArrayList seenAps = client.getSeenAccessPoints(); ! ! if (sr != null){ ! ! for (int i = 0; i < sr.length; i++){ ! SimpleScanResultDTO r = sr[i]; ! String mac = r.getMacAP(); ! // Gibt es ggf. einen AP mit der Mac-Adresse? ! AccessPointNode ap = nodeModel.findAccessPoint(mac); ! if (ap == null){ ! // Nein ! ap = new AccessPointNode(nodeModel); ! ap.setMacAddress(mac); ! nodeModel.addNode(ap); ! //ap.setName(mac); } else{ ! // AccessPoint nur aktualisieren? ! if (seenAps.remove(ap)){ ! // Nur Signallevel aktualisieren ! client.setSignalLevelForAcessPoint(ap, r.getSignalLevel().doubleValue()); ! } else{ ! // Neu ! client.seesAccessPoint(ap, r.getSignalLevel().doubleValue()); ! } } } + } + // Alle APs aus seenAps werden demzufolge nicht mehr gesehen und // dies teilen wir unserem Modell mit --- NEW FILE: SOAPServerManager.java --- /* * Created on 12.12.2004 */ package net.sf.magicmap.client.controller; import java.io.IOException; import java.rmi.RemoteException; import net.sf.magicmap.client.delegate.MapDelegate; import net.sf.magicmap.client.delegate.PositionDelegate; import net.sf.magicmap.client.delegate.SessionDelegate; import net.sf.magicmap.client.delegate.interfaces.MapFacadeInterface; import net.sf.magicmap.client.delegate.interfaces.PositionFacadeInterface; import net.sf.magicmap.client.delegate.interfaces.SessionFacadeInterface; import net.sf.magicmap.client.interfaces.CreateNewMapCallback; import net.sf.magicmap.client.interfaces.CreatePositionCallback; import net.sf.magicmap.client.interfaces.DeletePositionCallback; import net.sf.magicmap.client.interfaces.FetchPositionsCallback; import net.sf.magicmap.client.interfaces.MapCallback; import net.sf.magicmap.client.interfaces.MapNamesCallback; import net.sf.magicmap.client.interfaces.MovePositionCallback; import net.sf.magicmap.client.interfaces.PositionCallback; import net.sf.magicmap.client.interfaces.ServerConnectCallback; import net.sf.magicmap.client.interfaces.ServerDisconnectCallback; import net.sf.magicmap.client.meta.MapInfo; import net.sf.magicmap.client.utils.Settings; import net.sf.magicmap.client.utils.Version; import net.sf.magicmap.server.dto.MapDTO; import net.sf.magicmap.server.dto.PositionDTO; import net.sf.magicmap.server.dto.SignalCharacterDTO; /** * Managet die Client-Server-Kommunikation sowie die * Verbindung selbst. * @author thuebner */ public class SOAPServerManager extends ServerManager { private static String mutex = "net.sf.magicmap.client.controller.Controller"; private SessionFacadeInterface sessionDelegate; // Verbindung zum Server private MapFacadeInterface mapDelegate; public PositionFacadeInterface positionDelgate; public SOAPServerManager(Controller controller) { super(controller); this.sessionDelegate = null; this.positionDelgate = null; this.mapDelegate = null; } /** * Stellt Verbindung zum Server her * */ public void connect(final ServerConnectCallback callback){ if (isConnected()){ System.out.println("Already connected."); } else{ Thread connectionThread = new Thread() { public void run(){ synchronized (mutex){ try{ SOAPServerManager.this.sessionDelegate = new SessionDelegate(); SOAPServerManager.this.sessionId = SOAPServerManager.this.sessionDelegate.connect(Settings .getClientName(), Settings.getClientMAC(), Settings.getClientPassword(), Version.PROTOCOL_VERSION); SOAPServerManager.this.mapDelegate = new MapDelegate(); SOAPServerManager.this.positionDelgate = new PositionDelegate(); callback.connected(SOAPServerManager.this.sessionId); } catch (Exception e){ callback.connectionError(e); } } } }; connectionThread.start(); } } /** * * @param callback */ public void disconnect(final ServerDisconnectCallback callback){ if (isConnected()){ Thread disconnectionThread = new Thread() { public void run(){ synchronized (mutex){ try{ SOAPServerManager.this.sessionDelegate.disconnect(Settings.getClientName(), Settings.getClientMAC(), Settings.getClientPassword(), sessionId); SOAPServerManager.this.positionDelgate = null; SOAPServerManager.this.mapDelegate = null; SOAPServerManager.this.sessionDelegate = null; callback.disconnected(); } catch (Exception e){ callback.disconnectionError(e); } SOAPServerManager.this.sessionId = -1; } } }; disconnectionThread.start(); } } /** * * @param name * @param URL * @param width * @param height * @param callback */ public void createNewMap(final String name, final String URL, final int width, final int height, final CreateNewMapCallback callback){ if (isConnected()){ Thread mapCreationThread = new Thread() { public void run(){ synchronized (mutex){ try{ SOAPServerManager.this.mapDelegate.createNewMap(sessionId, name, URL, width, height); MapInfo mapinfo = new MapInfo(); mapinfo.name = name; mapinfo.imageURL = URL; mapinfo.width = width; mapinfo.height = height; callback.newMapCreated(mapinfo); } catch (Exception e){ e.printStackTrace(); callback.createNewMapError(e); } } } }; mapCreationThread.start(); } } /** * Liefert die eindeutigen Namen der auf dem Server angelegten Karten * zurück. * @param callback MapNamesCallback Objekt welches das MapNamesCallback implementiert * um die Kartennamen bzw. die */ public void retrieveMapNames(final MapNamesCallback callback){ if (isConnected()){ Thread getMapNamesThread = new Thread() { public void run(){ synchronized (mutex){ try{ String[] names = SOAPServerManager.this.mapDelegate.getMapNames(); callback.mapNamesReceived(names); } catch (Exception e){ e.printStackTrace(); callback.getMapNamesError(e); } } } }; getMapNamesThread.start(); } } /** * Lädt Daten zu einer Karte vom Server. Das Ergebniss wird über eine Callback * Funktionen geliefert. * @param name * @param callback */ public void retrieveMap(final String name, final MapCallback callback){ if (isConnected()){ Thread getMapThread = new Thread() { public void run(){ synchronized (mutex){ try{ MapDTO mapDTO = SOAPServerManager.this.mapDelegate.getMap(name); callback.mapReceived(mapDTO); } catch (Exception e){ callback.getMapError(e); } } } }; getMapThread.start(); } } /** * Erzeugt einen Referenzpunkt auf dem Server * @param node * @param callback */ public void createLocation(final int x, final int y, final boolean fixed, final String name, final CreatePositionCallback callback){ if (isConnected()){ final SignalCharacterDTO signalCharacter = currentSignalCharacter(); System.out.println("signalCharacter.getSimpleScanResults() " + signalCharacter.getSimpleScanResults()); Thread createPositionThread = new Thread() { public void run(){ synchronized (mutex){ try{ SOAPServerManager.this.positionDelgate.createOrUpdatePosition(SOAPServerManager.this.sessionId, controller.getCurrentMap().name, x, y, signalCharacter, name, fixed); // TODO: Zusätzliche Parameter zur Position callback.positionCreated(); } catch (Exception e){ callback.positionCreationError(e); } } } }; createPositionThread.start(); } } /** * Entfernt einen Referenzpunkt oder die Positionierung eines * AccessPoints oder Clients mit gegebener Id vom Server * @param node * @param callback */ public void deletePosition(final long positionId, final DeletePositionCallback callback){ if (isConnected()){ Thread deletePositionThread = new Thread() { public void run(){ synchronized (mutex){ try{ SOAPServerManager.this.positionDelgate.deletePosition(sessionId, positionId); System.out.println("PositionID " + positionId + " deleted."); // TODO: Zusätzliche Parameter zur Position callback.positionDeleted(positionId); } catch (Exception e){ callback.positionDeleteError(e); } } } }; deletePositionThread.start(); } } /** * Bewegt einen Referenzpunkt oder die Positionierung eines * AccessPoints oder Clients mit gegebener Id vom Server * @param node * @param callback */ public void movePosition(final long positionId, final int x, final int y, final boolean fixed, final MovePositionCallback callback){ if (isConnected()){ Thread movePositionThread = new Thread() { public void run(){ synchronized (mutex){ try{ SOAPServerManager.this.positionDelgate.movePosition(sessionId, positionId, x, y, fixed); // TODO: Zusätzliche Parameter zur Position callback.positionMoved(positionId); } catch (Exception e){ callback.positionMoveError(e); } } } }; movePositionThread.start(); } } /* public void createOrUpdateClientPosition(long sessionId, String mapName, int positionX, int positionY, public void createOrUpdateAccessPosition(long sessionId, String mapName, int positionX, int positionY, String accessPointMac) throws RemoteException, MapException, SessionException{ public void movePosition(long sessionId, long positionId, int newPositionX, int newPositionY) throws RemoteException, public void deletePosition(long sessionId, long positionId) throws RemoteException, MapException, SessionException{ */ /** * Eine Position von (-1,-1) bedeutet, dass der Client nicht fixiert ist sondern * frei beweglich ist. Es werden dann nur seine Signalstärken geupdatet. * @param x X-Koordinate bzgl. Map * @param y Y-Koordinate bzgl. Map * @param clientMac MAC-Adresses des betreffenden Clients * @param callback Callback */ public void setClientPosition(final int x, final int y, final boolean fixed, final String clientMac, final PositionCallback callback){ if (isConnected()){ Thread positionThread = new Thread() { public void run(){ synchronized (mutex){ try{ SOAPServerManager.this.positionDelgate.createOrUpdateClientPosition(sessionId, controller.getCurrentMap().name, x, y, currentSignalCharacter(), clientMac, fixed); // TODO: Zusätzliche Parameter zur Position callback.positionUpdated(clientMac); } catch (Exception e){ callback.positionError(e); } } } }; positionThread.start(); } } /** * Eine Position von (-1,-1) bedeutet, dass der Client nicht fixiert ist sondern * frei beweglich ist. Es werden dann nur seine Signalstärken geupdatet. * @param x X-Koordinate bzgl. Map * @param y Y-Koordinate bzgl. Map * @param clientMac MAC-Adresses des betreffenden Clients * @param callback Callback */ public void setAccessPointPosition(final int x, final int y, final boolean fixed, final String accessPointMac, final PositionCallback callback){ if (isConnected()){ Thread positionThread = new Thread() { public void run(){ synchronized (mutex){ try{ SOAPServerManager.this.positionDelgate.createOrUpdateAccessPosition(sessionId, controller.getCurrentMap().name, x, y, accessPointMac, fixed); // TODO: Zusätzliche Parameter zur Position callback.positionUpdated(accessPointMac); } catch (Exception e){ callback.positionError(e); } } } }; positionThread.start(); } } public void fetchPositionsFromServer(final FetchPositionsCallback callback){ if (isConnected()){ Thread fetchPositionsThread = new Thread() { public void run(){ synchronized (mutex){ try{ PositionDTO[] positions = SOAPServerManager.this.positionDelgate.getPositionsForMapSince( SOAPServerManager.this.sessionId, controller.getCurrentMap().name, timestamp); for (int i = 0; i < positions.length; i++){ if (positions[i].getLastModified().longValue() > SOAPServerManager.this.timestamp){ SOAPServerManager.this.timestamp = positions[i].getLastModified().longValue(); } } callback.positionsFetched(positions); } catch (Exception e){ callback.positionFetchError(e); } } } }; fetchPositionsThread.start(); } } /* (non-Javadoc) * @see net.sf.magicmap.client.interfaces.ServerPollerListener#positionCreatedOrUpdatedOrDeleted(java.lang.String, long, net.sf.magicmap.client.delegate.dto.PositionDTO) */ public void positionCreatedOrUpdatedOrDeleted(String mapName, long timeStamp, PositionDTO position){ // TODO Auto-generated method stub } /** * @param poller */ public void submitClientInfo(){ if (isConnected() && !controller.isInvisible()){ final SignalCharacterDTO signalCharacter = currentSignalCharacter(); Thread updateClientThread = new Thread() { public void run(){ synchronized (mutex){ try{ int x = controller.getClientPosX(); int y = controller.getClientPosY(); if (x < 0) x = 0; else if (x >= controller.getCurrentMap().width) x = controller.getCurrentMap().width - 1; if (y < 0) y = 0; else if (y >= controller.getCurrentMap().height) y = controller.getCurrentMap().height - 1;; SOAPServerManager.this.positionDelgate.createOrUpdateClientPosition(SOAPServerManager.this.sessionId, controller.getCurrentMap().name, x, y, signalCharacter, controller.getClient().getMacAddress(), controller.getClient().isFix()); // TODO: Zusätzliche Parameter zur Position System.out.println("Client info submitted."); } catch (Exception e){ e.printStackTrace(); } } } }; updateClientThread.start(); } } /* (non-Javadoc) * @see net.sf.magicmap.client.controller.ServerManager#reloadMap() */ public void reloadMap(){ try{ positionDelgate = new PositionDelegate(); } catch (RemoteException e){ // TODO Auto-generated catch block e.printStackTrace(); } } /* (non-Javadoc) * @see net.sf.magicmap.client.controller.ServerManager#closeMap() */ public void closeMap(){ if (positionDelgate != null){ try{ positionDelgate.close(); } catch (IOException e){ e.printStackTrace(); } } } } --- NEW FILE: VirtualServerManager.java --- /* * Created on 10.05.2005 * */ package net.sf.magicmap.client.controller; import net.sf.magicmap.client.interfaces.CreateNewMapCallback; import net.sf.magicmap.client.interfaces.CreatePositionCallback; import net.sf.magicmap.client.interfaces.DeletePositionCallback; import net.sf.magicmap.client.interfaces.FetchPositionsCallback; import net.sf.magicmap.client.interfaces.MapCallback; import net.sf.magicmap.client.interfaces.MapNamesCallback; import net.sf.magicmap.client.interfaces.MovePositionCallback; import net.sf.magicmap.client.interfaces.PositionCallback; import net.sf.magicmap.client.interfaces.ServerConnectCallback; import net.sf.magicmap.client.interfaces.ServerDisconnectCallback; import net.sf.magicmap.client.meta.MapInfo; import net.sf.magicmap.client.utils.Settings; import net.sf.magicmap.client.utils.Version; import net.sf.magicmap.server.Init; import net.sf.magicmap.server.dto.MapDTO; import net.sf.magicmap.server.dto.PositionDTO; import net.sf.magicmap.server.dto.SignalCharacterDTO; import net.sf.magicmap.server.facade.MapFacade; import net.sf.magicmap.server.facade.PositionFacade; import net.sf.magicmap.server.facade.SessionFacade; /** * @author thuebner * */ public class VirtualServerManager extends ServerManager { private static String mutex = "net.sf.magicmap.client.controller.Controller"; /** * @param controller */ public VirtualServerManager(Controller controller) { super(controller); } MapFacade mapFacade; private SessionFacade sessionFacade; private PositionFacade positionFacade; /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#resetTimestamp() */ public void resetTimestamp(){ this.timestamp = -1; } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#isConnected() */ public boolean isConnected(){ return (this.sessionId != -1); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#connect(net.sf.magicmap.client.interfaces.ServerConnectCallback) */ public void connect(ServerConnectCallback callback){ if (isConnected()){ System.out.println("Already connected."); } else{ System.out.println("Connect to local DB"); // init JDO Init.initJDO("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:magicmap;create=true", "magicmap", "hamilton"); mapFacade = new MapFacade(); sessionFacade = new SessionFacade(); positionFacade = new PositionFacade(); try{ sessionId = sessionFacade.connect(Settings.getClientName(), Settings.getClientMAC(), Settings .getClientPassword(), Version.PROTOCOL_VERSION); callback.connected(sessionId); } catch (Exception e){ callback.connectionError(e); } } } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#disconnect(net.sf.magicmap.client.interfaces.ServerDisconnectCallback) */ public void disconnect(ServerDisconnectCallback callback){ if (!isConnected()) return; callback.disconnected(); this.sessionId = -1; } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#createNewMap(java.lang.String, * java.lang.String, int, int, * net.sf.magicmap.client.interfaces.CreateNewMapCallback) */ public void createNewMap(final String name, final String URL, final int width, final int height, final CreateNewMapCallback callback){ if (!isConnected()) return; Thread mapCreationThread = new Thread() { public void run(){ synchronized (mutex){ try{ mapFacade.createNewMap(sessionId, name, URL, width, height); MapInfo mapinfo = new MapInfo(); mapinfo.name = name; mapinfo.imageURL = URL; mapinfo.width = width; mapinfo.height = height; callback.newMapCreated(mapinfo); } catch (Exception e){ e.printStackTrace(); callback.createNewMapError(e); } } } }; mapCreationThread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#retrieveMapNames(net.sf.magicmap.client.interfaces.MapNamesCallback) */ public void retrieveMapNames(final MapNamesCallback callback){ if (!isConnected()) return; Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ String[] names = mapFacade.getMapNames(); callback.mapNamesReceived(names); } catch (Exception e){ e.printStackTrace(); callback.getMapNamesError(e); } } } }; thread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#retrieveMap(java.lang.String, * net.sf.magicmap.client.interfaces.MapCallback) */ public void retrieveMap(final String name, final MapCallback callback){ if (!isConnected()) return; Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ MapDTO mapDTO = mapFacade.getMap(name); callback.mapReceived(mapDTO); } catch (Exception e){ callback.getMapError(e); } } } }; thread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#createLocation(int, * int, boolean, java.lang.String, * net.sf.magicmap.client.interfaces.CreatePositionCallback) */ public void createLocation(final int x, final int y, final boolean fixed, final String name, final CreatePositionCallback callback){ if (!isConnected()) return; final SignalCharacterDTO signalCharacter = currentSignalCharacter(); System.out.println("signalCharacter.getSimpleScanResults() " + signalCharacter.getSimpleScanResults()); Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ positionFacade.createOrUpdatePosition(sessionId, controller.getCurrentMap().name, x, y, signalCharacter, name, fixed); // TODO: Zusätzliche Parameter zur Position callback.positionCreated(); } catch (Exception e){ callback.positionCreationError(e); } } } }; thread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#deletePosition(long, * net.sf.magicmap.client.interfaces.DeletePositionCallback) */ public void deletePosition(final long positionId, final DeletePositionCallback callback){ if (!isConnected()) return; Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ positionFacade.deletePosition(sessionId, positionId); System.out.println("PositionID " + positionId + " deleted."); // TODO: Zusätzliche Parameter zur Position callback.positionDeleted(positionId); } catch (Exception e){ callback.positionDeleteError(e); } } } }; thread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#movePosition(long, * int, int, boolean, * net.sf.magicmap.client.interfaces.MovePositionCallback) */ public void movePosition(final long positionId, final int x, final int y, final boolean fixed, final MovePositionCallback callback){ if (!isConnected()) return; Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ positionFacade.movePosition(sessionId, positionId, x, y, fixed); // TODO: Zusätzliche Parameter zur Position callback.positionMoved(positionId); } catch (Exception e){ callback.positionMoveError(e); } } } }; thread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#setClientPosition(int, * int, boolean, java.lang.String, * net.sf.magicmap.client.interfaces.PositionCallback) */ public void setClientPosition(final int x, final int y, final boolean fixed, final String clientMac, final PositionCallback callback){ if (!isConnected()) return; Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ positionFacade.createOrUpdateClientPosition(sessionId, controller.getCurrentMap().name, x, y, currentSignalCharacter(), clientMac, fixed); // TODO: Zusätzliche Parameter zur Position callback.positionUpdated(clientMac); } catch (Exception e){ callback.positionError(e); } } } }; thread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#setAccessPointPosition(int, * int, boolean, java.lang.String, * net.sf.magicmap.client.interfaces.PositionCallback) */ public void setAccessPointPosition(final int x, final int y, final boolean fixed, final String accessPointMac, final PositionCallback callback){ if (!isConnected()) return; Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ positionFacade.createOrUpdateAccessPosition(sessionId, controller.getCurrentMap().name, x, y, accessPointMac, fixed); // TODO: Zusätzliche Parameter zur Position callback.positionUpdated(accessPointMac); } catch (Exception e){ callback.positionError(e); } } } }; thread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#fetchPositionsFromServer(net.sf.magicmap.client.interfaces.FetchPositionsCallback) */ public void fetchPositionsFromServer(final FetchPositionsCallback callback){ if (!isConnected()) return; Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ PositionDTO[] positions = positionFacade.getPositionsForMapSince(sessionId, controller.getCurrentMap().name, timestamp); for (int i = 0; i < positions.length; i++){ if (positions[i].getLastModified().longValue() > timestamp){ timestamp = positions[i].getLastModified().longValue(); } } callback.positionsFetched(positions); } catch (Exception e){ callback.positionFetchError(e); } } } }; thread.start(); } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#positionCreatedOrUpdatedOrDeleted(java.lang.String, * long, net.sf.magicmap.server.dto.PositionDTO) */ public void positionCreatedOrUpdatedOrDeleted(String mapName, long timeStamp, PositionDTO position){ // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see net.sf.magicmap.client.controller.ServerManager#submitClientInfo() */ public void submitClientInfo(){ if (!isConnected()) return; final SignalCharacterDTO signalCharacter = currentSignalCharacter(); Thread thread = new Thread() { public void run(){ synchronized (mutex){ try{ int x = controller.getClientPosX(); int y = controller.getClientPosY(); if (x < 0) x = 0; else if (x >= controller.getCurrentMap().width) x = controller.getCurrentMap().width - 1; if (y < 0) y = 0; else if (y >= controller.getCurrentMap().height) y = controller.getCurrentMap().height - 1;; positionFacade.createOrUpdateClientPosition(sessionId, controller.getCurrentMap().name, x, y, signalCharacter, controller.getClient().getMacAddress(), controller.getClient().isFix()); // TODO: Zusätzliche Parameter zur Position System.out.println("Client info submitted."); } catch (Exception e){ e.printStackTrace(); } } } }; thread.start(); } /* (non-Javadoc) * @see net.sf.magicmap.client.controller.ServerManager#reloadMap() */ public void reloadMap(){ // TODO Auto-generated method stub } /* (non-Javadoc) * @see net.sf.magicmap.client.controller.ServerManager#closeMap() */ public void closeMap(){ // TODO Auto-generated method stub } } Index: Controller.java =================================================================== RCS file: /cvsroot/magicmap/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Controller.java 12 Feb 2005 16:00:28 -0000 1.2 --- Controller.java 11 May 2005 10:51:27 -0000 1.3 *************** *** 9,16 **** import java.net.MalformedURLException; import java.net.UnknownHostException; - import java.rmi.RemoteException; import java.util.ArrayList; - import net.sf.magicmap.client.delegate.PositionDelegate; import net.sf.magicmap.client.gui.utils.CallbackHandler; import net.sf.magicmap.client.interfaces.CreateNewMapCallback; --- 9,14 ---- *************** *** 87,93 **** this.scanner = null; this.currentMap = null; ! this.serverManager = new ServerManager(this); this.pollhandler = new PollHandler(this); - this.poller = new ServerPoller(serverManager, pollhandler); this.callbackHandler = new CallbackHandler(); try{ --- 85,90 ---- this.scanner = null; this.currentMap = null; ! this.serverManager = null; this.pollhandler = new PollHandler(this); this.callbackHandler = new CallbackHandler(); try{ *************** *** 214,218 **** */ public boolean isConnected(){ ! return serverManager.isConnected(); } --- 211,215 ---- */ public boolean isConnected(){ ! return (serverManager != null && serverManager.isConnected()); } *************** *** 235,246 **** this.currentMap = map; try{ ! this.serverManager.positionDelgate = new PositionDelegate(); this.mapView.loadMap(map); } catch (MalformedURLException e){ System.out.println("Map loading failed." + e.getMessage()); closeMap(); - } catch (RemoteException e){ - System.out.println("Map loading failed." + e.getMessage()); - closeMap(); } if (isMapLoaded() && isConnected()){ --- 232,240 ---- this.currentMap = map; try{ ! serverManager.reloadMap(); this.mapView.loadMap(map); } catch (MalformedURLException e){ System.out.println("Map loading failed." + e.getMessage()); closeMap(); } if (isMapLoaded() && isConnected()){ *************** *** 273,283 **** this.currentMap = null; this.mapView.unloadMap(); ! if (this.serverManager.positionDelgate != null){ ! try{ ! this.serverManager.positionDelgate.close(); ! } catch (IOException e){ ! e.printStackTrace(); ! } ! } poller.stop(); nodeModel.clear(); --- 267,271 ---- this.currentMap = null; this.mapView.unloadMap(); ! serverManager.closeMap(); poller.stop(); nodeModel.clear(); *************** *** 325,328 **** --- 313,323 ---- public void connect(ServerConnectCallback callback){ + if (Settings.isUseNoServer()){ + serverManager = new VirtualServerManager(this); + } else{ + serverManager = new SOAPServerManager(this); + } + // Poller erzeugen (benötigt ServerManager) + this.poller = new ServerPoller(serverManager, pollhandler); serverManager.connect(callback); } Index: ServerPoller.java =================================================================== RCS file: /cvsroot/magicmap/magicmapclient/src/net/sf/magicmap/client/controller/ServerPoller.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ServerPoller.java 12 Feb 2005 16:00:28 -0000 1.2 --- ServerPoller.java 11 May 2005 10:51:27 -0000 1.3 *************** *** 37,41 **** public void start(){ ! this.timer.schedule(builderTimerTask(), Settings.POLL_INTERVAL, Settings.POLL_INTERVAL); } --- 37,41 ---- public void start(){ ! this.timer.schedule(builderTimerTask(), Settings.POLL_DELAY, Settings.POLL_INTERVAL); } Index: ServerManager.java =================================================================== RCS file: /cvsroot/magicmap/magicmapclient/src/net/sf/magicmap/client/controller/ServerManager.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ServerManager.java 16 Feb 2005 09:02:31 -0000 1.5 --- ServerManager.java 11 May 2005 10:51:27 -0000 1.6 *************** *** 1,4 **** /* ! * Created on 12.12.2004 */ --- 1,7 ---- /* ! * Created on 10.05.2005 ! * ! * TODO To change the template for this generated file go to ! * Window - Preferences - Java - Code Style - Code Templates */ *************** *** 12,21 **** import java.util.Iterator; - import net.sf.magicmap.client.delegate.MapDelegate; - import net.sf.magicmap.client.delegate.PositionDelegate; - import net.sf.magicmap.client.delegate.SessionDelegate; - import net.sf.magicmap.client.delegate.interfaces.MapFacadeInterface; - import net.sf.magicmap.client.delegate.interfaces.PositionFacadeInterface; - import net.sf.magicmap.client.delegate.interfaces.SessionFacadeInterface; import net.sf.magicmap.client.interfaces.CreateNewMapCallback; import net.sf.magicmap.client.interfaces.CreatePositionCallback; --- 15,18 ---- *************** *** 28,36 **** import net.sf.magicmap.client.interfaces.ServerConnectCallback; import net.sf.magicmap.client.interfaces.ServerDisconnectCallback; - import net.sf.magicmap.client.meta.MapInfo; import net.sf.magicmap.client.model.measurement.SeenAccessPoint; - import net.sf.magicmap.client.utils.Settings; - import net.sf.magicmap.client.utils.Version; - import net.sf.magicmap.server.dto.MapDTO; import net.sf.magicmap.server.dto.PositionDTO; import net.sf.magicmap.server.dto.SignalCharacterDTO; --- 25,29 ---- *************** *** 38,64 **** /** - * Managet die Client-Server-Kommunikation sowie die - * Verbindung selbst. * @author thuebner */ ! public class ServerManager { ! ! private static String mutex = "net.sf.magicmap.client.controller.Controller"; ! ! private Controller controller; ! private SessionFacadeInterface sessionDelegate; // Verbindung zum Server ! private MapFacadeInterface mapDelegate; ! public PositionFacadeInterface positionDelgate; ! private long sessionId; ! private long timestamp; ! public ServerManager(Controller controller) { ! this.controller = controller; ! this.sessionDelegate = null; ! this.positionDelgate = null; ! this.mapDelegate = null; ! this.timestamp = -1; ! this.sessionId = -1; ! } public void resetTimestamp(){ --- 31,44 ---- /** * @author thuebner + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates */ ! public abstract class ServerManager { ! protected long sessionId = -1; ! protected long timestamp = -1; ! protected Controller controller; public void resetTimestamp(){ *************** *** 70,214 **** } ! /** ! * Stellt Verbindung zum Server her ! * ! */ ! public void connect(final ServerConnectCallback callback){ ! if (isConnected()){ ! System.out.println("Already connected."); ! } else{ ! Thread connectionThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! ServerManager.this.sessionDelegate = new SessionDelegate(); ! ServerManager.this.sessionId = ServerManager.this.sessionDelegate.connect(Settings.getClientName(), ! Settings.getClientMAC(), Settings.getClientPassword(), Version.PROTOCOL_VERSION); ! ServerManager.this.mapDelegate = new MapDelegate(); ! ServerManager.this.positionDelgate = new PositionDelegate(); ! callback.connected(ServerManager.this.sessionId); ! } catch (Exception e){ ! callback.connectionError(e); ! } ! } ! } ! }; ! connectionThread.start(); ! } ! } ! ! /** ! * ! * @param callback ! */ ! public void disconnect(final ServerDisconnectCallback callback){ ! if (isConnected()){ ! Thread disconnectionThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! ServerManager.this.sessionDelegate.disconnect(Settings.getClientName(), Settings.getClientMAC(), Settings ! .getClientPassword(), sessionId); ! ServerManager.this.positionDelgate = null; ! ServerManager.this.mapDelegate = null; ! ServerManager.this.sessionDelegate = null; ! callback.disconnected(); ! } catch (Exception e){ ! callback.disconnectionError(e); ! } ! ServerManager.this.sessionId = -1; ! } ! } ! }; ! disconnectionThread.start(); ! } ! } ! ! /** ! * ! * @param name ! * @param URL ! * @param width ! * @param height ! * @param callback ! */ ! public void createNewMap(final String name, final String URL, final int width, final int height, ! final CreateNewMapCallback callback){ ! if (isConnected()){ ! Thread mapCreationThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! ServerManager.this.mapDelegate.createNewMap(sessionId, name, URL, width, height); ! MapInfo mapinfo = new MapInfo(); ! mapinfo.name = name; ! mapinfo.imageURL = URL; ! mapinfo.width = width; ! mapinfo.height = height; ! callback.newMapCreated(mapinfo); ! } catch (Exception e){ ! e.printStackTrace(); ! callback.createNewMapError(e); ! } ! } ! } ! }; ! mapCreationThread.start(); ! } ! } ! ! /** ! * Liefert die eindeutigen Namen der auf dem Server angelegten Karten ! * zurück. ! * @param callback MapNamesCallback Objekt welches das MapNamesCallback implementiert ! * um die Kartennamen bzw. die ! */ ! public void retrieveMapNames(final MapNamesCallback callback){ ! if (isConnected()){ ! Thread getMapNamesThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! String[] names = ServerManager.this.mapDelegate.getMapNames(); ! callback.mapNamesReceived(names); ! } catch (Exception e){ ! e.printStackTrace(); ! callback.getMapNamesError(e); ! } ! } ! } ! }; ! getMapNamesThread.start(); ! } } ! /** ! * Lädt Daten zu einer Karte vom Server. Das Ergebniss wird über eine Callback ! * Funktionen geliefert. ! * @param name ! * @param callback ! */ ! public void retrieveMap(final String name, final MapCallback callback){ ! if (isConnected()){ ! Thread getMapThread = new Thread() { ! public void run(){ ! synchronized (mutex){ ! try{ ! MapDTO mapDTO = ServerManager.this.mapDelegate.getMap(name); ! callback.mapReceived(mapDTO); ! } catch (Exception e){ ! callback.getMapError(e); ! } ! } ! } ! }; ! getMapThread.start(); ! } ! } /** --- 50,60 ---- } ! public ServerManager(Controller controller) { ! this.controller = controller; } ! public abstract void reloadMap(); ! public abstract void closeMap(); /** *************** *** 217,221 **** * @return */ ! private SignalCharacterDTO currentSignalCharacter(){ SignalCharacterDTO signalCharacter = new SignalCharacterDTO(); Collection accessPoints = controller.getMeasurementModel().getAccessPoints(); --- 63,67 ---- * @return */ ! protected SignalCharacterDTO currentSignalCharacter(){ SignalCharacterDTO signalCharacter = new SignalCharacterDTO(); Collection accessPoints = controller.getMeasurementModel().getAccessPoints(); *************** *** 230,235 **** if (signalCharacter.getSimpleScanResults() == null){ list = new ArrayList(); ! } else { ! list = new ArrayList(Arrays.asList(signalCharacter.getSimpleScanResults())); } Calendar c = new GregorianCalendar(); --- 76,81 ---- if (signalCharacter.getSimpleScanResults() == null){ list = new ArrayList(); ! } else{ ! list = new ArrayList(Arrays.asList(signalCharacter.getSimpleScanResults())); } Calendar c = new GregorianCalendar(); *************** *** 250,281 **** /** * Erzeugt einen Referenzpunkt auf dem Server * @param node * @param callback */ ! public void createLocation(final int x, final int y, final boolean fixed, final String name, ! final CreatePositionCallback callback){ ! if (isConnected()){ ! final SignalCharacterDTO signalCharacter = currentSignalCharacter(); ! System.out.println("signalCharacter.getSimpleScanResults() " + signalCharacter.getSimpleScanResults()); ! ! Thread createPositionThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! ServerManager.this.positionDelgate.createOrUpdatePosition(ServerManager.this.sessionId, controller ! .getCurrentMap().name, x, y, signalCharacter, name, fixed); ! // TODO: Zusätzliche Parameter zur Position ! callback.positionCreated(); ! } catch (Exception e){ ! callback.positionCreationError(e); ! } ! } ! } ! }; ! createPositionThread.start(); ! } ! } /** --- 96,144 ---- /** + * Stellt Verbindung zum Server her + * + */ + public abstract void connect(final ServerConnectCallback callback); + + /** + * + * @param callback + */ + public abstract void disconnect(final ServerDisconnectCallback callback); + + /** + * + * @param name + * @param URL + * @param width + * @param height + * @param callback + */ + public abstract void createNewMap(final String name, final String URL, final int width, final int height, + final CreateNewMapCallback callback); + + /** + * Liefert die eindeutigen Namen der auf dem Server angelegten Karten + * zurück. + * @param callback MapNamesCallback Objekt welches das MapNamesCallback implementiert + * um die Kartennamen bzw. die + */ + public abstract void retrieveMapNames(final MapNamesCallback callback); + + /** + * Lädt Daten zu einer Karte vom Server. Das Ergebniss wird über eine Callback + * Funktionen geliefert. + * @param name + * @param callback + */ + public abstract void retrieveMap(final String name, final MapCallback callback); + + /** * Erzeugt einen Referenzpunkt auf dem Server * @param node * @param callback */ ! public abstract void createLocation(final int x, final int y, final boolean fixed, final String name, ! final CreatePositionCallback callback); /** *************** *** 285,308 **** * @param callback */ ! public void deletePosition(final long positionId, final DeletePositionCallback callback){ ! if (isConnected()){ ! Thread deletePositionThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! ServerManager.this.positionDelgate.deletePosition(sessionId, positionId); ! System.out.println("PositionID " + positionId + " deleted."); ! // TODO: Zusätzliche Parameter zur Position ! callback.positionDeleted(positionId); ! } catch (Exception e){ ! callback.positionDeleteError(e); ! } ! } ! } ! }; ! deletePositionThread.start(); ! } ! } /** --- 148,152 ---- * @param callback */ ! public abstract void deletePosition(final long positionId, final DeletePositionCallback callback); /** *************** *** 312,335 **** * @param callback */ ! public void movePosition(final long positionId, final int x, final int y, final boolean fixed, ! final MovePositionCallback callback){ ! if (isConnected()){ ! Thread movePositionThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! ServerManager.this.positionDelgate.movePosition(sessionId, positionId, x, y, fixed); ! // TODO: Zusätzliche Parameter zur Position ! callback.positionMoved(positionId); ! } catch (Exception e){ ! callback.positionMoveError(e); ! } ! } ! } ! }; ! movePositionThread.start(); ! } ! } /* --- 156,161 ---- * @param callback */ ! public abstract void movePosition(final long positionId, final int x, final int y, final boolean fixed, ! final MovePositionCallback callback); /* *************** *** 338,372 **** public void movePosition(long sessionId, long positionId, int newPositionX, int newPositionY) throws RemoteException, public void deletePosition(long sessionId, long positionId) throws RemoteException, MapException, SessionException{ ! */ ! ! /** ! * Eine Position von (-1,-1) bedeutet, dass der Client nicht fixiert ist sondern ! * frei beweglich ist. Es werden dann nur seine Signalstärken geupdatet. ! * @param x X-Koordinate bzgl. Map ! * @param y Y-Koordinate bzgl. Map ! * @param clientMac MAC-Adresses des betreffenden Clients ! * @param callback Callback ! */ ! public void setClientPosition(final int x, final int y, final boolean fixed, final String clientMac, ! final PositionCallback callback){ ! if (isConnected()){ ! Thread positionThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! ServerManager.this.positionDelgate.createOrUpdateClientPosition(sessionId, ! controller.getCurrentMap().name, x, y, currentSignalCharacter(), clientMac, fixed); ! // TODO: Zusätzliche Parameter zur Position ! callback.positionUpdated(clientMac); ! } catch (Exception e){ ! callback.positionError(e); ! } ! } ! } ! }; ! positionThread.start(); ! } ! } /** --- 164,169 ---- public void movePosition(long sessionId, long positionId, int newPositionX, int newPositionY) throws RemoteException, public void deletePosition(long sessionId, long positionId) throws RemoteException, MapException, SessionException{ ! */public abstract void setClientPosition(final int x, final int y, final boolean fixed, final String clientMac, ! final PositionCallback callback); /** *************** *** 378,471 **** * @param callback Callback */ ! public void setAccessPointPosition(final int x, final int y, final boolean fixed, final String accessPointMac, ! final PositionCallback callback){ ! if (isConnected()){ ! Thread positionThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! ServerManager.this.positionDelgate.createOrUpdateAccessPosition(sessionId, ! controller.getCurrentMap().name, x, y, accessPointMac, fixed); ! // TODO: Zusätzliche Parameter zur Position ! callback.positionUpdated(accessPointMac); ! } catch (Exception e){ ! callback.positionError(e); ! } ! } ! } ! }; ! positionThread.start(); ! } ! } ! ! public void fetchPositionsFromServer(final FetchPositionsCallback callback){ ! if (isConnected()){ ! Thread fetchPositionsThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! PositionDTO[] positions = ServerManager.this.positionDelgate.getPositionsForMapSince( ! ServerManager.this.sessionId, controller.getCurrentMap().name, timestamp); ! for (int i = 0; i < positions.length; i++){ ! if (positions[i].getLastModified().longValue() > ServerManager.this.timestamp){ ! ServerManager.this.timestamp = positions[i].getLastModified().longValue(); ! } ! } ! callback.positionsFetched(positions); ! } catch (Exception e){ ! callback.positionFetchError(e); ! } ! } ! } ! }; ! fetchPositionsThread.start(); ! } ! } /* (non-Javadoc) * @see net.sf.magicmap.client.interfaces.ServerPollerListener#positionCreatedOrUpdatedOrDeleted(java.lang.String, long, net.sf.magicmap.client.delegate.dto.PositionDTO) ! */ ! public void positionCreatedOrUpdatedOrDeleted(String mapName, long timeStamp, PositionDTO position){ ! // TODO Auto-generated method stub ! ! } /** * @param poller */ ! public void submitClientInfo(){ ! if (isConnected() && !controller.isInvisible()){ ! final SignalCharacterDTO signalCharacter = currentSignalCharacter(); ! Thread updateClientThread = new Thread() { ! ! public void run(){ ! synchronized (mutex){ ! try{ ! int x = controller.getClientPosX(); ! int y = controller.getClientPosY(); ! if (x < 0) ! x = 0; ! else if (x >= controller.getCurrentMap().width) x = controller.getCurrentMap().width - 1; ! if (y < 0) ! y = 0; ! else if (y >= controller.getCurrentMap().height) y = controller.getCurrentMap().height - 1;; ! ! ServerManager.this.positionDelgate.createOrUpdateClientPosition(ServerManager.this.sessionId, controller ! .getCurrentMap().name, x, y, signalCharacter, controller.getClient().getMacAddress(), controller ! .getClient().isFix()); ! // TODO: Zusätzliche Parameter zur Position ! System.out.println("Client info submitted."); ! } catch (Exception e){ ! e.printStackTrace(); ! } ! } ! } ! }; ! updateClientThread.start(); ! } ! } ! } \ No newline at end of file --- 175,190 ---- * @param callback Callback */ ! public abstract void setAccessPointPosition(final int x, final int y, final boolean fixed, ! final String accessPointMac, final PositionCallback callback); ! public abstract void fetchPositionsFromServer(final FetchPositionsCallback callback); /* (non-Javadoc) * @see net.sf.magicmap.client.interfaces.ServerPollerListener#positionCreatedOrUpdatedOrDeleted(java.lang.String, long, net.sf.magicmap.client.delegate.dto.PositionDTO) ! */public abstract void positionCreatedOrUpdatedOrDeleted(String mapName, long timeStamp, PositionDTO position); /** * @param poller */ ! public abstract void submitClientInfo(); } \ No newline at end of file |