| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #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); |
| | | } |
| | | } |