mrDarker
2025-07-24 98d66db6f691dcffd21f77130c138f710704b14c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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 0;
    }
 
    int CPin::recvIntent(CIntent* pIntent)
    {
        ASSERT(m_pEquipment);
        return m_pEquipment->recvIntent(this, pIntent);
    }
}