From a1bcbe41d45924713c4ead9b25ac5518473c9ca9 Mon Sep 17 00:00:00 2001 From: korovkin Date: Fri, 14 Apr 2006 19:22:37 +0000 Subject: Added RFCOMM <-> serial line forwarding functionality. --- (limited to 'noncore/net/opietooth/manager/bluebase.cpp') diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 0649514..9ec5bf8 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp @@ -21,6 +21,10 @@ #include "devicehandler.h" #include "btconnectionitem.h" #include "rfcommassigndialogimpl.h" +#include "forwarder.h" +#include +#include +#include /* OPIE */ #include @@ -41,6 +45,7 @@ using namespace Opie::Core; #include #include #include +#include #include #include #include @@ -55,6 +60,16 @@ using namespace Opie::Core; #include using namespace OpieTooth; +//Array of possible speeds of the serial port +struct SerSpeed { + const char* str; //string value + int val; //value itself +} speeds[] = { + { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 }, + { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 }, + { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 }, + { "115200", B115200} +}; BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) : BluetoothBase( parent, name, fl ) @@ -78,6 +93,7 @@ BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), this, SLOT( addSignalStrength(const QString&,const QString&) ) ); + connect(runButton, SIGNAL(clicked()), this, SLOT(doForward())); // let hold be rightButtonClicked() QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold); @@ -108,6 +124,12 @@ BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) readSavedDevices(); addServicesToDevices(); QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) ); + forwarder = NULL; + serDevName->setText(tr("/dev/ircomm0")); + for (unsigned int i = 0; i < (sizeof(speeds) / sizeof(speeds[0])); i++) { + serSpeed->insertItem(speeds[i].str); + } + serSpeed->setCurrentItem((sizeof(speeds) / sizeof(speeds[0])) - 1); } /** @@ -680,3 +702,42 @@ bool BlueBase::find( const RemoteDevice& rem ) } return false; // not found } + +/** + * Start process of the cell phone forwarding + */ +void BlueBase::doForward() +{ + if (forwarder && forwarder->isRunning()) { + runButton->setText("start gateway"); + forwarder->stop(); + delete forwarder; + forwarder = NULL; + return; + } + QString str = serDevName->text(); + forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val); + connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)), + this, SLOT(forwardExited(Opie::Core::OProcess*))); + if (forwarder->start(OProcess::NotifyOnExit) < 0) { + QMessageBox::critical(this, tr("Forwarder Error"), + tr("Forwarder start error:") + tr(strerror(errno))); + return; + } + runButton->setText("stop gateway"); +} + +/** + * React on the process end + */ +void BlueBase::forwardExit(Opie::Core::OProcess* proc) +{ + if (proc->exitStatus() != 0) + QMessageBox::critical(this, tr("Forwarder Error"), + tr("Forwarder start error")); + delete proc; + forwarder = NULL; + runButton->setText("start gateway"); +} + +//eof -- cgit v0.9.0.2