1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package com.intel.bluetooth.emu;
27
28 import java.util.Enumeration;
29 import java.util.Hashtable;
30 import java.util.Vector;
31
32 import com.intel.bluetooth.DebugLog;
33 import com.intel.bluetooth.RemoteDeviceHelper;
34
35
36
37
38 class DeviceSDP {
39
40 private long address;
41
42 private Hashtable<Long, ServicesDescriptor> services = new Hashtable<Long, ServicesDescriptor>();
43
44 DeviceSDP(long address) {
45 this.address = address;
46 }
47
48 synchronized void updateServiceRecord(long handle, ServicesDescriptor sdpData) {
49 Long key = new Long(handle);
50 boolean update = (services.get(key) != null);
51 services.put(key, sdpData);
52
53 String[] serviceUuidSet = sdpData.getUuidSet();
54 for (int i = 0; i < serviceUuidSet.length; i++) {
55 DebugLog.debug((update ? "Update" : "Create") + " Srv on "
56 + RemoteDeviceHelper.getBluetoothAddress(address) + " " + handle + " " + i + " "
57 + serviceUuidSet[i]);
58 }
59 }
60
61 synchronized void removeServiceRecord(long handle) {
62 ServicesDescriptor srv = (ServicesDescriptor) services.remove(new Long(handle));
63 if (srv != null) {
64 DebugLog.debug("Remove Srv on " + RemoteDeviceHelper.getBluetoothAddress(address) + " " + handle);
65 }
66 }
67
68 ServicesDescriptor getServicesDescriptor(long handle) {
69 return (ServicesDescriptor) services.get(new Long(handle));
70 }
71
72 synchronized long[] searchServices(String[] uuidSet) {
73 Vector<Long> handles = new Vector<Long>();
74
75 for (Enumeration<Long> iterator = services.keys(); iterator.hasMoreElements();) {
76 Long key = (Long) iterator.nextElement();
77 ServicesDescriptor service = (ServicesDescriptor) services.get(key);
78 String[] serviceUuidSet = service.getUuidSet();
79
80 int match = 0;
81 for (int i = 0; i < serviceUuidSet.length; i++) {
82 for (int k = 0; k < uuidSet.length; k++) {
83 if (uuidSet[k].equals(serviceUuidSet[i])) {
84 match++;
85 break;
86 }
87 }
88 }
89 if (match == uuidSet.length) {
90 handles.addElement(key);
91 }
92 }
93
94 long[] h = new long[handles.size()];
95 int i = 0;
96 for (Enumeration<Long> e = handles.elements(); e.hasMoreElements();) {
97 h[i++] = ((Long) e.nextElement()).intValue();
98 }
99 return h;
100 }
101 }