Java Code Examples for javax.bluetooth.BluetoothStateException

The following are top voted examples for showing how to use javax.bluetooth.BluetoothStateException. 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: pcstatus   File: BluetoothSPPServer.java   Source Code and License 7 votes vote down vote up
/**
 * if bluetooth connection is available, <code>sendBluetoothMessage()</code> run <code>sendReciveMessageThread()</code>.
 * Else, checks if Bluetooth is activated and chooses if close connection or wait again
 */
void sendBluetoothMessage() {
    if (connectionIsAvaible) {
        if (outStream != null) {
            if (sendReciveMessageThread.isInterrupted()) {
                messageThreadExecutor.execute(sendReciveMessageThread);
                System.out.println("thread creato e avviato");
                sendBluetoothMessage();
            } else {
                sendReciveMessageThread.interrupt();
                messageThreadExecutor.execute(sendReciveMessageThread);
            }
        }
    } else {
        try {
            if (LocalDevice.getLocalDevice() != null && !LocalDevice.getLocalDevice().getFriendlyName().equals("null"))
                System.out.println("connessione non stabilita " + LocalDevice.getLocalDevice().getFriendlyName());
            else {
                closeConnection();
            }
        } catch (BluetoothStateException | NullPointerException e) {
            e.printStackTrace();
            closeConnection();
        }
    }
}
 
Example 2
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 7 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 3
Project: ShootOFF   File: BluetoothServer.java   Source Code and License 6 votes vote down vote up
private Optional<String> getLocalAddress() {
	try {
		final LocalDevice localDevice = LocalDevice.getLocalDevice();

		// Insert colons into the address because android needs them
		final StringBuilder addressBuilder = new StringBuilder();
		final String originalAddress = localDevice.getBluetoothAddress();
		for (int i = 0; i < originalAddress.length(); i++) {
			addressBuilder.append(originalAddress.charAt(i));
			if (i > 0 && i < originalAddress.length() - 1 && i % 2 != 0) addressBuilder.append(':');
		}

		return Optional.of(addressBuilder.toString());
	} catch (BluetoothStateException e) {
		logger.error("Failed to access local bluetooth device to fetch its address. Ensure the "
				+ "system's bluetooth service is started with \"sudo systemctl start bluetooth\" "
				+ "and the bluetooth stack is on in the system settings", e);
		return Optional.empty();
	}
}
 
Example 4
Project: bauhinia   File: BlueCoveExceptionFactory.java   Source Code and License 6 votes vote down vote up
public CoronataException correspondingTo(BluetoothStateException cause) {
	String errorMsg = cause.getMessage().toLowerCase();

	if (errorMsg.contains("librar") && errorMsg.contains("not available")) {
		return problemLoadingLibraries(cause);

	} else if (errorMsg.contains("device is not available") ||
			errorMsg.contains("stack not detected")) {
		return bluetoothAdapterIsOff(cause);

	} else if (errorMsg.contains("device is not ready")) {
		return deviceIsNotReady(cause);

	} else {
		return unexpectedError(cause);
	}
}
 
Example 5
Project: PanBox   File: PanboxClient.java   Source Code and License 6 votes vote down vote up
public BluetoothPairingInformation initDevicePairingBluetooth()
		throws BluetoothStateException, InterruptedException {
	// This is the first time we are going to touch the Bluetooth API so we
	// should attach our logger to the com.intel.bluetooth logging
	appendBluetoothLogging();

	// Make bluetooth device discoverbale!
	LocalDevice local = LocalDevice.getLocalDevice();
	try {
		local.setDiscoverable(DiscoveryAgent.GIAC);
	} catch (BluetoothStateException e) {
		logger.debug(
				"PanboxClient : initDevicePairingBluetooth : First try to set discoverable failed. Will try again in 1sec.");
		Thread.sleep(1000);
		local.setDiscoverable(DiscoveryAgent.GIAC);
	}

	// setting LocalDevice is only need for Linux, since on Windows we
	// bluecove only supports one device!
	BluetoothPairingInformation info = new BluetoothPairingInformation(local);
	extendPairingInformation(info);
	return info;
}
 
