1 /* 2 * Copyright (C) 2023-2023 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: supply a helper to define some methods for stub object. 15 * Author: zhangge 16 * Create: 2022-06-15 17 */ 18 19 #ifndef CAST_STUB_HELPER_H 20 #define CAST_STUB_HELPER_H 21 22 #include <map> 23 #include "cast_engine_log.h" 24 #include "iremote_stub.h" 25 26 namespace OHOS { 27 namespace CastEngine { 28 #define DECLARE_STUB_TASK_MAP(className) \ 29 private: \ 30 using className##Func = int32_t (className::*)(MessageParcel &, MessageParcel &); \ 31 std::map<uint32_t, className##Func> taskMap_ 32 33 #define FILL_SINGLE_STUB_TASK(id, func) taskMap_[id] = (func) 34 35 #define RETURN_IF_WRONG_INTERFACE_TOKEN(data) \ 36 if (GetDescriptor() != (data).ReadInterfaceToken()) { \ 37 CLOGE("Invalid interface token"); \ 38 return ERR_FLATTEN_OBJECT; \ 39 } 40 41 #define RETRUEN_IF_WRONG_TASK(code, data, reply, option) \ 42 do { \ 43 RETURN_IF_WRONG_INTERFACE_TOKEN(data); \ 44 if (taskMap_.count(code) == 0) { \ 45 CLOGE("Invalid code:%d", code); \ 46 return IPCObjectStub::OnRemoteRequest(code, data, reply, option); \ 47 } \ 48 } while (0) 49 50 #define EXECUTE_SINGLE_STUB_TASK(code, data, reply) (this->*taskMap_[code])(data, reply) 51 } // namespace CastEngine 52 } // namespace OHOS 53 54 #endif 55