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 MSG_HANDLE_THREAD_H 16 #define MSG_HANDLE_THREAD_H 17 18 #include <string> 19 #include "message_queue.h" 20 #include "base_thread.h" 21 22 namespace OHOS { 23 namespace IntellVoiceUtils { 24 class MsgHandleThread : public BaseThread { 25 public: 26 MsgHandleThread(); 27 // for compatible with wakeup engine 28 explicit MsgHandleThread(std::shared_ptr<MessageQueue> callbackMsgQue); 29 explicit MsgHandleThread(MsgHandleThread *callbackThread); 30 ~MsgHandleThread() override; 31 bool SendMsg(Message msg); 32 bool SendMsg(std::shared_ptr<Message> msg); 33 bool SendSynMsg(std::shared_ptr<Message> msg); 34 void SetCallbackThread(MsgHandleThread *tmpCallbackThread); 35 36 protected: 37 // subclass should override this function most time 38 virtual bool HandleMsg(Message &msg); 39 virtual void SendbackMsg(Message msg); 40 41 private: 42 void Run() override; 43 44 std::shared_ptr<MessageQueue> callbackMsgQue_ = nullptr; 45 MessageQueue msgQue_; 46 MsgHandleThread *callbackThread_; 47 }; 48 } 49 } 50 #endif 51