packets need a copy function

pull/1/head
Tom Early 3 years ago
parent cb56ec2245
commit fd9ddd7181

@ -211,11 +211,6 @@ void CDextraProtocol::HandleQueue(void)
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetPacketModule()) )
{
if (packet->IsDvHeader())
{
buffer.Dump("Header packet");
std::cout << "Is going to " << client->GetCallsign() << " at " << client->GetIp() << std::endl;
}
// no, send the packet
int n = packet->IsDvHeader() ? 5 : 1;
for ( int i = 0; i < n; i++ )

@ -167,6 +167,11 @@ CDvFramePacket::CDvFramePacket(const int16_t *usrp, uint16_t streamid, bool isla
m_TCPack.codec_in = ECodecType::usrp;
}
std::unique_ptr<CPacket> CDvFramePacket::Copy(void)
{
return std::unique_ptr<CPacket>(new CDvFramePacket(*this));
}
// Network
unsigned int CDvFramePacket::GetNetworkSize()
{

@ -63,6 +63,7 @@ public:
void EncodeInterlinkPacket(CBuffer &buf) const;
// identity
std::unique_ptr<CPacket> Copy(void);
bool IsDvHeader(void) const { return false; }
bool IsDvFrame(void) const { return true; }

@ -165,6 +165,11 @@ CDvHeaderPacket::CDvHeaderPacket(const CM17Packet &m17) : CPacket(m17)
m_csRPT1.SetCSModule('G');
}
std::unique_ptr<CPacket> CDvHeaderPacket::Copy(void)
{
return std::unique_ptr<CPacket>(new CDvHeaderPacket(*this));
}
////////////////////////////////////////////////////////////////////////////////////////
// conversion

@ -66,6 +66,7 @@ public:
void EncodeInterlinkPacket(CBuffer &buf) const;
// identity
std::unique_ptr<CPacket> Copy(void);
bool IsDvHeader(void) const { return true; }
bool IsDvFrame(void) const { return false; }

@ -41,6 +41,7 @@ public:
CPacket(const CM17Packet &);
// identity
virtual std::unique_ptr<CPacket> Copy(void) = 0;
virtual bool IsDvHeader(void) const = 0;
virtual bool IsDvFrame(void) const = 0;
bool IsLastPacket(void) const { return m_bLastPacket; }

@ -80,7 +80,7 @@ public:
virtual void Task(void) = 0;
// pass-through
void Push(std::shared_ptr<CPacket> p) { m_Queue.Push(p); }
void Push(std::unique_ptr<CPacket> p) { m_Queue.Push(std::move(p)); }
protected:
// stream helpers
@ -126,7 +126,7 @@ protected:
std::unordered_map<uint16_t, std::shared_ptr<CPacketStream>> m_Streams;
// queue
CSafePacketQueue<std::shared_ptr<CPacket>> m_Queue;
CSafePacketQueue<std::unique_ptr<CPacket>> m_Queue;
// thread
std::atomic<bool> keep_running;

@ -265,10 +265,8 @@ void CReflector::RouterThread(const char ThisModule)
while (keep_running)
{
// wait until something shows up
auto uptmp = streamIn->PopWait();
// convert the incoming packet to a shared_ptr
std::shared_ptr<CPacket> packet = std::move(uptmp);
// set origin
auto packet = streamIn->PopWait();
packet->SetPacketModule(ThisModule);
// iterate on all protocols
@ -276,22 +274,18 @@ void CReflector::RouterThread(const char ThisModule)
for ( auto it=m_Protocols.begin(); it!=m_Protocols.end(); it++ )
{
// make a copy! after the Push(tmp), tmp will be nullptr!
auto tmp = packet;
auto copy = packet->Copy();
// if packet is header, update RPT2 according to protocol
if ( tmp->IsDvHeader() )
if ( copy->IsDvHeader() )
{
// get our callsign
CCallsign csRPT = (*it)->GetReflectorCallsign();
csRPT.SetCSModule(ThisModule);
//(dynamic_cast<CDvHeaderPacket *>(tmp.get()))->SetRpt2Callsign(csRPT);
auto x = dynamic_cast<CDvHeaderPacket *>(tmp.get());
x->SetRpt2Callsign(csRPT);
if ((*it)->GetPort() == 30001)
std::cout << (*it)->GetReflectorCallsign() << ": " << csRPT << " == " << x->GetRpt2Callsign() << std::endl;
(dynamic_cast<CDvHeaderPacket *>(copy.get()))->SetRpt2Callsign(csRPT);
}
(*it)->Push(tmp);
(*it)->Push(std::move(copy));
}
m_Protocols.Unlock();
}

Loading…
Cancel
Save

Powered by TurnKey Linux.