15e81a82fSopenharmony_ci/* 25e81a82fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 35e81a82fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45e81a82fSopenharmony_ci * you may not use this file except in compliance with the License. 55e81a82fSopenharmony_ci * You may obtain a copy of the License at 65e81a82fSopenharmony_ci * 75e81a82fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85e81a82fSopenharmony_ci * 95e81a82fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105e81a82fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115e81a82fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125e81a82fSopenharmony_ci * See the License for the specific language governing permissions and 135e81a82fSopenharmony_ci * limitations under the License. 145e81a82fSopenharmony_ci * Description: message definition 155e81a82fSopenharmony_ci * Author: lijianzhao 165e81a82fSopenharmony_ci * Create: 2022-01-19 175e81a82fSopenharmony_ci */ 185e81a82fSopenharmony_ci 195e81a82fSopenharmony_ci#ifndef MESSAGE_H 205e81a82fSopenharmony_ci#define MESSAGE_H 215e81a82fSopenharmony_ci 225e81a82fSopenharmony_ci#include <chrono> 235e81a82fSopenharmony_ci#include <functional> 245e81a82fSopenharmony_ci#include <string> 255e81a82fSopenharmony_ci 265e81a82fSopenharmony_ci#include "cast_engine_common.h" 275e81a82fSopenharmony_ci 285e81a82fSopenharmony_cinamespace OHOS { 295e81a82fSopenharmony_cinamespace CastEngine { 305e81a82fSopenharmony_cinamespace CastEngineService { 315e81a82fSopenharmony_ciclass Message { 325e81a82fSopenharmony_cipublic: 335e81a82fSopenharmony_ci int what_; 345e81a82fSopenharmony_ci int arg1_{ 0 }; 355e81a82fSopenharmony_ci int arg2_{ 0 }; 365e81a82fSopenharmony_ci EventCode eventCode_{ EventCode::DEFAULT_EVENT }; 375e81a82fSopenharmony_ci 385e81a82fSopenharmony_ci using Function = std::function<void()>; 395e81a82fSopenharmony_ci Function task_ = nullptr; 405e81a82fSopenharmony_ci 415e81a82fSopenharmony_ci std::chrono::system_clock::time_point when_; 425e81a82fSopenharmony_ci 435e81a82fSopenharmony_ci // 用于保存指针类型数据 445e81a82fSopenharmony_ci intptr_t ptrArg_ = -1; 455e81a82fSopenharmony_ci 465e81a82fSopenharmony_ci std::string strArg_; 475e81a82fSopenharmony_ci 485e81a82fSopenharmony_cipublic: 495e81a82fSopenharmony_ci Message(); 505e81a82fSopenharmony_ci Message(const Message &msg); 515e81a82fSopenharmony_ci Message &operator=(const Message &msg); 525e81a82fSopenharmony_ci explicit Message(int what); 535e81a82fSopenharmony_ci Message(int what, std::string strArg); 545e81a82fSopenharmony_ci Message(int what, std::string deviceId, EventCode eventCode) : what_(what), 555e81a82fSopenharmony_ci eventCode_(eventCode), strArg_(deviceId) {} 565e81a82fSopenharmony_ci Message(int what, int arg1); 575e81a82fSopenharmony_ci Message(int what, int arg1, int arg2); 585e81a82fSopenharmony_ci Message(int what, int arg1, int arg2, long uptimeMillis); 595e81a82fSopenharmony_ci Message(int what, int arg1, int arg2, long uptimeMillis, std::string strArg); 605e81a82fSopenharmony_ci Message(int what, int arg1, std::string strArg); 615e81a82fSopenharmony_ci virtual ~Message() = default; 625e81a82fSopenharmony_ci 635e81a82fSopenharmony_ci void SetWhen(long uptimeMillis); 645e81a82fSopenharmony_ci void SetFunction(Function func); 655e81a82fSopenharmony_ci void SetPtrArg(intptr_t arg); 665e81a82fSopenharmony_ci void SetStrArg(std::string strArg); 675e81a82fSopenharmony_ci 685e81a82fSopenharmony_ci bool operator>(const Message &msg) const 695e81a82fSopenharmony_ci { 705e81a82fSopenharmony_ci return (this->when_ > msg.when_); 715e81a82fSopenharmony_ci } 725e81a82fSopenharmony_ci 735e81a82fSopenharmony_ci bool operator<(const Message &msg) const 745e81a82fSopenharmony_ci { 755e81a82fSopenharmony_ci return (this->when_ < msg.when_); 765e81a82fSopenharmony_ci } 775e81a82fSopenharmony_ci 785e81a82fSopenharmony_ci bool operator==(const Message &msg) const 795e81a82fSopenharmony_ci { 805e81a82fSopenharmony_ci return (this->what_ == msg.what_) && (this->task_ != nullptr) && (msg.task_ != nullptr); 815e81a82fSopenharmony_ci } 825e81a82fSopenharmony_ci 835e81a82fSopenharmony_ci bool operator==(int what) const 845e81a82fSopenharmony_ci { 855e81a82fSopenharmony_ci return (this->what_ == what); 865e81a82fSopenharmony_ci } 875e81a82fSopenharmony_ci}; 885e81a82fSopenharmony_ci} // namespace CastEngineService 895e81a82fSopenharmony_ci} // namespace CastEngine 905e81a82fSopenharmony_ci} // namespace OHOS 915e81a82fSopenharmony_ci 925e81a82fSopenharmony_ci#endif