home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 Mobile
/
Chip_Mobile_2001.iso
/
palm
/
business
/
printcar
/
printcar.exe
/
src
/
IrDA
/
IrPort.cc
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-06
|
3KB
|
152 lines
//
// $Id: IrPort.cc,v 1.4 2000/06/06 09:30:57 sergey Exp $
//
#include <Pilot.h>
#include <irlib.h>
#include "IrPort.h"
#include "IrConnection.h"
#include "IrError.h"
#include "Util/Error.h"
#include "Util/Assert.h"
namespace IrDA
{
//==============================================================================
// Constants
//==============================================================================
const Word NULL_REF_NUM = 0xFFFF;
//==============================================================================
// Port class
//==============================================================================
Port::Port():
_opened(false),
_refNum(NULL_REF_NUM),
_connection(new Connection)
{}
Port::~Port()
{
close();
delete _connection;
}
// operations
bool Port::open(Callback* callback)
{
assert(!_opened);
if(!initIrLib())
return false;
if (IrOpen(_refNum, irOpenOptSpeed115200) != 0)
{
IrError::openIrLibraryError();
return false;
}
// connection could be NULL if allocation in constructor has been failed
if (_connection == NULL || !_connection->init(_refNum, callback))
{
IrClose(_refNum);
return false;
}
_opened = true;
return true;
}
void Port::close()
{
if (isOpened())
{
_connection->shutdown();
if (!IrClose(_refNum) == 0)
IrError::closeIrLibraryError();
_opened = false;
}
}
bool Port::connect()
{
assert(isOpened());
return _connection->connect();
}
void Port::disconnect()
{
assert(isOpened());
_connection->disconnect();
}
bool Port::sendData(const Byte* data, int size)
{
assert(isOpened());
if (_connection->ready())
return _connection->sendData(data, size);
return false;
}
bool Port::blockingSendData(const Byte* data, int size)
{
assert(isOpened());
if (_connection->ready())
return _connection->blockingSendData(data, size);
return false;
}
// attributes
bool Port::isConnected() const
{
return isOpened() && _connection->ready();
}
int Port::getMaxTxSize() const
{
assert(isOpened());
if (_connection->ready())
return _connection->getMaxTxSize();
}
bool Port::dataSendReady() const
{
assert(isOpened());
if (_connection->ready())
return _connection->dataSendReady();
}
// implementation
bool Port::initIrLib()
{
if (_refNum == NULL_REF_NUM)
{
if (SysLibFind(irLibName, &_refNum) != 0)
{
Util::Error::findLibraryError(irLibName);
_refNum = NULL_REF_NUM;
return false;
}
}
return true;
}
}
// namespace IrDA