1 /* 2 * Copyright (C) 2021 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_HOST_ENDPOINT_MANAGER_H_ 18 #define CHRE_CORE_HOST_ENDPOINT_MANAGER_H_ 19 20 #include <cinttypes> 21 22 #include "chre/util/system/debug_dump.h" 23 #include "chre_api/chre/event.h" 24 25 namespace chre { 26 27 /** 28 * Connected host endpoint metadata, which should only be accessed by the 29 * main CHRE event loop. 30 */ 31 class HostEndpointManager : public NonCopyable { 32 public: 33 /** 34 * Updates host endpoint connection to CHRE. 35 * 36 * @param info Metadata about the host endpoint that connected. 37 */ 38 void postHostEndpointConnected(const struct chreHostEndpointInfo &info); 39 40 /** 41 * Updates host endpoint disconnection to CHRE. 42 * 43 * @param hostEndpointId The host endpoint ID. 44 */ 45 void postHostEndpointDisconnected(uint16_t hostEndpointId); 46 47 /** 48 * Gets the Host endpoint information if it has been connected. 49 * 50 * @param hostEndpointId The host endpoint ID. 51 * @param info Where the retrieved info will be stored. 52 * @return true if the id is connected. 53 * @return false if the id is not connected. 54 */ 55 bool getHostEndpointInfo(uint16_t hostEndpointId, 56 struct chreHostEndpointInfo *info); 57 58 private: 59 /** 60 * Stores host endpoint information if it is connected. 61 */ 62 chre::DynamicVector<struct chreHostEndpointInfo> mHostEndpoints = 63 chre::DynamicVector<struct chreHostEndpointInfo>(); 64 65 /** 66 * Returns the index of where the endpoint id is stored 67 * 68 * @param hostEndpointId The host endpoint ID. 69 * @param index Where the retrieved index will be returned. 70 * @return true if the id is connected. 71 * @return false if the id is not connected. 72 */ 73 bool isHostEndpointConnected(uint16_t hostEndpointId, size_t *index); 74 75 /** 76 * Callback function used in event loop to connect or disconnect the host 77 * endpoint. 78 * 79 * @param type Type if system callback type, needs to be 80 * HostEndpointDisconnected or HostEndpointConnected 81 * @param data Arbitrary data to provide to the callback 82 * @param extraData Additional arbitrary data to provide to the callback 83 */ 84 void hostNotificationCallback(uint16_t type, void *data, void *extraData); 85 86 /** 87 * Get the hostNotificationCallback of the HostEndpointManager in 88 * EventLoopManager 89 */ 90 auto getHostNotificationCallback(); 91 }; 92 93 } // namespace chre 94 95 #endif // CHRE_CORE_HOST_ENDPOINT_MANAGER_H_ 96