Java Code Examples for javax.bluetooth.RemoteDevice

The following are top voted examples for showing how to use javax.bluetooth.RemoteDevice. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Ardulink-1   File: ArdulinkDiscoveryListener.java   Source Code and License 7 votes vote down vote up
@Override
public void serviceSearchCompleted(int arg0, int arg1) {
	
	Map<String, ServiceRecord> ports = new HashMap<String, ServiceRecord>();
	
	for (Entry<RemoteDevice, ServiceRecord[]> entry : services.entrySet()) {
		RemoteDevice remoteDevice = entry.getKey();
		ServiceRecord service = findService(entry.getValue());
		if (service != null) {
			String name = "noname";
			try {
				name = remoteDevice.getFriendlyName(false);
			} catch (Exception e) {
			}

			name += " " + remoteDevice.getBluetoothAddress();
			ports.put(name, service);
		}
	}
	
	bluetoothConnection.setPorts(ports);
	
       synchronized (lock) {
           lock.notify();
       }
}
 
Example 2
Project: bauhinia   File: IdentifyNextDeviceState.java   Source Code and License 6 votes vote down vote up
@Override
State run() {
	if (candidates.isEmpty()) return states.startInquiry();

	CandidateDevice current = candidates.pop();
	RemoteDevice btDevice = current.btDevice;
	String btAddress = btDevice.getBluetoothAddress();

	final String name;
	try {
		name = btDevice.getFriendlyName(false);
	} catch (IOException e) {
		return states.identificationRejected(btAddress);
	}

	if (!isWiiRemote(name)) {
		return states.identifiedAsNonWiiRemote(btAddress);
	}

	return states.openControlPipe(btAddress);
}
 
Example 3
Project: dazzl   File: MonitoringThreadImpl.java   Source Code and License 6 votes vote down vote up
private BluetoothDevice remoteDevice2BluetoothDevice(RemoteDevice device)
{
    String address;
    String name;

    address = device.getBluetoothAddress();
    try
    {
        name = device.getFriendlyName(false);
    }
    catch (IOException e)
    {
        name = UNKNOWN_NAME;
    }

    return new BluetoothDeviceImpl(address, name);
}
 
Example 4
Project: dazzl   File: MonitoringThreadImpl.java   Source Code and License 6 votes vote down vote up
/**
 * Inform listeners about a device that appeared.
 * 
 * @param device the device that appeared.
 */
private void fireDeviceAppeared(RemoteDevice device)
{
    BluetoothDevice bluetoothDevice;

    bluetoothDevice = remoteDevice2BluetoothDevice(device);
    logger.debug("Discovered device: " + bluetoothDevice); //$NON-NLS-1$

    synchronized (monitoringListeners)
    {
        Iterator i = monitoringListeners.iterator();
        while (i.hasNext())
        {
            BluetoothPresenceListener ml = (BluetoothPresenceListener) i
                    .next();
            ml.deviceAppeared(bluetoothDevice);
        }
    }
}
 
Example 5
Project: dazzl   File: MonitoringThreadImpl.java   Source Code and License 6 votes vote down vote up
/**
 * Inform listeners about a device that disappeared.
 * 
 * @param device the device that disappeared.
 */
private void fireDeviceDisappeared(RemoteDevice device)
{
    BluetoothDevice bluetoothDevice;

    bluetoothDevice = remoteDevice2BluetoothDevice(device);
    logger.debug("Lost device: " + bluetoothDevice); //$NON-NLS-1$

    synchronized (monitoringListeners)
    {
        Iterator i = monitoringListeners.iterator();
        while (i.hasNext())
        {
            BluetoothPresenceListener ml = (BluetoothPresenceListener) i
                    .next();
            ml.deviceDisappeared(bluetoothDevice);
        }
    }
}
 
