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 PASTE_BOARD_CLIENT_H 17 #define PASTE_BOARD_CLIENT_H 18 19 #include <functional> 20 #include <singleton.h> 21 #include <ohos/aafwk/content/want.h> 22 #include "paste_data_record.h" 23 #include "paste_data.h" 24 #include "i_pasteboard_service.h" 25 #include "pasteboard_observer.h" 26 27 namespace OHOS { 28 namespace MiscServices { 29 class PasteboardSaDeathRecipient : public IRemoteObject::DeathRecipient { 30 public: 31 explicit PasteboardSaDeathRecipient(); 32 ~PasteboardSaDeathRecipient() = default; 33 void OnRemoteDied(const wptr<IRemoteObject> &object) override; 34 private: 35 DISALLOW_COPY_AND_MOVE(PasteboardSaDeathRecipient); 36 }; 37 38 class PasteboardClient : public DelayedSingleton<PasteboardClient> { 39 DECLARE_DELAYED_SINGLETON(PasteboardClient); 40 public: 41 DISALLOW_COPY_AND_MOVE(PasteboardClient); 42 43 /** 44 * CreateHtmlTextRecord 45 * @descrition Create Html Text Record. 46 * @param std::string text. 47 * @return PasteDataRecord. 48 */ 49 std::shared_ptr<PasteDataRecord> CreateHtmlTextRecord(const std::string &text); 50 51 /** 52 * CreatePlainTextRecord 53 * @descrition Create Plaint Text Record. 54 * @param std::string text. 55 * @return PasteDataRecord. 56 */ 57 std::shared_ptr<PasteDataRecord> CreatePlainTextRecord(const std::string &text); 58 59 /** 60 * CreateUriRecord 61 * @descrition Create Uri Text Record. 62 * @param OHOS::Uri uri. 63 * @return PasteDataRecord. 64 */ 65 std::shared_ptr<PasteDataRecord> CreateUriRecord(const OHOS::Uri &uri); 66 67 /** 68 * CreateWantRecord 69 * @descrition Create Plaint Want Record. 70 * @param OHOS::AAFwk::Want want. 71 * @return PasteDataRecord. 72 */ 73 std::shared_ptr<PasteDataRecord> CreateWantRecord(std::shared_ptr<OHOS::AAFwk::Want> want); 74 75 /** 76 * CreateHtmlData 77 * @descrition Create Html Paste Data. 78 * @param std::string text . 79 * @return PasteData. 80 */ 81 std::shared_ptr<PasteData> CreateHtmlData(const std::string &htmlText); 82 83 /** 84 * CreatePlainTextData 85 * @descritionCreate Plain Text Paste Data. 86 * @param std::string text . 87 * @return PasteData. 88 */ 89 std::shared_ptr<PasteData> CreatePlainTextData(const std::string &text); 90 91 /** 92 * CreateUriData 93 * @descrition Create Uri Paste Data. 94 * @param OHOS::Uri uri . 95 * @return PasteData. 96 */ 97 std::shared_ptr<PasteData> CreateUriData(const OHOS::Uri &uri); 98 99 /** 100 * CreateWantData 101 * @descrition Create Want Paste Data. 102 * @param OHOS::AAFwk::Want want . 103 * @return PasteData. 104 */ 105 std::shared_ptr<PasteData> CreateWantData(std::shared_ptr<OHOS::AAFwk::Want> want); 106 /** 107 * GetPasteData 108 * @descrition 109 * @return bool. 110 */ 111 bool GetPasteData(PasteData& pasteData); 112 113 /** 114 * HasPasteData 115 * @descrition 116 * @return bool true on success, false on failure. 117 */ 118 bool HasPasteData(); 119 120 /** 121 * Clear 122 * @descrition Clear Current pasteboard data 123 * @return bool true on success, false on failure. 124 */ 125 void Clear(); 126 127 /** 128 * SetPasteData 129 * @descrition 130 * @param pasteData . 131 * @return void. 132 */ 133 void SetPasteData(PasteData& pasteData); 134 135 /** 136 * AddPasteboardChangedObserver 137 * @descrition 138 * @param observer pasteboard change callback. 139 * @return void. 140 */ 141 void AddPasteboardChangedObserver(std::shared_ptr<PasteboardObserver> callback); 142 143 /** 144 * RemovePasteboardChangedObserver 145 * @descrition 146 * @param observer pasteboard change callback. 147 * @return void. 148 */ 149 void RemovePasteboardChangedObserver(std::shared_ptr<PasteboardObserver> callback); 150 151 void OnRemoteSaDied(const wptr<IRemoteObject> &object); 152 private: 153 void ConnectService(); 154 155 static sptr<IPasteboardService> pasteboardServiceProxy_; 156 static std::mutex instanceLock_; 157 158 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 159 }; 160 } // MiscServices 161 } // OHOS 162 #endif // PASTE_BOARD_CLIENT_H