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 */ 15 16 #ifndef HIVIEW_BASE_EVENT_EXPORT_BASE_HANDLER_H 17 #define HIVIEW_BASE_EVENT_EXPORT_BASE_HANDLER_H 18 19 #include <memory> 20 #include <variant> 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 struct BaseRequest { 25 template <typename Derived> DownCastToBaseRequest26static std::shared_ptr<Derived> DownCastTo(std::shared_ptr<BaseRequest> request) 27 { 28 return std::static_pointer_cast<Derived>(request); 29 } 30 }; 31 using RequestPtr = std::shared_ptr<BaseRequest>; 32 33 class ExportBaseHandler { 34 public: 35 ExportBaseHandler() = default; 36 virtual ~ExportBaseHandler() = default; 37 38 public: 39 virtual bool HandleRequest(RequestPtr request) = 0; SetNextHandler(std::shared_ptr<ExportBaseHandler> nextHandler)40 void SetNextHandler(std::shared_ptr<ExportBaseHandler> nextHandler) 41 { 42 nextHandler_ = nextHandler; 43 } 44 45 protected: 46 std::shared_ptr<ExportBaseHandler> nextHandler_; 47 }; 48 } // namespace HiviewDFX 49 } // namespace OHOS 50 51 #endif // HIVIEW_BASE_EVENT_EXPORT_BASE_HANDLER_H