htiextension/com.nokia.s60tools.hticonnection/src/com/nokia/s60tools/hticonnection/services/connectiontestservice/ConnectionTestService.java
author dpodwall
Tue, 12 Jan 2010 13:17:53 -0600
changeset 0 61163b28edca
permissions -rw-r--r--
initial EPL conversion
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.services.connectiontestservice;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    19
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    20
import java.util.List;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    21
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    22
import com.nokia.s60tools.hticonnection.core.RequestQueueManager;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    23
import com.nokia.s60tools.hticonnection.core.RequestResult;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    24
import com.nokia.s60tools.hticonnection.exceptions.ConnectionException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    25
import com.nokia.s60tools.hticonnection.exceptions.HTIException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    26
import com.nokia.s60tools.hticonnection.exceptions.ServiceShutdownException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    27
import com.nokia.s60tools.hticonnection.services.HTIVersion;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    28
import com.nokia.s60tools.hticonnection.services.IConnectionTestService;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    29
import com.nokia.s60tools.util.console.IConsolePrintUtility;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    30
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    31
/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    32
 * Service that contains interface for testing if connection is ready for use.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    33
 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    34
public class ConnectionTestService implements IConnectionTestService{
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    35
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    36
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    37
	 * Print utility used to report errors, warnings, and info messages.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    38
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    39
	private final IConsolePrintUtility printUtility;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    40
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    41
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    42
	 * Constructor. 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    43
	 * @param printUtility Used for printing messages.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    44
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    45
	public ConnectionTestService(IConsolePrintUtility printUtility){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    46
		this.printUtility = printUtility;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    47
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    48
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    49
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    50
	 * @see com.nokia.s60tools.hticonnection.services.IConnectionTestService#isReady()
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    51
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    52
	public boolean isReady(){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    53
		ConnectionTestRequest request = new ConnectionTestRequest();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    54
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    55
		try {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    56
			// Getting result for connection test.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    57
			RequestResult result = RequestQueueManager.getInstance().submit(request, printUtility);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    58
			return result.getBooleanData();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    59
		} catch (Exception e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    60
			// Request failed.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    61
			return false;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    62
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    63
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    64
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    65
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    66
	 * @see com.nokia.s60tools.hticonnection.services.IConnectionTestService#listServices()
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    67
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    68
	public List<String> listServices() throws HTIException, ConnectionException, ServiceShutdownException{
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    69
		ListServiceRequest request = new ListServiceRequest();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    70
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    71
		// Getting result for connection test.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    72
		RequestResult result = RequestQueueManager.getInstance().submit(request, printUtility);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    73
		return result.getListData();
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
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    77
	 * @see com.nokia.s60tools.hticonnection.services.IConnectionTestService#getVersion()
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    78
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    79
	public HTIVersion getVersion() throws HTIException, ConnectionException, ServiceShutdownException{
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    80
		GetVersionRequest request = new GetVersionRequest();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    81
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    82
		// Getting result for connection test.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    83
		RequestResult result = RequestQueueManager.getInstance().submit(request, printUtility);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    84
		return result.getHTIVersionData();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    85
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    86
}