| 116 | } |
| 117 | |
| 118 | void get_debug_message_log_impl(McContext context, |
| 119 | McUint32 count, McSize bufSize, |
| 120 | McDebugSource* sources, McDebugType* types, McDebugSeverity* severities, |
| 121 | McSize* lengths, McChar* messageLog, McUint32& numFetched) |
| 122 | { |
| 123 | MCUT_ASSERT(context != nullptr); |
| 124 | |
| 125 | std::shared_ptr<context_t> context_ptr = g_contexts.find_first_if([=](const std::shared_ptr<context_t> cptr) { return cptr->m_user_handle == context; }); |
| 126 | |
| 127 | if (context_ptr == nullptr) { |
| 128 | throw std::invalid_argument("invalid context"); |
| 129 | } |
| 130 | |
| 131 | numFetched = 0; |
| 132 | |
| 133 | if (messageLog == nullptr) { |
| 134 | context_ptr->dbg_cb(MC_DEBUG_SOURCE_API, MC_DEBUG_TYPE_OTHER, 0, MC_DEBUG_SEVERITY_NOTIFICATION, "output messageLog is NULL. Return."); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | McSize messageLogOffset = 0; |
| 139 | |
| 140 | const uint32_t N = std::min((uint32_t)count, (uint32_t)context_ptr->m_debug_logs.size()); |
| 141 | |
| 142 | // for internal message |
| 143 | for (numFetched = 0; numFetched < N; ++numFetched) { |
| 144 | |
| 145 | const context_t::debug_log_msg_t& cur_dbg_msg = context_ptr->m_debug_logs[numFetched]; |
| 146 | const McSize msg_length = (McSize)cur_dbg_msg.str.size(); |
| 147 | const McSize newLengthOfActualMessageLog = (messageLogOffset + msg_length); |
| 148 | |
| 149 | if (newLengthOfActualMessageLog > bufSize) { |
| 150 | break; // stop |
| 151 | } |
| 152 | |
| 153 | if (sources != nullptr) { |
| 154 | sources[numFetched] = cur_dbg_msg.source; |
| 155 | } |
| 156 | |
| 157 | if (types != nullptr) { |
| 158 | types[numFetched] = cur_dbg_msg.type; |
| 159 | } |
| 160 | |
| 161 | if (severities != nullptr) { |
| 162 | severities[numFetched] = cur_dbg_msg.severity; |
| 163 | } |
| 164 | |
| 165 | if (lengths != nullptr) { |
| 166 | lengths[numFetched] = msg_length; |
| 167 | } |
| 168 | |
| 169 | // copy into output array |
| 170 | memcpy(messageLog + messageLogOffset, cur_dbg_msg.str.data(), msg_length); |
| 171 | |
| 172 | messageLogOffset = newLengthOfActualMessageLog; |
| 173 | } |
| 174 | } |
| 175 |
no test coverage detected