@@ -31,21 +31,21 @@ CRemoteCalls::~CRemoteCalls()
31
31
}
32
32
33
33
34
- void CRemoteCalls::Call ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
34
+ void CRemoteCalls::Call ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
35
35
{
36
- m_calls.push_back ( new CRemoteCall ( szServerHost, szResourceName, szFunctionName, arguments, luaMain, iFunction, uiConnectionAttempts, uiConnectTimeoutMs ) );
36
+ m_calls.push_back ( new CRemoteCall ( szServerHost, szResourceName, szFunctionName, arguments, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs ) );
37
37
m_calls.back ()->MakeCall ();
38
38
}
39
39
40
- void CRemoteCalls::Call ( const char * szURL, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
40
+ void CRemoteCalls::Call ( const char * szURL, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
41
41
{
42
- m_calls.push_back ( new CRemoteCall ( szURL, arguments, luaMain, iFunction, uiConnectionAttempts, uiConnectTimeoutMs ) );
42
+ m_calls.push_back ( new CRemoteCall ( szURL, arguments, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs ) );
43
43
m_calls.back ()->MakeCall ();
44
44
}
45
45
46
- void CRemoteCalls::Call ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
46
+ void CRemoteCalls::Call ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
47
47
{
48
- m_calls.push_back ( new CRemoteCall ( szURL, fetchArguments, strPostData, bPostBinary, luaMain, iFunction, uiConnectionAttempts, uiConnectTimeoutMs ) );
48
+ m_calls.push_back ( new CRemoteCall ( szURL, fetchArguments, strPostData, bPostBinary, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs ) );
49
49
m_calls.back ()->MakeCall ();
50
50
}
51
51
@@ -86,9 +86,58 @@ bool CRemoteCalls::CallExists ( CRemoteCall * call )
86
86
return false ;
87
87
}
88
88
89
+ // Map quene index into download manager id
90
+ EDownloadModeType CRemoteCalls::GetDownloadModeFromQueueIndex ( uint uiIndex )
91
+ {
92
+ uiIndex %= ( EDownloadMode::CALL_REMOTE_LAST - EDownloadMode::CALL_REMOTE_FIRST );
93
+ uiIndex += EDownloadMode::CALL_REMOTE_FIRST;
94
+ return (EDownloadModeType)uiIndex;
95
+ }
96
+
97
+ // Map quene name to download manager id
98
+ EDownloadModeType CRemoteCalls::GetDownloadModeForQueueName ( const SString& strQueueName )
99
+ {
100
+ uint* pIndex = MapFind ( m_QueueIndexMap, strQueueName );
101
+ if ( pIndex )
102
+ {
103
+ return GetDownloadModeFromQueueIndex ( *pIndex );
104
+ }
105
+ else
106
+ {
107
+ // Find lowest unused index
108
+ uint idx = 0 ;
109
+ while ( MapContainsValue ( m_QueueIndexMap, idx ) )
110
+ {
111
+ idx++;
112
+ }
113
+ // Add new mapping
114
+ MapSet ( m_QueueIndexMap, strQueueName, idx );
115
+ return GetDownloadModeFromQueueIndex ( idx );
116
+ }
117
+ }
118
+
119
+
120
+ void CRemoteCalls::ProcessQueuedFiles ( void )
121
+ {
122
+ for ( auto iter = m_QueueIndexMap.cbegin (); iter != m_QueueIndexMap.cend (); )
123
+ {
124
+ EDownloadModeType downloadMode = GetDownloadModeFromQueueIndex ( iter->second );
125
+ if ( g_pNetServer->GetHTTPDownloadManager ( downloadMode )->ProcessQueuedFiles () )
126
+ {
127
+ // Queue empty, so remove name mapping if not default queue
128
+ if ( iter->first != CALL_REMOTE_DEFAULT_QUEUE_NAME )
129
+ {
130
+ iter = m_QueueIndexMap.erase ( iter );
131
+ continue ;
132
+ }
133
+ }
134
+ ++iter;
135
+ }
136
+ }
137
+
89
138
// //////////////////////////////////////////////////////////////////////////////
90
139
91
- CRemoteCall::CRemoteCall ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
140
+ CRemoteCall::CRemoteCall ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
92
141
{
93
142
m_VM = luaMain;
94
143
m_iFunction = iFunction;
@@ -98,12 +147,13 @@ CRemoteCall::CRemoteCall ( const char * szServerHost, const char * szResourceNam
98
147
m_bIsFetch = false ;
99
148
100
149
m_strURL = SString ( " http://%s/%s/call/%s" , szServerHost, szResourceName, szFunctionName );
150
+ m_strQueueName = strQueueName;
101
151
m_uiConnectionAttempts = uiConnectionAttempts;
102
152
m_uiConnectTimeoutMs = uiConnectTimeoutMs;
103
153
}
104
154
105
155
// arbitary URL version
106
- CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
156
+ CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
107
157
{
108
158
m_VM = luaMain;
109
159
m_iFunction = iFunction;
@@ -113,12 +163,13 @@ CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * arguments, CLuaMa
113
163
m_bIsFetch = false ;
114
164
115
165
m_strURL = szURL;
166
+ m_strQueueName = strQueueName;
116
167
m_uiConnectionAttempts = uiConnectionAttempts;
117
168
m_uiConnectTimeoutMs = uiConnectTimeoutMs;
118
169
}
119
170
120
171
// Fetch version
121
- CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
172
+ CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
122
173
: m_FetchArguments ( *fetchArguments )
123
174
{
124
175
m_VM = luaMain;
@@ -129,6 +180,7 @@ CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * fetchArguments, c
129
180
m_bIsFetch = true ;
130
181
131
182
m_strURL = szURL;
183
+ m_strQueueName = strQueueName;
132
184
m_uiConnectionAttempts = uiConnectionAttempts;
133
185
m_uiConnectTimeoutMs = uiConnectTimeoutMs;
134
186
}
@@ -140,7 +192,8 @@ CRemoteCall::~CRemoteCall ()
140
192
141
193
void CRemoteCall::MakeCall ()
142
194
{
143
- CNetHTTPDownloadManagerInterface * downloadManager = g_pNetServer->GetHTTPDownloadManager ( EDownloadMode::CALL_REMOTE );
195
+ EDownloadModeType downloadMode = g_pGame->GetRemoteCalls ()->GetDownloadModeForQueueName ( m_strQueueName );
196
+ CNetHTTPDownloadManagerInterface * downloadManager = g_pNetServer->GetHTTPDownloadManager ( downloadMode );
144
197
downloadManager->QueueFile ( m_strURL, NULL , 0 , m_strData.c_str (), m_strData.length (), m_bPostBinary, this , DownloadFinishedCallback, false , m_uiConnectionAttempts, m_uiConnectTimeoutMs );
145
198
}
146
199
0 commit comments