From 3628a707a38e1c590216c5983c9b97b9c742f86c Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期一, 24 三月 2025 09:01:42 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/CPin.cpp | 129 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 129 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/CPin.cpp b/SourceCode/Bond/Servo/CPin.cpp
new file mode 100644
index 0000000..4a57efb
--- /dev/null
+++ b/SourceCode/Bond/Servo/CPin.cpp
@@ -0,0 +1,129 @@
+#include "stdafx.h"
+#include "CPin.h"
+#include "CEquipment.h"
+
+
+namespace SERVO {
+ CPin::CPin()
+ {
+ m_pEquipment = nullptr;
+ m_pConnectedPin = nullptr;
+ }
+
+ CPin::CPin(CEquipment* pEquipment, PinType type, char* pszName)
+ {
+ m_type = type;
+ m_strName = pszName;
+ m_pEquipment = pEquipment;
+ m_pConnectedPin = nullptr;
+ }
+
+ CPin::~CPin()
+ {
+
+ }
+
+ std::string& CPin::getName()
+ {
+ return m_strName;
+ }
+
+ int CPin::getType()
+ {
+ return m_type;
+ }
+
+ BOOL CPin::isConnected()
+ {
+ return m_pConnectedPin != NULL;
+ }
+
+ CPin* CPin::getConnectedPin()
+ {
+ return m_pConnectedPin;
+ }
+
+ CEquipment* CPin::getEquipment()
+ {
+ return m_pEquipment;
+ }
+
+ // 接受连接
+ // pPin -- 指定要连接的pin
+ // 返回 >= 0连接成功
+ int CPin::accpetConnect(CPin* pPin)
+ {
+ assert(pPin);
+
+
+ // 是否已经连接
+ if (m_pConnectedPin != NULL) {
+ return -1;
+ }
+
+ // 必须是一个输入一个输出(一个公一个母)
+ if (m_type == pPin->getType()) {
+ return -2;
+ }
+ m_pConnectedPin = pPin;
+
+
+ return 0;
+ }
+
+ int CPin::connectPin(CPin* pPin)
+ {
+ assert(pPin);
+
+
+ // 是否已经连接
+ if (m_pConnectedPin != NULL) {
+ return -1;
+ }
+
+
+ // 必须是一个输入一个输出(一个公一个母)
+ if (m_type == pPin->getType()) {
+ return -2;
+ }
+
+
+ // 对方接受连接?
+ int nRet = pPin->accpetConnect(this);
+ if (nRet < 0) {
+ return nRet;
+ }
+ m_pConnectedPin = pPin;
+
+
+ return 0;
+ }
+
+ int CPin::disconnect()
+ {
+ if (m_pConnectedPin == NULL) {
+ return -1;
+ }
+
+ assert(m_pConnectedPin->m_pConnectedPin == this);
+ m_pConnectedPin->m_pConnectedPin = NULL;
+ m_pConnectedPin = NULL;
+
+ return 0;
+ }
+
+ int CPin::sendIntent(CIntent* pIntent)
+ {
+ if (m_pConnectedPin != NULL) {
+ return m_pConnectedPin->recvIntent(pIntent);
+ }
+
+ return FLOW_REJECT;
+ }
+
+ int CPin::recvIntent(CIntent* pIntent)
+ {
+ assert(m_pEquipment);
+ return m_pEquipment->recvIntent(this, pIntent);
+ }
+}
--
Gitblit v1.9.3