#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) {
|
m_pConnectedPin->recvIntent(pIntent);
|
}
|
|
return 0;
|
}
|
|
int CPin::recvIntent(CIntent* pIntent)
|
{
|
assert(m_pEquipment);
|
m_pEquipment->recvIntent(this, pIntent);
|
return 0;
|
}
|
}
|