///////////////////////////////////////////////////////////////////// Starts asynchronous read from the specified file MT: Main thread only
| 109 | // Starts asynchronous read from the specified file |
| 110 | // MT: Main thread only |
| 111 | IReadStream_AutoPtr CRefStreamEngine::StartRead (const char* szSource, const char* szFilePathPC, IStreamCallback* pCallback, StreamReadParams* pParams) |
| 112 | { |
| 113 | unsigned nFlags = 0; |
| 114 | if (pParams) |
| 115 | nFlags = pParams->nFlags; |
| 116 | |
| 117 | m_pPak->RecordFile( szFilePathPC ); |
| 118 | |
| 119 | // get rid of some jobs if there are too many in the queue |
| 120 | if (!(nFlags & SRP_QUICK_STARTREAD)) |
| 121 | while (numIOJobs(eWaiting) >= m_nMaxQueueLength) |
| 122 | { |
| 123 | m_pLog->LogWarning("StreamEngine: The number of jobs waiting %d >= max queue length %d, waiting to free up the queue", numIOJobs(eWaiting), m_nMaxQueueLength); |
| 124 | UpdateAndWait(20, FLAGS_DISABLE_CALLBACK_TIME_QUOTA); |
| 125 | } |
| 126 | |
| 127 | char szFilePathBuf[CCryPak::g_nMaxPath]; |
| 128 | const char* szFilePath = m_pPak->AdjustFileName (szFilePathPC, szFilePathBuf, pParams && (pParams->nFlags & SRP_FLAGS_PATH_REAL) ? ICryPak::FLAGS_PATH_REAL: 0); |
| 129 | |
| 130 | // first try to find such file; if it's already pending, add a client to it only |
| 131 | CRefReadStream_AutoPtr pStream; |
| 132 | NameStreamMap::iterator it = m_mapFilesByName.find (szFilePath); |
| 133 | |
| 134 | if (it == m_mapFilesByName.end()) |
| 135 | { |
| 136 | pStream = new CRefReadStream (szFilePath, this); |
| 137 | } |
| 138 | else |
| 139 | pStream = it->second; |
| 140 | |
| 141 | // make sure that the permanent streams get locked in memory; |
| 142 | // if it's already locked, insert() won't do anything |
| 143 | if (nFlags & SRP_FLAGS_MAKE_PERMANENT) |
| 144 | m_setLockedStreams.insert (pStream); |
| 145 | else |
| 146 | if (nFlags & SRP_FLAGS_MAKE_TRANSIENT) |
| 147 | m_setLockedStreams.erase (pStream); |
| 148 | |
| 149 | // at this moment the stream should self-register in this engine and the stream sets should get initialized |
| 150 | CRefReadStreamProxy_AutoPtr pProxy = new CRefReadStreamProxy(szSource, pStream, pCallback, pParams); |
| 151 | |
| 152 | // register the proxy |
| 153 | AddIOJob (pProxy); |
| 154 | |
| 155 | if (!(nFlags & SRP_QUICK_STARTREAD)) |
| 156 | Update(0); |
| 157 | |
| 158 | return (IReadStream*)pProxy; |
| 159 | } |
| 160 | |
| 161 | // signals that this proxy needs to be executed (StartRead called) |
| 162 | void CRefStreamEngine::AddIOJob (CRefReadStreamProxy* pJobProxy) |
no test coverage detected