Example #1
0
BthUtils::~BthUtils()
{
	//Set radio mode back to original state
	BthSetMode(m_dwBluetoothMode);
	if(m_pStart)
	{
		for(m_pCurrentDevice	= m_pStart;m_pCurrentDevice;)
		{
			DeviceList *temp	= m_pCurrentDevice;
			m_pCurrentDevice	= m_pCurrentDevice->NextDevice;
			free(temp);
		}
		m_pStart=NULL;
	}

	if(m_socketClient)
	    closesocket (m_socketClient);
    if(m_socketServer)
        closesocket (m_socketServer);
	
	//Terminate the read thread that receives chat messages from the client
	if(m_hReadThread)
	{
		DWORD dwExitCode = 0;
		TerminateThread(m_hReadThread, dwExitCode);
	}

	WSACleanup();

}
Example #2
0
void RhoBluetoothManager::freeAll() {
	LOG(INFO)  + "RhoBluetoothManager::freeAll()";
	//Set radio mode back to original state
	BthSetMode(m_dwBluetoothMode);
	if(m_pStart)
	{
		for(m_pCurrentDevice	= m_pStart;m_pCurrentDevice;)
		{
			RhoDeviceList *temp	= m_pCurrentDevice;
			m_pCurrentDevice	= m_pCurrentDevice->NextDevice;
			free(temp);
		}
		m_pStart=NULL;
	}

	if(m_socketClient) {
		closesocket (m_socketClient);
	}
	if(m_socketServer) {
		closesocket (m_socketServer);
	}

	//Terminate the read thread that receives chat messages from the client
	if(m_hReadThread)
	{
		DWORD dwExitCode = 0;
		TerminateThread(m_hReadThread, dwExitCode);
	}
	if (m_hDiscoverThred) {
		DWORD dwExitCode = 0;
		TerminateThread(m_hDiscoverThred, dwExitCode);
	}
	if (m_hDiscoveredThread) {
		DWORD dwExitCode = 0;
		TerminateThread(m_hDiscoveredThread, dwExitCode);
	}
	if (mReadedString) {
		delete mReadedString;
		mReadedString = NULL;
	}

//	WSACleanup();

	freeAllBlocks();
}
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;
}
Example #4
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);
	}
}
Example #5
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,"");
}