1 /* 2 * Copyright (C) 2017 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_CORE_WWAN_REQUEST_MANAGER_H_ 18 #define CHRE_CORE_WWAN_REQUEST_MANAGER_H_ 19 20 #ifdef CHRE_WWAN_SUPPORT_ENABLED 21 22 #include <cstdint> 23 24 #include "chre/core/api_manager_common.h" 25 #include "chre/core/nanoapp.h" 26 #include "chre/platform/platform_wwan.h" 27 #include "chre/util/non_copyable.h" 28 #include "chre/util/optional.h" 29 #include "chre/util/system/debug_dump.h" 30 31 namespace chre { 32 33 /** 34 * The WwanRequestManager handles requests from nanoapps for WWAN data. This 35 * includes multiplexing multiple requests into one for the platform to handle. 36 * 37 * This class is effectively a singleton as there can only be one instance of 38 * the PlatformWwan instance. 39 */ 40 class WwanRequestManager : public NonCopyable { 41 public: 42 /** 43 * Initializes the underlying platform-specific WWAN module. Must be called 44 * prior to invoking any other methods in this class. 45 */ 46 void init(); 47 48 /** 49 * @return the WWAN capabilities exposed by this platform. 50 */ 51 uint32_t getCapabilities(); 52 53 /** 54 * Performs a request for cell neighbor info for the given nanoapp. 55 * 56 * @param nanoapp The nanoapp requesting the cell info. 57 * @param cookie A cookie provided by the nanoapp to supply context in the 58 * asynchronous result event. 59 * @return true if the request was accepted. 60 */ 61 bool requestCellInfo(Nanoapp *nanoapp, const void *cookie); 62 63 /** 64 * Handles the result of a cell info request. 65 * 66 * @param result the results of a cell info request. 67 */ 68 void handleCellInfoResult(chreWwanCellInfoResult *result); 69 70 /** 71 * Prints state in a string buffer. Must only be called from the context of 72 * the main CHRE thread. 73 * 74 * @param debugDump The debug dump wrapper where a string can be printed 75 * into one of the buffers. 76 */ 77 void logStateToBuffer(DebugDumpWrapper &debugDump) const; 78 79 private: 80 //! The instance of the platform WWAN interface. 81 PlatformWwan mPlatformWwan; 82 83 // TODO: Support multiple requests for cell info by enqueuing them and 84 // requesting one after another. 85 //! The nanoapp that is currently requesting cell info. At this time only one 86 //! nanoapp can have a pending request for cell info. 87 Optional<uint16_t> mCellInfoRequestingNanoappInstanceId; 88 89 //! The cookie passed in by a nanoapp making a request for cell info. Note 90 //! that this will only be valid if the mCellInfoRequestingNanoappInstanceId 91 //! is set. 92 const void *mCellInfoRequestingNanoappCookie; 93 94 //! ErrorCode Histogram for collected errors, the index of this array 95 //! corresponds to the type of the errorcode 96 uint32_t mCellInfoErrorHistogram[CHRE_ERROR_SIZE] = {0}; 97 98 /** 99 * Handles the result of a request for cell info. See handleCellInfoResult 100 * which may be called from any thread. This thread is intended to be invoked 101 * on the CHRE event loop thread. 102 * 103 * @param result the result of the request for cell info. 104 */ 105 void handleCellInfoResultSync(chreWwanCellInfoResult *result); 106 107 /** 108 * Handles the releasing of a WWAN cell info result and unsubscribes the 109 * nanoapp who made the request for cell info from cell info events. 110 * 111 * @param result The cell info result to release. 112 */ 113 void handleFreeCellInfoResult(chreWwanCellInfoResult *result); 114 115 /** 116 * Releases a cell info result after nanoapps have consumed it. 117 * 118 * @param eventType the type of event being freed. 119 * @param eventData a pointer to the scan event to release. 120 */ 121 static void freeCellInfoResultCallback(uint16_t eventType, void *eventData); 122 }; 123 124 } // namespace chre 125 126 #endif // CHRE_WWAN_SUPPORT_ENABLED 127 128 #endif // CHRE_CORE_WWAN_REQUEST_MANAGER_H_ 129