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_SLPI_PLATFORM_DEBUG_DUMP_MANAGER_BASE_H_
18 #define CHRE_PLATFORM_SLPI_PLATFORM_DEBUG_DUMP_MANAGER_BASE_H_
19 
20 #include <cstdbool>
21 #include <cstddef>
22 #include <cstdint>
23 
24 #ifdef CHRE_ENABLE_ASH_DEBUG_DUMP
25 #include "ash/debug.h"
26 #endif  // CHRE_ENABLE_ASH_DEBUG_DUMP
27 
28 namespace chre {
29 
30 /**
31  * SLPI-specific debug dump functionality.
32  */
33 class PlatformDebugDumpManagerBase {
34  public:
35   /**
36    * Constructor that registers to the underlying debug dump utility if
37    * available.
38    */
39   PlatformDebugDumpManagerBase();
40 
41   /**
42    * Destructor that unregisters to the underlying debug dump utility if
43    * available.
44    */
45   ~PlatformDebugDumpManagerBase();
46 
47   /**
48    * To be called when receiving a debug dump request from host.
49    *
50    * @param hostClientId The host client ID that requested the debug dump.
51    *
52    * @return true if successfully triggered the debug dump process.
53    */
54   bool onDebugDumpRequested(uint16_t hostClientId);
55 
56   /**
57    * @see PlatformDebugDumpManager::sendDebugDump
58    */
59   void sendDebugDumpResult(const char *debugStr, size_t debugStrSize,
60                            bool complete);
61 
62 #ifdef CHRE_ENABLE_ASH_DEBUG_DUMP
63   /**
64    * Set the ASH debug dump handle.
65    */
setHandle(uint32_t handle)66   void setHandle(uint32_t handle) {
67     mHandle = handle;
68   }
69 #endif  // CHRE_ENABLE_ASH_DEBUG_DUMP
70 
71  protected:
72   //! Host client ID that triggered the debug dump process.
73   uint16_t mHostClientId = 0;
74 
75   //! Number of times sendDebugDumpToHost called with debugStrSize > 0.
76   uint32_t mDataCount = 0;
77 
78   //! Whenther the last debug dump session has been marked complete.
79   bool mComplete = true;
80 
81 #ifdef CHRE_ENABLE_ASH_DEBUG_DUMP
82   //! Upper bound on the largest string size that can be provided in a single
83   //! call to sendDebugDump(), including NULL termination.
84   static constexpr size_t kDebugDumpStrMaxSize = ASH_DEBUG_DUMP_STR_MAX_SIZE;
85 
86   //! ASH debug dump handle.
87   uint32_t mHandle = 0;
88 #else   // CHRE_ENABLE_ASH_DEBUG_DUMP
89   static constexpr size_t kDebugDumpStrMaxSize = CHRE_MESSAGE_TO_HOST_MAX_SIZE;
90 #endif  // CHRE_ENABLE_ASH_DEBUG_DUMP
91 };
92 
93 }  // namespace chre
94 
95 #endif  // CHRE_PLATFORM_SLPI_PLATFORM_DEBUG_DUMP_MANAGER_BASE_H_
96