1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "chre/platform/platform_debug_dump_manager.h"
18
19 #include "chpp/platform/chpp_init.h"
20 #include "chre/core/event_loop_manager.h"
21 #include "chre/platform/log.h"
22 #include "chre/target_platform/host_link_base.h"
23 #include "chre/target_platform/platform_debug_dump_manager_base.h"
24
25 #include <cstring>
26
27 namespace chre {
28
sendDebugDump(const char * debugStr,bool complete)29 void PlatformDebugDumpManager::sendDebugDump(const char *debugStr,
30 bool complete) {
31 // DDM is guaranteed to call complete=true at the end of a debug dump session.
32 // However, sendDebugDumpResult may not get called with complete=true.
33 // Therefore, mDataCount has to be reset here instead of in
34 // sendDebugDumpResult(), to properly start the next debug dump session.
35 if (mComplete) {
36 mDataCount = 0;
37 }
38 mComplete = complete;
39
40 sendDebugDumpResult(debugStr, strlen(debugStr), complete);
41 }
42
logStateToBuffer(DebugDumpWrapper & debugDump)43 void PlatformDebugDumpManager::logStateToBuffer(DebugDumpWrapper &debugDump) {
44 chpp::logStateToBuffer(debugDump);
45 }
46
onDebugDumpRequested(uint16_t hostClientId)47 void PlatformDebugDumpManagerBase::onDebugDumpRequested(uint16_t hostClientId) {
48 mHostClientId = hostClientId;
49
50 EventLoopManagerSingleton::get()->getDebugDumpManager().trigger();
51 }
52
sendDebugDumpResult(const char * debugStr,size_t debugStrSize,bool complete)53 void PlatformDebugDumpManagerBase::sendDebugDumpResult(const char *debugStr,
54 size_t debugStrSize,
55 bool complete) {
56 if (debugStrSize > 0) {
57 mDataCount++;
58 }
59 sendDebugDumpResultToHost(mHostClientId, debugStr, debugStrSize, complete,
60 mDataCount);
61 }
62
63 } // namespace chre
64