xref: /aosp_15_r20/system/chre/core/include/chre/core/ble_request_multiplexer.h (revision 84e339476a462649f82315436d70fd732297a399)
1 /*
2  * Copyright (C) 2022 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_BLE_REQUEST_MULTIPLEXER_H_
18 #define CHRE_CORE_BLE_REQUEST_MULTIPLEXER_H_
19 
20 #include "chre/core/ble_request.h"
21 #include "chre/core/request_multiplexer.h"
22 
23 namespace chre {
24 
25 /**
26  * Synchronous callback used in forEachRequest.
27  */
28 typedef void(RequestCallbackFunction)(BleRequest &req, void *data);
29 
30 /**
31  * Provides methods on top of the RequestMultiplexer class specific for working
32  * with BleRequest objects.
33  */
34 class BleRequestMultiplexer : public RequestMultiplexer<BleRequest> {
35  public:
36   /**
37    * Returns the list of current requests in the multiplexer.
38    *
39    * NOTE: Mutating these requests in a way that would change the underlying
40    * maximal request isn't supported and will cause problems.
41    */
42   DynamicVector<BleRequest> &getMutableRequests();
43 
44   /**
45    * Searches through the list of BLE requests for a request owned by the
46    * given nanoapp. The provided index pointer is populated with the
47    * index of the request if it is found and the pointer is not null.
48    *
49    * @param instanceId The instance ID of the nanoapp whose request is being
50    *        searched for.
51    * @param index A pointer to an index that is populated if a
52    *        request for this nanoapp is found.
53    * @return A pointer to a BleRequest that is owned by the provided
54    *         nanoapp if one is found otherwise nullptr.
55    */
56   const BleRequest *findRequest(uint16_t instanceId, size_t *index);
57 
58   /**
59    * @param status Status type to check if any requests have
60    * @return True if any requests with the provided status are in the
61    *         multiplexer.
62    */
63   bool hasRequests(RequestStatus status) const;
64 
65   /**
66    * Removes all requests of a particular status type from the multiplexer.
67    *
68    * @param status Status type that should be removed from the request queue.
69    */
70   void removeRequests(RequestStatus status);
71 
72   /**
73    * Removes all disabled requests from the multiplexer.
74    */
75   void removeDisabledRequests();
76 
77   /**
78    * @return true if current maximal request is enabled.
79    */
80   bool isMaximalRequestEnabled();
81 };
82 
83 }  // namespace chre
84 
85 #endif  // CHRE_CORE_BLE_REQUEST_MULTIPLEXER_H_
86