RsGxsChannels local search support

This commit is contained in:
Gioacchino Mazzurco 2018-11-17 17:19:13 +01:00
parent f670a18b13
commit 2b58e3f461
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
5 changed files with 60 additions and 1 deletions

View File

@ -3429,3 +3429,9 @@ void RsGenExchange::turtleSearchRequest(const std::string& match_string)
{
mNetService->turtleSearchRequest(match_string) ;
}
bool RsGenExchange::localSearch( const std::string& matchString,
std::list<RsGxsGroupSummary>& results )
{
return mNetService->search(matchString, results);
}

View File

@ -313,6 +313,15 @@ public:
void turtleGroupRequest(const RsGxsGroupId& group_id);
void turtleSearchRequest(const std::string& match_string);
/**
* @brief Search local groups. Blocking API.
* @param matchString string to look for in the search
* @param results storage for results
* @return false on error, true otherwise
*/
bool localSearch( const std::string& matchString,
std::list<RsGxsGroupSummary>& results );
protected:
bool messagePublicationTest(const RsGxsMsgMetaData&) ;

View File

@ -287,6 +287,19 @@ public:
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
rstime_t maxWait = 300 ) = 0;
/**
* @brief Search local channels
* @jsonapi{development}
* @param[in] matchString string to look for in the search
* @param multiCallback function that will be called for each result
* @param[in] maxWait maximum wait time in seconds for search results
* @return false on error, true otherwise
*/
virtual bool localSearchRequest(
const std::string& matchString,
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
rstime_t maxWait = 30 ) = 0;
/* Following functions are deprecated as they expose internal functioning
* semantic, instead of a safe to use API */

View File

@ -36,6 +36,7 @@
#include "retroshare/rsnotify.h"
#include <cstdio>
#include <chrono>
// For Dummy Msgs.
#include "util/rsrandom.h"
@ -1969,6 +1970,31 @@ bool p3GxsChannels::turtleChannelRequest(
return true;
}
/// @see RsGxsChannels::localSearchRequest
bool p3GxsChannels::localSearchRequest(
const std::string& matchString,
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
rstime_t maxWait )
{
if(matchString.empty())
{
std::cerr << __PRETTY_FUNCTION__ << " match string can't be empty!"
<< std::endl;
return false;
}
auto timeout = std::chrono::steady_clock::now() + std::chrono::seconds(maxWait);
RsThread::async([=]()
{
std::list<RsGxsGroupSummary> results;
RsGenExchange::localSearch(matchString, results);
if(std::chrono::steady_clock::now() < timeout)
for(const RsGxsGroupSummary& result : results) multiCallback(result);
});
return true;
}
void p3GxsChannels::receiveDistantSearchResults(
TurtleRequestId id, const RsGxsGroupId& grpId )
{

View File

@ -118,6 +118,11 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
rstime_t maxWait = 300 );
/// @see RsGxsChannels::localSearchRequest
virtual bool localSearchRequest(const std::string& matchString,
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
rstime_t maxWait = 30 ) override;
/**
* Receive results from turtle search @see RsGenExchange @see RsNxsObserver
* @see RsGxsNetService::receiveTurtleSearchResults