• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 
16 #include "message.h"
17 
18 namespace OHOS {
19 namespace MiscServices {
20     /*! Constructor
21     \param msgId a message Id
22     \param msgContent the content of a message
23     */
Message(int32_t msgId,MessageParcel * msgContent)24     Message::Message(int32_t msgId, MessageParcel *msgContent)
25     {
26         msgId_ = msgId;
27         msgContent_ = msgContent;
28         if (msgContent_) {
29             msgContent_->RewindRead(0);
30         }
31     }
32 
33     /*! Constructor
34     \param msg a source message
35     */
Message(const Message & msg)36     Message::Message(const Message& msg)
37     {
38         msgId_ = msg.msgId_;
39         if (msgContent_) {
40             delete msgContent_;
41             msgContent_ = nullptr;
42         }
43         MessageParcel *src = msg.msgContent_;
44         if (src) {
45             msgContent_ = new MessageParcel();
46             msgContent_->ParseFrom(src->GetData(), src->GetDataSize());
47         }
48     }
49 
operator =(const Message & msg)50     Message& Message::operator =(const Message& msg)
51     {
52         if (this == &msg) {
53             return *this;
54         }
55         msgId_ = msg.msgId_;
56         if (msgContent_) {
57             delete msgContent_;
58             msgContent_ = nullptr;
59         }
60         if (msg.msgContent_) {
61             msgContent_ = new MessageParcel();
62             msgContent_->ParseFrom(msg.msgContent_->GetData(), msg.msgContent_->GetDataSize());
63             msgContent_->RewindRead(0);
64         }
65         return *this;
66     }
67 
~Message()68     Message::~Message()
69     {
70         if (msgContent_) {
71             delete msgContent_;
72             msgContent_ = nullptr;
73         }
74     }
75 } // namespace MiscServices
76 } // namespace OHOS
77