summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamr7 <samr7@126591fb-c623-4b62-a76d-97a8e4f34109>2008-12-15 20:05:58 +0000
committersamr7 <samr7@126591fb-c623-4b62-a76d-97a8e4f34109>2008-12-15 20:05:58 +0000
commit761963e51215c233b49819ae1d685f935c33d33e (patch)
tree6f39cef62500d2e667a117ad962fd39c83498e10
parent45f0c5213d76a9272900b1f045cbb58863fa6dff (diff)
downloadnohands-761963e51215c233b49819ae1d685f935c33d33e.tar.gz
Improve handling of auto-reconnection, notification of the "connecting"
state for HfpSession/AudioGateway, and name lookups. git-svn-id: http://nohands.svn.sourceforge.net/svnroot/nohands/trunk@69 126591fb-c623-4b62-a76d-97a8e4f34109
-rw-r--r--hfpd/objects.cpp12
-rw-r--r--include/libhfp/hfp.h11
-rw-r--r--libhfp/hfp.cpp109
3 files changed, 93 insertions, 39 deletions
diff --git a/hfpd/objects.cpp b/hfpd/objects.cpp
index a71b9ca..4d7dd2f 100644
--- a/hfpd/objects.cpp
+++ b/hfpd/objects.cpp
@@ -481,7 +481,11 @@ NotifyConnection(libhfp::HfpSession *sessp, ErrorInfo *reason)
DoDisconnect();
}
- else if (st == HFPD_AG_CONNECTING) {
+ else if (st == HFPD_AG_CONNECTED) {
+ char buf[32];
+ m_sess->GetDevice()->GetAddr(buf);
+ GetDi()->LogInfo("AG %s: Connected", buf);
+
/*
* Trigger a name lookup if one would be helpful.
* This is probably the best time to do it for
@@ -492,12 +496,6 @@ NotifyConnection(libhfp::HfpSession *sessp, ErrorInfo *reason)
(void) sessp->GetDevice()->ResolveName();
}
- if (st == HFPD_AG_CONNECTED) {
- char buf[32];
- m_sess->GetDevice()->GetAddr(buf);
- GetDi()->LogInfo("AG %s: Connected", buf);
- }
-
UpdateState(st);
}
diff --git a/include/libhfp/hfp.h b/include/libhfp/hfp.h
index 8bf1b3f..5d67006 100644
--- a/include/libhfp/hfp.h
+++ b/include/libhfp/hfp.h
@@ -95,21 +95,24 @@ private:
char *m_svc_desc;
sdp_record_t *m_sdp_rec;
- TimerNotifier *m_timer;
-
- void Timeout(TimerNotifier*);
+ void AutoReconnectTimeout(TimerNotifier*);
bool m_sco_enable;
ListItem m_autoreconnect_list;
int m_autoreconnect_timeout;
bool m_autoreconnect_set;
+ TimerNotifier *m_autoreconnect_timer;
+
+ ListItem m_autoreconnect_now_list;
+ bool m_autoreconnect_now_set;
+ TimerNotifier *m_autoreconnect_now_timer;
bool m_complaint_sco_mtu;
bool m_complaint_sco_vs;
bool m_complaint_sco_listen;
- void AddAutoReconnect(HfpSession *sessp);
+ void AddAutoReconnect(HfpSession *sessp, bool now = false);
void RemoveAutoReconnect(HfpSession *sessp);
bool ScoListen(ErrorInfo *error);
diff --git a/libhfp/hfp.cpp b/libhfp/hfp.cpp
index 09770fd..5ddeb57 100644
--- a/libhfp/hfp.cpp
+++ b/libhfp/hfp.cpp
@@ -54,8 +54,10 @@ HfpService(int caps)
: RfcommService(HANDSFREE_AGW_SVCLASS_ID),
m_sco_listen(-1), m_sco_listen_not(0),
m_brsf_my_caps(caps), m_svc_name(0), m_svc_desc(0),
- m_sdp_rec(0), m_timer(0), m_sco_enable(true),
+ m_sdp_rec(0), m_sco_enable(true),
m_autoreconnect_timeout(15000), m_autoreconnect_set(false),
+ m_autoreconnect_timer(0),
+ m_autoreconnect_now_set(false), m_autoreconnect_now_timer(0),
m_complaint_sco_mtu(false), m_complaint_sco_vs(false),
m_complaint_sco_listen(false)
{
@@ -72,23 +74,33 @@ HfpService::
free(m_svc_desc);
m_svc_desc = 0;
}
- assert(!m_timer);
+ assert(!m_autoreconnect_timer);
+ assert(!m_autoreconnect_now_timer);
}
void HfpService::
-Timeout(TimerNotifier *timerp)
+AutoReconnectTimeout(TimerNotifier *timerp)
{
ListItem retrylist;
- assert(timerp == m_timer);
- assert(m_autoreconnect_set);
- m_autoreconnect_set = false;
+ if (timerp == m_autoreconnect_timer) {
+ assert(m_autoreconnect_set);
+ m_autoreconnect_set = false;
+ retrylist.AppendItemsFrom(m_autoreconnect_list);
+
+ } else {
+ assert(timerp == m_autoreconnect_now_timer);
+ assert(m_autoreconnect_now_set);
+ m_autoreconnect_now_set = false;
+ retrylist.AppendItemsFrom(m_autoreconnect_now_list);
+ }
- retrylist.AppendItemsFrom(m_autoreconnect_list);
while (!retrylist.Empty()) {
HfpSession *sessp = GetContainer(retrylist.next, HfpSession,
m_autoreconnect_links);
sessp->m_autoreconnect_links.UnlinkOnly();
+
+ /* Always append to the delayed list */
m_autoreconnect_list.AppendItem(sessp->m_autoreconnect_links);
sessp->AutoReconnect();
@@ -96,21 +108,30 @@ Timeout(TimerNotifier *timerp)
if (!m_autoreconnect_list.Empty() && !m_autoreconnect_set) {
m_autoreconnect_set = true;
- m_timer->Set(m_autoreconnect_timeout);
+ m_autoreconnect_timer->Set(m_autoreconnect_timeout);
}
}
void HfpService::
-AddAutoReconnect(HfpSession *sessp)
+AddAutoReconnect(HfpSession *sessp, bool now)
{
assert(sessp->m_autoreconnect_links.Empty());
assert(!sessp->IsConnected() && !sessp->IsConnecting());
- if (m_timer && !m_autoreconnect_set) {
- m_autoreconnect_set = true;
- m_timer->Set(m_autoreconnect_timeout);
+ if (now) {
+ if (m_autoreconnect_now_timer && !m_autoreconnect_now_set) {
+ m_autoreconnect_now_set = true;
+ m_autoreconnect_now_timer->Set(0);
+ }
+ m_autoreconnect_now_list.AppendItem(sessp->
+ m_autoreconnect_links);
+ } else {
+ if (m_autoreconnect_timer && !m_autoreconnect_set) {
+ m_autoreconnect_set = true;
+ m_autoreconnect_timer->Set(m_autoreconnect_timeout);
+ }
+ m_autoreconnect_list.AppendItem(sessp->m_autoreconnect_links);
}
- m_autoreconnect_list.AppendItem(sessp->m_autoreconnect_links);
}
void HfpService::
@@ -119,9 +140,18 @@ RemoveAutoReconnect(HfpSession *sessp)
assert(!sessp->m_autoreconnect_links.Empty());
sessp->m_autoreconnect_links.Unlink();
- if (m_timer && m_autoreconnect_list.Empty() && m_autoreconnect_set) {
+ if (m_autoreconnect_timer &&
+ m_autoreconnect_list.Empty() &&
+ m_autoreconnect_set) {
m_autoreconnect_set = false;
- m_timer->Cancel();
+ m_autoreconnect_timer->Cancel();
+ }
+
+ if (m_autoreconnect_now_timer &&
+ m_autoreconnect_now_list.Empty() &&
+ m_autoreconnect_now_set) {
+ m_autoreconnect_now_set = false;
+ m_autoreconnect_now_timer->Cancel();
}
}
@@ -461,15 +491,26 @@ bool HfpService::
Start(ErrorInfo *error)
{
assert(GetHub());
- assert(!m_timer);
- m_timer = GetDi()->NewTimer();
- if (!m_timer) {
+ assert(!m_autoreconnect_timer);
+ assert(!m_autoreconnect_now_timer);
+
+ m_autoreconnect_timer = GetDi()->NewTimer();
+ if (!m_autoreconnect_timer) {
if (error)
error->SetNoMem();
return false;
}
+ m_autoreconnect_timer->Register(this,
+ &HfpService::AutoReconnectTimeout);
- m_timer->Register(this, &HfpService::Timeout);
+ m_autoreconnect_now_timer = GetDi()->NewTimer();
+ if (!m_autoreconnect_now_timer) {
+ if (error)
+ error->SetNoMem();
+ goto failed;
+ }
+ m_autoreconnect_now_timer->Register(this,
+ &HfpService::AutoReconnectTimeout);
if (!RfcommListen(error))
goto failed;
@@ -482,7 +523,12 @@ Start(ErrorInfo *error)
if (!m_autoreconnect_list.Empty() && !m_autoreconnect_set) {
m_autoreconnect_set = true;
- m_timer->Set(0);
+ m_autoreconnect_timer->Set(0);
+ }
+
+ if (!m_autoreconnect_now_list.Empty() && !m_autoreconnect_now_set) {
+ m_autoreconnect_now_set = true;
+ m_autoreconnect_now_timer->Set(0);
}
return true;
@@ -500,10 +546,15 @@ Stop(void)
SdpUnregister();
RfcommCleanup();
ScoCleanup();
- if (m_timer) {
+ if (m_autoreconnect_timer) {
m_autoreconnect_set = false;
- delete m_timer;
- m_timer = 0;
+ delete m_autoreconnect_timer;
+ m_autoreconnect_timer = 0;
+ }
+ if (m_autoreconnect_now_timer) {
+ m_autoreconnect_now_set = false;
+ delete m_autoreconnect_now_timer;
+ m_autoreconnect_now_timer = 0;
}
}
@@ -703,6 +754,9 @@ NotifyConnectionState(ErrorInfo *async_error)
if (IsRfcommConnecting()) {
assert(m_conn_state == BTS_Disconnected);
m_conn_state = BTS_RfcommConnecting;
+ assert(!async_error);
+ if (cb_NotifyConnection.Registered())
+ cb_NotifyConnection(this, 0);
}
else if (IsRfcommConnected()) {
@@ -802,7 +856,8 @@ AutoReconnect(void)
assert(m_conn_autoreconnect);
assert(m_conn_state == BTS_Disconnected);
- (void) Connect();
+ if (Connect() && cb_NotifyConnection.Registered())
+ cb_NotifyConnection(this, 0);
/*
* We could invoke cb_NotifyConnectionState here, but
@@ -819,10 +874,8 @@ SetAutoReconnect(bool enable)
if (enable && !m_conn_autoreconnect) {
Get();
m_conn_autoreconnect = true;
- if (m_conn_state == BTS_Disconnected) {
- GetService()->AddAutoReconnect(this);
- (void) Connect();
- }
+ if (m_conn_state == BTS_Disconnected)
+ GetService()->AddAutoReconnect(this, true);
}
else if (!enable && m_conn_autoreconnect) {
m_conn_autoreconnect = false;