Expose the total number of sections via ICaptureAccess

* This lets external code iterate over all sections.
This commit is contained in:
baldurk
2017-12-20 17:17:41 +00:00
parent cb4fb770e9
commit 669fa9dc40
3 changed files with 61 additions and 1 deletions
+7
View File
@@ -1103,6 +1103,13 @@ and construction of files.
)");
struct ICaptureAccess
{
DOCUMENT(R"(Retrieve the total number of available sections.
:return: The number of sections in the capture
:rtype: ``int``.
)");
virtual int GetSectionCount() = 0;
DOCUMENT(R"(Locate the index of a section by its name. Returns ``-1`` if the section is not found.
This index should not be cached, as writing sections could re-order the indices.
+45 -1
View File
@@ -35,7 +35,7 @@
#include "strings/string_utils.h"
#include "replay_proxy.h"
static const uint32_t RemoteServerProtocolVersion = 2;
static const uint32_t RemoteServerProtocolVersion = 3;
enum RemoteServerPacket
{
@@ -61,6 +61,7 @@ enum RemoteServerPacket
eRemoteServer_ListDir,
eRemoteServer_ExecuteAndInject,
eRemoteServer_ShutdownServer,
eRemoteServer_GetSectionCount,
eRemoteServer_FindSectionByName,
eRemoteServer_FindSectionByType,
eRemoteServer_GetSectionProperties,
@@ -559,6 +560,18 @@ static void ActiveRemoteClientThread(ClientThread *threadData)
SERIALISE_ELEMENT(StackFrames);
}
}
else if(type == eRemoteServer_GetSectionCount)
{
reader.EndChunk();
int count = rdc ? rdc->NumSections() : 0;
{
WRITE_DATA_SCOPE();
SCOPED_SERIALISE_CHUNK(eRemoteServer_GetSectionCount);
SERIALISE_ELEMENT(count);
}
}
else if(type == eRemoteServer_FindSectionByName)
{
std::string name;
@@ -1408,6 +1421,37 @@ public:
rend->Shutdown();
}
int GetSectionCount()
{
if(!Connected())
return 0;
{
WRITE_DATA_SCOPE();
SCOPED_SERIALISE_CHUNK(eRemoteServer_GetSectionCount);
}
int count = 0;
{
READ_DATA_SCOPE();
RemoteServerPacket type = ser.ReadChunk<RemoteServerPacket>();
if(type == eRemoteServer_GetSectionCount)
{
SERIALISE_ELEMENT(count);
}
else
{
RDCERR("Unexpected response to GetSectionCount");
}
ser.EndChunk();
}
return count;
}
int FindSectionByName(const char *name)
{
if(!Connected())
+9
View File
@@ -165,6 +165,7 @@ public:
// ICaptureAccess
int GetSectionCount();
int FindSectionByName(const char *name);
int FindSectionByType(SectionType type);
SectionProperties GetSectionProperties(int index);
@@ -603,6 +604,14 @@ Thumbnail CaptureFile::GetThumbnail(FileType type, uint32_t maxsize)
return ret;
}
int CaptureFile::GetSectionCount()
{
if(!m_RDC)
return 0;
return m_RDC->NumSections();
}
int CaptureFile::FindSectionByName(const char *name)
{
if(!m_RDC)