1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef ST_AUDIO_SOCKET_THREAD_H 16 #define ST_AUDIO_SOCKET_THREAD_H 17 18 #include <memory> 19 #include <string> 20 21 #include "hdf_device_desc.h" 22 #include "hdf_types.h" 23 #include "v5_0/audio_types.h" 24 #include "audio_pnp_param.h" 25 26 namespace OHOS { 27 namespace AudioStandard { 28 using namespace std; 29 30 class AudioSocketThread { 31 public: 32 static bool IsUpdatePnpDeviceState(AudioEvent *pnpDeviceEvent); 33 static void UpdatePnpDeviceState(AudioEvent *pnpDeviceEvent); 34 static int AudioPnpUeventOpen(int *fd); 35 static ssize_t AudioPnpReadUeventMsg(int sockFd, char *buffer, size_t length); 36 static bool AudioPnpUeventParse(const char *msg, const ssize_t strLength); 37 static void UpdateDeviceState(AudioEvent audioEvent); 38 static int32_t DetectAnalogHeadsetState(AudioEvent *audioEvent); 39 static int32_t DetectDPState(AudioEvent *audioEvent); 40 static void SetAudioPnpUevent(AudioEvent *audioEvent, char switchState); 41 static AudioEvent audioSocketEvent_; 42 43 private: 44 static int32_t SetAudioPnpServerEventValue(AudioEvent *audioEvent, struct AudioPnpUevent *audioPnpUevent); 45 static int32_t AudioAnalogHeadsetDetectDevice(struct AudioPnpUevent *audioPnpUevent); 46 static int32_t AudioDpDetectDevice(struct AudioPnpUevent *audioPnpUevent); 47 static int32_t AudioAnahsDetectDevice(struct AudioPnpUevent *audioPnpUevent); 48 static int32_t AudioHDMIDetectDevice(struct AudioPnpUevent *audioPnpUevent); 49 static int32_t SetAudioAnahsEventValue(AudioEvent *audioEvent, struct AudioPnpUevent *audioPnpUevent); 50 static int32_t ReadAndScanDpState(const std::string &path, uint32_t &eventType); 51 static int32_t ReadAndScanDpName(const std::string &path, std::string &name); 52 static int32_t AudioNnDetectDevice(struct AudioPnpUevent *audioPnpUevent); 53 static int32_t AudioMicBlockDevice(struct AudioPnpUevent *audioPnpUevent); 54 }; 55 56 } // namespace AudioStandard 57 } // namespace OHOS 58 #endif // ST_AUDIO_SOCKET_THREAD_H