Expose /rsFiles/turtleSearchRequest via JSON API

Expose new async C++ API RsFiles::turtleSearchRequest with callback
Modernize TurtleFileInfo serialization code keeping retrocompatibility
This commit is contained in:
Gioacchino Mazzurco 2018-08-25 17:58:04 +02:00
parent a8b2532d3b
commit c50405c070
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
5 changed files with 107 additions and 66 deletions

View file

@ -24,6 +24,8 @@
#include <list>
#include <iostream>
#include <string>
#include <functional>
#include <chrono>
#include "rstypes.h"
#include "serialiser/rsserializable.h"
@ -315,8 +317,24 @@ public:
virtual uint32_t getMaxUploadSlotsPerFriend()=0;
virtual void setFilePermDirectDL(uint32_t perm)=0;
virtual uint32_t filePermDirectDL()=0;
virtual TurtleRequestId turtleSearch(const std::string& string_to_match) =0;
virtual TurtleRequestId turtleSearch(const RsRegularExpression::LinearizedExpression& expr) =0;
/**
* @brief Request remote files search
* @jsonapi{development}
* @param[in] matchString string to look for in the search
* @param multiCallback function that will be called each time a search
* result is received
* @param[in] maxWait maximum wait time in seconds for search results
* @return false on error, true otherwise
*/
virtual bool turtleSearchRequest(
const std::string& matchString,
const std::function<void (const std::list<TurtleFileInfo>& results)>& multiCallback,
std::time_t maxWait = 300 ) = 0;
virtual TurtleRequestId turtleSearch(const std::string& string_to_match) = 0;
virtual TurtleRequestId turtleSearch(
const RsRegularExpression::LinearizedExpression& expr) = 0;
/***
* Control of Downloads Priority.

View file

@ -38,30 +38,33 @@ class RsTurtle;
/**
* Pointer to global instance of RsTurtle service implementation
* @jsonapi{development}
*/
extern RsTurtle* rsTurtle;
typedef uint32_t TurtleRequestId ;
typedef RsPeerId TurtleVirtualPeerId;
// This is the structure used to send back results of the turtle search
// to the notifyBase class, or send info to the GUI.
struct TurtleFileInfo //: RsSerializable
/**
* This is the structure used to send back results of the turtle search,
* to other peers, to the notifyBase class, to the search caller or to the GUI.
*/
struct TurtleFileInfo : RsSerializable
{
RsFileHash hash;
std::string name;
uint64_t size;
/*
uint64_t size; /// File size
RsFileHash hash; /// File hash
std::string name; /// File name
/// @see RsSerializable::serial_process
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(hash);
RS_SERIAL_PROCESS(name);
RS_SERIAL_PROCESS(size);
}*/
RS_SERIAL_PROCESS(hash);
// Use String TLV serial process for retrocompatibility
RsTypeSerializer::serial_process(
j, ctx, TLV_TYPE_STR_NAME, name, "name" );
}
};
struct TurtleTunnelRequestDisplayInfo