• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 PASTEBOARD_DEVICE_PROFILE_CLIENT_H
17 #define PASTEBOARD_DEVICE_PROFILE_CLIENT_H
18 
19 #include <condition_variable>
20 #include <map>
21 #include <memory>
22 #include <mutex>
23 
24 #include "i_distributed_device_profile.h"
25 #include "iremote_object.h"
26 #include "system_ability_load_callback_stub.h"
27 
28 namespace OHOS {
29 namespace DistributedDeviceProfile {
30 class DeviceProfileLoadCb : public SystemAbilityLoadCallbackStub {
31 public:
32     void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override;
33     void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
34 };
35 
36 class DeviceProfileClient {
37 public:
38     static DeviceProfileClient &GetInstance();
39 
40     int32_t PutCharacteristicProfile(const CharacteristicProfile &characteristicProfile);
41     int32_t GetCharacteristicProfile(const std::string &deviceId, const std::string &serviceName,
42         const std::string &characteristicId, CharacteristicProfile &characteristicProfile);
43     int32_t SubscribeDeviceProfile(const SubscribeInfo &subscribeInfo);
44     int32_t UnSubscribeDeviceProfile(const SubscribeInfo &subscribeInfo);
45     void SendSubscribeInfos();
46     void ClearDeviceProfileService();
47 
48     void LoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject);
49     void LoadSystemAbilityFail();
50 
51 private:
52     sptr<IDistributedDeviceProfile> LoadDeviceProfileService();
53     sptr<IDistributedDeviceProfile> GetDeviceProfileService();
54 
55     std::mutex serviceLock_;
56     std::condition_variable proxyConVar_;
57     sptr<IDistributedDeviceProfile> dpProxy_ = nullptr;
58 
59     std::mutex subscribeLock_;
60     std::map<std::string, SubscribeInfo> subscribeInfos_;
61 };
62 } // namespace DistributedDeviceProfile
63 } // namespace OHOS
64 #endif // PASTEBOARD_DEVICE_PROFILE_CLIENT_H
65