Example 6
Project: PanBox   File: AddDeviceBluetoothActionListener.java   Source Code and License 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	try {
		BluetoothPairingInformation pInfo = client
				.initDevicePairingBluetooth();
		if (pInfo != null) {
			new PairNewDeviceDialog(clientGuiFrame, client, pInfo);
		} else {
			logger.info("AddDeviceBluetoothActionListener : Bluetooth device pairing aborted!");
		}
	} catch (BluetoothStateException | InterruptedException ex) {
		if (ex.getMessage().contains("Device is not available") || ex.getMessage().contains("BluetoothStack not detected")) {
			JOptionPane
					.showMessageDialog(
							clientGuiFrame,
							bundle.getString("AddDeviceBluetoothActionListener.noDevice.Message"),
							bundle.getString("error"),
							JOptionPane.ERROR_MESSAGE);
		}
		logger.error(
				"AddDeviceBluetoothActionListener : Bluetooth device exited with exception: ",
				ex);
	}
}
 
Example 7
Project: dazzl   File: MonitoringThreadImpl.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 */
MonitoringThreadImpl() throws BluetoothException
{
    super("Bluetooth Monitoring"); //$NON-NLS-1$
    try
    {
        this.localDevice = LocalDevice.getLocalDevice();
    }
    catch (BluetoothStateException e)
    {
        throw new BluetoothException(e.getMessage());
    }

    this.localAddress = localDevice.getBluetoothAddress();
    this.localName = localDevice.getFriendlyName();
    this.discoveryAgent = localDevice.getDiscoveryAgent();

    logger.debug("LocalAdress: " + localAddress + ", Name: " + localName); //$NON-NLS-1$ //$NON-NLS-2$
    
    this.monitoringListeners = new ArrayList();
    this.discoveryInProgress = false;
    this.pass = 0;
}
 
Example 8
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 9
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 10
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 11
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 12
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 13
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 14
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 15
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 16
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 17
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 18
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 19
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 20
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 21
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 22
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 23
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 24
Project: BGSEP   File: BluetoothServer.java   Source Code and License 6 votes vote down vote up
private BluetoothServer() {
	clients = new ConcurrentHashMap<Integer, BluetoothClient>();
	try {
		device = LocalDevice.getLocalDevice();
		if (device != null) {
			if (!LocalDevice.isPowerOn()) {
				System.out.println("Device power is off. Turn it on!");
				System.exit(1);
			}
		} else {
			System.out.println("No device");
			System.exit(1);
		}
	} catch (BluetoothStateException e) {
		System.out.println(e.getMessage());
		System.exit(1);

	}
}
 
Example 25
Project: bluecove-osx   File: BlueCoveImpl.java   Source Code and License 6 votes vote down vote up
static void loadNativeLibraries(BluetoothStack stack) throws BluetoothStateException {
	// Check is libraries already loaded
	try {
		if ((UtilsJavaSE.canCallNotLoadedNativeMethod) && (stack.isNativeCodeLoaded())) {
			return;
		}
	} catch (Error e) {
		// We caught UnsatisfiedLinkError
	}
	LibraryInformation[] libs = stack.requireNativeLibraries();
	if ((libs == null) || (libs.length == 0)) {
		// No native libs for this stack
		return;
	}
	for (int i = 0; i < libs.length; i++) {
		Class c = libs[i].stackClass;
		if (c == null) {
			c = stack.getClass();
		}
		if (!NativeLibLoader.isAvailable(libs[i].libraryName, c)) {
			throw new BluetoothStateException("BlueCove library " + libs[i].libraryName + " not available");
		}
	}
}
 
Example 26
Project: bluecove-osx   File: BlueCoveImpl.java   Source Code and License 6 votes vote down vote up
/**
 * Applications should not used this function.
 *
 * @return current BluetoothStack implementation
 * @throws BluetoothStateException
 *             when BluetoothStack not detected. If one connected the hardware later, BlueCove would be able to
 *             recover and start correctly
 * @exception Error
 *                if called from outside of BlueCove internal code.
 */
public synchronized BluetoothStack getBluetoothStack() throws BluetoothStateException {
	Utils.isLegalAPICall(fqcnSet);
	BluetoothStackHolder sh = currentStackHolder(false);
	if ((sh != null) && (sh.bluetoothStack != null)) {
		return sh.bluetoothStack;
	} else if ((sh == null) && (threadStack != null)) {
		throw new BluetoothStateException("No BluetoothStack or Adapter for current thread");
	}

	BluetoothStack stack;
	if (accessControlContext == null) {
		stack = detectStack();
	} else {
		stack = detectStackPrivileged();
	}
	return stack;
}
 
Example 27
Project: bluecove-osx   File: DeviceInquiryThread.java   Source Code and License 6 votes vote down vote up
/**
 * Start DeviceInquiry and wait for startException or deviceInquiryStartedCallback
 */
