-
Notifications
You must be signed in to change notification settings - Fork 0
/
igtlTCPConnectorBase.cxx
109 lines (84 loc) · 2.46 KB
/
igtlTCPConnectorBase.cxx
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
/*=========================================================================
Program: Connector Base Class for OpenIGTLink Proxy
Module: $RCSfile: $
Language: C++
Date: $Date: $
Version: $Revision: $
Copyright (c) Brigham and Women's Hospital. All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <string.h>
#include "igtlTCPConnectorBase.h"
#include "igtlOSUtil.h"
namespace igtl
{
const char* TCPConnectorBase::StatusString[] = {
"OFF",
"WAITING",
"CONNECTED",
"ERROR"
};
//-----------------------------------------------------------------------------
TCPConnectorBase::TCPConnectorBase()
{
this->Hostname = "localhost";
this->Port = 0;
this->Active = 0;
this->Status = STATUS_STOP;
this->ConfigurationUpdated = true;
this->DataReceivedFlag = false;
this->DataSentFlag = false;
}
//-----------------------------------------------------------------------------
TCPConnectorBase::~TCPConnectorBase()
{
}
//-----------------------------------------------------------------------------
void TCPConnectorBase::PrintSelf(std::ostream& os) const
{
this->Superclass::PrintSelf(os);
}
//-----------------------------------------------------------------------------
void TCPConnectorBase::MonitorThreadFunction(void * ptr)
{
igtl::MultiThreader::ThreadInfo* info =
static_cast<igtl::MultiThreader::ThreadInfo*>(ptr);
TCPConnectorBase * con = static_cast<TCPConnectorBase *>(info->UserData);
con->Active = 0;
while (con->Active >= 0)
{
if (con->ConfigurationUpdated)
{
con->ConfigurationUpdated = false;
if (!con->Initialize())
{
return;
}
}
con->Status = STATUS_STOP;
while (con->Active)
{
con->Status = STATUS_WAITING;
if(con->WaitForConnection())
{
con->Status = STATUS_CONNECTED;
while (con->Status == STATUS_CONNECTED)
{
if (con->ReceiveMessage() == 0)
{
// Disconnected
con->CloseConnection();
con->Status = STATUS_WAITING;
break;
}
con->SetDataReceivedFlag();
}
}
}
igtl::Sleep(500);
}
con->Finalize();
}
} // End of igtl namespace