Skip to content

Commit

Permalink
handle all resources as shared_ptr (fixing error in measuring network…
Browse files Browse the repository at this point in the history
… send/rec)
  • Loading branch information
rex-schilasky committed Jan 14, 2025
1 parent e75a706 commit 938513b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions contrib/mma/include/windows/mma_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class MMAWindows : public MMAImpl
QueryManager query_manager_;
std::shared_ptr<Processor> processor_;
std::shared_ptr<Memory> memory_;
std::shared_ptr<Disk> disk_;
std::shared_ptr<Network> network_;
std::shared_ptr<Processes> processes_;

std::list<std::shared_ptr<Resource>> total_network_cards_;
Expand Down
20 changes: 12 additions & 8 deletions contrib/mma/src/windows/mma_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,28 @@ bool MMAWindows::init()
pdhStatus = PdhOpenQuery(nullptr, 0, &h_query_);
CheckPDH("PdhOpenQuery", pdhStatus);

// PROCESSOR
processor_ = std::make_shared<Processor>();
processor_->RefreshData(h_query_, pdhStatus);

// MEMORY
memory_ = std::make_shared<Memory>();

Disk disk_resource;
total_disks_ = disk_resource.GetResourceInfo(h_query_, pdhStatus, query_manager_);
// DISK
disk_ = std::make_shared<Disk>();
total_disks_ = disk_->GetResourceInfo(h_query_, pdhStatus, query_manager_);

Network network_resource;
total_network_cards_ = network_resource.GetResourceInfo(h_query_, pdhStatus, query_manager_);
// NETWORK
network_ = std::make_shared<Network>();
total_network_cards_ = network_->GetResourceInfo(h_query_, pdhStatus, query_manager_);

pdhStatus = PdhCollectQueryData(h_query_);

CheckPDH("PdhCollectQueryData", pdhStatus);

// PROCESSES
processes_ = std::make_shared<Processes>();

nr_of_cpu_cores = processor_->GetNumbersOfCpuCores(); // the nr. of cores is static show we need to call once this function
lpBuffer = new char[4026];
_In_ UINT uSize = 0;
Expand Down Expand Up @@ -147,12 +153,10 @@ bool MMAWindows::Get(eCAL::pb::mma::State& state)
state.clear_disks();
state.clear_networks();

Disk disk;
auto disks = disk.GetResourceInfo(h_query_, pdhStatus, query_manager_);
auto disks = disk_->GetResourceInfo(h_query_, pdhStatus, query_manager_);
RefreshResource(total_disks_, disks);

Network network;
auto networks = network.GetResourceInfo(h_query_, pdhStatus, query_manager_);
auto networks = network_->GetResourceInfo(h_query_, pdhStatus, query_manager_);
RefreshResource(total_network_cards_, networks);

memory_->RefreshData();
Expand Down

0 comments on commit 938513b

Please sign in to comment.