static boolean startInquiry(BluetoothStack stack, DeviceInquiryRunnable inquiryRunnable, int accessCode,
		DiscoveryListener listener) throws BluetoothStateException {
	DeviceInquiryThread t = (new DeviceInquiryThread(stack, inquiryRunnable, accessCode, listener));
	// In case the BTStack hangs, exit JVM anyway
	UtilsJavaSE.threadSetDaemon(t);
	synchronized (t.inquiryStartedEvent) {
		t.start();
		while (!t.started && !t.terminated) {
			try {
				t.inquiryStartedEvent.wait();
			} catch (InterruptedException e) {
				return false;
			}
			if (t.startException != null) {
				throw t.startException;
			}
		}
	}
	DebugLog.debug("startInquiry return", t.started);
	return t.started;
}
 
Example 28
Project: bluecove-osx   File: SearchServicesThread.java   Source Code and License 6 votes vote down vote up
public void run() {
	int respCode = DiscoveryListener.SERVICE_SEARCH_ERROR;
	try {
		BlueCoveImpl.setThreadBluetoothStack(stack);
		respCode = serachRunnable.runSearchServices(this, attrSet, uuidSet, device, listener);
	} catch (BluetoothStateException e) {
		startException = e;
		return;
	} finally {
		finished = true;
		unregisterThread();
		synchronized (serviceSearchStartedEvent) {
			serviceSearchStartedEvent.notifyAll();
		}
		DebugLog.debug("runSearchServices ends", getTransID());
		if (started) {
			Utils.j2meUsagePatternDellay();
			listener.serviceSearchCompleted(getTransID(), respCode);
		}
	}
}
 
Example 29
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 30
Project: Nird2   File: BluetoothPlugin.java   Source Code and License 5 votes vote down vote up
private void makeDeviceDiscoverable() {
	// Try to make the device discoverable (requires root on Linux)
	try {
		localDevice.setDiscoverable(GIAC);
	} catch (BluetoothStateException e) {
		if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
	}
}
 
Example 31
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 32
Project: Nird2   File: BluetoothPlugin.java   Source Code and License 5 votes vote down vote up
private void makeDeviceDiscoverable() {
	// Try to make the device discoverable (requires root on Linux)
	try {
		localDevice.setDiscoverable(GIAC);
	} catch (BluetoothStateException e) {
		if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
	}
}
 
Example 33
Project: bluetooth-client-hc06   File: BluetoothScanThread.java   Source Code and License 5 votes vote down vote up
private void discoverDevices() throws BluetoothStateException {
    foundDevices = new ArrayList<>();
    agent.startInquiry(DiscoveryAgent.GIAC, getDiscoveryListener());
    try {
        synchronized (LOCK) {
            LOCK.wait();
        }
    } catch (InterruptedException e) {
        LOGGER.error("Error when discoverDevices().", e);
        fireBluetooothEvent(new ErrorEvent(e, this));
    }
}
 
Example 34
Project: bluetooth-client-hc06   File: BluetoothScanThread.java   Source Code and License 5 votes vote down vote up
private void discoverServices(RFCommBluetoothDevice device) throws BluetoothStateException {
    this.tempDevice = device;
    agent.searchServices(null, uuidSet, this.tempDevice.getRemoteDevice(), getDiscoveryListener());
    try {
        synchronized (LOCK) {
            LOCK.wait();
        }
    } catch (InterruptedException e) {
        LOGGER.error("Error when discoverServices().", e);
        fireBluetooothEvent(new ErrorEvent(e, this));
    }
}
 
Example 35
Project: bauhinia   File: BlueCoveExceptionFactory.java   Source Code and License 5 votes vote down vote up
private CoronataException
		problemLoadingLibraries(BluetoothStateException cause) {
	return new CoronataException(cause,
			"Unable to load required libraries for BlueCove.\n" +
			"\tCheck if the requirements described here were met:" +
			" http://www.bluecove.org/bluecove-gpl/index.html\n" +
			"\tTry installing one of these packages:" +
			" libbluetooth-dev (Ubuntu)," +
			" bluez-libs-devel (Fedora), bluez-devel (openSUSE)\n" +
			"");
}
 
Example 36
Project: bauhinia   File: BlueCoveExceptionFactory.java   Source Code and License 5 votes vote down vote up
private CoronataException
		bluetoothAdapterIsOff(BluetoothStateException cause) {
	return new CoronataException(cause,
			"Bluetooth adapter is unavailable. Make sure it is enabled. " +
			"If it is a USB adapter, check if it is connected." +
			"");
}
 
