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 #ifndef CHRE_PLATFORM_PLATFORM_DEBUG_DUMP_MANAGER_H_
18 #define CHRE_PLATFORM_PLATFORM_DEBUG_DUMP_MANAGER_H_
19 
20 #include <cstdbool>
21 #include <cstddef>
22 
23 #include "chre/target_platform/platform_debug_dump_manager_base.h"
24 #include "chre/util/non_copyable.h"
25 #include "chre/util/system/debug_dump.h"
26 #include "chre_api/chre/re.h"
27 
28 namespace chre {
29 
30 /**
31  * The common interface to debug dump functionality that has platform-specific
32  * implementation but must be supported for every platform.
33  */
34 class PlatformDebugDumpManager : public PlatformDebugDumpManagerBase,
35                                  public NonCopyable {
36  public:
37   /**
38    * Adds an ASCII string to appear in the debug dump and sends it to the host.
39    *
40    * Strings longer than kDebugDumpStrMaxSize will be truncated.
41    *
42    * @param debugStr A null-terminated string containing debug data. Must be a
43    *        valid pointer, but can be an empty string.
44    * @param complete true if no more debug data is expected.
45    */
46   void sendDebugDump(const char *debugStr, bool complete);
47 
48   /**
49    * A function to log platform-specific debug dumps. Must only be called from
50    * the context of the main CHRE thread.
51    *
52    * @param debugDump Reference to the debug dump wrapper to print logs.
53    */
54   void logStateToBuffer(DebugDumpWrapper &debugDump);
55 
56  private:
57   //! kDebugDumpStrMaxSize must be provided by PlatformDebugDumpManagerBase.
58   //!
59   //! It sets an upper bound on the largest string size that can be provided in
60   //! a single call to sendDebugDump(), including null termination, without
61   //! getting truncated.
62   static_assert(kDebugDumpStrMaxSize >= CHRE_DEBUG_DUMP_MINIMUM_MAX_SIZE,
63                 "kDebugDumpStrMaxSize must be >="
64                 " CHRE_DEBUG_DUMP_MINIMUM_MAX_SIZE");
65 };
66 
67 }  // namespace chre
68 
69 #endif  // CHRE_PLATFORM_PLATFORM_DEBUG_DUMP_MANAGER_H_
70