1/*
2 * IXConnectionState.cpp
3 * Author: Benjamin Sergeant
4 * Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
5 */
6
7#include "IXConnectionState.h"
8
9namespace ix
10{
11 std::atomic<uint64_t> ConnectionState::_globalId(0);
12
13 ConnectionState::ConnectionState()
14 : _terminated(false)
15 {
16 computeId();
17 }
18
19 void ConnectionState::computeId()
20 {
21 _id = std::to_string(_globalId++);
22 }
23
24 const std::string& ConnectionState::getId() const
25 {
26 return _id;
27 }
28
29 std::shared_ptr<ConnectionState> ConnectionState::createConnectionState()
30 {
31 return std::make_shared<ConnectionState>();
32 }
33
34 void ConnectionState::setOnSetTerminatedCallback(const OnSetTerminatedCallback& callback)
35 {
36 _onSetTerminatedCallback = callback;
37 }
38
39 bool ConnectionState::isTerminated() const
40 {
41 return _terminated;
42 }
43
44 void ConnectionState::setTerminated()
45 {
46 _terminated = true;
47
48 if (_onSetTerminatedCallback)
49 {
50 _onSetTerminatedCallback();
51 }
52 }
53
54 const std::string& ConnectionState::getRemoteIp()
55 {
56 return _remoteIp;
57 }
58
59 int ConnectionState::getRemotePort()
60 {
61 return _remotePort;
62 }
63
64 void ConnectionState::setRemoteIp(const std::string& remoteIp)
65 {
66 _remoteIp = remoteIp;
67 }
68
69 void ConnectionState::setRemotePort(int remotePort)
70 {
71 _remotePort = remotePort;
72 }
73} // namespace ix
74