author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 29 Jul 2010 15:59:01 -0700 | |
changeset 460 | c0bff5ed874c |
parent 459 | c278f0c8917f |
permissions | -rw-r--r-- |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
1 |
/** |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
2 |
* Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
3 |
* All rights reserved. |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
8 |
* |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
* Contributors: |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
12 |
* Description: |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
13 |
* Overview: |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
14 |
* Details: |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
15 |
* Platforms/Drives/Compatibility: |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
16 |
* Assumptions/Requirement/Pre-requisites: |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
17 |
* Failures and causes: |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
18 |
*/ |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
19 |
package org.symbian.tools.mtw.ui.deployment.bluetooth; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
20 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
21 |
import java.io.EOFException; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
22 |
import java.io.File; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
23 |
import java.io.FileInputStream; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
24 |
import java.io.IOException; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
25 |
import java.io.InputStream; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
26 |
import java.io.OutputStream; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
27 |
import java.text.MessageFormat; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
28 |
import java.util.Collection; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
29 |
import java.util.LinkedList; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
30 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
31 |
import javax.bluetooth.BluetoothConnectionException; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
32 |
import javax.bluetooth.BluetoothStateException; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
33 |
import javax.bluetooth.DeviceClass; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
34 |
import javax.bluetooth.DiscoveryListener; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
35 |
import javax.bluetooth.LocalDevice; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
36 |
import javax.bluetooth.RemoteDevice; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
37 |
import javax.bluetooth.ServiceRecord; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
38 |
import javax.bluetooth.UUID; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
39 |
import javax.microedition.io.Connector; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
40 |
import javax.obex.ClientSession; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
41 |
import javax.obex.HeaderSet; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
42 |
import javax.obex.Operation; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
43 |
import javax.obex.ResponseCodes; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
44 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
45 |
import org.eclipse.core.runtime.CoreException; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
46 |
import org.eclipse.core.runtime.IProgressMonitor; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
47 |
import org.eclipse.core.runtime.IStatus; |
460
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
48 |
import org.eclipse.core.runtime.MultiStatus; |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
49 |
import org.eclipse.core.runtime.PlatformObject; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
50 |
import org.eclipse.core.runtime.Status; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
51 |
import org.eclipse.core.runtime.SubProgressMonitor; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
52 |
import org.eclipse.ui.IMemento; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
53 |
import org.symbian.tools.mtw.core.MTWCore; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
54 |
import org.symbian.tools.mtw.core.projects.IMTWProject; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
55 |
import org.symbian.tools.mtw.core.runtimes.IPackager; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
56 |
import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
57 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
58 |
public class BluetoothTarget extends PlatformObject implements IDeploymentTarget { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
59 |
private static final UUID OBEX_OBJECT_PUSH = new UUID(0x1105); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
60 |
private String serviceURL; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
61 |
private RemoteDevice device; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
62 |
protected String[] exceptionCodes = new String[] { "OBEX_HTTP_UNSUPPORTED_TYPE", "OBEX_HTTP_FORBIDDEN" }; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
63 |
private String message = "Deployment was successful. Please follow on-screen instructions to complete application deployment on your device."; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
64 |
private final String name; |
456
12b549765c34
Refactoring and adding better bluetooth target decoration
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
455
diff
changeset
|
65 |
private final BluetoothTargetType provider; |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
66 |
private final Collection<IStatus> statuses = new LinkedList<IStatus>(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
67 |
|
456
12b549765c34
Refactoring and adding better bluetooth target decoration
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
455
diff
changeset
|
68 |
public BluetoothTarget(String name, RemoteDevice device, BluetoothTargetType provider) { |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
69 |
this.name = name; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
70 |
this.device = device; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
71 |
this.provider = provider; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
72 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
73 |
|
460
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
74 |
public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) throws CoreException { |
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
75 |
message = "Deployment was successful. Please follow on-screen instructions to complete application deployment on your device."; |
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
76 |
statuses.clear(); |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
77 |
monitor.beginTask(String.format("Deploying application %s to %s", project.getName(), name), |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
78 |
IProgressMonitor.UNKNOWN); |
459
c278f0c8917f
Refactored packager and deployer interfaces
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
457
diff
changeset
|
79 |
final File application = packager.packageApplication(project, new SubProgressMonitor(monitor, 100)); |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
80 |
try { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
81 |
deployWidget(application, packager.getFileType(project), new SubProgressMonitor(monitor, 10)); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
82 |
} finally { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
83 |
application.delete(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
84 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
85 |
monitor.done(); |
460
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
86 |
MultiStatus multiStatus = new MultiStatus(MTWCore.PLUGIN_ID, 0, message, null); |
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
87 |
for (IStatus status : statuses) { |
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
88 |
multiStatus.add(status); |
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
89 |
} |
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
90 |
return multiStatus; |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
91 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
92 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
93 |
private void deployWidget(File inputWidget, String fileType, IProgressMonitor progressMonitor) throws CoreException { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
94 |
if (device == null) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
95 |
provider.discoverTargets(new SubProgressMonitor(progressMonitor, 10)); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
96 |
if (device == null) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
97 |
throw new CoreException(new Status(IStatus.ERROR, MTWCore.PLUGIN_ID, String.format( |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
98 |
"Device %s is not available", name))); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
99 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
100 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
101 |
progressMonitor.beginTask("Deploying application", IProgressMonitor.UNKNOWN); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
102 |
InputStream in = null; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
103 |
OutputStream os = null; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
104 |
Operation putOperation = null; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
105 |
ClientSession clientSession = null; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
106 |
try { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
107 |
if (!provider.isBloothToothConnected()) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
108 |
String msg = "Bluetooth is either disabled or not present in the system."; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
109 |
emitStatus(IStatus.ERROR, msg, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
110 |
return; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
111 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
112 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
113 |
String message = MessageFormat.format("Searching for the service for the selected device \"{0}\"", |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
114 |
new Object[] { getName() }); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
115 |
emitStatus(IStatus.OK, message, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
116 |
String servicesFound = getServicesFound(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
117 |
if (servicesFound == null || servicesFound.length() < 1) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
118 |
message = MessageFormat.format("Cannot find service to the device \"{0}\"", new Object[] { getName() }); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
119 |
emitStatus(IStatus.ERROR, message, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
120 |
return; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
121 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
122 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
123 |
message = MessageFormat.format("Service for the device \"{0}\" found", new Object[] { getName() }); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
124 |
emitStatus(IStatus.OK, message, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
125 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
126 |
clientSession = (ClientSession) Connector.open(servicesFound); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
127 |
HeaderSet hsConnectReply = clientSession.connect(null); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
128 |
if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
129 |
emitStatus(IStatus.OK, "Failed to connect to the service", progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
130 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
131 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
132 |
emitStatus(IStatus.OK, "Deployment Started", progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
133 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
134 |
HeaderSet hsOperation = clientSession.createHeaderSet(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
135 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
136 |
if (progressMonitor.isCanceled()) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
137 |
emitStatus(IStatus.CANCEL, "Deployment was canceled", progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
138 |
return; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
139 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
140 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
141 |
// Send widget to server |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
142 |
in = new FileInputStream(inputWidget); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
143 |
message = MessageFormat.format("Deploying file from {0}", new Object[] { inputWidget.getAbsolutePath() }); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
144 |
emitStatus(IStatus.OK, message, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
145 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
146 |
hsOperation.setHeader(HeaderSet.NAME, inputWidget.getName()); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
147 |
hsOperation.setHeader(HeaderSet.TYPE, fileType); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
148 |
int size = (int) inputWidget.length(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
149 |
byte file[] = new byte[size]; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
150 |
hsOperation.setHeader(HeaderSet.LENGTH, new Long(file.length)); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
151 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
152 |
// Create PUT Operation |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
153 |
putOperation = clientSession.put(hsOperation); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
154 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
155 |
os = putOperation.openOutputStream(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
156 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
157 |
long start = System.currentTimeMillis(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
158 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
159 |
byte[] buf = new byte[16 * 1024]; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
160 |
int len; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
161 |
while ((len = in.read(buf)) > 0) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
162 |
os.write(buf, 0, len); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
163 |
if (progressMonitor.isCanceled()) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
164 |
putOperation.abort(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
165 |
emitStatus(IStatus.CANCEL, "Deployment was canceled", progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
166 |
return; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
167 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
168 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
169 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
170 |
os.flush(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
171 |
os.close(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
172 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
173 |
long elapsed = System.currentTimeMillis() - start; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
174 |
emitStatus(IStatus.OK, "elapsed time: " + elapsed / 1000.0 + " seconds", progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
175 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
176 |
int responseCode = putOperation.getResponseCode(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
177 |
if (responseCode == ResponseCodes.OBEX_HTTP_OK) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
178 |
message = MessageFormat.format("File deployed to {0}", new Object[] { getName() }); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
179 |
emitStatus(IStatus.OK, message, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
180 |
} else { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
181 |
message = "Error during deployment, OBEX error: " + responseCode; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
182 |
emitStatus(IStatus.ERROR, message, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
183 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
184 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
185 |
} catch (BluetoothConnectionException x) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
186 |
String message = getExceptionMessage(x.getMessage()); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
187 |
emitStatus(IStatus.ERROR, message, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
188 |
} catch (IOException e) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
189 |
String message = getExceptionMessage(e.getMessage()); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
190 |
emitStatus(IStatus.ERROR, message, progressMonitor); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
191 |
} finally { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
192 |
try { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
193 |
if (in != null) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
194 |
in.close(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
195 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
196 |
if (putOperation != null) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
197 |
putOperation.close(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
198 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
199 |
if (clientSession != null) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
200 |
clientSession.disconnect(null); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
201 |
clientSession.close(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
202 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
203 |
} catch (EOFException eof) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
204 |
// EOFException is now caught |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
205 |
// Ignore the error since deployment has already completed |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
206 |
//Activator.log(IStatus.ERROR, "EOF encountered while cleaning up Bluetooth deployment", eof); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
207 |
} catch (IOException x) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
208 |
MTWCore.log("Error cleaning up BlueTooth deployment", x); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
209 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
210 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
211 |
return; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
212 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
213 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
214 |
protected void emitStatus(int severity, String statusDescription, IProgressMonitor monitor) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
215 |
statuses.add(new Status(severity, MTWCore.PLUGIN_ID, statusDescription)); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
216 |
monitor.setTaskName(statusDescription); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
217 |
if (severity != IStatus.OK) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
218 |
message = statusDescription; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
219 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
220 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
221 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
222 |
/** |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
223 |
* Returns the customized methods from the exception error code. If it |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
224 |
* matches it returns the customized message else returns the exception itself |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
225 |
* @param message exception message |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
226 |
* @return the customized message |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
227 |
*/ |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
228 |
protected String getExceptionMessage(String message) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
229 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
230 |
if (message.contains(exceptionCodes[0])) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
231 |
return "Device does not support the widget deployment"; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
232 |
} else if (message.contains(exceptionCodes[1])) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
233 |
return "Deployment rejected by the device"; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
234 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
235 |
return message; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
236 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
237 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
238 |
public String getId() { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
239 |
return getName(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
240 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
241 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
242 |
public String getName() { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
243 |
return name; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
244 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
245 |
|
456
12b549765c34
Refactoring and adding better bluetooth target decoration
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
455
diff
changeset
|
246 |
private String getServicesFound() { |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
247 |
try { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
248 |
serviceURL = ""; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
249 |
UUID serviceUUID = OBEX_OBJECT_PUSH; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
250 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
251 |
final Object serviceSearchCompletedEvent = new Object(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
252 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
253 |
DiscoveryListener listener = new DiscoveryListener() { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
254 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
255 |
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
256 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
257 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
258 |
public void inquiryCompleted(int discType) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
259 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
260 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
261 |
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
262 |
try { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
263 |
for (int i = 0; i < servRecord.length; i++) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
264 |
if (servRecord[i].getHostDevice().getFriendlyName(false).equals(name)) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
265 |
serviceURL = servRecord[i].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
266 |
false); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
267 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
268 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
269 |
} catch (BluetoothStateException e) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
270 |
MTWCore.log(e.getMessage(), e); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
271 |
} catch (IOException e) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
272 |
MTWCore.log(e.getMessage(), e); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
273 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
274 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
275 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
276 |
public void serviceSearchCompleted(int transID, int respCode) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
277 |
synchronized (serviceSearchCompletedEvent) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
278 |
serviceSearchCompletedEvent.notifyAll(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
279 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
280 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
281 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
282 |
}; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
283 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
284 |
UUID[] searchUuidSet = new UUID[] { serviceUUID }; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
285 |
int[] attrIDs = new int[] { 0x0100 }; // Service name |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
286 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
287 |
synchronized (serviceSearchCompletedEvent) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
288 |
LocalDevice.getLocalDevice().getDiscoveryAgent() |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
289 |
.searchServices(attrIDs, searchUuidSet, device, listener); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
290 |
serviceSearchCompletedEvent.wait(); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
291 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
292 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
293 |
} catch (IOException e) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
294 |
MTWCore.log("Error in Bluetooth service discovery", e); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
295 |
} catch (InterruptedException e) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
296 |
MTWCore.log("Error in Bluetooth service discovery", e); |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
297 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
298 |
return serviceURL; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
299 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
300 |
|
460
c0bff5ed874c
Local filesystem deployment was added
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
459
diff
changeset
|
301 |
public void init(IMTWProject project, IPackager packager, IMemento memento) { |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
302 |
// nothing |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
303 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
304 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
305 |
public void save(IMemento memento) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
306 |
// nothing |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
307 |
} |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
308 |
|
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
309 |
public void setAddress(RemoteDevice device) { |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
310 |
this.device = device; |
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
311 |
} |
456
12b549765c34
Refactoring and adding better bluetooth target decoration
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
455
diff
changeset
|
312 |
|
12b549765c34
Refactoring and adding better bluetooth target decoration
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
455
diff
changeset
|
313 |
public boolean isDiscovered() { |
12b549765c34
Refactoring and adding better bluetooth target decoration
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
455
diff
changeset
|
314 |
return device != null; |
12b549765c34
Refactoring and adding better bluetooth target decoration
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
455
diff
changeset
|
315 |
} |
457
f1087591ff71
Targets presentation can be customized
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
456
diff
changeset
|
316 |
|
f1087591ff71
Targets presentation can be customized
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
456
diff
changeset
|
317 |
public String getDescription() { |
f1087591ff71
Targets presentation can be customized
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
456
diff
changeset
|
318 |
return device == null ? "This device was remembered from past sessions and may not be available" : String |
f1087591ff71
Targets presentation can be customized
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
456
diff
changeset
|
319 |
.format("Remote device with address %s", device.getBluetoothAddress()); |
f1087591ff71
Targets presentation can be customized
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
456
diff
changeset
|
320 |
} |
455
5da55957c779
Bluetooth support was refactored on top of a new frameworks
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
321 |
} |