javax.bluetooth.DiscoveryListener Java Examples
The following examples show how to use
javax.bluetooth.DiscoveryListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceSearcher.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
public void errorResponse(int errorCode, String info, int transactionID) { if (DEBUG) { System.out.println(cn + ".errorResponse: called"); } stop(); if ((errorCode == SDP_INVALID_VERSION) || (errorCode == SDP_INVALID_SYNTAX) || (errorCode == SDP_INVALID_PDU_SIZE) || (errorCode == SDP_INVALID_CONTINUATION_STATE) || (errorCode == SDP_INSUFFICIENT_RESOURCES)) { notifyListener(DiscoveryListener.SERVICE_SEARCH_ERROR); System.err.println(info); } else if (errorCode == SDP_INVALID_SR_HANDLE) { notifyListener(DiscoveryListener.SERVICE_SEARCH_NO_RECORDS); System.err.println(info); } else if (errorCode == IO_ERROR) { notifyListener(DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE); } else if (errorCode == TERMINATED) { new NotifyListenerRunner( DiscoveryListener.SERVICE_SEARCH_TERMINATED); } }
Example #2
Source File: ServiceSearcher.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
public int searchService(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener) throws BluetoothStateException, IllegalArgumentException { if (DEBUG) { System.out.println("- serviceSearcher: initializing"); } initialize(attrSet, uuidSet, btDev); if (discListener == null) { throw new NullPointerException("DiscoveryListener is null"); } this.discListener = discListener; return start(); }
Example #3
Source File: DiscoveryAgentImpl.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
public boolean cancelInquiry(DiscoveryListener listener) { if (listener == null) { throw new NullPointerException("null listener"); } synchronized (d_lock) { /* no inquiry was started */ if (d_listener == null) { return false; } /* not valid listener */ if (d_listener != listener) { return false; } /* process the inquiry in the device specific way */ cancelInquiry(); } inquiryCompleted(DiscoveryListener.INQUIRY_TERMINATED); return true; }
Example #4
Source File: BluetoothStack.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public boolean cancelInquiry(DiscoveryListener listener) { if (discListener != listener) { return false; } if (cancelInquiry()) { stopPolling(); discListener = null; return true; } return false; }
Example #5
Source File: ServiceSearcher.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
boolean cancel() { synchronized (this) { if (inactive) { return false; } inactive = true; if (sdp == null) { return false; } if (canceled) { return false; } canceled = true; } // cancel running effective transaction if any. // if sdp.cancelServiceSearch returns false (there is no running // transactions) then call the notification directly. if (!sdp.cancelServiceSearch(transactionID)) { new NotifyListenerRunner( DiscoveryListener.SERVICE_SEARCH_TERMINATED); } return true; }
Example #6
Source File: ServiceSearcher.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public void serviceSearchResponse(int[] handleList, int transactionID) { if (DEBUG) { System.out.println(cn + ".serviceSearchResponse: called"); } // there is no reason to perform response processing if search // is canceled if (isCanceled()) { return; } if (handleList == null || handleList.length == 0) { stop(); notifyListener(DiscoveryListener.SERVICE_SEARCH_NO_RECORDS); return; } synchronized (this) { handles = handleList; processedHandle = 0; } try { // there is no reason to request service attributes if service // search is canceled if (isCanceled()) { return; } sdp.serviceAttributeRequest(handles[processedHandle], attrSet, transactionID, this); } catch (IOException ioe) { if (DEBUG) { ioe.printStackTrace(); } stop(); notifyListener(DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE); } }
Example #7
Source File: DiscoveryAgentImpl.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public void inquiryCompleted(int discType) { DiscoveryListener listener; synchronized (d_lock) { listener = d_listener; d_listener = null; } new Completed(listener, discType); }
Example #8
Source File: DiscoveryAgentImpl.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public boolean startInquiry(int accessCode, DiscoveryListener listener) throws BluetoothStateException { if (accessCode != DiscoveryAgent.GIAC && accessCode != DiscoveryAgent.LIAC && (accessCode < 0x9E8B00 || accessCode > 0x9E8B3F)) { throw new IllegalArgumentException("Access code is out of range: " + accessCode); } if (listener == null) { throw new NullPointerException("null listener"); } /* IMPL_NOTE see // kvem/classes/com/sun/kvem/jsr082/impl/bluetooth/ // BTDeviceDiscoverer.java // heck what access codes should be supported. // Return false if access code is not supported. */ synchronized (d_lock) { if (d_listener != null) { throw new BluetoothStateException( "The previous device discovery is running..."); } d_listener = listener; /* process the inquiry in the device specific way */ return startInquiry(accessCode); } }
Example #9
Source File: BluetoothStack.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
void onInquiryComplete(boolean success) { if (discListener == null) { return; } stopPolling(); discListener = null; inquiryHistory.removeAllElements(); int type = success ? DiscoveryListener.INQUIRY_COMPLETED : DiscoveryListener.INQUIRY_ERROR; DiscoveryAgentImpl.getInstance().inquiryCompleted(type); }
Example #10
Source File: BluetoothStack.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public boolean startInquiry(int accessCode, DiscoveryListener listener) { if (discListener != null || listener == null) { return false; } discListener = listener; if (startInquiry(accessCode)) { inquiryHistory.removeAllElements(); startPolling(); return true; } return false; }
Example #11
Source File: DiscoveryAgentImpl.java From pluotsorbet with GNU General Public License v2.0 | 4 votes |
public int searchServices(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener) throws BluetoothStateException { if (DEBUG) { System.out.println("searchServices: "); System.out.println("\tattrSet=" + attrSet); if (attrSet != null) { for (int i = 0; i < attrSet.length; i++) { System.out.println("\tattrSet[" + i + "]=0x" + attrSet[i]); } } System.out.println("\tuuidSet=" + uuidSet); if (uuidSet != null) { for (int i = 0; i < uuidSet.length; i++) { System.out.println("\tuuidSet[" + i + "]=" + uuidSet[i]); } } System.out.println("\tadderess=" + btDev.getBluetoothAddress()); } if (uuidSet == null) { throw new NullPointerException("UUID set is null"); } if (uuidSet.length == 0 || uuidSet.length > MAX_ALLOWED_UUIDS ) { throw new IllegalArgumentException("Invalid UUID set length"); } if (btDev == null) { throw new NullPointerException("null instance of RemoteDevice"); } /* the 'transID' is assigned by service discoverer */ int transID = ServiceDiscovererFactory.getServiceDiscoverer(). searchService( ServiceSearcherBase.extendByStandardAttrs(attrSet), ServiceSearcherBase.removeDuplicatedUuids(uuidSet), btDev, discListener); if (DEBUG) { System.out.println("\ttransID=" + transID); } return transID; }
Example #12
Source File: ServiceSearcher.java From pluotsorbet with GNU General Public License v2.0 | 4 votes |
private int start() throws BluetoothStateException { if (DEBUG) { System.out.println("- serviceSearcher: start"); } synchronized (ServiceSearcher.class) { if (requestCounter == ServiceRecordImpl.TRANS_MAX) { throw new BluetoothStateException( "Too much concurrent requests"); } requestCounter++; } transactionID = SDPClientTransaction.newTransactionID(); searchers.put(new Integer(transactionID), this); synchronized (this) { notified = false; } handles = null; processedHandle = 0; try { sdp = new JavaSDPClient(btDev.getBluetoothAddress()); sdp.serviceSearchAttributeRequest(attrSet, uuidSet, transactionID, this); // sdp.serviceSearchRequest(uuidSet, transactionID, this); } catch (IOException ioe) { if (DEBUG) { ioe.printStackTrace(); } synchronized (this) { stop(); new NotifyListenerRunner( DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE); } } if (DEBUG) { System.out.println("- serviceSearch: started with transaction: " + transactionID); } return transactionID; }
Example #13
Source File: DiscoveryAgentImpl.java From pluotsorbet with GNU General Public License v2.0 | 4 votes |
Completed(DiscoveryListener listener, int discType) { this.listener = listener; this.discType = discType; new Thread(this).start(); }
Example #14
Source File: ServiceSearcher.java From pluotsorbet with GNU General Public License v2.0 | 4 votes |
public void serviceAttributeResponse(int[] attrIDs, DataElement[] attributeValues, int transactionID) { if (DEBUG) { System.out.println(cn + ".serviceAttributeResponse: called"); } // there is no reason to process service attributes if service // search is canceled if (isCanceled()) { return; } synchronized (this) { processedHandle++; } if (attributeValues != null) { ServiceRecordImpl[] serviceRecordSet = new ServiceRecordImpl[1]; serviceRecordSet[0] = new ServiceRecordImpl(btDev, attrIDs, attributeValues); try { // The spec for DiscoveryAgent.cancelServiceSearch() says: // "After receiving SERVICE_SEARCH_TERMINATED event, // no further servicesDiscovered() events will occur // as a result of this search." if (isCanceled()) { return; } System.out.println("serviceSearch: notify serviceDiscovered"); discListener.servicesDiscovered(this.transactionID, serviceRecordSet); } catch (Throwable e) { e.printStackTrace(); } } if (processedHandle == handles.length) { stop(); if (DEBUG) { System.out .println("serviceSearch: notify service search completed"); } notifyListener(DiscoveryListener.SERVICE_SEARCH_COMPLETED); return; } try { // there is no reason to continue attributes discovery if search // is canceled if (isCanceled()) { return; } sdp.serviceAttributeRequest(handles[processedHandle], attrSet, transactionID, this); } catch (IOException ioe) { if (DEBUG) { ioe.printStackTrace(); } stop(); notifyListener(DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE); } }
Example #15
Source File: ServiceSearcher.java From pluotsorbet with GNU General Public License v2.0 | 4 votes |
public void serviceSearchAttributeResponse(int[] attrIDs, DataElement[] attributeValues, int transactionID) { if (DEBUG) { System.out.println(cn + ".serviceSearchAttributeResponse: called"); } // there is no reason to process service attributes if service // search is canceled if (isCanceled()) { return; } if (attrIDs == null || attrIDs.length <= 0 || attributeValues == null || attrIDs.length != attributeValues.length) { notifyListener(DiscoveryListener.SERVICE_SEARCH_NO_RECORDS); return; } int firstPos = 0; Vector responceRecords = new Vector(); for (int i = 1; i < attrIDs.length; i++) { if (attrIDs[i] == 0) { responceRecords.addElement(getOneRecord(attrIDs, attributeValues, firstPos, i)); firstPos = i; } } responceRecords.addElement(getOneRecord(attrIDs, attributeValues, firstPos, attrIDs.length)); ServiceRecordImpl[] records = new ServiceRecordImpl[responceRecords.size()]; for (int i=0; i<responceRecords.size(); i++) { records[i]=(ServiceRecordImpl)responceRecords.elementAt(i); } try { // The spec for DiscoveryAgent.cancelServiceSearch() says: // "After receiving SERVICE_SEARCH_TERMINATED event, // no further servicesDiscovered() events will occur // as a result of this search." if (isCanceled()) { return; } if (DEBUG) { System.out.println("serviceSearch: notify serviceDiscovered"); } discListener.servicesDiscovered(this.transactionID, records); } catch (Throwable e) { e.printStackTrace(); } stop(); if (DEBUG) { System.out .println("serviceSearch: notify service_search_completed"); } notifyListener(DiscoveryListener.SERVICE_SEARCH_COMPLETED); return; }
Example #16
Source File: ServiceSearcher.java From pluotsorbet with GNU General Public License v2.0 | 4 votes |
private void notifyListener(int respCode) { // guard against multiple notification calls synchronized (this) { if (!notified) { notified = true; } else { return; } } if (DEBUG) { String codeStr = "Undefined"; switch (respCode) { case DiscoveryListener.SERVICE_SEARCH_COMPLETED: codeStr = "SERVICE_SEARCH_COMPLETED"; break; case DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE: codeStr = "SERVICE_SEARCH_DEVICE_NOT_REACHABLE"; break; case DiscoveryListener.SERVICE_SEARCH_ERROR: codeStr = "SERVICE_SEARCH_ERROR"; break; case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS: codeStr = "SERVICE_SEARCH_NO_RECORDS"; break; case DiscoveryListener.SERVICE_SEARCH_TERMINATED: codeStr = "SERVICE_SEARCH_TERMINATED"; break; default: } if (DEBUG) { System.out.println("serviceSearchCompleted:"); System.out.println("\ttransID=" + transactionID); System.out.println("\trespCode=" + codeStr); System.out.println("\tinactive=" + inactive); } } try { discListener.serviceSearchCompleted(transactionID, respCode); } catch (Throwable e) { e.printStackTrace(); } }
Example #17
Source File: ServiceDiscoverer.java From pluotsorbet with GNU General Public License v2.0 | 4 votes |
public int searchService(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener) throws BluetoothStateException ;