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 #ifndef OHOS_INTER_IPC_MESSAGE_BIND_MARCROS_H 17 #define OHOS_INTER_IPC_MESSAGE_BIND_MARCROS_H 18 #include "common/sharing_log.h" 19 namespace OHOS { 20 namespace Sharing { 21 22 #define BEGIN_IPC_MESSAGE_ENCODE_BIND \ 23 virtual int32_t OnIpcMessage(const int32_t nMsgType, MessageParcel &ipcMsg, std::shared_ptr<BaseMsg> &sharingMsg) \ 24 { \ 25 switch (nMsgType) { 26 #define IPC_MESSAGE_ENCODE_BIND(SERVICE_TYPE, MESSAGE_TYPE) \ 27 case MESSAGE_TYPE: { \ 28 auto message = static_pointer_cast<SERVICE_TYPE>(sharingMsg); \ 29 if (message) { \ 30 message->IpcSerialize(ipcMsg); \ 31 } else { \ 32 SHARING_LOGE("encode error, message type: %{public}d.", MESSAGE_TYPE); \ 33 } \ 34 break; \ 35 } 36 37 #define END_IPC_MESSAGE_ENCODE_BIND \ 38 default: { \ 39 SHARING_LOGE("cann't process, may be message type error, message type: %{public}d.", nMsgType); \ 40 break; \ 41 } \ 42 } \ 43 return 0; \ 44 } 45 46 #define BEGIN_IPC_MESSAGE_DECODE_BIND \ 47 virtual int32_t OnIpcMessage(const int32_t nMsgType, std::shared_ptr<BaseMsg> &sharingMsg, MessageParcel &ipcMsg) \ 48 { \ 49 switch (nMsgType) { 50 #define IPC_MESSAGE_DECODE_BIND(SERVICE_TYPE, MESSAGE_TYPE) \ 51 case MESSAGE_TYPE: { \ 52 auto message = std::make_shared<SERVICE_TYPE>(); \ 53 if (0 == message->IpcDeserialize(ipcMsg)) { \ 54 sharingMsg = std::move(message); \ 55 return 0; \ 56 } else { \ 57 SHARING_LOGE("decode error, message type: %{public}d.", MESSAGE_TYPE); \ 58 } \ 59 break; \ 60 } 61 62 #define END_IPC_MESSAGE_DECODE_BIND \ 63 default: { \ 64 SHARING_LOGE("cann't process, may be message type error, message type: %{public}d.", nMsgType); \ 65 break; \ 66 } \ 67 } \ 68 return 0; \ 69 } 70 71 } // namespace Sharing 72 } // namespace OHOS 73 74 #endif 75