File: XnLinkMsgParser.cpp

package info (click to toggle)
openni2 2.2.0.33%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 22,216 kB
  • sloc: cpp: 111,197; ansic: 35,511; sh: 10,542; python: 1,313; java: 952; makefile: 575; xml: 12
file content (87 lines) | stat: -rw-r--r-- 1,757 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "XnLinkMsgParser.h"
#include "XnLinkProtoUtils.h"
#include "XnLinkDefs.h"
#include <XnOS.h>
#include <XnLog.h>

namespace xn
{

LinkMsgParser::LinkMsgParser()
{
	m_pDestBuffer = NULL;
	m_pCurrDest = NULL;
	m_pDestEnd = NULL;
}

LinkMsgParser::~LinkMsgParser()
{
	Shutdown();
}

XnStatus LinkMsgParser::Init()
{
	return XN_STATUS_OK;
}

void LinkMsgParser::Shutdown()
{
	m_pDestBuffer = NULL;
	m_pCurrDest = NULL;
	m_pDestEnd = NULL;
}

XnStatus LinkMsgParser::BeginParsing(void* pDestBuffer, XnUInt32 nDestBufferSize)
{
	XN_VALIDATE_INPUT_PTR(pDestBuffer);
	m_pDestBuffer = reinterpret_cast<XnUInt8*>(pDestBuffer);
	m_pCurrDest = m_pDestBuffer;
	m_pDestEnd = m_pDestBuffer + nDestBufferSize;

	return XN_STATUS_OK;
}

XnStatus LinkMsgParser::ParsePacket(const LinkPacketHeader& header, const XnUInt8* pData)
{
	XnStatus nRetVal = XN_STATUS_OK;
	nRetVal = ParsePacketImpl(header.GetFragmentationFlags(), pData, pData + header.GetDataSize(), m_pCurrDest, m_pDestEnd);
	XN_IS_STATUS_OK(nRetVal);

	return XN_STATUS_OK;
}

const void* LinkMsgParser::GetParsedData() const
{
	return m_pDestBuffer;
}

XnUInt32 LinkMsgParser::GetParsedSize() const
{
	return XnUInt32(m_pCurrDest - m_pDestBuffer);
}

XnUInt32 LinkMsgParser::GetBufferSize() const
{
	return XnUInt32(m_pDestEnd - m_pDestBuffer);
}

XnStatus LinkMsgParser::ParsePacketImpl(XnLinkFragmentation /*fragmentation*/,
										const XnUInt8* pSrc, 
										const XnUInt8* pSrcEnd, 
										XnUInt8*& pDst, 
										const XnUInt8* pDstEnd)
{
	XnSizeT nPacketDataSize = pSrcEnd - pSrc;
	if (pDst + nPacketDataSize > pDstEnd)
	{
		XN_ASSERT(FALSE);
		return XN_STATUS_OUTPUT_BUFFER_OVERFLOW;
	}

	xnOSMemCopy(pDst, pSrc, nPacketDataSize);
	pDst += nPacketDataSize;

	return XN_STATUS_OK;
}

}