source: trunk/XSUC/Connection.cpp@ 12

Last change on this file since 12 was 11, checked in by marrucho, 12 years ago
File size: 2.4 KB
Line 
1// Connection.cpp: implementation of the CConnection class.
2//
3//////////////////////////////////////////////////////////////////////
4
5#include "stdafx.h"
6#include "Connection.h"
7
8#ifdef _DEBUG
9#undef THIS_FILE
10static char THIS_FILE[]=__FILE__;
11#define new DEBUG_NEW
12#endif
13
14//////////////////////////////////////////////////////////////////////
15// Construction/Destruction
16//////////////////////////////////////////////////////////////////////
17
18IMPLEMENT_DYNAMIC( CConnection , CObject)
19
20
21CConnection::CConnection()
22{
23 m_pModbus=NULL;
24}
25
26CConnection::~CConnection()
27{
28
29
30}
31
32
33CConnection::CConnection(WORD wType , LPCTSTR sKey)
34{
35 m_sKey = sKey;
36 m_wType = wType;
37
38 switch (wType) {
39
40 case AUTO:
41 m_pModbus= new CAutoModbus();
42 break;
43 case REMOTE:
44 m_pModbus= new CRemoteModbus();
45 break;
46 default:
47 ASSERT(FALSE); //Type Error
48 }
49
50}
51
52CConnection::CConnection(const CConnection& rConnection)
53{
54 m_pModbus = rConnection.m_pModbus;
55 m_sKey = rConnection.m_sKey;
56 m_wType = rConnection.m_wType;
57
58}
59
60
61CAutoModbus* CConnection::AutoPtr()
62{
63 if (AUTO==m_wType) {
64 return (CAutoModbus*)m_pModbus;
65 }
66 else {
67 ASSERT(FALSE);//Type Error
68 return NULL;
69 }
70}
71
72CRemoteModbus* CConnection::RemotePtr()
73{
74 if (REMOTE==m_wType) {
75 return (CRemoteModbus*)m_pModbus;
76 }
77 else {
78 ASSERT(FALSE);//Type Error
79 return NULL;
80 }
81
82}
83
84void CConnection::Delete()
85{
86
87 if (m_pModbus!=NULL) {
88 switch (m_wType) {
89
90 case AUTO:
91 delete AutoPtr();
92 break;
93 case REMOTE:
94 delete RemotePtr();
95 break;
96 default:
97 ASSERT(FALSE); //Type Error
98 }
99 }
100
101 delete this;
102}
103
104
105CString CConnection::DcomServer()
106{
107 return m_sDcomServer;
108}
109
110void CConnection::DcomServer(LPCTSTR szDcomServer)
111{
112 m_sDcomServer=szDcomServer;
113}
114
115CString CConnection::Key() {
116 return m_sKey;
117}
118
119WORD CConnection::Type() {
120
121 return m_wType;
122
123}
124
125
126 void CConnection::Serialize( CArchive& archive )
127 {
128 // call base class function first
129 // base class is CObject in this case
130 CObject::Serialize( archive );
131
132
133 // now do the stuff for our specific class
134 if( archive.IsStoring() ){
135 archive <<m_sDcomServer;
136 }
137 else {
138 archive >>m_sDcomServer;
139 }
140
141 switch(Type()) {
142 case AUTO:
143 AutoPtr()->Serialize(archive);
144 break;
145 case REMOTE:
146 RemotePtr()->Serialize(archive);
147 break;
148 }
149
150 }
Note: See TracBrowser for help on using the repository browser.