pcap: add dtor

this fixes issue if object is destroyed and PCAP is still open
This commit is contained in:
Andre Puschmann 2019-06-07 22:14:24 +02:00
parent 67b6a40c1b
commit 414e55fafc
2 changed files with 15 additions and 4 deletions

View File

@ -30,7 +30,8 @@ namespace srslte {
class mac_pcap
{
public:
mac_pcap() {enable_write=false; ue_id=0; pcap_file = NULL; };
mac_pcap();
~mac_pcap();
void enable(bool en);
void open(const char *filename, uint32_t ue_id = 0);
void close();

View File

@ -25,7 +25,14 @@
#include "srslte/common/mac_pcap.h"
namespace srslte {
mac_pcap::mac_pcap() : enable_write(false), ue_id(0), pcap_file(nullptr) {}
mac_pcap::~mac_pcap()
{
close();
}
void mac_pcap::enable(bool en)
{
enable_write = true;
@ -39,8 +46,11 @@ void mac_pcap::open(const char* filename, uint32_t ue_id)
void mac_pcap::close()
{
enable_write = false;
fprintf(stdout, "Saving MAC PCAP file\n");
LTE_PCAP_Close(pcap_file);
if (pcap_file != nullptr) {
fprintf(stdout, "Saving MAC PCAP file\n");
LTE_PCAP_Close(pcap_file);
pcap_file = nullptr;
}
}
void mac_pcap::set_ue_id(uint16_t ue_id) {