diff --git a/src/chat/distantchat.cc b/src/chat/distantchat.cc index 621e92229e..f3ce2800f8 100644 --- a/src/chat/distantchat.cc +++ b/src/chat/distantchat.cc @@ -184,6 +184,7 @@ void DistantChatService::notifyTunnelStatus( const RsGxsTunnelId& tunnel_id, uin DISTANT_CHAT_DEBUG() << "DistantChatService::notifyTunnelStatus(): got notification " << std::hex << tunnel_status << std::dec << " for tunnel " << tunnel_id << std::endl; #endif +#warning TODO: I had to comment out calls to notifyPeerStatusChanged, which anyway looked misplaced here. Probably a hack. switch(tunnel_status) { default: @@ -191,15 +192,15 @@ void DistantChatService::notifyTunnelStatus( const RsGxsTunnelId& tunnel_id, uin break ; case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_CAN_TALK: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is secured. You can talk!") ; - RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_ONLINE) ; + //RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_ONLINE) ; break ; case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_TUNNEL_DN: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is down...") ; - RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ; + //RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ; break ; case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is down...") ; - RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ; + //RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ; break ; } } diff --git a/src/chat/distributedchat.cc b/src/chat/distributedchat.cc index cacd68e08a..0ae7becb8f 100644 --- a/src/chat/distributedchat.cc +++ b/src/chat/distributedchat.cc @@ -607,8 +607,13 @@ void DistributedChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item) for(std::list::const_iterator it = invitationNeeded.begin();it!=invitationNeeded.end();++it) invitePeerToLobby(*it,item->PeerId(),false) ; - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; - _should_reset_lobby_counts = false ; + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; + + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED; + rsEvents->postEvent(ev); + + _should_reset_lobby_counts = false ; } void DistributedChatService::addTimeShiftStatistics(int D) @@ -654,7 +659,14 @@ void DistributedChatService::addTimeShiftStatistics(int D) #endif if(expected > 9) // if more than 20 samples - RsServer::notify()->notifyChatLobbyTimeShift( (int)pow(2.0f,expected)) ; + { + //LIST_CHANGEDRsServer::notify()->notifyChatLobbyTimeShift( (int)pow(2.0f,expected)) ; + + auto ev = std::make_shared(); + ev->mEventCode = RsSystemErrorEventCode::TIME_SHIFT_PROBLEM; + ev->mTimeShift = (int)pow(2.0f,expected); + rsEvents->postEvent(ev); + } total = 0.0f ; log_delay_histogram.clear() ; @@ -754,7 +766,12 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem * std::cerr << " doing specific job for this status item." << std::endl; #endif - if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_LEFT) // if a peer left. Remove its nickname from the list. + auto ev = std::make_shared(); + ev->mGxsId = item->signature.keyId; + ev->mLobbyId = item->lobby_id; + ev->str = item->string1; + + if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_LEFT) // if a peer left. Remove its nickname from the list. { #ifdef DEBUG_CHAT_LOBBIES std::cerr << " removing nickname " << item->nick << " from lobby " << std::hex << item->lobby_id << std::dec << std::endl; @@ -780,7 +797,8 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem * std::cerr << " (EE) nickname " << item->nick << " not in participant nicknames list!" << std::endl; #endif } - } + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_LEFT; + } else if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_JOINED) // if a joined left. Add its nickname to the list. { #ifdef DEBUG_CHAT_LOBBIES @@ -800,7 +818,8 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem * // trigger a keep alive packets so as to inform the new participant of our presence in the chatroom it->second.last_keep_alive_packet_time = 0 ; } - } + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_JOINED ; + } else if(item->event_type == RS_CHAT_LOBBY_EVENT_KEEP_ALIVE) // keep alive packet. { #ifdef DEBUG_CHAT_LOBBIES @@ -818,9 +837,16 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem * std::cerr << " added nickname " << item->nick << " from lobby " << std::hex << item->lobby_id << std::dec << std::endl; #endif } - } + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_KEEP_ALIVE ; + } + else if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_STATUS) + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_STATUS ; + else if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME) + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME; - RsServer::notify()->notifyChatLobbyEvent(item->lobby_id,item->event_type,item->signature.keyId,item->string1); + rsEvents->postEvent(ev); + + //RsServer::notify()->notifyChatLobbyEvent(item->lobby_id,item->event_type,item->signature.keyId,item->string1); } void DistributedChatService::getListOfNearbyChatLobbies(std::vector& visible_lobbies) @@ -1392,7 +1418,12 @@ void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item) _lobby_invites_queue[item->lobby_id] = invite ; } // 2 - notify the gui to ask the user. - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_INVITATION, NOTIFY_TYPE_ADD); + + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_INVITE_RECEIVED; + rsEvents->postEvent(ev); + + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_INVITATION, NOTIFY_TYPE_ADD); } void DistributedChatService::getPendingChatLobbyInvites(std::list& invites) @@ -1494,10 +1525,15 @@ bool DistributedChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id,const std::cerr << " Notifying of new recvd msg." << std::endl ; #endif - RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD); - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD); + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD); - // send AKN item + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED; + rsEvents->postEvent(ev); + + RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD); + + // send AKN item sendLobbyStatusNewPeer(lobby_id) ; return true ; @@ -1613,8 +1649,13 @@ bool DistributedChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id,co for(std::list::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) invitePeerToLobby(lobby_id,*it) ; - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; - sendLobbyStatusNewPeer(lobby_id) ; + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; + + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED; + rsEvents->postEvent(ev); + + sendLobbyStatusNewPeer(lobby_id) ; return true ; } @@ -1663,9 +1704,13 @@ ChatLobbyId DistributedChatService::createChatLobby(const std::string& lobby_nam for(std::set::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) invitePeerToLobby(lobby_id,*it) ; - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; - triggerConfigSave(); + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED; + rsEvents->postEvent(ev); + + triggerConfigSave(); return lobby_id ; } @@ -1698,7 +1743,12 @@ void DistributedChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribe } } - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_MOD) ; + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_MOD) ; + + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED; + rsEvents->postEvent(ev); + } void DistributedChatService::unsubscribeChatLobby(const ChatLobbyId& id) @@ -1744,7 +1794,12 @@ void DistributedChatService::unsubscribeChatLobby(const ChatLobbyId& id) } triggerConfigSave(); // so that we save the subscribed lobbies - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_DEL) ; + + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_DEL) ; + + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED; + rsEvents->postEvent(ev); // done! } @@ -1890,7 +1945,11 @@ void DistributedChatService::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, _lobby_default_identity.erase(lobby_id); } - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED; + rsEvents->postEvent(ev); + + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; triggerConfigSave(); } @@ -2024,7 +2083,13 @@ void DistributedChatService::cleanLobbyCaches() // update the gui for(std::list::const_iterator it(changed_lobbies.begin());it!=changed_lobbies.end();++it) - RsServer::notify()->notifyChatLobbyEvent(*it,RS_CHAT_LOBBY_EVENT_KEEP_ALIVE,RsGxsId(),"") ; + { + //RsServer::notify()->notifyChatLobbyEvent(*it,RS_CHAT_LOBBY_EVENT_KEEP_ALIVE,RsGxsId(),"") ; + + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_KEEP_ALIVE; + rsEvents->postEvent(ev); + } // send peer joined for(std::list::const_iterator it(joined_lobby_ids.begin());it!=joined_lobby_ids.end();++it) @@ -2197,9 +2262,13 @@ bool DistributedChatService::processLoadListItem(const RsItem *item) // make the UI aware of the existing chat room - RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; + //RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; + + auto ev = std::make_shared(); + ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED; + rsEvents->postEvent(ev); - return true; + return true; } return false ; diff --git a/src/chat/p3chatservice.cc b/src/chat/p3chatservice.cc index 3fbbdaf757..13102ffc4a 100644 --- a/src/chat/p3chatservice.cc +++ b/src/chat/p3chatservice.cc @@ -598,7 +598,15 @@ void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca) #ifdef CHAT_DEBUG std::cerr << "Received avatar data for peer " << ca->PeerId() << ". Notifying." << std::endl ; #endif - RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId().toStdString()) ; + //RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId().toStdString()) ; + + if(rsEvents) + { + auto e = std::make_shared(); + e->mSslId = ca->PeerId(); + e->mEventCode = RsFriendListEventCode::NODE_AVATAR_CHANGED; + rsEvents->postEvent(e); + } } uint32_t p3ChatService::getMaxMessageSecuritySize(int type) @@ -1003,7 +1011,14 @@ void p3ChatService::setOwnCustomStateString(const std::string& s) mServiceCtrl->getPeersConnected(getServiceInfo().mServiceType, onlineList); } - RsServer::notify()->notifyOwnStatusMessageChanged() ; + //RsServer::notify()->notifyOwnStatusMessageChanged() ; + if(rsEvents) + { + auto e = std::make_shared(); + e->mEventCode = RsFriendListEventCode::OWN_STATUS_CHANGED; + e->mSslId = mServiceCtrl->getOwnId(); + rsEvents->postEvent(e); + } // alert your online peers to your newly set status std::set::iterator it(onlineList.begin()); @@ -1019,7 +1034,7 @@ void p3ChatService::setOwnCustomStateString(const std::string& s) IndicateConfigChanged(); } -void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size) +void p3ChatService::setOwnNodeAvatarJpegData(const unsigned char *data,int size) { { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1043,7 +1058,15 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size) } IndicateConfigChanged(); - RsServer::notify()->notifyOwnAvatarChanged() ; + //RsServer::notify()->notifyOwnAvatarChanged() ; + + if(rsEvents) + { + auto e = std::make_shared(); + e->mEventCode = RsFriendListEventCode::OWN_AVATAR_CHANGED; + e->mSslId = mServiceCtrl->getOwnId(); + rsEvents->postEvent(e); + } #ifdef CHAT_DEBUG std::cerr << "p3chatservice:setOwnAvatarJpegData() done." << std::endl ; diff --git a/src/chat/p3chatservice.h b/src/chat/p3chatservice.h index bc4dd56b9d..56c625671d 100644 --- a/src/chat/p3chatservice.h +++ b/src/chat/p3chatservice.h @@ -44,7 +44,7 @@ typedef RsPeerId ChatLobbyVirtualPeerId ; struct RsChatMessageEvent : RsEvent { - RsChatMessageEvent() : RsEvent(RsEventType::CHAT_MESSAGE) {} + RsChatMessageEvent() : RsEvent(RsEventType::CHAT_SERVICE) {} ~RsChatMessageEvent() override = default; ///* @see RsEvent @see RsSerializable @@ -152,7 +152,7 @@ class p3ChatService : * Sets the avatar data and size for client's account * @param data is copied, so should be destroyed by the caller */ - void setOwnAvatarJpegData(const unsigned char *data,int size) ; + void setOwnNodeAvatarJpegData(const unsigned char *data,int size) ; /*! * Gets the avatar data for clients account diff --git a/src/file_sharing/directory_updater.cc b/src/file_sharing/directory_updater.cc index ed34b6cf9d..354f3b3171 100644 --- a/src/file_sharing/directory_updater.cc +++ b/src/file_sharing/directory_updater.cc @@ -135,9 +135,15 @@ bool LocalDirectoryUpdater::sweepSharedDirectories(bool& some_files_not_ready) mIsChecking = true; - RsServer::notify()->notifyListPreChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + //RsServer::notify()->notifyListPreChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); - /* recursive update algorithm works that way: + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::OWN_DIR_LIST_PROCESSING; + rsEvents->postEvent(ev); + } + /* recursive update algorithm works that way: * - the external loop starts on the shared directory list and goes through * sub-directories * - at the same time, it updates the local list of shared directories. @@ -223,8 +229,14 @@ bool LocalDirectoryUpdater::sweepSharedDirectories(bool& some_files_not_ready) * dir list, because the two are not necessarily in the same order. */ } - RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); - mIsChecking = false; + //RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::OWN_DIR_LIST_UPDATED; + rsEvents->postEvent(ev); + } + mIsChecking = false; return true; } diff --git a/src/file_sharing/hash_cache.cc b/src/file_sharing/hash_cache.cc index 62924d70a1..4d1bb0f92b 100644 --- a/src/file_sharing/hash_cache.cc +++ b/src/file_sharing/hash_cache.cc @@ -58,15 +58,24 @@ HashStorage::HashStorage(const std::string& save_file_name) void HashStorage::togglePauseHashingProcess() { - RS_STACK_MUTEX(mHashMtx) ; - mHashingProcessPaused = !mHashingProcessPaused ; + RS_STACK_MUTEX(mHashMtx) ; + mHashingProcessPaused = !mHashingProcessPaused ; + + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = mHashingProcessPaused? (RsSharedDirectoriesEventCode::HASHING_PROCESS_PAUSED):(RsSharedDirectoriesEventCode::HASHING_PROCESS_RESUMED); + rsEvents->postEvent(ev); + } } + bool HashStorage::hashingProcessPaused() { RS_STACK_MUTEX(mHashMtx) ; return mHashingProcessPaused; } +#ifdef TO_REMOVE static std::string friendlyUnit(uint64_t val) { const std::string units[6] = {"B","KB","MB","GB","TB","PB"}; @@ -86,6 +95,7 @@ static std::string friendlyUnit(uint64_t val) sprintf(buf,"%2.2f",double(val)/fact*1024.0f) ; return std::string(buf) + " TB"; } +#endif void HashStorage::threadTick() { @@ -136,13 +146,6 @@ void HashStorage::threadTick() stopHashThread(); } - if(rsEvents) - { - auto ev = std::make_shared(); - ev->mEventCode = RsSharedDirectoriesEventCode::DIRECTORY_SWEEP_ENDED; - rsEvents->postEvent(ev); - } - //RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_FINISH, "") ; } else { @@ -182,19 +185,23 @@ void HashStorage::threadTick() std::string tmpout; +#ifdef TO_REMOVE if(mCurrentHashingSpeed > 0) rs_sprintf(tmpout, "%lu/%lu (%s - %d%%, %d MB/s) : %s", (unsigned long int)mHashCounter+1, (unsigned long int)mTotalFilesToHash, friendlyUnit(mTotalHashedSize).c_str(), int(mTotalHashedSize/double(mTotalSizeToHash)*100.0), mCurrentHashingSpeed,job.full_path.c_str()) ; else rs_sprintf(tmpout, "%lu/%lu (%s - %d%%) : %s", (unsigned long int)mHashCounter+1, (unsigned long int)mTotalFilesToHash, friendlyUnit(mTotalHashedSize).c_str(), int(mTotalHashedSize/double(mTotalSizeToHash)*100.0), job.full_path.c_str()) ; +#endif { - /* Emit deprecated event only for retrocompatibility - * TODO: create a proper event with structured data instead of a - * formatted string */ auto ev = std::make_shared(); ev->mEventCode = RsSharedDirectoriesEventCode::HASHING_FILE; - ev->mMessage = tmpout; - rsEvents->postEvent(ev); + ev->mHashingSpeed = mCurrentHashingSpeed; + ev->mHashCounter = mHashCounter; + ev->mTotalFilesToHash = mTotalFilesToHash; + ev->mTotalHashedSize = mTotalHashedSize; + ev->mTotalSizeToHash = mTotalSizeToHash; + ev->mFilePath = job.full_path; + rsEvents->postEvent(ev); } double seconds_origin = rstime::RsScopeTimer::currentTime() ; @@ -239,12 +246,19 @@ void HashStorage::threadTick() if(!hash.isNull()) job.client->hash_callback(job.client_param, job.full_path, hash, size); +#ifdef TO_REMOVE /* Notify we completed hashing a file */ - auto ev = std::make_shared(); - ev->mFilePath = job.full_path; + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::FILE_HASHING_COMPLETED; + ev->mFilePath = job.full_path; ev->mHashingSpeed = mCurrentHashingSpeed; ev->mFileHash = hash; - rsEvents->postEvent(ev); + ev->mHashCounter = mHashCounter+1; + ev->mTotalFilesToHash = mTotalFilesToHash; + ev->mTotalHashedSize = mTotalHashedSize; + ev->mTotalSizeToHash = mTotalSizeToHash; + rsEvents->postEvent(ev); +#endif } bool HashStorage::requestHash(const std::string& full_path,uint64_t size,rstime_t mod_time,RsFileHash& known_hash,HashStorageClient *c,uint32_t client_param) @@ -332,6 +346,12 @@ void HashStorage::startHashThread() mHashCounter = 0; mTotalHashedSize = 0; + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::HASHING_PROCESS_STARTED; + rsEvents->postEvent(ev); + } start("fs hash cache") ; } } @@ -348,6 +368,13 @@ void HashStorage::stopHashThread() mTotalSizeToHash = 0; mTotalFilesToHash = 0; } + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::HASHING_PROCESS_FINISHED; + rsEvents->postEvent(ev); + } + } void HashStorage::clean() diff --git a/src/file_sharing/p3filelists.cc b/src/file_sharing/p3filelists.cc index cda6e4e829..1a6a849d23 100644 --- a/src/file_sharing/p3filelists.cc +++ b/src/file_sharing/p3filelists.cc @@ -142,7 +142,7 @@ void p3FileDatabase::updateShareFlags(const SharedDirInfo& info) mLocalSharedDirs->updateShareFlags(info) ; } - RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + //RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_OFTEN); if(rsEvents) @@ -215,7 +215,13 @@ int p3FileDatabase::tick() } #warning mr-alice 2016-08-19: "This should be removed, but it's necessary atm for updating the GUI" - RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + //RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::OWN_DIR_LIST_UPDATED; + rsEvents->postEvent(ev); + } checkSendBannedFilesInfo(); } @@ -225,11 +231,27 @@ int p3FileDatabase::tick() IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_OFTEN); if(mUpdateFlags & P3FILELISTS_UPDATE_FLAG_LOCAL_DIRS_CHANGED) - RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + { + //RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::OWN_DIR_LIST_UPDATED; + rsEvents->postEvent(ev); + } + } if(mUpdateFlags & P3FILELISTS_UPDATE_FLAG_REMOTE_DIRS_CHANGED) - RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); + { + //RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::FRIEND_DIR_LIST_UPDATED; + rsEvents->postEvent(ev); + } + } mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ; } @@ -265,7 +287,15 @@ int p3FileDatabase::tick() // avoid syncing the GUI at every dir sync which kills performance. if(mLastDataRecvTS + 5 < now && mLastDataRecvTS + 20 > now) - RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); // notify the GUI if the hierarchy has changed + { + //RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); // notify the GUI if the hierarchy has changed + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::FRIEND_DIR_LIST_UPDATED; + rsEvents->postEvent(ev); + } + } } return 0; @@ -1012,8 +1042,14 @@ bool p3FileDatabase::removeExtraFile(const RsFileHash& hash) mLastExtraFilesCacheUpdate = 0 ; // forced cache reload } - RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); - return ret; + //RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::EXTRA_LIST_FILE_REMOVED; + rsEvents->postEvent(ev); + } + return ret; } void p3FileDatabase::getExtraFilesDirDetails_locked(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const @@ -1950,7 +1986,13 @@ void p3FileDatabase::handleDirSyncResponse(RsFileListsSyncResponseItem*& sitem) if(mLastDataRecvTS + 1 < now) // avoid notifying the GUI too often as it kills performance. { - RsServer::notify()->notifyListPreChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); // notify the GUI if the hierarchy has changed + // RsServer::notify()->notifyListPreChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); // notify the GUI if the hierarchy has changed + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mEventCode = RsSharedDirectoriesEventCode::FRIEND_DIR_LIST_UPDATED; + rsEvents->postEvent(ev); + } mLastDataRecvTS = now; } #ifdef DEBUG_P3FILELISTS diff --git a/src/gossipdiscovery/p3gossipdiscovery.cc b/src/gossipdiscovery/p3gossipdiscovery.cc index b3361eaaef..e25b61c17a 100644 --- a/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/src/gossipdiscovery/p3gossipdiscovery.cc @@ -128,7 +128,9 @@ RsServiceInfo p3discovery2::getServiceInfo() } p3discovery2::~p3discovery2() -{ rsEvents->unregisterEventsHandler(mRsEventsHandle); } +{ + rsEvents->unregisterEventsHandler(mRsEventsHandle); +} void p3discovery2::addFriend(const RsPeerId &sslId) { diff --git a/src/pqi/authgpg.cc b/src/pqi/authgpg.cc index a4c7d69d84..e09d1e9161 100644 --- a/src/pqi/authgpg.cc +++ b/src/pqi/authgpg.cc @@ -629,7 +629,15 @@ bool AuthPGP::AllowConnection(const RsPgpId& gpg_id, bool accept) instance()->IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_NOW); - RsServer::notify()->notifyListChange(NOTIFY_LIST_FRIENDS, accept ? NOTIFY_TYPE_ADD : NOTIFY_TYPE_DEL); + //RsServer::notify()->notifyListChange(NOTIFY_LIST_FRIENDS, accept ? NOTIFY_TYPE_ADD : NOTIFY_TYPE_DEL); + + if(rsEvents) + { + auto e = std::make_shared(); + e->mEventCode = accept ? (RsFriendListEventCode::PROFILE_ADDED) : (RsFriendListEventCode::PROFILE_REMOVED); + e->mPgpId = gpg_id; + rsEvents->postEvent(e); + } return true; } diff --git a/src/pqi/p3linkmgr.cc b/src/pqi/p3linkmgr.cc index 97a889b794..ef6a10f5ff 100644 --- a/src/pqi/p3linkmgr.cc +++ b/src/pqi/p3linkmgr.cc @@ -486,15 +486,15 @@ void p3LinkMgrIMPL::tickMonitors() /* notify GUI */ if (rsEvents && (peer.actions & RS_PEER_CONNECTED)) { - auto e = std::make_shared(); - e->mConnectionInfoCode = RsConnectionEventCode::PEER_CONNECTED; + auto e = std::make_shared(); + e->mEventCode = RsFriendListEventCode::NODE_CONNECTED; e->mSslId = peer.id; rsEvents->postEvent(e); } if (rsEvents && (peer.actions & RS_PEER_DISCONNECTED)) { - auto e = std::make_shared(); - e->mConnectionInfoCode = RsConnectionEventCode::PEER_DISCONNECTED; + auto e = std::make_shared(); + e->mEventCode = RsFriendListEventCode::NODE_DISCONNECTED; e->mSslId = peer.id; rsEvents->postEvent(e); } diff --git a/src/pqi/p3notify.cc b/src/pqi/p3notify.cc index 28cb33e9e8..7ae9dd8d33 100644 --- a/src/pqi/p3notify.cc +++ b/src/pqi/p3notify.cc @@ -217,28 +217,26 @@ void p3Notify::notifyChatLobbyEvent(uint64_t lobby_id, uint32_t event_type,const void p3Notify::notifyListPreChange(int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListPreChange(list,type) ; } void p3Notify::notifyListChange (int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListChange (list,type) ; } -void p3Notify::notifyErrorMsg (int list, int sev, std::string msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyErrorMsg(list,sev,msg) ; } +//void p3Notify::notifyErrorMsg (int list, int sev, std::string msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyErrorMsg(list,sev,msg) ; } void p3Notify::notifyChatMessage (const ChatMessage &msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatMessage(msg) ; } void p3Notify::notifyChatStatus (const ChatId& chat_id, const std::string& status_string) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatStatus(chat_id,status_string) ; } void p3Notify::notifyChatCleared (const ChatId& chat_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatCleared(chat_id) ; } -void p3Notify::notifyChatLobbyTimeShift (int time_shift) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatLobbyTimeShift(time_shift) ; } +//void p3Notify::notifyChatLobbyTimeShift (int time_shift) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatLobbyTimeShift(time_shift) ; } void p3Notify::notifyCustomState (const std::string& peer_id , const std::string& status_string ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyCustomState (peer_id,status_string) ; } -void p3Notify::notifyHashingInfo (uint32_t type , const std::string& fileinfo ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHashingInfo (type,fileinfo) ; } -//void p3Notify::notifyTurtleSearchResult (const RsPeerId& pid , uint32_t search_id , const std::list& files ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(pid,search_id,files) ; } #warning MISSING CODE HERE //void p3Notify::notifyTurtleSearchResult (uint32_t search_id , const std::list& groups ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(search_id,groups) ; } -void p3Notify::notifyPeerHasNewAvatar (std::string peer_id ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerHasNewAvatar(peer_id) ; } -void p3Notify::notifyOwnAvatarChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnAvatarChanged() ; } -void p3Notify::notifyOwnStatusMessageChanged() { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnStatusMessageChanged() ; } -void p3Notify::notifyDiskFull (uint32_t location , uint32_t size_limit_in_MB ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiskFull (location,size_limit_in_MB) ; } -void p3Notify::notifyPeerStatusChanged (const std::string& peer_id , uint32_t status ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChanged (peer_id,status) ; } +//void p3Notify::notifyPeerHasNewAvatar (std::string peer_id ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerHasNewAvatar(peer_id) ; } +//void p3Notify::notifyOwnAvatarChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnAvatarChanged() ; } +//void p3Notify::notifyOwnStatusMessageChanged() { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnStatusMessageChanged() ; } +//void p3Notify::notifyDiskFull (uint32_t location , uint32_t size_limit_in_MB ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiskFull (location,size_limit_in_MB) ; } +//void p3Notify::notifyPeerStatusChanged (const std::string& peer_id , uint32_t status ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChanged (peer_id,status) ; } +//void p3Notify::notifyPeerStatusChangedSummary () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChangedSummary() ; } -void p3Notify::notifyPeerStatusChangedSummary () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChangedSummary() ; } void p3Notify::notifyDiscInfoChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiscInfoChanged () ; } -void p3Notify::notifyDownloadComplete (const std::string& fileHash ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadComplete (fileHash) ; } -void p3Notify::notifyDownloadCompleteCount (uint32_t count ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadCompleteCount (count) ; } +//void p3Notify::notifyDownloadComplete (const std::string& fileHash ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadComplete (fileHash) ; } +//void p3Notify::notifyDownloadCompleteCount (uint32_t count ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadCompleteCount (count) ; } void p3Notify::notifyHistoryChanged (uint32_t msgId , int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHistoryChanged (msgId,type) ; } bool p3Notify::cachePgpPassphrase(const std::string& s) diff --git a/src/pqi/p3notify.h b/src/pqi/p3notify.h index 3d78cdf8c5..34504f124e 100644 --- a/src/pqi/p3notify.h +++ b/src/pqi/p3notify.h @@ -93,29 +93,28 @@ class p3Notify: public RsNotify // void notifyListPreChange (int /* list */, int /* type */) ; void notifyListChange (int /* list */, int /* type */) ; - void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) ; +// void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) ; void notifyChatMessage (const ChatMessage& /* msg */) ; void notifyChatStatus (const ChatId& /* chat_id */, const std::string& /* status_string */) ; void notifyChatCleared (const ChatId& /* chat_id */) ; void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ , const RsGxsId & /* nickname */, const std::string& /* any string */) ; void notifyChatLobbyTimeShift (int /* time_shift*/) ; void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) ; - void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) ; - void notifyTurtleSearchResult (const RsPeerId &pid, uint32_t /* search_id */, const std::list& /* files */) ; +// void notifyTurtleSearchResult (const RsPeerId &pid, uint32_t /* search_id */, const std::list& /* files */) ; #warning MISSING CODE HERE // void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list& /* groups */) ; - void notifyPeerHasNewAvatar (std::string /* peer_id */) ; - void notifyOwnAvatarChanged () ; - void notifyOwnStatusMessageChanged () ; - void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) ; - void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) ; +// void notifyPeerHasNewAvatar (std::string /* peer_id */) ; +// void notifyOwnAvatarChanged () ; +// void notifyOwnStatusMessageChanged () ; +// void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) ; +// void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) ; void notifyConnectionWithoutCert (); - void notifyPeerStatusChangedSummary () ; +// void notifyPeerStatusChangedSummary () ; void notifyDiscInfoChanged () ; - void notifyDownloadComplete (const std::string& /* fileHash */) ; - void notifyDownloadCompleteCount (uint32_t /* count */) ; +// void notifyDownloadComplete (const std::string& /* fileHash */) ; +// void notifyDownloadCompleteCount (uint32_t /* count */) ; void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) ; bool askForPassword (const std::string& title, const std::string& /* key_details */, bool /* prev_is_bad */, std::string&, bool *cancelled /* password */ ) ; diff --git a/src/pqi/p3peermgr.cc b/src/pqi/p3peermgr.cc index 1933683f07..205e2989e2 100644 --- a/src/pqi/p3peermgr.cc +++ b/src/pqi/p3peermgr.cc @@ -1840,11 +1840,11 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons if(rsEvents) { - auto ev = std::make_shared(); + auto ev = std::make_shared(); ev->mSslId = from; ev->mOwnLocator = RsUrl(own_addr); ev->mReportedLocator = RsUrl(addr); - ev->mConnectionInfoCode = RsConnectionEventCode::PEER_REPORTS_WRONG_IP; + ev->mEventCode = RsFriendListEventCode::NODE_REPORTS_WRONG_IP; rsEvents->postEvent(ev); } } @@ -2803,7 +2803,13 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo) std::cerr << "(II) Added new group with ID " << groupInfo.id << ", name=\"" << groupInfo.name << "\"" << std::endl; } - RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD); + //RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD); + if(rsEvents) + { + auto e = std::make_shared(); + e->mEventCode = RsFriendListEventCode::GROUP_ADDED ; + rsEvents->postEvent(e); + } IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_OFTEN); @@ -2843,10 +2849,17 @@ bool p3PeerMgrIMPL::editGroup(const RsNodeGroupId& groupId, RsGroupInfo &groupIn if (changed) { - RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD); + //RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD); + + if(rsEvents) + { + auto e = std::make_shared(); + e->mEventCode = RsFriendListEventCode::GROUP_CHANGED ; + rsEvents->postEvent(e); + } IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_OFTEN); - } + } return changed; } @@ -2885,8 +2898,14 @@ bool p3PeerMgrIMPL::removeGroup(const RsNodeGroupId& groupId) } if (changed) { - RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_DEL); + //RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_DEL); + if(rsEvents) + { + auto e = std::make_shared(); + e->mEventCode = RsFriendListEventCode::GROUP_REMOVED ; + rsEvents->postEvent(e); + } IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_OFTEN); } @@ -2973,8 +2992,14 @@ bool p3PeerMgrIMPL::assignPeersToGroup(const RsNodeGroupId &groupId, const std:: } if (changed) { - RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD); + //RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD); + if(rsEvents) + { + auto e = std::make_shared(); + e->mEventCode = RsFriendListEventCode::GROUP_CHANGED ; + rsEvents->postEvent(e); + } IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_OFTEN); } diff --git a/src/pqi/p3servicecontrol.cc b/src/pqi/p3servicecontrol.cc index 9bf3b3c620..b0a4362038 100644 --- a/src/pqi/p3servicecontrol.cc +++ b/src/pqi/p3servicecontrol.cc @@ -759,9 +759,14 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId) } recordFilterChanges_locked(peerId, originalFilter, peerFilter); - using Evt_t = RsPeerStateChangedEvent; + using Evt_t = RsFriendListEvent; + if(rsEvents) - rsEvents->postEvent(std::unique_ptr(new Evt_t(peerId))); + { + auto ev = std::make_shared(); + ev->mSslId = peerId; + rsEvents->postEvent(ev); + } return true; } diff --git a/src/retroshare/rsevents.h b/src/retroshare/rsevents.h index 3fe4fc5ae6..db08972eab 100644 --- a/src/retroshare/rsevents.h +++ b/src/retroshare/rsevents.h @@ -65,15 +65,15 @@ enum class RsEventType : uint32_t AUTHSSL_CONNECTION_AUTENTICATION = 3, /// @see pqissl - PEER_CONNECTION = 4, + FRIEND_LIST = 4, // former PEER_STATUS /// @see RsGxsChanges, used also in @see RsGxsBroadcast GXS_CHANGES = 5, /// Emitted when a peer state changes, @see RsPeers - PEER_STATE_CHANGED = 6, + _________UNUSED___001_ = 6, // former PEER_STATE_CHANGED - /// @see RsMailStatusEvent + /// @see RsMailStatusEvent MAIL_STATUS = 7, /// @see RsGxsCircleEvent @@ -98,7 +98,7 @@ enum class RsEventType : uint32_t FILE_TRANSFER = 14, /// @see RsMsgs - CHAT_MESSAGE = 15, + CHAT_SERVICE = 15, /// @see rspeers.h NETWORK = 16, @@ -110,7 +110,7 @@ enum class RsEventType : uint32_t JSON_API = 18, /** Emitted to update library clients about file hashing being completed */ - FILE_HASHING_COMPLETED = 20, + _________UNUSED___002_ = 20, // former FILE_HASING_COMPLETE /// @see rspeers.h TOR_MANAGER = 21, @@ -121,6 +121,9 @@ enum class RsEventType : uint32_t /// @see RsWireEvent WIRE = 23, + /// @see RsWireEvent + SYSTEM_ERROR = 24, // general system notifications + __MAX /// Used internally, keep last }; @@ -270,3 +273,21 @@ class RsEvents virtual ~RsEvents(); }; + +enum class RsSystemErrorEventCode: uint8_t +{ + TIME_SHIFT_PROBLEM = 0x01, // Computer universal time is different from friends + DISK_SPACE_ERROR = 0x02, // Disk full +}; + +struct RsSystemErrorEvent : RsEvent +{ + RsSystemErrorEvent() : RsEvent(RsEventType::SYSTEM_ERROR) {} + virtual ~RsSystemErrorEvent() override = default; + + RsSystemErrorEventCode mEventCode; + + float mTimeShift; + int mDiskErrorLocation; // { RS_PARTIALS_DIRECTORY, RS_CONFIG_DIRECTORY, RS_DOWNLOAD_DIRECTORY } + int mDiskErrorSizeLimit;// size limit in MB +}; diff --git a/src/retroshare/rsfiles.h b/src/retroshare/rsfiles.h index 3c7ec8052d..f00c07af71 100644 --- a/src/retroshare/rsfiles.h +++ b/src/retroshare/rsfiles.h @@ -181,13 +181,18 @@ const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // di enum class RsSharedDirectoriesEventCode: uint8_t { UNKNOWN = 0x00, - STARTING_DIRECTORY_SWEEP = 0x01, // (void) - HASHING_FILE = 0x02, // mMessage: full path and hashing speed of the file being hashed - DIRECTORY_SWEEP_ENDED = 0x03, // (void) - SAVING_FILE_INDEX = 0x04, // (void) - EXTRA_LIST_FILE_ADDED = 0x05, // (void) - EXTRA_LIST_FILE_REMOVED = 0x06, // (void) - SHARED_DIRS_LIST_CHANGED = 0x07, // (void) + HASHING_PROCESS_STARTED = 0x01, // (void) + HASHING_PROCESS_PAUSED = 0x02, // (void) + HASHING_PROCESS_RESUMED = 0x04, // (void) + HASHING_PROCESS_FINISHED = 0x05, // (void) + HASHING_FILE = 0x06, // mMessage: full path and hashing speed of the file being hashed + SAVING_FILE_INDEX = 0x07, // (void) + EXTRA_LIST_FILE_ADDED = 0x08, // (void) + EXTRA_LIST_FILE_REMOVED = 0x09, // (void) + SHARED_DIRS_LIST_CHANGED = 0x0a, // (void) // list of own base shared directories/flags has changed. New sweep will occur soon + FRIEND_DIR_LIST_UPDATED = 0x0b, // NOTIFY_LIST_DIRLIST_FRIENDS, friend dir list has been updated + OWN_DIR_LIST_UPDATED = 0x0c, // NOTIFY_LIST_DIRLIST_LOCAL , own dir list has been updated + OWN_DIR_LIST_PROCESSING = 0x0d, // NOTIFY_LIST_DIRLIST_LOCAL prechange }; enum class RsFileTransferEventCode: uint8_t { @@ -197,49 +202,58 @@ enum class RsFileTransferEventCode: uint8_t { NEW_DISTANT_SEARCH_RESULTS = 0x03 }; -struct RS_DEPRECATED_FOR("Packing arbitrary data into an std::string is bad idea") -RsSharedDirectoriesEvent: RsEvent +struct RsSharedDirectoriesEvent: RsEvent { - RsSharedDirectoriesEvent() : RsEvent(RsEventType::SHARED_DIRECTORIES), mEventCode(RsSharedDirectoriesEventCode::UNKNOWN) {} + RsSharedDirectoriesEvent() + : RsEvent(RsEventType::SHARED_DIRECTORIES), mEventCode(RsSharedDirectoriesEventCode::UNKNOWN), + mHashingSpeed(0) {} ~RsSharedDirectoriesEvent() override = default; ///* @see RsEvent @see RsSerializable void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) override - { - RsEvent::serial_process(j, ctx); - - RS_SERIAL_PROCESS(mEventCode); - RS_SERIAL_PROCESS(mMessage); - } + { + RsEvent::serial_process(j, ctx); + + RS_SERIAL_PROCESS(mEventCode); + RS_SERIAL_PROCESS(mFilePath); + RS_SERIAL_PROCESS(mFileHash); + RS_SERIAL_PROCESS(mHashingSpeed); + RS_SERIAL_PROCESS(mHashCounter) ; + RS_SERIAL_PROCESS(mTotalFilesToHash) ; + RS_SERIAL_PROCESS(mTotalHashedSize) ; + RS_SERIAL_PROCESS(mTotalSizeToHash) ; + } RsSharedDirectoriesEventCode mEventCode; - std::string mMessage; + + std::string mFilePath; // Complete path of the file being hashed + RsFileHash mFileHash; // File hash, null if error occurred + uint32_t mHashingSpeed; // Hashing speed in MB/s + uint64_t mHashCounter ; // index of current file + uint64_t mTotalFilesToHash ;// total number of files to hash + uint64_t mTotalHashedSize ; // total hashed size so far, in MB + uint64_t mTotalSizeToHash ; // total size to hash in MB }; +#ifdef TO_REMOVE struct RsFileHashingCompletedEvent: RsEvent { - RsFileHashingCompletedEvent(): - RsEvent(RsEventType::FILE_HASHING_COMPLETED), mHashingSpeed(0) {} - - ///* @see RsEvent @see RsSerializable - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx ) override - { - RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mFilePath); - RS_SERIAL_PROCESS(mFileHash); - RS_SERIAL_PROCESS(mHashingSpeed); - } + RsFileHashingCompletedEvent(): + RsEvent(RsEventType::FILE_HASHING_COMPLETED), mHashingSpeed(0) {} - /// Complete path of the file being hashed - std::string mFilePath; - - /// File hash, null if error occurred - RsFileHash mFileHash; + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mFilePath); + RS_SERIAL_PROCESS(mFileHash); + RS_SERIAL_PROCESS(mHashingSpeed); + } - /// Hashing speed in MB/s - double mHashingSpeed; }; +#endif + struct RsFileTransferEvent: RsEvent { diff --git a/src/retroshare/rsmsgs.h b/src/retroshare/rsmsgs.h index cf6354fb6b..8496e45c1d 100644 --- a/src/retroshare/rsmsgs.h +++ b/src/retroshare/rsmsgs.h @@ -67,9 +67,9 @@ #define RS_MSG_SYSTEM (RS_MSG_USER_REQUEST | RS_MSG_FRIEND_RECOMMENDATION | RS_MSG_PUBLISH_KEY) -#define RS_CHAT_LOBBY_EVENT_PEER_LEFT 0x01 -#define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02 -#define RS_CHAT_LOBBY_EVENT_PEER_JOINED 0x03 +#define RS_CHAT_LOBBY_EVENT_PEER_LEFT 0x01 +#define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02 +#define RS_CHAT_LOBBY_EVENT_PEER_JOINED 0x03 #define RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME 0x04 #define RS_CHAT_LOBBY_EVENT_KEEP_ALIVE 0x05 @@ -536,6 +536,35 @@ class ChatLobbyInvite : RsSerializable } }; +enum class RsChatStatusEventCode: uint8_t +{ + NOTIFY_LIST_PRIVATE_INCOMING_CHAT, // new private incoming chat + NOTIFY_LIST_PRIVATE_OUTGOING_CHAT , // new private incoming chat + + CHAT_LOBBY_LIST_CHANGED = 0x03, // NOTIFY_LIST_CHAT_LOBBY_LIST , ADD/REMOVE , // new/removed chat lobby + CHAT_LOBBY_INVITE_RECEIVED = 0x04, // NOTIFY_LIST_CHAT_LOBBY_INVITE, received chat lobby invite + CHAT_LOBBY_EVENT_PEER_LEFT = 0x05, // RS_CHAT_LOBBY_EVENT_PEER_LEFT + CHAT_LOBBY_EVENT_PEER_STATUS = 0x06, // RS_CHAT_LOBBY_EVENT_PEER_STATUS + CHAT_LOBBY_EVENT_PEER_JOINED = 0x07, // RS_CHAT_LOBBY_EVENT_PEER_JOINED + CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME = 0x08, // RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME + CHAT_LOBBY_EVENT_KEEP_ALIVE = 0x09, // RS_CHAT_LOBBY_EVENT_KEEP_ALIVE +}; + +struct RsChatStatusEvent : RsEvent +{ + RsChatStatusEvent() : RsEvent(RsEventType::CHAT_SERVICE) {} + virtual ~RsChatStatusEvent() override = default; + + RsChatStatusEventCode mEventCode; + + uint64_t mLobbyId; + RsGxsId mGxsId; + std::string str; + ChatMessage msg; + int mTimeShift; +}; + + struct VisibleChatLobbyRecord : RsSerializable { VisibleChatLobbyRecord(): diff --git a/src/retroshare/rsnotify.h b/src/retroshare/rsnotify.h index f3bfe0d52f..b2ae5e1931 100644 --- a/src/retroshare/rsnotify.h +++ b/src/retroshare/rsnotify.h @@ -130,18 +130,18 @@ const uint32_t RS_FEED_ITEM_CIRCLE_INVITE_CANCELLED= RS_FEED_TYPE_CIRCLE | 0x00 const uint32_t RS_MESSAGE_CONNECT_ATTEMPT = 0x0001; const int NOTIFY_LIST_NEIGHBOURS = 1; -const int NOTIFY_LIST_FRIENDS = 2; +//const int NOTIFY_LIST_FRIENDS = 2; const int NOTIFY_LIST_SEARCHLIST = 4; const int NOTIFY_LIST_CHANNELLIST = 6; const int NOTIFY_LIST_TRANSFERLIST = 7; -const int NOTIFY_LIST_CONFIG = 8; +//const int NOTIFY_LIST_CONFIG = 8; const int NOTIFY_LIST_DIRLIST_LOCAL = 9; const int NOTIFY_LIST_DIRLIST_FRIENDS = 10; const int NOTIFY_LIST_FORUMLIST_LOCKED = 11; // use connect with Qt::QueuedConnection const int NOTIFY_LIST_PUBLIC_CHAT = 13; const int NOTIFY_LIST_PRIVATE_INCOMING_CHAT = 14; const int NOTIFY_LIST_PRIVATE_OUTGOING_CHAT = 15; -const int NOTIFY_LIST_GROUPLIST = 16; +//const int NOTIFY_LIST_GROUPLIST = 16; const int NOTIFY_LIST_CHANNELLIST_LOCKED = 17; // use connect with Qt::QueuedConnection const int NOTIFY_LIST_CHAT_LOBBY_INVITATION = 18; const int NOTIFY_LIST_CHAT_LOBBY_LIST = 19; @@ -222,27 +222,26 @@ class RS_DEPRECATED NotifyClient virtual void notifyListPreChange (int /* list */, int /* type */) {} virtual void notifyListChange (int /* list */, int /* type */) {} - virtual void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) {} +// virtual void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) {} virtual void notifyChatMessage (const ChatMessage& /* msg */) {} virtual void notifyChatStatus (const ChatId& /* chat_id */, const std::string& /* status_string */) {} virtual void notifyChatCleared (const ChatId& /* chat_id */) {} virtual void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ ,const RsGxsId& /* nickname */,const std::string& /* any string */) {} virtual void notifyChatLobbyTimeShift (int /* time_shift*/) {} virtual void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) {} - virtual void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) {} - virtual void notifyTurtleSearchResult (const RsPeerId& /* pid */, uint32_t /* search_id */, const std::list& /* files */) {} - virtual void notifyPeerHasNewAvatar (std::string /* peer_id */) {} - virtual void notifyOwnAvatarChanged () {} - virtual void notifyOwnStatusMessageChanged () {} - virtual void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) {} - virtual void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) {} +// virtual void notifyTurtleSearchResult (const RsPeerId& /* pid */, uint32_t /* search_id */, const std::list& /* files */) {} +// virtual void notifyPeerHasNewAvatar (std::string /* peer_id */) {} +// virtual void notifyOwnAvatarChanged () {} +// virtual void notifyOwnStatusMessageChanged () {} +// virtual void notifyDiskFull (uint32_t /* location */, uint32_t /* size limit in MB */) {} +// virtual void notifyPeerStatusChanged (const std::string& /* peer_id */, uint32_t /* status */) {} /* one or more peers has changed the states */ - virtual void notifyPeerStatusChangedSummary () {} +// virtual void notifyPeerStatusChangedSummary () {} virtual void notifyDiscInfoChanged () {} - virtual void notifyDownloadComplete (const std::string& /* fileHash */) {} - virtual void notifyDownloadCompleteCount (uint32_t /* count */) {} +// virtual void notifyDownloadComplete (const std::string& /* fileHash */) {} +// virtual void notifyDownloadCompleteCount (uint32_t /* count */) {} virtual void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) {} virtual bool askForPassword (const std::string& /* title */, const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */,bool& /* cancelled */ ) { return false ;} diff --git a/src/retroshare/rspeers.h b/src/retroshare/rspeers.h index ab8e1ae5ed..8b774c655e 100644 --- a/src/retroshare/rspeers.h +++ b/src/retroshare/rspeers.h @@ -29,6 +29,7 @@ #include "retroshare/rstypes.h" #include "retroshare/rsfiles.h" +#include "retroshare/rsstatus.h" #include "retroshare/rsids.h" #include "util/rsurl.h" #include "util/rsdeprecate.h" @@ -258,27 +259,41 @@ struct RsAuthSslConnectionAutenticationEvent : RsEvent ~RsAuthSslConnectionAutenticationEvent() override; }; -enum class RsConnectionEventCode: uint8_t +enum class RsFriendListEventCode: uint8_t { - UNKNOWN = 0x00, - PEER_CONNECTED = 0x01, - PEER_DISCONNECTED = 0x02, - PEER_TIME_SHIFT = 0x03, // mTimeShift = time shift in seconds - PEER_REPORTS_WRONG_IP = 0x04, // mPeerLocator = address reported, mOwnLocator = own address - PEER_ADDED = 0x05, - PEER_REMOVED = 0x06, + UNKNOWN = 0x00, + NODE_CONNECTED = 0x01, + NODE_DISCONNECTED = 0x02, + NODE_TIME_SHIFT = 0x03, // mTimeShift = time shift in seconds + NODE_REPORTS_WRONG_IP = 0x04, // mPeerLocator = address reported, mOwnLocator = own address + NODE_ADDED = 0x05, + NODE_REMOVED = 0x06, + NODE_STATUS_CHANGED = 0x07, // mSslId, mStatus + NODE_AVATAR_CHANGED = 0x08, // mSslId + + OWN_AVATAR_CHANGED = 0x09, + OWN_STATUS_CHANGED = 0x0a, + + PROFILE_ADDED = 0x0b, // mPgpId + PROFILE_REMOVED = 0x0c, // mPgpId + + GROUP_ADDED = 0x0d, + GROUP_REMOVED = 0x0e, + GROUP_CHANGED = 0x0f, }; -struct RsConnectionEvent : RsEvent +struct RsFriendListEvent : RsEvent { - RsConnectionEvent() - : RsEvent(RsEventType::PEER_CONNECTION), - mConnectionInfoCode(RsConnectionEventCode::UNKNOWN), mTimeShift(0) {} + RsFriendListEvent() + : RsEvent(RsEventType::FRIEND_LIST), + mEventCode(RsFriendListEventCode::UNKNOWN), mTimeShift(0) {} - RsConnectionEventCode mConnectionInfoCode; + RsFriendListEventCode mEventCode; RsPeerId mSslId; - RsUrl mOwnLocator; + RsPgpId mPgpId; + RsUrl mOwnLocator; RsUrl mReportedLocator; + RsStatusValue mStatus; /** If there is a time shift with the peer aka * mConnectionInfoCode == PEER_TIME_SHIFT contains the time shift value in @@ -291,14 +306,16 @@ struct RsConnectionEvent : RsEvent RsGenericSerializer::SerializeContext& ctx ) override { RsEvent::serial_process(j, ctx); - RS_SERIAL_PROCESS(mConnectionInfoCode); + RS_SERIAL_PROCESS(mEventCode); RS_SERIAL_PROCESS(mSslId); - RS_SERIAL_PROCESS(mOwnLocator); + RS_SERIAL_PROCESS(mPgpId); + RS_SERIAL_PROCESS(mOwnLocator); RS_SERIAL_PROCESS(mReportedLocator); - RS_SERIAL_PROCESS(mTimeShift); + RS_SERIAL_PROCESS(mStatus); + RS_SERIAL_PROCESS(mTimeShift); } - ~RsConnectionEvent() override; + ~RsFriendListEvent() override = default; }; enum class RsNetworkEventCode: uint8_t { @@ -497,6 +514,7 @@ struct RsGroupInfo : RsSerializable } }; +#ifdef TO_REMOVE /** Event emitted when a peer change state */ struct RsPeerStateChangedEvent : RsEvent { @@ -513,6 +531,7 @@ struct RsPeerStateChangedEvent : RsEvent RS_SERIAL_PROCESS(mSslId); } }; +#endif enum class RetroshareInviteFlags:uint32_t { NOTHING = 0x00, diff --git a/src/retroshare/rsstatus.h b/src/retroshare/rsstatus.h index 3173726bb0..d6518d3224 100644 --- a/src/retroshare/rsstatus.h +++ b/src/retroshare/rsstatus.h @@ -32,14 +32,16 @@ extern RsStatus *rsStatus; #include #include - -const uint32_t RS_STATUS_OFFLINE = 0x0000; -const uint32_t RS_STATUS_AWAY = 0x0001; -const uint32_t RS_STATUS_BUSY = 0x0002; -const uint32_t RS_STATUS_ONLINE = 0x0003; -const uint32_t RS_STATUS_INACTIVE = 0x0004; - -const uint32_t RS_STATUS_COUNT = 0x0005; // count of status +enum class RsStatusValue: int32_t { + RS_STATUS_UNKNOWN = 0x00, + RS_STATUS_OFFLINE = 0x01, + RS_STATUS_AWAY = 0x02, + RS_STATUS_BUSY = 0x03, + RS_STATUS_ONLINE = 0x04, + RS_STATUS_INACTIVE = 0x05, + + RS_STATUS_COUNT = 0x06, // count of status +}; //! data object for peer status information /*! @@ -48,11 +50,11 @@ const uint32_t RS_STATUS_COUNT = 0x0005; // count of status class StatusInfo { public: - StatusInfo() : status(RS_STATUS_OFFLINE), time_stamp(0) {} + StatusInfo() : status(RsStatusValue::RS_STATUS_UNKNOWN), time_stamp(0) {} public: RsPeerId id; - uint32_t status; + RsStatusValue status; rstime_t time_stamp; /// for owner time set, and for their peers time sent }; @@ -89,7 +91,7 @@ class RsStatus * @param status the status of the peers * @return will return false if status info does not belong to client */ - virtual bool sendStatus(const RsPeerId &id, uint32_t status) = 0; + virtual bool sendStatus(const RsPeerId &id, RsStatusValue status) = 0; }; diff --git a/src/rsserver/p3msgs.cc b/src/rsserver/p3msgs.cc index a6ae38f9d8..4c8907e068 100644 --- a/src/rsserver/p3msgs.cc +++ b/src/rsserver/p3msgs.cc @@ -439,7 +439,7 @@ void p3Msgs::getOwnAvatarData(unsigned char *& data,int& size) void p3Msgs::setOwnAvatarData(const unsigned char *data,int size) { - mChatSrv->setOwnAvatarJpegData(data,size) ; + mChatSrv->setOwnNodeAvatarJpegData(data,size) ; } void p3Msgs::getAvatarData(const RsPeerId& pid,unsigned char *& data,int& size) diff --git a/src/rsserver/p3peers.cc b/src/rsserver/p3peers.cc index 1d6f843070..2dd750d6e4 100644 --- a/src/rsserver/p3peers.cc +++ b/src/rsserver/p3peers.cc @@ -133,10 +133,12 @@ bool p3Peers::FriendsChanged(const RsPeerId& pid,bool add) #endif if(rsEvents) { - auto ev = std::make_shared(pid); + auto ev = std::make_shared(); + ev->mSslId = pid; + ev->mEventCode = add ? (RsFriendListEventCode::NODE_ADDED):(RsFriendListEventCode::NODE_REMOVED); rsEvents->postEvent(ev); } - RsServer::notify()->notifyListChange(NOTIFY_LIST_FRIENDS, add? NOTIFY_TYPE_ADD : NOTIFY_TYPE_DEL); // this is meant to disappear + //RsServer::notify()->notifyListChange(NOTIFY_LIST_FRIENDS, add? NOTIFY_TYPE_ADD : NOTIFY_TYPE_DEL); // this is meant to disappear /* TODO */ return false; @@ -1847,9 +1849,10 @@ void p3Peers::setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermi mPeerMgr->setServicePermissionFlags(gpg_id,flags) ; } +#ifdef TO_REMOVE RsPeerStateChangedEvent::RsPeerStateChangedEvent(RsPeerId sslId) : RsEvent(RsEventType::PEER_STATE_CHANGED), mSslId(sslId) {} +#endif RsPeers::~RsPeers() = default; RsAuthSslConnectionAutenticationEvent::~RsAuthSslConnectionAutenticationEvent() = default; -RsConnectionEvent::~RsConnectionEvent() = default; diff --git a/src/rsserver/p3status.cc b/src/rsserver/p3status.cc index 4185e68022..56f9725dbe 100644 --- a/src/rsserver/p3status.cc +++ b/src/rsserver/p3status.cc @@ -47,7 +47,7 @@ bool p3Status::getStatus(const RsPeerId &id, StatusInfo &statusInfo) return mStatusSrv->getStatus(id, statusInfo); } -bool p3Status::sendStatus(const RsPeerId &id, uint32_t status){ +bool p3Status::sendStatus(const RsPeerId &id, RsStatusValue status){ return mStatusSrv->sendStatus(id, status); } diff --git a/src/rsserver/p3status.h b/src/rsserver/p3status.h index a6ae941f00..7b89f6a54b 100644 --- a/src/rsserver/p3status.h +++ b/src/rsserver/p3status.h @@ -42,7 +42,7 @@ class p3Status : public RsStatus virtual bool getOwnStatus(StatusInfo& statusInfo); virtual bool getStatusList(std::list& statusInfo); virtual bool getStatus(const RsPeerId &id, StatusInfo &statusInfo); - virtual bool sendStatus(const RsPeerId &id, uint32_t status); + virtual bool sendStatus(const RsPeerId &id, RsStatusValue status); private: diff --git a/src/services/p3rtt.cc b/src/services/p3rtt.cc index 0dc2f41e27..56393120df 100644 --- a/src/services/p3rtt.cc +++ b/src/services/p3rtt.cc @@ -367,10 +367,10 @@ int p3rtt::storePongResult(const RsPeerId& id, uint32_t counter, double recv_ts, { if(rsEvents) { - auto ev = std::make_shared(); + auto ev = std::make_shared(); ev->mSslId = peerInfo->mId; ev->mTimeShift = static_cast(peerInfo->mCurrentMeanOffset); - ev->mConnectionInfoCode = RsConnectionEventCode::PEER_TIME_SHIFT; + ev->mEventCode = RsFriendListEventCode::NODE_TIME_SHIFT; rsEvents->postEvent(ev); } RsWarn() << __PRETTY_FUNCTION__ << " Peer: " << peerInfo->mId diff --git a/src/services/p3statusservice.cc b/src/services/p3statusservice.cc index c0953003a0..65c19f2ff7 100644 --- a/src/services/p3statusservice.cc +++ b/src/services/p3statusservice.cc @@ -36,7 +36,7 @@ std::ostream& operator<<(std::ostream& out, const StatusInfo& si) { out << "StatusInfo: " << std::endl; out << "id: " << si.id << std::endl; - out << "status: " << si.status << std::endl; + out << "status: " << (uint8_t)si.status << std::endl; out << "time_stamp: " << si.time_stamp << std::endl; return out; } @@ -89,7 +89,7 @@ bool p3StatusService::getOwnStatus(StatusInfo& statusInfo) // own status not set, set it to online statusInfo.id = ownId; - statusInfo.status = RS_STATUS_ONLINE; + statusInfo.status = RsStatusValue::RS_STATUS_ONLINE; std::pair pr(ownId, statusInfo); mStatusInfoMap.insert(pr); @@ -137,7 +137,7 @@ bool p3StatusService::getStatus(const RsPeerId &id, StatusInfo &statusInfo) statusInfo = StatusInfo(); statusInfo.id = id; - statusInfo.status = RS_STATUS_OFFLINE; + statusInfo.status = RsStatusValue::RS_STATUS_OFFLINE; return false; } @@ -147,7 +147,7 @@ bool p3StatusService::getStatus(const RsPeerId &id, StatusInfo &statusInfo) } /* id = "", status is sent to all online peers */ -bool p3StatusService::sendStatus(const RsPeerId &id, uint32_t status) +bool p3StatusService::sendStatus(const RsPeerId &id, RsStatusValue status) { StatusInfo statusInfo; std::set onlineList; @@ -159,7 +159,7 @@ bool p3StatusService::sendStatus(const RsPeerId &id, uint32_t status) statusInfo.status = status; // don't save inactive status - if(statusInfo.status != RS_STATUS_INACTIVE){ + if(statusInfo.status != RsStatusValue::RS_STATUS_INACTIVE){ // If your id is not set, set it if(mStatusInfoMap.find(statusInfo.id) == mStatusInfoMap.end()){ @@ -192,22 +192,28 @@ bool p3StatusService::sendStatus(const RsPeerId &id, uint32_t status) for(it = onlineList.begin(); it != onlineList.end(); ++it){ RsStatusItem* statusItem = new RsStatusItem(); statusItem->sendTime = time(NULL); - statusItem->status = statusInfo.status; + statusItem->status = (uint32_t)statusInfo.status; statusItem->PeerId(*it); sendItem(statusItem); } /* send notify of own status change */ - RsServer::notify()->notifyPeerStatusChanged(statusInfo.id.toStdString(), statusInfo.status); + //RsServer::notify()->notifyPeerStatusChanged(statusInfo.id.toStdString(), statusInfo.status); - return true; + auto e = std::make_shared(); + e->mSslId = statusInfo.id; + e->mStatus = statusInfo.status; + e->mEventCode = RsFriendListEventCode::NODE_STATUS_CHANGED; + rsEvents->postEvent(e); + + return true; } /******************************/ void p3StatusService::receiveStatusQueue() { - std::map changed; + std::map changed; { RsStackMutex stack(mStatusMtx); @@ -234,13 +240,16 @@ void p3StatusService::receiveStatusQueue() std::map::iterator mit = mStatusInfoMap.find(status_item->PeerId()); if(mit != mStatusInfoMap.end()){ + + auto status = RsStatusValue(status_item->status); + mit->second.id = status_item->PeerId(); - if (mit->second.status != status_item->status) { - changed [mit->second.id] = status_item->status; + if (mit->second.status != status) { + changed [mit->second.id] = status; } - mit->second.status = status_item->status; + mit->second.status = status; mit->second.time_stamp = status_item->sendTime; #ifdef STATUS_DEBUG } else { @@ -255,11 +264,17 @@ void p3StatusService::receiveStatusQueue() } /* UNLOCKED */ if (changed.size()) { - std::map::iterator it; - for (it = changed.begin(); it != changed.end(); ++it) { - RsServer::notify()->notifyPeerStatusChanged(it->first.toStdString(), it->second); - } - RsServer::notify()->notifyPeerStatusChangedSummary(); + std::map::iterator it; + for (it = changed.begin(); it != changed.end(); ++it) + { + //RsServer::notify()->notifyPeerStatusChanged(it->first.toStdString(), it->second); + auto e = std::make_shared(); + e->mSslId = it->first; + e->mStatus = RsStatusValue(it->second); + e->mEventCode = RsFriendListEventCode::NODE_STATUS_CHANGED; + rsEvents->postEvent(e); + } + //RsServer::notify()->notifyPeerStatusChangedSummary(); } } @@ -298,7 +313,7 @@ bool p3StatusService::saveList(bool& cleanup, std::list& ilist){ own_status->PeerId(own_info.id); own_status->sendTime = own_info.time_stamp; - own_status->status = own_info.status; + own_status->status = (uint32_t)own_info.status; ilist.push_back(own_status); @@ -318,7 +333,7 @@ bool p3StatusService::loadList(std::list& load) if(own_status != NULL) { own_info.id = mServiceCtrl->getOwnId(); - own_info.status = own_status->status; + own_info.status = RsStatusValue(own_status->status); own_info.time_stamp = own_status->sendTime; { @@ -368,16 +383,20 @@ void p3StatusService::statusChange(const std::list &plist) } /* UNLOCKED */ changedState = true; - RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_OFFLINE); - } + //RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_OFFLINE); + + auto e = std::make_shared(); + e->mSslId = it->id; + e->mStatus = RsStatusValue::RS_STATUS_OFFLINE; + e->mEventCode = RsFriendListEventCode::NODE_STATUS_CHANGED; + rsEvents->postEvent(e); + } if (it->actions & RS_SERVICE_PEER_CONNECTED) { /* send current status, only call getOwnStatus once in the loop */ if (statusInfo.id.isNull() == false || getOwnStatus(statusInfo)) - { sendStatus(it->id, statusInfo.status); - } { RsStackMutex stack(mStatusMtx); @@ -385,14 +404,20 @@ void p3StatusService::statusChange(const std::list &plist) /* We assume that the peer is online. If not, he send us a new status */ StatusInfo info; info.id = it->id; - info.status = RS_STATUS_ONLINE; + info.status = RsStatusValue::RS_STATUS_ONLINE; info.time_stamp = time(NULL); mStatusInfoMap[it->id] = info; } /* UNLOCKED */ changedState = true; - RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_ONLINE); + //RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_ONLINE); + + auto e = std::make_shared(); + e->mSslId = it->id; + e->mStatus = RsStatusValue::RS_STATUS_ONLINE; + e->mEventCode = RsFriendListEventCode::NODE_STATUS_CHANGED; + rsEvents->postEvent(e); } if (it->actions & RS_SERVICE_PEER_REMOVED) @@ -405,12 +430,18 @@ void p3StatusService::statusChange(const std::list &plist) } /* UNLOCKED */ changedState = true; - RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_OFFLINE); - } + //RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_OFFLINE); + + auto e = std::make_shared(); + e->mSslId = it->id; + e->mStatus = RsStatusValue::RS_STATUS_OFFLINE; + e->mEventCode = RsFriendListEventCode::NODE_STATUS_CHANGED; + rsEvents->postEvent(e); + } } - if (changedState) - { - RsServer::notify()->notifyPeerStatusChangedSummary(); - } +// if (changedState) +// { +// RsServer::notify()->notifyPeerStatusChangedSummary(); +// } } diff --git a/src/services/p3statusservice.h b/src/services/p3statusservice.h index ac0b70653f..99885da6e6 100644 --- a/src/services/p3statusservice.h +++ b/src/services/p3statusservice.h @@ -65,7 +65,7 @@ virtual bool getOwnStatus(StatusInfo& statusInfo); virtual bool getStatusList(std::list& statusInfo); virtual bool getStatus(const RsPeerId &id, StatusInfo &statusInfo); /* id = "", status is sent to all online peers */ -virtual bool sendStatus(const RsPeerId &id, uint32_t status); +virtual bool sendStatus(const RsPeerId &id, RsStatusValue status); /******************************/ diff --git a/src/util/rsdiscspace.cc b/src/util/rsdiscspace.cc index 11d01434ce..9ba2dbedce 100644 --- a/src/util/rsdiscspace.cc +++ b/src/util/rsdiscspace.cc @@ -195,7 +195,13 @@ bool RsDiscSpace::checkForDiscSpace(RsDiscSpace::DiscLocation loc) bool res = _current_size[loc] > _size_limit_mb ; if(_last_res[loc] && !res) - RsServer::notify()->notifyDiskFull(loc,_size_limit_mb) ; + { + auto ev = std::make_shared(); + ev->mEventCode = RsSystemErrorEventCode::DISK_SPACE_ERROR; + ev->mDiskErrorLocation = loc; + ev->mDiskErrorSizeLimit = _size_limit_mb; + rsEvents->postEvent(ev); + } _last_res[loc] = res ;