Example 37
Project: bauhinia   File: LoadLibraryState.java   Source Code and License 5 votes vote down vote up
@Override
State run() {
	try {
		BlueCoveLibraryFacade blueCoveLib = new BlueCoveLibraryFacade();
		leObserver.searchStarted(false);
		return states.startInquiry(blueCoveLib);

	} catch (BluetoothStateException e) {
		return states.bluetoothException(e);
	}
}
 
Example 38
Project: bauhinia   File: BluetoothExceptionState.java   Source Code and License 5 votes vote down vote up
BluetoothExceptionState(StateFactory states,
		CoronataLifecycleEventsObserver leObserver,
		BluetoothStateException exception) {
	this.states = states;
	this.leObserver = leObserver;
	this.exception = exception;
}
 
Example 39
Project: bauhinia   File: StartInquiryState.java   Source Code and License 5 votes vote down vote up
@Override
State run() {
	try {
		BluetoothInquiryResult inquiryResult = new BluetoothInquiryResult();
		blueCoveLib.startAsynchronousSearch(inquiryResult);
		return states.waitForInquiry(inquiryResult);

	} catch (BluetoothStateException e) {
		return states.bluetoothException(e);
	}
}
 
Example 40
Project: Blaubot   File: BlaubotJsr82BluetoothAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * @param uuidSet the uuid set
 * @param ownDevice th own device
 * @throws BluetoothStateException if the Jsr82 implementation is not available or cant access the bluetooth hardware
 */
   public BlaubotJsr82BluetoothAdapter(BlaubotUUIDSet uuidSet, IBlaubotDevice ownDevice) throws BluetoothStateException {
	this.uuidSet = uuidSet;
       this.ownDevice = ownDevice;
	this.connector = new BlaubotJsr82BluetoothConnector(this, ownDevice);
	this.acceptor = new BlaubotJsr82BluetoothAcceptor(this);
	this.bluetoothAdapterSempaphore = new Semaphore(1);
	this.connectionStateMachineConfig = new ConnectionStateMachineConfig();
	this.connectionStateMachineConfig.setCrowningPreparationTimeout(CROWNING_PREPARATION_TIMEOUT);
	this.connectionStateMachineConfig.setKingWithoutPeasantsTimeout(NO_PEASANTS_KING_TIMEOUT);
	this.adapterConfig = new BlaubotAdapterConfig();
	ConnectionStateMachineConfig.validateTimeouts(connectionStateMachineConfig, adapterConfig);
}
 
Example 41
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 42
Project: briar   File: BluetoothPlugin.java   Source Code and License 5 votes vote down vote up
private void makeDeviceDiscoverable() {
	// Try to make the device discoverable (requires root on Linux)
	try {
		localDevice.setDiscoverable(GIAC);
	} catch(BluetoothStateException e) {
		if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
	}
}
 
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) 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 44
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}
 
Example 45
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 46
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}
 
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: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}
 
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: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}
 
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
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}
 
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) 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 54
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}
 
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) 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 56
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}
 
Example 57
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 58
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}
 
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
/**
	 * Initiates the network instance. 
	 * It is called from the FrameworkFrontEnd.initFramework()
	 * 
	 * @throws BluetoothStateException Failed to initiate the network
	 */
	public void init() throws BluetoothStateException{
		
		isConnected = false;
		serviceSearchCompleted = false;
		serviceSearchFailed = false;
		
		
		// Sets the connectionURL used by the ConnectionListener
        String localNodeName = getFrameworkFrontEnd().getLocalNode().getNodeName();
        // Meisam changed x+y+z to x=x+y, x=x+z
        connectionURL = new StringBuffer().append("btspp://localhost:").append(getUUIDString()).append(";authenticate=false;encrypt=false;name=").append(localNodeName).toString();
		
        // Have to set the local device discoverable
//        try {
//            LocalDevice.getLocalDevice().setDiscoverable(javax.bluetooth.DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException bse) {
//           log.logException("ConnectionListener.ConnectionListener()",bse,false);
//           throw bse;
//        }  
        
        foundNodes = new Hashtable();
        // Creates the class that contains low level Bluetooth discovery operations.
        bluetoothServiceDiscovery = new BluetoothServiceDiscovery();
        
		/* The ConnectionListener instance that listens for incoming requests from
		 * other nodes in discovery mode. When this node is discovered the "discoverer"
		 * can choose to create a connection between the two, and the remote node is 
		 * represented by a node object localy on this node.
		 */
        setConnectionListener(new ConnectionListener(connectionURL));        
	}