htiextension/com.nokia.s60tools.hticonnection/src/com/nokia/s60tools/hticonnection/connection/HTIConnectedService.java
author Matti Laitinen <matti.t.laitinen@nokia.com>
Thu, 04 Mar 2010 13:38:40 +0200
changeset 7 018264c44c89
parent 0 61163b28edca
permissions -rw-r--r--
HTI Connection v1.3.1 - Supporting Carbide 2.5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     1
/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     3
* All rights reserved.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     4
* This component and the accompanying materials are made available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     6
* which accompanies this distribution, and is available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     8
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     9
* Initial Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    11
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    12
* Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    13
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    14
* Description:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    15
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    16
*/
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    17
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    18
package com.nokia.s60tools.hticonnection.connection;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    19
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    20
import org.eclipse.core.runtime.IProgressMonitor;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    21
import org.osgi.framework.Version;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    22
7
018264c44c89 HTI Connection v1.3.1 - Supporting Carbide 2.5
Matti Laitinen <matti.t.laitinen@nokia.com>
parents: 0
diff changeset
    23
import com.nokia.carbide.remoteconnections.interfaces.AbstractConnectedService2;
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    24
import com.nokia.carbide.remoteconnections.interfaces.AbstractSynchronizedConnection;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    25
import com.nokia.carbide.remoteconnections.interfaces.IService;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    26
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    27
import com.nokia.s60tools.hticonnection.core.HtiConnection;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    28
import com.nokia.s60tools.hticonnection.core.HtiConnection.ConnectionStatus;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    29
import com.nokia.s60tools.hticonnection.resources.Messages;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    30
import com.nokia.s60tools.hticonnection.services.HTIVersion;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    31
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    32
/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    33
 * Connected service for HTI to contain connection information.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    34
 */
7
018264c44c89 HTI Connection v1.3.1 - Supporting Carbide 2.5
Matti Laitinen <matti.t.laitinen@nokia.com>
parents: 0
diff changeset
    35
public class HTIConnectedService extends AbstractConnectedService2 {
018264c44c89 HTI Connection v1.3.1 - Supporting Carbide 2.5
Matti Laitinen <matti.t.laitinen@nokia.com>
parents: 0
diff changeset
    36
		
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    37
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    38
	 * Constructor.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    39
	 * @param service Service that is connected.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    40
	 * @param connection Connection that is connected.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    41
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    42
	public HTIConnectedService(IService service,
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    43
			AbstractSynchronizedConnection connection) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    44
		super(service, connection);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    45
		currentStatus = new Status();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    46
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    47
		currentStatus.setEStatus(EStatus.DOWN, Messages.getString("HTIConnectedService.NotConnected_ShortMsg"), ""); //$NON-NLS-1$ //$NON-NLS-2$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    48
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    49
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    50
	/* (non-Javadoc)
7
018264c44c89 HTI Connection v1.3.1 - Supporting Carbide 2.5
Matti Laitinen <matti.t.laitinen@nokia.com>
parents: 0
diff changeset
    51
	 * @see com.nokia.carbide.remoteconnections.interfaces.AbstractConnectedService2#runTestStatus(org.eclipse.core.runtime.IProgressMonitor)
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    52
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    53
	protected TestResult runTestStatus(IProgressMonitor monitor) {
7
018264c44c89 HTI Connection v1.3.1 - Supporting Carbide 2.5
Matti Laitinen <matti.t.laitinen@nokia.com>
parents: 0
diff changeset
    54
		if(!externalTesting) {
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    55
			// Not using automatic testing as it would take too much resources. Returning currently known status.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    56
			IStatus status = getStatusFromHtiConnection();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    57
			return new TestResult(status.getEStatus(), status.getShortDescription(), status.getLongDescription());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    58
		}
7
018264c44c89 HTI Connection v1.3.1 - Supporting Carbide 2.5
Matti Laitinen <matti.t.laitinen@nokia.com>
parents: 0
diff changeset
    59
			
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    60
		// Testing connection when user has ordered testing command from the settings wizard.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    61
		monitor.beginTask("Testing HTI Service", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    62
		IStatus status = HtiConnection.getInstance().testConnection(connection);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    63
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    64
		monitor.done();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    65
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    66
		return new TestResult(status.getEStatus(), status.getShortDescription(), status.getLongDescription());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    67
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    68
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    69
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    70
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectedService#getStatus()
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    71
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    72
	public IStatus getStatus() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    73
		return currentStatus;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    74
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    75
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    76
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    77
	 * Returns status of this connection.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    78
	 * @return Status of this connection.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    79
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    80
	public IStatus getStatusFromHtiConnection() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    81
		HtiConnection htiConnection = HtiConnection.getInstance();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    82
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    83
		HTIConnectionStatus status = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    84
		if(connection.equals(htiConnection.getCurrentConnection())) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    85
			// This connection is active, getting status.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    86
			ConnectionStatus connStatus = htiConnection.getConnectionStatus();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    87
			switch (connStatus) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    88
			case CONNECTED:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    89
				HTIVersion version = HtiConnection.getInstance().getHTIVersion();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    90
				status = new HTIConnectionStatus(this,
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    91
						EStatus.UP,
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    92
						Messages.getString("HTIConnectedService.Connected_ShortMsg"), //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    93
						Messages.getString("HTIConnectedService.ConnectedToHti_LongMsg") + version.toString()); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    94
				break;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    95
			case CONNECTING:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    96
				status = new HTIConnectionStatus(this,
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    97
						EStatus.UP,
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    98
						Messages.getString("HTIConnectedService.TryingToConnect_ShortMsg"), //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    99
						""); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   100
				break;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   101
			case SHUTDOWN:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   102
				status = new HTIConnectionStatus(this,
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   103
						EStatus.DOWN,
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   104
						Messages.getString("HTIConnectedService.NotConnected_ShortMsg"), //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   105
						""); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   106
				break;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   107
			case TESTING:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   108
				status = new HTIConnectionStatus(this, EStatus.UP, Messages.getString("HTIConnectedService.Testing_ShortMsg"), ""); //$NON-NLS-1$ //$NON-NLS-2$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   109
				break;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   110
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   111
		} 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   112
		if(status == null) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   113
			// This connection is not active.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   114
			status = new HTIConnectionStatus(this, EStatus.DOWN, Messages.getString("HTIConnectedService.NotConnected_ShortMsg"), "");	 //$NON-NLS-1$ //$NON-NLS-2$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   115
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   116
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   117
		return status;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   118
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   119
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   120
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   121
	 * Refreshes current status.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   122
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   123
	public void refreshStatus() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   124
		IStatus status = getStatusFromHtiConnection();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   125
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   126
		currentStatus.setEStatus(status.getEStatus(), status.getShortDescription(), status.getLongDescription());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   127
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   128
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   129
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   130
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectedService#setDeviceOS(java.lang.String, org.osgi.framework.Version)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   131
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   132
	public void setDeviceOS(String familyName, Version version) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   133
		// Not implemented.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   134
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   135
}