-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSockPair.cpp
107 lines (89 loc) · 2.71 KB
/
SockPair.cpp
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
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: SOCKPAIR.CPP
** COMPONENT: The Application
** DESCRIPTION: CSockPair class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "SockPair.hpp"
#include "Params.hpp"
#include "SockConfig.hpp"
#include <WCL/StrCvt.hpp>
#include "SockTraceApp.hpp"
/******************************************************************************
** Method: Constructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CSockPair::CSockPair(CSockConfigPtr pConfig, uint nInstance)
: m_pConfig(pConfig)
, m_nInstance(nInstance)
, m_nBytesSent(0)
, m_nBytesRecv(0)
{
CParams oParams;
// Set the common parameters.
oParams.Set(TXT("port"), CStrCvt::FormatInt(pConfig->m_nSrcPort));
oParams.Set(TXT("id"), CStrCvt::FormatInt(m_nInstance));
oParams.Set(TXT("dir"), TXT("sent"));
// Create the sent data log file path.
m_strSendFile = ParseFileName(m_pConfig->m_strSendFile, oParams);
oParams.Set(TXT("dir"), TXT("recv"));
// Create the sent data log file path.
m_strRecvFile = ParseFileName(m_pConfig->m_strRecvFile, oParams);
}
/******************************************************************************
** Method: Destructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CSockPair::~CSockPair()
{
}
/******************************************************************************
** Method: ParseFileName()
**
** Description: Parse the filename replacing the tokens with actual values.
**
** Parameters: pszFileName The filename template.
** oParams The parameter values.
**
** Returns: The parsed file name prefixed with the path.
**
*******************************************************************************
*/
CPath CSockPair::ParseFileName(const tchar* pszFileName, const CParams& oParams)
{
ASSERT(pszFileName != nullptr);
CPath strFileName = pszFileName;
size_t nStartChar = Core::npos;
// For all parameters...
while ((nStartChar = strFileName.Find('%')) != Core::npos)
{
size_t nEndChar = Core::npos;
// Find the parameter end marker.
if ((nEndChar = strFileName.Find('%', nStartChar+1)) == Core::npos)
break;
// Find the parameter value.
CString strValue = oParams.Find(strFileName.Mid(nStartChar+1, nEndChar-nStartChar-1));
// Substitute the parameter.
strFileName.Delete(nStartChar, nEndChar-nStartChar+1);
strFileName.Insert(nStartChar, strValue);
}
return App.m_appDataFolder / strFileName;
}