1 /* 2 * Copyright (c) 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 */ 15 16 #ifndef SECURITY_GUARD_EVENT_SUBSCRIBE_CLIENT_H 17 #define SECURITY_GUARD_EVENT_SUBSCRIBE_CLIENT_H 18 19 #include "acquire_data_manager_callback_service.h" 20 #include "event_info.h" 21 22 namespace OHOS::Security::SecurityGuard { 23 using EventCallback = std::function<void(const SecurityCollector::Event &event)>; 24 class EventSubscribeClient { 25 public: 26 int32_t Subscribe(int64_t eventId); 27 int32_t Unsubscribe(int64_t eventId); 28 int32_t AddFilter(const std::shared_ptr<EventMuteFilter> &filter); 29 int32_t RemoveFilter(const std::shared_ptr<EventMuteFilter> &filter); 30 static int32_t CreatClient(const std::string &eventGroup, EventCallback callback, 31 std::shared_ptr<EventSubscribeClient> &client); 32 private: 33 EventSubscribeClient() = default; 34 ~EventSubscribeClient() = default; 35 EventSubscribeClient(const EventSubscribeClient&) = delete; 36 EventSubscribeClient& operator= (const EventSubscribeClient&) = delete; 37 static std::string ConstructClientId(const AcquireDataManagerCallbackService *serviceCallback); 38 static int32_t SetDeathRecipient(std::shared_ptr<EventSubscribeClient> client, 39 const sptr<IRemoteObject> &remote); 40 static void Deleter(EventSubscribeClient *client); 41 class DeathRecipient : public IRemoteObject::DeathRecipient { 42 public: 43 DeathRecipient() = default; 44 ~DeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)45 void OnRemoteDied(const wptr<IRemoteObject> &remote) override {}; 46 }; 47 sptr<AcquireDataManagerCallbackService> callback_{}; 48 sptr<IRemoteObject::DeathRecipient> deathRecipient_{}; 49 std::string eventGroup_{}; 50 std::string clientId_{}; 51 }; 52 } 53 #endif 54