Fixing a bug in updating local prefix
diff --git a/src/chatdialog.cpp b/src/chatdialog.cpp
index ce972c3..91282da 100644
--- a/src/chatdialog.cpp
+++ b/src/chatdialog.cpp
@@ -720,7 +720,7 @@
m_scene->plot("Empty");
}
- // ui->textEdit->clear();
+ ui->textEdit->clear();
// keep the new prefix
QString newPrefix = m_user.getPrefix();
@@ -748,10 +748,10 @@
usleep(100000);
// Sync::CcnxWrapperPtr handle = boost::make_shared<Sync::CcnxWrapper> ();
// handle->setInterestFilter(m_user.getPrefix().toStdString(), bind(&ChatDialog::respondHistoryRequest, this, _1));
- sendJoin();
+ QTimer::singleShot(600, this, SLOT(sendJoin()));
m_timer->start(FRESHNESS * 1000);
disableTreeDisplay();
- enableTreeDisplay();
+ QTimer::singleShot(2200, this, SLOT(enableTreeDisplay()));
}catch(ndn::Error::ndnOperation& e){
emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
}
@@ -890,22 +890,36 @@
void
ChatDialog::updateLocalPrefix()
{
+ m_newLocalPrefixReady = false;
ndn::Ptr<ndn::Interest> interest = ndn::Ptr<ndn::Interest>(new ndn::Interest(ndn::Name("/local/ndn/prefix")));
interest->setChildSelector(ndn::Interest::CHILD_RIGHT);
+ interest->setInterestLifetime(1);
- ndn::Ptr<ndn::Closure> closure = ndn::Ptr<ndn::Closure>(new ndn::Closure(boost::bind(&ChatDialog::getLocalPrefix,
+ ndn::Ptr<ndn::Closure> closure = ndn::Ptr<ndn::Closure>(new ndn::Closure(boost::bind(&ChatDialog::onLocalPrefix,
this,
_1),
- boost::bind(&ChatDialog::getLocalPrefixTimeout,
+ boost::bind(&ChatDialog::onLocalPrefixTimeout,
this,
_1,
_2),
- boost::bind(&ChatDialog::getLocalPrefix,
+ boost::bind(&ChatDialog::onLocalPrefix,
this,
_1)));
m_localPrefixHandler->sendInterest(interest, closure);
-
+ while(m_newLocalPrefixReady == false)
+ {
+#if BOOST_VERSION >= 1050000
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
+#else
+ boost::this_thread::sleep(boost::posix_time::milliseconds(100));
+#endif
+ }
+ _LOG_DEBUG("now the prefix is " << m_localPrefix.toUri());
+ QString originPrefix = QString::fromStdString(m_newLocalPrefix.toUri());
+
+ if (originPrefix != "" && m_user.getOriginPrefix () != originPrefix)
+ emit settingUpdated(m_user.getNick (), m_user.getChatroom (), originPrefix);
}
static std::string chars2("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
@@ -924,18 +938,20 @@
}
void
-ChatDialog::getLocalPrefix(ndn::Ptr<ndn::Data> data)
+ChatDialog::onLocalPrefix(ndn::Ptr<ndn::Data> data)
{
string dataString(data->content().buf(), data->content().size());
QString originPrefix = QString::fromStdString (dataString).trimmed ();
-
- if (originPrefix != "" && m_user.getOriginPrefix () != originPrefix)
- emit settingUpdated(m_user.getNick (), m_user.getChatroom (), originPrefix);
+ string trimmedString = originPrefix.toStdString();
+ m_newLocalPrefix = ndn::Name(trimmedString);
+ m_newLocalPrefixReady = true;
}
void
-ChatDialog::getLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest)
+ChatDialog::onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest)
{
+ m_newLocalPrefix = m_localPrefix;
+ m_newLocalPrefixReady = true;
}
void
diff --git a/src/chatdialog.h b/src/chatdialog.h
index 7058d87..20280e8 100644
--- a/src/chatdialog.h
+++ b/src/chatdialog.h
@@ -149,10 +149,10 @@
ndn::Ptr<ndn::Interest> interest);
void
- getLocalPrefix(ndn::Ptr<ndn::Data> data);
+ onLocalPrefix(ndn::Ptr<ndn::Data> data);
void
- getLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure,
+ onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure,
ndn::Ptr<ndn::Interest> interest);
// void
@@ -284,7 +284,10 @@
ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
ndn::Ptr<ndn::security::Keychain> m_keychain;
ndn::Ptr<ndn::Wrapper> m_handler;
+
ndn::Ptr<ndn::Wrapper> m_localPrefixHandler;
+ ndn::Name m_newLocalPrefix;
+ bool m_newLocalPrefixReady;
User m_user;
std::string m_nick;
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index e31602d..95e1922 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -93,7 +93,7 @@
showError(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
}
-
+ m_localPrefix = Name("/private/local");
setLocalPrefix();
setInvitationListener();
@@ -260,7 +260,13 @@
ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry)
{
if(retry > 0)
- setLocalPrefix(retry - 1);
+ {
+ setLocalPrefix(retry - 1);
+ return;
+ }
+ else{
+ m_localPrefix = Name("/private/local");
+ }
}
void