Example 6
Project: pluotsorbet   File: BluetoothStack.java   Source Code and License 6 votes vote down vote up
void onInquiryResult(InquiryResult result) {
    if (discListener == null) {
        return;
    }
    String addr = result.getAddress();
    Enumeration e = inquiryHistory.elements();
    while (e.hasMoreElements()) {
        InquiryResult oldResult = (InquiryResult)e.nextElement();
        if (oldResult.getAddress().equals(addr)) {
            // inquiry result is already in our possession
            return;
        }
    }
    inquiryHistory.addElement(result);
    RemoteDevice dev
        = DiscoveryAgentImpl.getInstance().getRemoteDevice(addr);
    DiscoveryAgentImpl.getInstance().addCachedDevice(addr);
    discListener.deviceDiscovered(dev, result.getDeviceClass());
}
 
Example 7
Project: pluotsorbet   File: DiscoveryAgentImpl.java   Source Code and License 6 votes vote down vote up
public RemoteDevice[] retrieveDevices(int option) {
    switch (option) {
        case DiscoveryAgent.CACHED:
            // IMPL_NOTE: use native cache keeping addresses of found devices
            // to share the cache between multiple isolates
            return getCachedDevices();
        case DiscoveryAgent.PREKNOWN:
            Vector pk = BCC.getInstance().getPreknownDevices();
            if (pk == null || pk.size() == 0) {
                return null;
            }
            RemoteDevice[] res = new RemoteDevice[pk.size()];
            for (int i = 0; i < pk.size(); i++) {
                String addr = (String)pk.elementAt(i);
                res[i] = getRemoteDevice(addr);
            }
            return res;
        default:
            throw new IllegalArgumentException("Invalid option value: "
                    + option);
    }
}
 
Example 8
Project: pluotsorbet   File: SelectServiceHandler.java   Source Code and License 6 votes vote down vote up
private String selectFromDevicesList(RemoteDevice[] devs, UUID uuid,
        int security, boolean master, Hashtable disDevsHash) {
    if (devs == null) {
        return null;
    }

    for (int i = 0; i < devs.length; i++) {
        if (disDevsHash.put(devs[i], devs[i]) != null) {
            continue;
        }
        String url = selectService(devs[i], uuid, security, master);

        if (url != null) {
            if (DEBUG) {
                System.out.println("\turl=" + url);
            }
            return url;
        }
    }
    return null;
}
 
Example 9
Project: pluotsorbet   File: ServiceSearcher.java   Source Code and License 6 votes vote down vote up
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 10
Project: sphero-bluecove   File: SpheroDiscovery.java   Source Code and License 6 votes vote down vote up
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass btClass) {
if(btDevice.getBluetoothAddress().startsWith(SPHERO_IEEE_OUI)) {
	System.out.println("Found a Sphero nearby!");
	Sphero s = null;
	try {
		s = new Sphero(btDevice.getBluetoothAddress(), btDevice.getFriendlyName(false), Sphero.SPP_DEFAULT_CHANNEL);
	} catch (IOException e) {
		s = new Sphero(btDevice.getBluetoothAddress(), "Unknown", 1);
	}
	System.out.println(s.getBluetoothAddress() + "  " + s.getFriendlyName());
       spherosDiscovered.add(s);
} else {
	System.out.println("Found some other Bluetooth device.");
}
		
  }
 
Example 11
Project: worldmap-classic   File: RemoteDeviceUI.java   Source Code and License 6 votes vote down vote up
/**
 * refresh the list with blutooth devices
 */
