bool ConnectivityBluetooth::run()
{
	CoInitializeEx (0, COINIT_MULTITHREADED);

	if (registerSDPService(&sdpRecordHandle) < 0) {
		CM_DBG("WSAGetLastError=%s\n", StrError(WSAGetLastError()));
		fflush(stdout);
		CM_DBG("Could not register SDP service\n");
		return false;
	}

	cancelableSleep(5000);

	while (!shouldExit()) {
		
		bluetoothDiscovery(this);

#define BLUETOOTH_FORCE_DISCOVERABLE_MODE

#ifdef BLUETOOTH_FORCE_DISCOVERABLE_MODE
		DWORD mode;

		if (BthGetMode(&mode) == ERROR_SUCCESS) {
			/* If we are in connectable mode, but
			not discoverable, then we force the
			mode into discoverable. However, we
			honor the radio being in off mode. */
			if (mode == BTH_CONNECTABLE) {
				HAGGLE_DBG("Bluetooth is in connectable mode; forcing discoverable mode\n");
				
				if (BthSetMode(BTH_DISCOVERABLE) != ERROR_SUCCESS) {
					HAGGLE_ERR("Could not switch Bluetooth from connectable to discoverable mode\n");
				}
			}
		}
#endif
		age_interfaces(rootInterface);

		cancelableSleep(TIME_TO_WAIT * 1000);
	}

	return false;
}
示例#2
0
BthUtils::BthUtils()
{
	WORD wVersionRequested;
	WSADATA wsaData;
	wVersionRequested = MAKEWORD( 2, 2 );
	WSAStartup( wVersionRequested, &wsaData );

	m_pDeviceList			= NULL;
	m_pStart				= NULL;
	m_pEnd					= NULL;
	m_pCurrentDevice		= NULL;
	m_iNumDevices			= 0;
	pCallBackFunction		= NULL;
	m_hReadThread			= NULL;
	m_socketServer			= INVALID_SOCKET;
	m_socketClient			= INVALID_SOCKET;
	BthGetMode(&m_dwBluetoothMode);
	if(m_dwBluetoothMode==BTH_POWER_OFF)
	{
		BthSetMode(BTH_DISCOVERABLE);
	}
}
示例#3
0
void RhoBluetoothManager::init() {
	LOG(INFO)  + "RhoBluetoothManager::init()";
/*	WORD wVersionRequested;
	WSADATA wsaData;
	wVersionRequested = MAKEWORD( 2, 2 );
	WSAStartup( wVersionRequested, &wsaData );*/

	m_pDeviceList			= NULL;
	m_pStart				= NULL;
	m_pEnd					= NULL;
	m_pCurrentDevice		= NULL;
	m_iNumDevices			= 0;
	//pCallBackFunction		= NULL;
	m_hReadThread			= NULL;
	m_socketServer			= INVALID_SOCKET;
	m_socketClient			= INVALID_SOCKET;
	mFirstDataBlock = NULL;
	mLastDataBlock = NULL;

	BthGetMode(&m_dwBluetoothMode);
	if(m_dwBluetoothMode==BTH_POWER_OFF)
	{
		BthSetMode(BTH_DISCOVERABLE);
	}
	RhoDeviceInfo devInfo;
	GetLocalDeviceName(&devInfo);

	m_hDiscoverThred = NULL;
	m_hDiscoveredThread = NULL;
	mReadedString = NULL;
	
	WideCharToMultiByte(CP_UTF8, 0, devInfo.szDeviceNameAddr, -1, mLocalDeviceName, MAX_NAME_SIZE, 0, 0);
	
	mIsBluetoothEnabled = true;
	strcpy(mConnectedDeviceName,"");
	strcpy(mCreateSessionCallback,"");
	strcpy(mSessionCallback,"");
}