CVS commit by gulino: Device hotplug M +41 -12 device.cpp 1.3 M +8 -1 device.h 1.5 --- kdenonbeta/kmobiletools/kmobiletools/engines/at_engine/device.cpp #1.2:1.3 @@ -28,5 +28,5 @@ #include #include - +#include #include #include @@ -44,10 +44,8 @@ Device::Device(const char* name) locked=false; modem=-1; - modem = open( Config->at_path() , O_RDWR | O_NOCTTY | O_NONBLOCK ); - kdDebug() << "Modem handle: " << modem << endl; - setupModem(); - sendCommand("\x1A\r",5); - sendCommand(Config->at_initString()+ "\r",5); - if ( Config->at_initString2().length() >0 ) sendCommand(Config->at_initString2() + "\r",5); + + QTimer *devicePollTimer = new QTimer( this ); + connect( devicePollTimer, SIGNAL(timeout()), this, SLOT(slotDevicePoll() ) ); + devicePollTimer->start( 400, FALSE ); } @@ -232,2 +230,33 @@ QString Device::decodePDU( QString text return decoded; } + + +/*! + \fn Device::slotDevicePoll() + */ +void Device::slotDevicePoll() +{ + /** A little bit of documentation here... + When modem is -1, we're not connected, so we should try to connect. + When modem is positive, we send a ioctl to check if it's already online, if not we send a disconnect() signal + */ + if(modem==-1) + { + modem = open( Config->at_path() , O_RDWR | O_NOCTTY | O_NONBLOCK ); + kdDebug() << "Modem handle: " << modem << endl; + setupModem(); + sendCommand("\x1A\r",5); + sendCommand(Config->at_initString()+ "\r",5); + if ( Config->at_initString2().length() >0 ) sendCommand(Config->at_initString2() + "\r",5); + emit connected(); + return; + } + if(ioctl(modem, TIOCMGET, &ioctlDummy) == -1 ) + { + emit disconnected(); + modem=-1; + kdDebug() << "Modem disconnected" << endl; + return; + } + kdDebug() << "Modem works correctly" << endl; +} --- kdenonbeta/kmobiletools/kmobiletools/engines/at_engine/device.h #1.4:1.5 @@ -29,5 +29,5 @@ */ class DevicesConfig; - +class QTimer; class Device : public QObject { @@ -45,5 +45,7 @@ public: private: DevicesConfig* Config; + QTimer *devicePollTimer; long jobCount; + int ioctlDummy; protected: void setupModem(); @@ -56,4 +58,9 @@ public slots: int sendChar(unsigned char c); char* getDevBuffer(); + void slotDevicePoll(); +signals: + void disconnected(); + void connected(); + void error(); };