From 22137ea1df173a3c58a641eb9cd12999258faf18 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 07 一月 2025 17:00:49 +0800
Subject: [PATCH] 1.模拟添加PLC,删除PLC

---
 SourceCode/Bond/BoounionPLC/Model.cpp |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/BoounionPLC/Model.cpp b/SourceCode/Bond/BoounionPLC/Model.cpp
index 307a16a..e5c97c6 100644
--- a/SourceCode/Bond/BoounionPLC/Model.cpp
+++ b/SourceCode/Bond/BoounionPLC/Model.cpp
@@ -23,6 +23,10 @@
 
 CModel::~CModel()
 {
+	for (auto item : m_mapPlc) {
+		delete item.second;
+	}
+	m_mapPlc.clear();
 }
 
 IObservable* CModel::getObservable()
@@ -286,3 +290,30 @@
 {
 
 }
+
+std::map<std::string, CPLC*>& CModel::gtPlcMap()
+{
+	return m_mapPlc;
+}
+
+int CModel::addPlc(const char* pszName, const char* pszIp, const unsigned int port)
+{
+	auto iter = m_mapPlc.find(pszName);
+	if (iter != m_mapPlc.end()) return -1;
+	CPLC* pPLC = new CPLC(pszName, pszIp, port);
+	m_mapPlc[pszName] = pPLC;
+
+	notifyPtr(RX_CODE_ADD_PLC, pPLC);
+	return 0;
+}
+
+int CModel::removePlc(const char* pszName)
+{
+	auto iter = m_mapPlc.find(pszName);
+	if (iter == m_mapPlc.end()) return -1;
+
+	notifyPtr(RX_CODE_REMOVE_PLC, iter->second);
+	delete iter->second;
+	m_mapPlc.erase(iter);
+	return 0;
+}

--
Gitblit v1.9.3