Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
9564f55a
Commit
9564f55a
authored
Sep 29, 2005
by
jpbl
Browse files
better connection handling
parent
2dcc14a0
Changes
13
Hide whitespace changes
Inline
Side-by-side
src/gui/official/PhoneLineManagerImpl.cpp
View file @
9564f55a
...
...
@@ -18,6 +18,9 @@ PhoneLineManagerImpl::PhoneLineManagerImpl()
{
EventFactory
::
instance
().
registerEvent
<
HangupEvent
>
(
"002"
);
EventFactory
::
instance
().
registerEvent
<
IncommingEvent
>
(
"001"
);
QObject
::
connect
(
this
,
SIGNAL
(
connected
()),
this
,
SLOT
(
startSession
()));
}
PhoneLineManagerImpl
::~
PhoneLineManagerImpl
()
...
...
@@ -42,6 +45,14 @@ PhoneLineManagerImpl::initialize()
}
}
void
PhoneLineManagerImpl
::
start
()
{
isInitialized
();
mSession
->
connect
();
}
void
PhoneLineManagerImpl
::
isInitialized
()
{
QMutexLocker
guard
(
&
mIsInitializedMutex
);
...
...
@@ -50,6 +61,12 @@ void PhoneLineManagerImpl::isInitialized()
}
}
void
PhoneLineManagerImpl
::
connect
()
{
mSession
->
connect
();
}
void
PhoneLineManagerImpl
::
startSession
()
{
...
...
src/gui/official/PhoneLineManagerImpl.hpp
View file @
9564f55a
...
...
@@ -44,6 +44,8 @@ public:
signals:
void
unselected
(
unsigned
int
);
void
selected
(
unsigned
int
);
void
connected
();
void
disconnected
();
public
slots
:
/**
...
...
@@ -56,11 +58,18 @@ public slots:
void
initialize
();
/**
* This will send all the command needed when a
* connection has just been established.
* This function will make the process to start.
* It will connect to the server, and start the
* event handling.
*/
void
startSession
();
void
start
();
/**
* This will ask the session to connect
* to the sflphone server.
*/
void
connect
();
void
sendKey
(
Qt
::
Key
c
);
/**
...
...
@@ -135,6 +144,13 @@ public slots:
*/
PhoneLine
*
selectNextAvailableLine
();
private
slots
:
/**
* This will send all the command needed when a
* connection has just been established.
*/
void
startSession
();
private:
void
isInitialized
();
...
...
src/gui/official/RequesterImpl.cpp
View file @
9564f55a
...
...
@@ -86,6 +86,18 @@ RequesterImpl::registerSession(const std::string &id,
mSessions
.
insert
(
std
::
make_pair
(
id
,
s
));
}
void
RequesterImpl
::
connect
(
const
std
::
string
&
id
)
{
std
::
map
<
std
::
string
,
SessionIO
*
>::
iterator
pos
=
mSessions
.
find
(
id
);
if
(
pos
==
mSessions
.
end
())
{
throw
std
::
logic_error
(
"Trying to connect an unknown session."
);
}
pos
->
second
->
connect
();
}
int
RequesterImpl
::
getCodeCategory
(
const
std
::
string
&
code
)
{
...
...
src/gui/official/RequesterImpl.hpp
View file @
9564f55a
...
...
@@ -79,6 +79,11 @@ class RequesterImpl
*/
void
registerSession
(
const
std
::
string
&
id
,
SessionIO
*
io
);
/**
* Will ask the session IO with id to connect.
*/
void
connect
(
const
std
::
string
&
id
);
/**
* This function is used to notify that the SessionIO
* input of a session is down. It means that we no longer
...
...
src/gui/official/SFLPhoneApp.cpp
View file @
9564f55a
...
...
@@ -29,6 +29,7 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
Requester
::
instance
().
registerObject
<
CallRelatedRequest
>
(
std
::
string
(
"hold"
));
Requester
::
instance
().
registerObject
<
CallRelatedRequest
>
(
std
::
string
(
"unhold"
));
Requester
::
instance
().
registerObject
<
CallRelatedRequest
>
(
std
::
string
(
"hangup"
));
PhoneLineManager
::
instance
().
start
();
}
void
...
...
@@ -62,4 +63,9 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w)
&
PhoneLineManager
::
instance
(),
SLOT
(
clear
()));
QObject
::
connect
(
w
,
SIGNAL
(
keyPressed
(
Qt
::
Key
)),
&
PhoneLineManager
::
instance
(),
SLOT
(
sendKey
(
Qt
::
Key
)));
QObject
::
connect
(
&
PhoneLineManager
::
instance
(),
SIGNAL
(
disconnected
()),
w
,
SLOT
(
askReconnect
()));
QObject
::
connect
(
w
,
SIGNAL
(
reconnectAsked
()),
&
PhoneLineManager
::
instance
(),
SLOT
(
connect
()));
}
src/gui/official/SFLPhoneWindow.cpp
View file @
9564f55a
#include "SFLPhoneWindow.hpp"
#include <QLabel>
#include <QMessageBox>
#include <QPixmap>
#include <QKeyEvent>
#include <iostream>
...
...
@@ -96,3 +97,21 @@ SFLPhoneWindow::keyPressEvent(QKeyEvent *e) {
// Misc. key
emit
keyPressed
(
Qt
::
Key
(
e
->
key
()));
}
void
SFLPhoneWindow
::
askReconnect
()
{
int
ret
=
QMessageBox
::
critical
(
NULL
,
tr
(
"SFLPhone disconnected"
),
tr
(
"The link between SFLPhone and SFLPhoned is broken.
\n
"
"Do you want to try to reconnect? If not, the application
\n
"
"will close."
),
QMessageBox
::
Retry
|
QMessageBox
::
Default
,
QMessageBox
::
Cancel
|
QMessageBox
::
Escape
);
if
(
ret
==
QMessageBox
::
Retry
)
{
emit
reconnectAsked
();
}
else
{
close
();
}
}
src/gui/official/SFLPhoneWindow.hpp
View file @
9564f55a
...
...
@@ -21,6 +21,14 @@ private:
signals:
void
keyPressed
(
Qt
::
Key
);
void
reconnectAsked
();
public
slots
:
/**
* This function will prompt a message box, to ask
* if the user want to reconnect to sflphoned.
*/
void
askReconnect
();
protected:
void
keyPressEvent
(
QKeyEvent
*
e
);
...
...
src/gui/official/Session.cpp
View file @
9564f55a
...
...
@@ -49,6 +49,13 @@ Session::playTone() const
return
Requester
::
instance
().
send
(
mId
,
"playtone"
,
std
::
list
<
std
::
string
>
());
}
void
Session
::
connect
()
const
{
return
Requester
::
instance
().
connect
(
mId
);
}
std
::
string
Session
::
getEvents
()
const
{
...
...
src/gui/official/Session.hpp
View file @
9564f55a
...
...
@@ -49,6 +49,11 @@ class Session
*/
std
::
string
getEvents
()
const
;
/**
* This function will ask to the SessionIO
* linked to this session to connect.
*/
void
connect
()
const
;
Call
createCall
()
const
;
...
...
src/gui/official/SessionIO.hpp
View file @
9564f55a
...
...
@@ -35,6 +35,9 @@ class SessionIO : public QObject
public:
virtual
~
SessionIO
(){}
public
slots
:
virtual
void
connect
()
{}
/**
* You can use this function for sending request.
* The sending is non-blocking. This function will
...
...
src/gui/official/TCPSessionIO.cpp
View file @
9564f55a
...
...
@@ -18,8 +18,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <QMessageBox>
#include "globals.h"
#include "Requester.hpp"
#include "TCPSessionIO.hpp"
...
...
@@ -35,28 +33,22 @@ TCPSessionIO::TCPSessionIO(const QString &hostname, quint16 port)
this
,
SLOT
(
sendWaitingRequests
()));
QObject
::
connect
(
mSocket
,
SIGNAL
(
connected
()),
this
,
SIGNAL
(
connected
()));
QObject
::
connect
(
mSocket
,
SIGNAL
(
disconnected
()),
this
,
SLOT
(
askReconnect
()));
QObject
::
connect
(
mSocket
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SLOT
(
askReconnect
()));
this
,
SLOT
(
error
()));
QObject
::
connect
(
mSocket
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SIGNAL
(
disconnected
()));
}
TCPSessionIO
::~
TCPSessionIO
()
{}
void
TCPSessionIO
::
askReconnect
()
TCPSessionIO
::
error
()
{
_debug
(
"TCPSessionIO: Link broken.
\n
"
);
int
ret
=
QMessageBox
::
critical
(
NULL
,
tr
(
"SFLPhone disconnected"
),
tr
(
"The link between SFLPhone and SFLPhoned is broken.
\n
"
"Do you want to try to reconnect?"
),
QMessageBox
::
Retry
|
QMessageBox
::
Default
,
QMessageBox
::
Cancel
|
QMessageBox
::
Escape
);
if
(
ret
==
QMessageBox
::
Retry
)
{
connect
();
}
_debug
(
"TCPSessionIO: %s. %d
\n
"
,
mSocket
->
errorString
().
toStdString
().
c_str
(),
mSocket
->
state
());
mSocket
->
close
();
}
void
...
...
src/gui/official/TCPSessionIO.hpp
View file @
9564f55a
...
...
@@ -42,6 +42,7 @@ public:
signals:
void
connected
();
void
disconnected
();
public
slots
:
/**
...
...
@@ -57,10 +58,6 @@ public slots:
virtual
void
send
(
const
QString
&
request
);
virtual
void
send
(
const
std
::
string
&
request
);
/**
*/
void
askReconnect
();
/**
* This function is called when we have
* incomming data on the socket.
...
...
@@ -75,6 +72,13 @@ public slots:
virtual
void
receive
(
std
::
string
&
answer
);
virtual
void
connect
();
private
slots
:
/**
* This function is called when we have an error
* on the socket.
*/
void
error
();
private:
QTcpSocket
*
mSocket
;
QString
mHostname
;
...
...
src/gui/official/TCPSessionIOCreator.cpp
View file @
9564f55a
...
...
@@ -12,7 +12,8 @@ TCPSessionIOCreator::create()
{
TCPSessionIO
*
t
=
new
TCPSessionIO
(
mHostname
,
mPort
);
QObject
::
connect
(
t
,
SIGNAL
(
connected
()),
&
PhoneLineManager
::
instance
(),
SLOT
(
startSession
()));
t
->
connect
();
&
PhoneLineManager
::
instance
(),
SIGNAL
(
connected
()));
QObject
::
connect
(
t
,
SIGNAL
(
disconnected
()),
&
PhoneLineManager
::
instance
(),
SIGNAL
(
disconnected
()));
return
t
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment