1 /*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 "ipc_msg_encoder.h"
17 #include "sharing_log.h"
18
19 namespace OHOS {
20 namespace Sharing {
21
MsgEncode(MessageParcel &ipcMsg, std::shared_ptr<BaseMsg> &sharingMsg)22 int32_t IpcMsgEncoder::MsgEncode(MessageParcel &ipcMsg, std::shared_ptr<BaseMsg> &sharingMsg)
23 {
24 SHARING_LOGD("trace.");
25 int32_t nMsgType = sharingMsg->GetMsgId();
26 ipcMsg.WriteInt32(nMsgType);
27
28 return this->OnIpcMessage(nMsgType, ipcMsg, sharingMsg);
29 }
30
DomainMsgEncode(MessageParcel &ipcMsg, std::shared_ptr<BaseDomainMsg> &sharingMsg)31 int32_t IpcMsgEncoder::DomainMsgEncode(MessageParcel &ipcMsg, std::shared_ptr<BaseDomainMsg> &sharingMsg)
32 {
33 SHARING_LOGD("trace.");
34 auto msg = std::static_pointer_cast<BaseMsg>(sharingMsg);
35 int32_t ret = MsgEncode(ipcMsg, msg);
36 if (ret != 0) {
37 SHARING_LOGE("MsgEncode domain msg failed.");
38 return ret;
39 }
40
41 return 0;
42 }
43
44 } // namespace Sharing
45 } // namespace OHOS