heathrow: use unique_ptr with internal objects.

This commit is contained in:
Maxim Poliakovski 2021-10-25 00:26:02 +02:00
parent 767735251b
commit 3f20d0a700
3 changed files with 19 additions and 29 deletions

View File

@ -24,12 +24,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/viacuda.h> #include <devices/common/viacuda.h>
#include <devices/ioctrl/macio.h> #include <devices/ioctrl/macio.h>
#include <devices/sound/awacs.h> #include <devices/sound/awacs.h>
#include <loguru.hpp>
#include <machines/machinebase.h> #include <machines/machinebase.h>
#include <cinttypes> #include <cinttypes>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include <loguru.hpp> #include <memory>
/** Heathrow Mac I/O device emulation. /** Heathrow Mac I/O device emulation.
@ -39,35 +40,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std; using namespace std;
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") { HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
this->nvram = new NVram(); this->nvram = std::unique_ptr<NVram> (new NVram());
this->viacuda = new ViaCuda(); this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
gMachineObj->add_subdevice("ViaCuda", this->viacuda); gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
// initialize sound chip and its DMA output channel, then wire them together // initialize sound chip and its DMA output channel, then wire them together
this->screamer = new AwacsScreamer(); this->screamer = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
this->snd_out_dma = new DMAChannel(); this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
this->screamer->set_dma_out(this->snd_out_dma); this->screamer->set_dma_out(this->snd_out_dma.get());
this->snd_out_dma->set_callbacks( this->snd_out_dma->set_callbacks(
std::bind(&AwacsScreamer::dma_start, this->screamer), std::bind(&AwacsScreamer::dma_start, this->screamer.get()),
std::bind(&AwacsScreamer::dma_end, this->screamer) std::bind(&AwacsScreamer::dma_end, this->screamer.get())
); );
this->mesh = new MESHController(HeathrowMESHID); this->mesh = std::unique_ptr<MESHController> (new MESHController(HeathrowMESHID));
} }
HeathrowIC::~HeathrowIC() {
if (this->nvram)
delete (this->nvram);
if (this->viacuda)
delete (this->viacuda);
if (this->mesh)
delete (this->mesh);
}
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) { uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
return this->pci_cfg_hdr[reg_offs & 0xFF]; return this->pci_cfg_hdr[reg_offs & 0xFF];
} }

View File

@ -63,6 +63,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/sound/awacs.h> #include <devices/sound/awacs.h>
#include <cinttypes> #include <cinttypes>
#include <memory>
/** /**
Heathrow ASIC emulation Heathrow ASIC emulation
@ -91,7 +92,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class HeathrowIC : public PCIDevice { class HeathrowIC : public PCIDevice {
public: public:
HeathrowIC(); HeathrowIC();
~HeathrowIC(); ~HeathrowIC() = default;
bool supports_type(HWCompType type) { bool supports_type(HWCompType type) {
return type == HWCompType::MMIO_DEV; return type == HWCompType::MMIO_DEV;
@ -148,12 +149,12 @@ private:
uint32_t aux_ctrl = 0; // aux features control register uint32_t aux_ctrl = 0; // aux features control register
/* device cells */ /* device cells */
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it std::unique_ptr<ViaCuda> viacuda; // VIA cell with Cuda MCU attached to it
NVram* nvram; // NVRAM cell std::unique_ptr<NVram> nvram; // NVRAM cell
AwacsScreamer *screamer; // Screamer audio codec instance std::unique_ptr<AwacsScreamer> screamer; // Screamer audio codec instance
MESHController *mesh; // MESH SCSI cell instance std::unique_ptr<MESHController> mesh; // MESH SCSI cell instance
DMAChannel* snd_out_dma; std::unique_ptr<DMAChannel> snd_out_dma;
}; };
#endif /* MACIO_H */ #endif /* MACIO_H */

View File

@ -149,7 +149,7 @@ private:
class AwacsScreamer : public AwacsBase { class AwacsScreamer : public AwacsBase {
public: public:
AwacsScreamer(); AwacsScreamer();
~AwacsScreamer(); ~AwacsScreamer() = default;
uint32_t snd_ctrl_read(uint32_t offset, int size); uint32_t snd_ctrl_read(uint32_t offset, int size);
void snd_ctrl_write(uint32_t offset, uint32_t value, int size); void snd_ctrl_write(uint32_t offset, uint32_t value, int size);