summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/modem.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp45
1 files changed, 22 insertions, 23 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index 5139482..002c8e7 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -59,13 +59,13 @@
qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \
exit(1); }
static sigjmp_buf jmp_buffer;
-Modem *Modem::modem = 0;
+//Modem *Modem::modem = 0;
const char* pppdPath() {
// wasting a few bytes
static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)];
static char *pppdPath = 0L;
@@ -88,37 +88,36 @@ const char* pppdPath() {
}
return pppdPath;
}
-Modem::Modem()
+Modem::Modem( PPPData* pd )
{
- if (Modem::modem != 0) return; //CORRECT?
+ _pppdata = pd;
modemfd = -1;
_pppdExitStatus = -1;
pppdPid = -1;
sn = 0L;
data_mode = false;
modem_is_locked = false;
lockfile[0] = '\0';
device = "/dev/modem";
- modem = this;
}
-Modem::~Modem() {
- modem = 0;
+Modem::~Modem()
+{
}
speed_t Modem::modemspeed() {
// convert the string modem speed int the gpppdata object to a t_speed type
// to set the modem. The constants here should all be ifdef'd because
// other systems may not have them
- int i = PPPData::data()->speed().toInt()/100;
+ int i = _pppdata->speed().toInt()/100;
switch(i) {
case 24:
return B2400;
break;
case 96:
@@ -162,23 +161,23 @@ speed_t Modem::modemspeed() {
bool Modem::opentty() {
// int flags;
//begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
close(modemfd);
- device = PPPData::data()->modemDevice();
+ device = _pppdata->modemDevice();
if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) {
qDebug("error opening modem device !");
errmsg = i18n("Unable to open modem.");
return false;
}
//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
//}
#if 0
- if(PPPData::data()->UseCDLine()) {
+ if(_pppdata->UseCDLine()) {
if(ioctl(modemfd, TIOCMGET, &flags) == -1) {
errmsg = i18n("Unable to detect state of CD line.");
::close(modemfd);
modemfd = -1;
return false;
}
@@ -220,14 +219,14 @@ bool Modem::opentty() {
tty.c_cflag |= CLOCAL; // ignore modem status lines
tty.c_iflag = IGNBRK | IGNPAR /* | ISTRIP */ ;
tty.c_lflag &= ~ICANON; // non-canonical mode
tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHOKE);
- if(PPPData::data()->flowcontrol() != "None") {
- if(PPPData::data()->flowcontrol() == "CRTSCTS") {
+ if(_pppdata->flowcontrol() != "None") {
+ if(_pppdata->flowcontrol() == "CRTSCTS") {
tty.c_cflag |= CRTSCTS;
}
else {
tty.c_iflag |= IXON | IXOFF;
tty.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
tty.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
@@ -350,13 +349,13 @@ bool Modem::writeChar(unsigned char c) {
bool Modem::writeLine(const char *buf) {
int len = strlen(buf);
char *b = new char[len+2];
memcpy(b, buf, len);
// different modems seem to need different line terminations
- QString term = PPPData::data()->enter();
+ QString term = _pppdata->enter();
if(term == "LF")
b[len++]='\n';
else if(term == "CR")
b[len++]='\r';
else if(term == "CR/LF") {
b[len++]='\r';
@@ -390,15 +389,15 @@ bool Modem::hangup() {
// is this Escape & HangupStr stuff really necessary ? (Harri)
if (data_mode) escape_to_command_mode();
// Then hangup command
- writeLine(PPPData::data()->modemHangupStr().local8Bit());
+ writeLine(_pppdata->modemHangupStr().local8Bit());
- usleep(PPPData::data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec
+ usleep(_pppdata->modemInitDelay() * 10000); // 0.01 - 3.0 sec
#ifndef DEBUG_WO_DIALING
if (sigsetjmp(jmp_buffer, 1) == 0) {
// set alarm in case tcsendbreak() hangs
signal(SIGALRM, alarm_handler);
alarm(2);
@@ -428,13 +427,13 @@ bool Modem::hangup() {
ioctl(modemfd, TIOCMSET, &modemstat);
ioctl(modemfd, TIOCMGET, &modemstat);
modemstat |= TIOCM_DTR;
ioctl(modemfd, TIOCMSET, &modemstat);
#endif
- usleep(PPPData::data()->modemInitDelay() * 10000); // 0.01 - 3.0 secs
+ usleep(_pppdata->modemInitDelay() * 10000); // 0.01 - 3.0 secs
cfsetospeed(&temptty, modemspeed());
cfsetispeed(&temptty, modemspeed());
tcsetattr(modemfd, TCSAFLUSH, &temptty);
#endif
return true;
@@ -451,17 +450,17 @@ void Modem::escape_to_command_mode() {
// Need to send properly timed escape sequence to put modem in command state.
// Escape codes and guard times are controlled by S2 and S12 values.
//
tcflush(modemfd, TCIOFLUSH);
// +3 because quiet time must be greater than guard time.
- usleep((PPPData::data()->modemEscapeGuardTime()+3)*20000);
- QCString tmp = PPPData::data()->modemEscapeStr().local8Bit();
+ usleep((_pppdata->modemEscapeGuardTime()+3)*20000);
+ QCString tmp = _pppdata->modemEscapeStr().local8Bit();
write(modemfd, tmp.data(), tmp.length());
tcflush(modemfd, TCIOFLUSH);
- usleep((PPPData::data()->modemEscapeGuardTime()+3)*20000);
+ usleep((_pppdata->modemEscapeGuardTime()+3)*20000);
data_mode = false;
}
const QString Modem::modemMessage() {
@@ -571,22 +570,22 @@ QString Modem::parseModemSpeed(const QString &s) {
// Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if
// a lock file can't be created ( permission problem )
int Modem::lockdevice() {
int fd;
char newlock[80]=""; // safe
- if(!PPPData::data()->modemLockFile()) {
+ if(!_pppdata->modemLockFile()) {
qDebug("The user doesn't want a lockfile.");
return 0;
}
if (modem_is_locked)
return 1;
QString lockfile = LOCK_DIR"/LCK..";
- lockfile += PPPData::data()->modemDevice().mid(5); // append everything after /dev/
+ lockfile += _pppdata->modemDevice().mid(5); // append everything after /dev/
if(access(QFile::encodeName(lockfile), F_OK) == 0) {
// if ((fd = Requester::rq->
if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) {
// Mario: it's not necessary to read more than lets say 32 bytes. If
// file has more than 32 bytes, skip the rest
@@ -611,13 +610,13 @@ if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) {
return 1;
qDebug( "lockfile is stale" );
}
}
- fd = openLockfile(PPPData::data()->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT);
+ fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT);
if(fd >= 0) {
sprintf(newlock,"%010d\n", getpid());
qDebug("Locking Device: %s", newlock);
write(fd, newlock, strlen(newlock));
close(fd);
@@ -985,21 +984,21 @@ void Modem::parseargs(char* buf, char** args) {
*args = 0L;
}
bool Modem::execPPPDaemon(const QString & arguments)
{
if(execpppd(arguments)==0) {
- PPPData::data()->setpppdRunning(true);
+ _pppdata->setpppdRunning(true);
return true;
} else
return false;
}
void Modem::killPPPDaemon()
{
- PPPData::data()->setpppdRunning(false);
+ _pppdata->setpppdRunning(false);
killpppd();
}
int Modem::pppdExitStatus()
{
return _pppdExitStatus;