/* * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HDI_PROXY_BROKER_H #define HDI_PROXY_BROKER_H #include #include #include namespace OHOS { namespace HDI { template class IProxyBroker : public OHOS::PeerHolder, public OHOS::IRemoteBroker, public INTERFACE { public: explicit IProxyBroker(const sptr &object); virtual ~IProxyBroker() = default; virtual sptr AsInterface(); sptr AsObject() override; }; template IProxyBroker::IProxyBroker(const sptr &object) : PeerHolder(object) { } template sptr IProxyBroker::AsInterface() { return this; } template sptr IProxyBroker::AsObject() { return Remote(); } template inline sptr hdi_facecast(const sptr &object) { const std::u16string descriptor = INTERFACE::GetDescriptor(); BrokerRegistration ®istration = BrokerRegistration::Get(); sptr broker = registration.NewInstance(descriptor, object); INTERFACE *proxyBroker = static_cast *>(broker.GetRefPtr()); return static_cast(proxyBroker); } template inline sptr hdi_objcast(const sptr &iface) { IProxyBroker *brokerObject = static_cast *>(iface.GetRefPtr()); return brokerObject->AsObject(); } } // namespace HDI } // namespace OHOS #endif // HDI_PROXY_BROKER_H