public void showui() {
	//*** super.deleteAll();
	while (super.size() > 0) {
		super.delete(0);
	}

	if (BLUElet.devices.size() > 0) {
		for (int i = 0; i < BLUElet.devices.size(); i++) {
			try {
				RemoteDevice device = (RemoteDevice) BLUElet.devices.elementAt(i);
				String name = device.getFriendlyName(false);
				append(name, null);

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	} else {
		append("[No Device Found]", null);
	}
}
 
Example 12
Project: worldmap-classic   File: Util.java   Source Code and License 6 votes vote down vote up
public static void printRemoteDevice(RemoteDevice dev, DeviceClass devClass) {
	try {
		System.out.println("Print Remote Device " + dev.getBluetoothAddress());
		System.out.println("Name: " + dev.getFriendlyName(false));
		System.out.println("Auth: " + dev.isAuthenticated() + " Encrypted: " + dev.isEncrypted() + " Trusted: " + dev.isTrustedDevice());

		if (devClass != null) {
			System.out.println("MajorDevice:"
					+ majorToName(devClass.getMajorDeviceClass()));
			System.out.println("MinorDevice:"
					+ minorToName(devClass.getMajorDeviceClass(),
					devClass.getMinorDeviceClass()));
			System.out.println("ServiceClass:");
			String[] str = Util.majorServiceToName(devClass.getServiceClasses());
			for (int i = 0; i < str.length; i++) {
				System.out.println("  " + str[i]);
			}
		}
	} catch (IOException e) {
	}
}
 
Example 13
Project: Nird2   File: InvitationListener.java   Source Code and License 5 votes vote down vote up
@Override
public void deviceDiscovered(RemoteDevice device, DeviceClass deviceClass) {
	UUID[] uuids = new UUID[] {new UUID(uuid, false)};
	// Try to discover the services associated with the UUID
	try {
		discoveryAgent.searchServices(null, uuids, device, this);
		searches.incrementAndGet();
	} catch (BluetoothStateException e) {
		if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
	}
}
 
Example 14
Project: Nird2   File: InvitationListener.java   Source Code and License 5 votes vote down vote up
@Override
public void deviceDiscovered(RemoteDevice device, DeviceClass deviceClass) {
	UUID[] uuids = new UUID[] {new UUID(uuid, false)};
	// Try to discover the services associated with the UUID
	try {
		discoveryAgent.searchServices(null, uuids, device, this);
		searches.incrementAndGet();
	} catch (BluetoothStateException e) {
		if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
	}
}
 
Example 15
Project: pcstatus   File: BluetoothSPPServer.java   Source Code and License 5 votes vote down vote up
/**
 * start server creating an UUID and a connection String,
 * then waiting for a device to connect
 */
private void bluetoothServer() {
    if (sendReciveMessageThread.isAlive()) {
        sendReciveMessageThread.interrupt();
    }
    try {
        //Create a UUID for SPP
        UUID uuid = new UUID("1101", true);
        //Create the servicve url
        String connectionString = "btspp://localhost:" + uuid + ";name=Sample SPP Server";

        //open server url
        streamConnNotifier = (StreamConnectionNotifier) Connector.open(connectionString);

        //Wait for client connection
        System.out.println("\nServer Started. Waiting for clients to connect...");

        StreamConnection connection = streamConnNotifier.acceptAndOpen();

        System.out.println("Remote device address: " + RemoteDevice.getRemoteDevice(connection).getBluetoothAddress());
        System.out.println("Remote device name: " + RemoteDevice.getRemoteDevice(connection).getFriendlyName(true));

        //the stream is opened both in and out
        outStream = connection.openOutputStream();
        inStream = connection.openInputStream();
        connectionIsAvaible = true;
        SingletonStaticGeneralStats.getInstance().setBluetoothServerCreated(true);
        sendBluetoothMessage();
    } catch (IOException e) {
        e.printStackTrace();
        //in case of problems, the connection is stopped
        closeConnection();
    }
}
 
Example 16
Project: jolie   File: BluetoothService.java   Source Code and License 5 votes vote down vote up
public void deviceDiscovered( RemoteDevice btDevice, DeviceClass cod )
{
	Value dValue = Value.create();
	dValue.getFirstChild( "address" ).setValue( btDevice.getBluetoothAddress() );
	try {
		dValue.getFirstChild( "name" ).setValue( btDevice.getFriendlyName( true ) );
	} catch( IOException e ) {}
	value.getChildren( "device" ).add( dValue );
}
 
Example 17
Project: openhab-hdl   File: BTDeviceDiscoveryService.java   Source Code and License 5 votes vote down vote up
/**
 * transforms a {@link RemoteDevice} object from the bluecove API to our own datastructure for bluetooth devices
 * 
 * @param btDevice the device coming from the bluecove API
 * @return an instance of our own bluetooth device data structure
 */
private static BluetoothDevice toBluetoothDevice(RemoteDevice btDevice) {
	String address = btDevice.getBluetoothAddress();
	String friendlyName = "";
	try {
		friendlyName = btDevice.getFriendlyName(false);
	} catch (IOException e) {
		// no friendly name accessible, let's ignore that
	}
	boolean paired = btDevice.isTrustedDevice();
	return new BluetoothDevice(address, friendlyName, paired);
}
 
Example 18
Project: Ardulink-1   File: ArdulinkDiscoveryListener.java   Source Code and License 5 votes vote down vote up
@Override
public void servicesDiscovered(int transID, ServiceRecord[] serviceRecords) {
	for(ServiceRecord serviceRecord : serviceRecords) {
		RemoteDevice currentDevice = serviceRecord.getHostDevice();
		services.put(currentDevice, serviceRecords);
	}
}
 
Example 19
Project: PanBox   File: PAKBluetoothPairingHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void initCommunication() throws Exception {
	this.dataInputStream = new ObjectInputStream(
			connection.openDataInputStream());
	this.dataOutputStream = new ObjectOutputStream(
			connection.openDataOutputStream());
	this.idA = RemoteDevice.getRemoteDevice(connection)
			.getBluetoothAddress();
	this.idB = LocalDevice.getLocalDevice().getBluetoothAddress();
}
 
Example 20
Project: PanBox   File: RemoveDeviceDiscoveryTest.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException,
		IOException {
	List<RemoteDevice> devices = RemoteDeviceDiscovery.discover();

	for (RemoteDevice device : devices) {
		System.out.println("ADDR: " + device.getBluetoothAddress()
				+ ", NAME: " + device.getFriendlyName(false));
	}
}
 
Example 21
Project: Blaubot   File: rfcommserver.java   Source Code and License 5 votes vote down vote up
public void startserver() {
    try {
        String url = "btspp://localhost:" + uuid +
                //  new UUID( 0x1101 ).toString() +
                ";name=File Server";
        StreamConnectionNotifier service = (StreamConnectionNotifier) Connector.open(url);

        StreamConnection con = service.acceptAndOpen();
        OutputStream dos = con.openOutputStream();
        InputStream dis = con.openInputStream();

        InputStreamReader daf = new InputStreamReader(System.in);
        BufferedReader sd = new BufferedReader(daf);
        RemoteDevice dev = RemoteDevice.getRemoteDevice(con);

        String greeting = "hi";
        dos.write(greeting.getBytes(Charset.forName("utf-8")));
        dos.flush();
        byte buffer[] = new byte[1024];
        int bytes_read = dis.read(buffer);
        String received = new String(buffer, 0, bytes_read, Charset.forName("utf-8"));
        System.out.println
                ("Message:" + received + "From:"
                        + dev.getBluetoothAddress());
        // con.close();
    } catch (IOException e) {
        System.err.print(e.toString());
    }
}
 
Example 22
Project: Blaubot   File: rfcommclient.java   Source Code and License 5 votes vote down vote up
public void startclient() {
    try {
        String remoteAddr = "001F8100011C";
        String url = "btspp://" + remoteAddr + ":2";
        StreamConnection con = (StreamConnection) Connector.open(url);
        OutputStream os = con.openOutputStream();
        InputStream is = con.openInputStream();
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader bufReader = new BufferedReader(isr);
        RemoteDevice dev = RemoteDevice.getRemoteDevice(con);

        /**   if (dev !=null) {
         File f = new File("test.xml");
         InputStream sis = new FileInputStream("test.xml");
         OutputStream oo = new FileOutputStream(f);
         byte buf[] = new byte[1024];
         int len;
         while ((len=sis.read(buf))>0)
         oo.write(buf,0,len);
         sis.close();
         }  **/

        if (con != null) {
            while (true) {
                //sender string
                System.out.println("Server Found:"
                        + dev.getBluetoothAddress() + "\r\n" + "Put your string" + "\r\n");
                String str = bufReader.readLine();
                os.write(str.getBytes());
                //reciever string
                byte buffer[] = new byte[1024];
                int bytes_read = is.read(buffer);
                String received = new String(buffer, 0, bytes_read);
                System.out.println("client: " + received + "from:" + dev.getBluetoothAddress());
            }
        }
    } catch (Exception e) {
    }
}
 
Example 23
Project: briar   File: InvitationListener.java   Source Code and License 5 votes vote down vote up
public void deviceDiscovered(RemoteDevice device, DeviceClass deviceClass) {
	UUID[] uuids = new UUID[] { new UUID(uuid, false) };
	// Try to discover the services associated with the UUID
	try {
		discoveryAgent.searchServices(null, uuids, device, this);
		searches.incrementAndGet();
	} catch(BluetoothStateException e) {
		if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
	}
}
 
Example 24
Project: dazzl   File: MonitoringThreadImpl.java   Source Code and License 5 votes vote down vote up
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod)
{
    synchronized (currentDevices)
    {
        currentDevices.add(btDevice);
    }
}
 
Example 25
Project: dazzl   File: BluetoothDeviceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
 * This call back method will be called for each discovered bluetooth devices.
 */
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
	System.out.println("Device discovered: "+btDevice.getBluetoothAddress());
	//add the device to the vector
	if(!vecDevices.contains(btDevice)){
		vecDevices.addElement(btDevice);
	}
}
 
