1/* 2 * Copyright (C) 2021 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 OHOS_DHCP_CLIENT_STUB_H 17#define OHOS_DHCP_CLIENT_STUB_H 18 19#include <map> 20#include <string_ex.h> 21#ifndef OHOS_ARCH_LITE 22#include "iremote_stub.h" 23#include <iremote_broker.h> 24#include "message_parcel.h" 25#include "message_option.h" 26#endif 27#include "i_dhcp_client.h" 28#include "dhcp_client_callback_stub.h" 29 30namespace OHOS { 31namespace DHCP { 32class DhcpClientStub : public IRemoteStub<IDhcpClient> { 33public: 34 using handleFunc = std::function<int(uint32_t &, MessageParcel &, MessageParcel &, MessageOption &)>; 35 using HandleFuncMap = std::map<int, handleFunc>; 36 using RemoteDeathMap = std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>; 37 DhcpClientStub(); 38 39 virtual ~DhcpClientStub(); 40 virtual int OnRemoteRequest( 41 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 42private: 43 void InitHandleMap(void); 44 int OnRegisterCallBack(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 45 int OnStartDhcpClient(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 46 int OnSetConfiguration(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 47 int OnStopDhcpClient(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 48#ifndef OHOS_ARCH_LITE 49public: 50 class ClientDeathRecipient : public IRemoteObject::DeathRecipient { 51 public: 52 explicit ClientDeathRecipient(DhcpClientStub &client) : client_(client) {} 53 ~ClientDeathRecipient() override = default; 54 virtual void OnRemoteDied(const wptr<IRemoteObject>& remote) override 55 { 56 client_.OnRemoteDied(remote); 57 } 58 private: 59 DhcpClientStub &client_; 60 }; 61 void OnRemoteDied(const wptr<IRemoteObject> &remoteObject); 62 void RemoveDeviceCbDeathRecipient(void); 63 void RemoveDeviceCbDeathRecipient(const wptr<IRemoteObject> &remoteObject); 64 65 RemoteDeathMap remoteDeathMap; 66 std::mutex mutex_; 67#endif 68private: 69 HandleFuncMap handleFuncMap; 70 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 71}; 72} // namespace DHCP 73} // namespace OHOS 74#endif