From: Frank Seidel <frank@f-seidel.de>
Subject: Change portusage to use 2nd for only for setup and queries
---
 src/base/SerialPort.cpp                    |    6 ++--
 src/base/SerialPort.h                      |    3 +-
 src/controller/TheDeviceManagerSingleton.h |    3 ++
 src/model/Device.cpp                       |   42 +++++++++++++++++++++++++++++
 src/model/Device.h                         |    6 +++-
 src/model/PPPConnection.cpp                |   12 ++++++--
 6 files changed, 65 insertions(+), 7 deletions(-)

--- a/src/model/Device.cpp
+++ b/src/model/Device.cpp
@@ -167,6 +167,48 @@ Device::setupPPPPort(const QString& aSer
 	return true;
 }
 
+bool
+Device::dialPPPPort(const QString& atdCommand)
+{
+	DEBUG5("dialPPPPort called\n");
+	QString myAnswer("");
+	int ch;
+
+	if (thePPPSerialPortName.isEmpty() || atdCommand.isEmpty())
+		return false;
+
+	if (thePPPSerialPortPtr != NULL)
+	{
+		thePPPSerialPortPtr->closeDev();
+		delete thePPPSerialPortPtr;
+		thePPPSerialPortPtr = NULL;
+	}
+
+	thePPPSerialPortPtr = new SerialPort(false);
+
+        // the SerialPort class will automatically setup the Query class
+        if (thePPPSerialPortPtr->openDev(thePPPSerialPortName) == false)
+                goto not_good;
+
+	if (thePPPSerialPortPtr->writeDev("\r"+atdCommand+"\r") == false)
+		goto not_good;
+
+        while((ch=thePPPSerialPortPtr->getOneByte()) >0)
+                myAnswer += ch;
+
+	myAnswer.replace("\r\n", " ");
+	myAnswer.replace("\r", "");
+	DEBUG1("dialPPPPort answer: %s\n", myAnswer.ascii());
+
+	return true;
+
+not_good:
+        delete thePPPSerialPortPtr;
+	thePPPSerialPortPtr = NULL;
+
+        return false;
+}
+
 // ###########################################################################
 // ###########################################################################
 
--- a/src/model/Device.h
+++ b/src/model/Device.h
@@ -74,6 +74,9 @@ public:
 	 */
 	virtual bool setupPPPPort(const QString& aSerialPort);
 
+	/// dialPPPPort will issue a ATD on the ppp port
+	virtual bool dialPPPPort(const QString& atdCommand);
+
 	/// @returns PPP port device name
 	const QString&	getPPPSerialPortName(void) const	
 		{ return thePPPSerialPortName; };
@@ -120,6 +123,7 @@ protected:
 
 	ConnectionInfo* theConnectionInfoPtr;
 	SerialPort*	theATSerialPortPtr;
+	SerialPort*     thePPPSerialPortPtr;
 	
 	CardType	theDeviceType;
 
@@ -128,7 +132,7 @@ protected:
 	 *  call the *static* createDeviceInstance method for that
 	 */
 	Device() : theConnectionInfoPtr(NULL),
-		   theATSerialPortPtr(NULL) {};
+		   theATSerialPortPtr(NULL), thePPPSerialPortPtr(NULL) {};
 
 private:
 	/// private, unimplemented copy constructor - don't use
--- a/src/model/PPPConnection.cpp
+++ b/src/model/PPPConnection.cpp
@@ -343,10 +343,16 @@ PPPConnection::startPPP()
 	if (myQuery.runUntilDone() != Query::OK)
 		return false;
 	}
+	if (hasOnlyOnePort)
 	{
-	Query myQuery("ATD*99***" + myConnectStr.number(myCID) + "#");
-	// don't expect an OK following this one...
-	myQuery.run();
+		Query myQuery("ATD*99***" + myConnectStr.number(myCID) + "#");
+		// don't expect an OK following this one...
+		myQuery.run();
+	}
+	else
+	{
+		TheDeviceManagerSingleton::me().dialPPP("ATD*99***"
+			+ myConnectStr.number(myCID) + "#");
 	}
 
 	QStringList myPPPArguments = assembleArgumentList(myProfile);
--- a/src/controller/TheDeviceManagerSingleton.h
+++ b/src/controller/TheDeviceManagerSingleton.h
@@ -68,6 +68,9 @@ public:
 	static bool resetDevice()
 		{	return getDeviceRef().resetATSerial(); };
 
+	static bool dialPPP(const QString& atdCommand)
+		{       return getDeviceRef().dialPPPPort(atdCommand);};
+
 	/// the main entry member to the Singleton
 	static TheDeviceManagerSingleton& me(void);
 	
--- a/src/base/SerialPort.cpp
+++ b/src/base/SerialPort.cpp
@@ -39,7 +39,8 @@ bool SerialPort::closeDev()
 	if (theComFD != -1)
 		close(theComFD);
 	theComFD=-1;
-	Query::setSerial(NULL);
+	if (setQueryPort)
+		Query::setSerial(NULL);
 	return true;
 }
 
@@ -132,7 +133,8 @@ bool SerialPort::openDev(const QString&
   doSmallSleep(200000L); /* Wait a bit (DTR raise) */
   DEBUG5("Opened '%s' as FD %d\n", aDeviceName.ascii(), theComFD);
 
-  Query::setSerial(this);
+  if (setQueryPort)
+    Query::setSerial(this);
   return true;
 }
 
--- a/src/base/SerialPort.h
+++ b/src/base/SerialPort.h
@@ -42,7 +42,7 @@
 class SerialPort
 {
 public:
-	SerialPort()  : theComFD(-1) {};
+	SerialPort(bool modQuery = true)  : theComFD(-1), setQueryPort(modQuery) {};
 	virtual ~SerialPort();
 
 	/** open a serial device for communication. 
@@ -88,6 +88,7 @@ private:
 	
 	int thePortSpeed;
 	QString theDevName;
+	bool setQueryPort;
 };
 
 