Example 26
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 27
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 28
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 29
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 30
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 31
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 32
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 33
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 34
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 35
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 36
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 37
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 38
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 39
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 40
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 41
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 42
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 43
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 44
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 45
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 46
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 47
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 48
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 49
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 50
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 51
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 52
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 53
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 54
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 55
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 56
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 57
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 58
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) whenever a bluetooth device is discovered
   * 
   * @param remoteDevice The device discovered
   * @param deviceClass The device class of the discovered device
   * 
   */
  public void deviceDiscovered(RemoteDevice remoteDevice,DeviceClass deviceClass){

// The device class of the discovered device
int deviceclass = deviceClass.getMajorDeviceClass();
	
if(deviceclass==mobileDeviceClassCode){
	// Adds the discovered device to the devicesFound Vector
	devicesFound.addElement(remoteDevice);
}
  }
 
Example 59
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method is called by the javax.bluetooth.DiscoveryAgent (agent) when the discovery process is completed
   * 
   * @param discType The type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR 
   * 
   */
  public void inquiryCompleted(int discType) {
      
  	switch (discType) {

case DiscoveryListener.INQUIRY_COMPLETED:
	if(devicesFound.size()==0){
		log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","No devices found");
              // Send a message to the midlet
		currentNetwork.serviceSearchCompleted();
	}else{	
		try {
                  log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Found one or more devices");
			// The discovery agent searches for services on the first device stored in the devicesFound Vector
			agent.searchServices(attributes,uuids,(RemoteDevice)devicesFound.firstElement(),this);
			devicesFound.removeElementAt(0);
		} catch (BluetoothStateException bse) {
		    log.logException("BluetoothServiceDiscovery.serviceSearchCompleted", bse, true);
		}
	}    	
log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry completed");
break;

case DiscoveryListener.INQUIRY_ERROR:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry error");
break;

case DiscoveryListener.INQUIRY_TERMINATED:

log.logDebugInfo("BluetoothServiceDiscovery.inquiryCompleted()","Device inquiry terminated");
break;
}
  }
 
Example 60
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }