nethandler.cpp

来自「It s a tool designed to extract as much 」· C++ 代码 · 共 119 行

CPP
119
字号
/* -*- c++ -*- ---------------------------------------------------------------   Copyright (C) 2005, SWECO, All Rights Reserved.   Implementation of NetHandler class   Author: Zsolt Molnar (Zsolt.Molnar@ieee.org)   ---------------------------------------------------------------------------*/#include <sstream>#include "AppFactory.hh"#include "IRFCommHandler.hh"#include "NetHandler.hh"#include <iostream>namespace { 	const char rcs_id[] = "$Id$"; }bool NetHandler::connect(const Device& aDevice){	lock();	_toConnect.push_back(aDevice);	unlock();	return true;}	void NetHandler::unconnect(const Device& aDevice){	lock();	// Check if it is connected.	_tToConenct::iterator pos = find(_toConnect.begin(), 									 _toConnect.end(), aDevice);		if (pos != _toConnect.end()) {		_toConnect.erase(pos);	}	unlock();}void NetHandler::commit(){	lock();	// Go through the connection database.	for (_tToConenct::iterator pos = _toConnect.begin(); 		 pos != _toConnect.end(); ++pos) 	{		AppFactory::getRFCommHandler().serial_connect(*pos);	}		_toConnect.resize(0);	unlock();}#ifdef __TEST__#include <assert.h>#include <iostream>boolNetHandler::test(){	Device dev_1("00:0E:6D:32:0D:FF", Device::NOKIA6600);	Device dev_2("00:60:57:A3:DF:28", Device::NOKIA6600);	Device dev_3("11:11:11:11:11:11", Device::NOKIA6600);	// Check the bindings - must be 0	cout << endl << "Check the bindings: no bindings. Press enter if OK." 		 << endl;	system("rfcomm -a");	getchar();	// Connect 1 device	assert(connect(dev_1));	commit();	// Check the bindings	cout << endl << "Check the bindings: " << dev_1.devID 		 << " must be bound. Press enter if OK." << endl;	system("rfcomm -a");	getchar();		// Connect 1 more device	assert(connect(dev_2));	commit();	// check the binding	cout << endl << "Check the bindings: " << dev_1.devID 		 << " and " << dev_2.devID << " must be bound. Press enter if OK." 		 << endl;	system("rfcomm -a");	getchar();		// unconnect the last device	unconnect(dev_2);	commit();	cout << endl << "Check the bindings: " << dev_1.devID 		 << " and " << dev_2.devID << " must be bound. Press enter if OK." 		 << endl;	system("rfcomm -a");	getchar();	// reconenct a device	assert(connect(dev_1));	commit();	// Check the bindings	cout << endl << "Check the bindings: " << dev_1.devID 		 << " and " << dev_2.devID << " must be bound. Press enter if OK." 		 << endl;	system("rfcomm -a");	getchar();			cout << "NetHandler test passed" << endl;	return true;}#endif // #ifdef __TEST__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?