1 /*
2 * Copyright (c) 2024 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 * Description: message definition
15 * Author: lijianzhao
16 * Create: 2022-01-19
17 */
18
19 #include "message.h"
20 #include <chrono>
21
22 namespace OHOS {
23 namespace CastEngine {
24 namespace CastEngineService {
Message()25 Message::Message() : Message(0, 0, 0, 0) {}
26
Message(int what)27 Message::Message(int what) : Message(what, 0, 0, 0) {}
28
Message(int what,std::string strArg)29 Message::Message(int what, std::string strArg) : Message(what, 0, 0, 0, strArg) {}
30
Message(int what,int arg1)31 Message::Message(int what, int arg1) : Message(what, arg1, 0, 0) {}
32
Message(int what,int arg1,int arg2)33 Message::Message(int what, int arg1, int arg2) : Message(what, arg1, arg2, 0) {}
34
Message(int what,int arg1,std::string strArg)35 Message::Message(int what, int arg1, std::string strArg) : Message(what, arg1, 0, 0, strArg) {}
36
Message(int what,int arg1,int arg2,long uptimeMillis)37 Message::Message(int what, int arg1, int arg2, long uptimeMillis) : Message(what, arg1, arg2, uptimeMillis, "") {}
38
Message(int what,int arg1,int arg2,long uptimeMillis,std::string strArg)39 Message::Message(int what, int arg1, int arg2, long uptimeMillis, std::string strArg)
40 : what_(what), arg1_(arg1), arg2_(arg2), strArg_(strArg)
41 {
42 when_ = std::chrono::system_clock::now() + std::chrono::milliseconds(uptimeMillis);
43 task_ = nullptr;
44 ptrArg_ = -1;
45 }
46
SetWhen(long uptimeMillis)47 void Message::SetWhen(long uptimeMillis)
48 {
49 when_ = std::chrono::system_clock::now() + std::chrono::milliseconds(uptimeMillis);
50 }
51
SetFunction(Function func)52 void Message::SetFunction(Function func)
53 {
54 this->task_ = func;
55 }
56
SetPtrArg(intptr_t arg)57 void Message::SetPtrArg(intptr_t arg)
58 {
59 ptrArg_ = arg;
60 }
61
SetStrArg(std::string strArg)62 void Message::SetStrArg(std::string strArg)
63 {
64 this->strArg_ = strArg;
65 }
66
operator =(const Message & msg)67 Message &Message::operator=(const Message &msg)
68 {
69 this->arg1_ = msg.arg1_;
70 this->arg2_ = msg.arg2_;
71 this->what_ = msg.what_;
72 this->when_ = msg.when_;
73 this->task_ = msg.task_;
74 this->ptrArg_ = msg.ptrArg_;
75 this->strArg_ = msg.strArg_;
76 this->eventCode_ = msg.eventCode_;
77 return *this;
78 }
79
Message(const Message & msg)80 Message::Message(const Message &msg)
81 {
82 this->arg1_ = msg.arg1_;
83 this->arg2_ = msg.arg2_;
84 this->what_ = msg.what_;
85 this->when_ = msg.when_;
86 this->task_ = msg.task_;
87 this->ptrArg_ = msg.ptrArg_;
88 this->strArg_ = msg.strArg_;
89 this->eventCode_ = msg.eventCode_;
90 }
91 } // namespace CastEngineService
92 } // namespace CastEngine
93 } // namespace OHOS