Improved the notification model so that it uses Qt signals to avoid core dumps, and improved the gui to increase responsiveness (e.g. forum display, network discovery info, friends, msg deletion and selection)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1050 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-02-22 17:36:39 +00:00
parent 93fa052b58
commit 59cdaba9dc
25 changed files with 298 additions and 292 deletions

View file

@ -75,13 +75,14 @@ int main(int argc, char **argv)
}
/* cleanup */
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
ERR_remove_state(0);
EVP_cleanup();
//CRYPTO_mem_leaks(bio_err);
if (bio_err != NULL) BIO_free(bio_err);
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
ERR_remove_state(0);
EVP_cleanup();
//CRYPTO_mem_leaks(bio_err);
if (bio_err != NULL) BIO_free(bio_err);
return 1;
}
@ -146,5 +147,6 @@ int testForums(p3Forums *forum)
#else
sleep(1);
#endif
return 1 ;
}

View file

@ -109,19 +109,25 @@ int p3ChatService::sendChat(std::wstring msg)
class p3ChatService::AvatarInfo
{
public:
AvatarInfo()
{
_peer_is_new = false ; // true when the peer has a new avatar
_own_is_new = false ; // true when I myself a new avatar to send to this peer.
}
AvatarInfo(const unsigned char *jpeg_data,int size)
{
int n_c = size ;
int p = sizeof(wchar_t) ;
int p = 2 ;// minimum value for sizeof(wchar_t) over win/mac/linux ;
int n = n_c/p + 1 ;
_jpeg_wstring = std::wstring(n,0) ;
for(int i=0;i<n;++i)
{
wchar_t h = jpeg_data[p*i] ;
wchar_t h = jpeg_data[p*i+p-1] ;
for(int j=1;j<p;++j)
for(int j=p-2;j>=0;--j)
{
h = h << 8 ;
h += jpeg_data[p*i+j] ;
@ -135,7 +141,7 @@ class p3ChatService::AvatarInfo
void toUnsignedChar(unsigned char *& data,int& size) const
{
int p = sizeof(wchar_t) ;
int p = 2 ;// minimum value for sizeof(wchar_t) over win/mac/linux ;
int n = _jpeg_wstring.size() ;
int n_c = p*n ;
@ -146,7 +152,7 @@ class p3ChatService::AvatarInfo
{
wchar_t h = _jpeg_wstring[i] ;
for(int j=p-1;j>=0;--j)
for(int j=0;j<p;++j)
{
data[p*i+j] = (unsigned char)(h & 0xff) ;
h = h >> 8 ;
@ -177,16 +183,23 @@ int p3ChatService::sendPrivateChat(std::wstring msg, std::string id)
std::map<std::string,AvatarInfo*>::iterator it = _avatars.find(id) ;
if(it == _avatars.end())
{
_avatars[id] = new AvatarInfo ;
it = _avatars.find(id) ;
}
if(it != _avatars.end() && it->second->_own_is_new)
{
#ifdef CHAT_DEBUG
std::cerr << "p3ChatService::sendPrivateChat: new avatar never sent to peer " << id << ". Setting <new> flag to packet." << std::endl;
#endif
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
it->second->_own_is_new = false ;
}
std::cerr << "Sending msg to peer " << id << ", flags = " << ci->chatFlags << std::endl ;
#ifdef CHAT_DEBUG
std::cerr << "Sending msg to peer " << id << ", flags = " << ci->chatFlags << std::endl ;
std::cerr << "p3ChatService::sendPrivateChat() Item:";
std::cerr << std::endl;
ci->print(std::cerr);
@ -212,8 +225,8 @@ std::list<RsChatItem *> p3ChatService::getChatQueue()
std::cerr << std::endl;
ci->print(std::cerr);
std::cerr << std::endl;
#endif
std::cerr << "Got msg. Flags = " << ci->chatFlags << std::endl ;
#endif
if(ci->chatFlags & RS_CHAT_FLAG_CONTAINS_AVATAR) // no msg here. Just an avatar.
receiveAvatarJpegData(ci) ;

View file

@ -24,6 +24,7 @@
*/
#include "rsiface/rsiface.h"
#include "rsiface/rspeers.h"
#include "services/p3disc.h"
@ -298,13 +299,13 @@ void p3disc::sendOwnDetails(std::string to)
// Then send message.
{
//#ifdef P3DISC_DEBUG
#ifdef P3DISC_DEBUG
std::ostringstream out;
out << "p3disc::sendOwnDetails()";
out << "Constructing a RsDiscItem Message!" << std::endl;
out << "Sending to: " << to;
std::cerr << out.str() << std::endl;
//#endif
#endif
}
// Construct a message
@ -370,13 +371,13 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
/* send it off */
{
//#ifdef P3DISC_DEBUG
#ifdef P3DISC_DEBUG
std::ostringstream out;
out << "p3disc::sendPeerDetails()";
out << " Sending details of: " << about;
out << " to: " << to << std::endl;
std::cerr << out.str() << std::endl;
//#endif
#endif
}
@ -447,13 +448,19 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
if(*it == name)
{
di->discFlags |= P3DISC_FLAGS_PEER_TRUSTS_ME;
#ifdef P3DISC_DEBUG
std::cerr << " Peer " << about << "(" << name << ")" << " is trusting " << to << ", sending info." << std::endl ;
#endif
}
uint32_t certLen = 0;
unsigned char **binptr = (unsigned char **) &(di -> certDER.bin_data);
mAuthMgr->SaveCertificateToBinary(about, binptr, &certLen);
#ifdef P3DISC_DEBUG
std::cerr << "Saved certificate to binary in p3discReply. Length=" << certLen << std::endl ;
#endif
if (certLen > 0)
{
di -> certDER.bin_len = certLen;
@ -483,9 +490,9 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
/*************************************************************************************/
void p3disc::recvPeerOwnMsg(RsDiscItem *item)
{
//#ifdef P3DISC_DEBUG
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::recvPeerOwnMsg() From: " << item->PeerId() << std::endl;
//#endif
#endif
/* tells us their exact address (mConnectMgr can ignore if it looks wrong) */
uint32_t type = 0;
@ -530,8 +537,7 @@ void p3disc::recvPeerOwnMsg(RsDiscItem *item)
/* now reply with all details */
respondToPeer(item->PeerId());
addDiscoveryData(item->PeerId(), item->PeerId(),
item->laddr, item->saddr, item->discFlags, time(NULL));
addDiscoveryData(item->PeerId(), item->PeerId(), item->laddr, item->saddr, item->discFlags, time(NULL));
/* cleanup (handled by caller) */
}
@ -540,11 +546,11 @@ void p3disc::recvPeerOwnMsg(RsDiscItem *item)
void p3disc::recvPeerFriendMsg(RsDiscReply *item)
{
//#ifdef P3DISC_DEBUG
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::recvPeerFriendMsg() From: " << item->PeerId();
std::cerr << " About " << item->aboutId;
std::cerr << std::endl;
//#endif
#endif
/* tells us their exact address (mConnectMgr can ignore if it looks wrong) */
@ -595,6 +601,8 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
addDiscoveryData(item->PeerId(), peerId, item->laddr, item->saddr, item->discFlags, time(NULL));
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
/* cleanup (handled by caller) */
}
@ -604,8 +612,7 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
/*************************************************************************************/
int p3disc::addDiscoveryData(std::string fromId, std::string aboutId,
struct sockaddr_in laddr, struct sockaddr_in raddr, uint32_t flags, time_t ts)
int p3disc::addDiscoveryData(std::string fromId, std::string aboutId, struct sockaddr_in laddr, struct sockaddr_in raddr, uint32_t flags, time_t ts)
{
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/

View file

@ -24,6 +24,8 @@
*/
#include "rsiface/rsiface.h"
#include "pqi/pqibin.h"
#include "pqi/pqiarchive.h"
#include "pqi/p3connmgr.h"
@ -121,8 +123,11 @@ int p3MsgService::incomingMsgs()
{
RsMsgItem *mi;
int i = 0;
bool changed = false ;
while((mi = (RsMsgItem *) recvItem()) != NULL)
{
changed = true ;
++i;
mi -> recvTime = time(NULL);
mi -> msgFlags = RS_MSG_FLAGS_NEW;
@ -162,6 +167,9 @@ int p3MsgService::incomingMsgs()
/**** STACK UNLOCKED ***/
}
if(changed)
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
return 1;
}
@ -472,56 +480,70 @@ bool p3MsgService::removeMsgId(std::string mid)
{
std::map<uint32_t, RsMsgItem *>::iterator mit;
uint32_t msgId = atoi(mid.c_str());
bool changed = false ;
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
mit = imsg.find(msgId);
if (mit != imsg.end())
{
RsMsgItem *mi = mit->second;
imsg.erase(mit);
delete mi;
msgChanged.IndicateChanged();
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
mit = imsg.find(msgId);
if (mit != imsg.end())
{
changed = true ;
RsMsgItem *mi = mit->second;
imsg.erase(mit);
delete mi;
// msgChanged.IndicateChanged();
return true;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
mit = msgOutgoing.find(msgId);
if (mit != msgOutgoing.end())
{
changed = true ;
RsMsgItem *mi = mit->second;
msgOutgoing.erase(mit);
delete mi;
// msgChanged.IndicateChanged();
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
}
mit = msgOutgoing.find(msgId);
if (mit != msgOutgoing.end())
{
RsMsgItem *mi = mit->second;
msgOutgoing.erase(mit);
delete mi;
msgChanged.IndicateChanged();
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
if(changed)
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
return false;
}
bool p3MsgService::markMsgIdRead(std::string mid)
{
std::map<uint32_t, RsMsgItem *>::iterator mit;
std::map<uint32_t, RsMsgItem *>::iterator mit;
uint32_t msgId = atoi(mid.c_str());
bool changed = false ;
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
mit = imsg.find(msgId);
if (mit != imsg.end())
{
RsMsgItem *mi = mit->second;
mi -> msgFlags &= ~(RS_MSG_FLAGS_NEW);
msgChanged.IndicateChanged();
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
mit = imsg.find(msgId);
if (mit != imsg.end())
{
changed = true ;
RsMsgItem *mi = mit->second;
mi -> msgFlags &= ~(RS_MSG_FLAGS_NEW);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
}
return false;
if(changed) // no need to notify, because the msg is always
return true; // marked as read from the gui itself, so the gui
else // can mark it as read.
return false;
}
/****************************************/