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_DISTRIBUTED_DEVICE_PROFILE_CLIENT_H 17 #define OHOS_DISTRIBUTED_DEVICE_PROFILE_CLIENT_H 18 19 #include "idistributed_device_profile.h" 20 #include "single_instance.h" 21 #include "iprofile_event_callback.h" 22 #include "profile_event_notifier_stub.h" 23 #include "profile_event.h" 24 #include "event_handler.h" 25 #include "iremote_object.h" 26 27 namespace OHOS { 28 namespace DeviceProfile { 29 class DistributedDeviceProfileClient { 30 DECLARE_SINGLE_INSTANCE(DistributedDeviceProfileClient); 31 32 public: 33 int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile); 34 int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, 35 ServiceCharacteristicProfile& profile); 36 int32_t DeleteDeviceProfile(const std::string& serviceId); 37 int32_t SubscribeProfileEvent(const SubscribeInfo& subscribeInfo, 38 const std::shared_ptr<IProfileEventCallback>& eventCb); 39 int32_t UnsubscribeProfileEvent(ProfileEvent profileEvent, 40 const std::shared_ptr<IProfileEventCallback>& eventCb); 41 int32_t SubscribeProfileEvents(const std::list<SubscribeInfo>& subscribeInfos, 42 const std::shared_ptr<IProfileEventCallback>& eventCb, 43 std::list<ProfileEvent>& failedEvents); 44 int32_t UnsubscribeProfileEvents(const std::list<ProfileEvent>& profileEvents, 45 const std::shared_ptr<IProfileEventCallback>& eventCb, 46 std::list<ProfileEvent>& failedEvents); 47 int32_t SyncDeviceProfile(const SyncOptions& syncOptions, 48 const std::shared_ptr<IProfileEventCallback>& syncCb); 49 50 private: 51 class DeviceProfileDeathRecipient : public IRemoteObject::DeathRecipient { 52 public: 53 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 54 }; 55 56 struct SubscribeRecord { 57 std::list<SubscribeInfo> subscribeInfos; 58 sptr<IRemoteObject> notifier; 59 ProfileEvents profileEvents; 60 }; 61 62 sptr<IDistributedDeviceProfile> GetDeviceProfileService(); 63 bool CheckProfileInvalidity(const ServiceCharacteristicProfile& profile); 64 void OnServiceDied(const sptr<IRemoteObject>& remote); 65 void MergeSubscribeInfoLocked(std::list<SubscribeInfo>& subscribeInfos, 66 const std::list<SubscribeInfo>& newSubscribeInfos); 67 68 std::mutex serviceLock_; 69 std::mutex subscribeLock_; 70 sptr<IDistributedDeviceProfile> dpProxy_; 71 sptr<IRemoteObject::DeathRecipient> dpDeathRecipient_; 72 std::shared_ptr<AppExecFwk::EventHandler> dpClientHandler_; 73 std::map<std::shared_ptr<IProfileEventCallback>, SubscribeRecord> subscribeRecords_; 74 }; 75 } // namespace DeviceProfile 76 } // namespace OHOS 77 #endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_CLIENT_H