/* * 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 OHOS_DM_IPC_SERVER_STUB_H #define OHOS_DM_IPC_SERVER_STUB_H #include #include #include #include #include #include #include "ipc_remote_broker.h" #include "ipc_req.h" #include "ipc_rsp.h" #include "iremote_stub.h" #include "dm_single_instance.h" #include "system_ability.h" namespace OHOS { namespace DistributedHardware { enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; class AppDeathRecipient : public IRemoteObject::DeathRecipient { public: /** * @tc.name: AppDeathRecipient::OnRemoteDied * @tc.desc: OnRemoteDied function of the App DeathRecipient * @tc.type: FUNC */ void OnRemoteDied(const wptr &remote) override; AppDeathRecipient() = default; ~AppDeathRecipient() override = default; }; class IpcServerStub : public SystemAbility, public IRemoteStub { DECLARE_SYSTEM_ABILITY(IpcServerStub); DM_DECLARE_SINGLE_INSTANCE_BASE(IpcServerStub); public: /** * @tc.name: IpcServerStub::OnStart * @tc.desc: OnStart of the IpcServerStub * @tc.type: FUNC */ void OnStart() override; /** * @tc.name: IpcServerStub::OnStop * @tc.desc: OnStop of the IpcServerStub * @tc.type: FUNC */ void OnStop() override; /** * @tc.name: IpcServerStub::OnRemoteRequest * @tc.desc: On Remote Request of the IpcServerStub * @tc.type: FUNC */ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; /** * @tc.name: IpcServerStub::SendCmd * @tc.desc: Send Cmd of the IpcServerStub * @tc.type: FUNC */ int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; /** * @tc.name: IpcServerStub::RegisterDeviceManagerListener * @tc.desc: Register DeviceManager Listener of the IpcServerStub * @tc.type: FUNC */ int32_t RegisterDeviceManagerListener(std::string &pkgName, sptr listener); /** * @tc.name: IpcServerStub::UnRegisterDeviceManagerListener * @tc.desc: UnRegister DeviceManager Listener of the IpcServerStub * @tc.type: FUNC */ int32_t UnRegisterDeviceManagerListener(std::string &pkgName); /** * @tc.name: IpcServerStub::QueryServiceState * @tc.desc: Query Service State of the IpcServerStub * @tc.type: FUNC */ ServiceRunningState QueryServiceState() const; /** * @tc.name: IpcServerStub::SendALL * @tc.desc: SendALL of the IpcServerStub * @tc.type: FUNC */ int32_t SendALL(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); /** * @tc.name: IpcServerStub::GetAllPkgName * @tc.desc: Get All PkgName from dmListener_ * @tc.type: FUNC */ std::vector GetAllPkgName(); /** * @tc.name: IpcServerStub::GetDmListener * @tc.desc: Get DmListener of the IpcServerStub * @tc.type: FUNC */ const sptr GetDmListener(std::string pkgName) const; /** * @tc.name: IpcServerStub::GetDmListenerPkgName * @tc.desc: Get DmListener PkgName of the IpcServerStub * @tc.type: FUNC */ const std::string GetDmListenerPkgName(const wptr &remote) const; /** * @tc.name: IpcServerStub::Dump * @tc.desc: Dump of the Device Manager Service * @tc.type: FUNC */ int32_t Dump(int32_t fd, const std::vector& args) override; /** * @tc.name: IpcServerStub::OnAddSystemAbility * @tc.desc: OnAddSystemAbility of the IpcServerStub * @tc.type: FUNC */ void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; /** * @tc.name: IpcServerStub::OnRemoveSystemAbility * @tc.desc: OnRemoveSystemAbility of the IpcServerStub * @tc.type: FUNC */ void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; private: IpcServerStub(); ~IpcServerStub() override = default; bool Init(); private: bool registerToService_; ServiceRunningState state_; mutable std::mutex listenerLock_; std::map> appRecipient_; std::map> dmListener_; }; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_IPC_SERVER_STUB_H