1 /* 2 * Copyright (C) 2022 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 #ifndef NDEF_FORMATABLE_TAG_H 16 #define NDEF_FORMATABLE_TAG_H 17 18 #include "basic_tag_session.h" 19 #include "ndef_message.h" 20 21 namespace OHOS { 22 namespace NFC { 23 namespace KITS { 24 class NdefFormatableTag final : public BasicTagSession { 25 public: 26 explicit NdefFormatableTag(std::weak_ptr<TagInfo> tag); ~NdefFormatableTag()27 ~NdefFormatableTag() {} 28 29 /** 30 * @Description Get an object of NdefFormatableTag for the given tag. 31 * @param tag compatible with all types of tag 32 * @return std::shared_ptr<NdefFormatableTag> 33 */ 34 static std::shared_ptr<NdefFormatableTag> GetTag(std::weak_ptr<TagInfo> tag); 35 /** 36 * @Description format a tag as NDEF tag, then write Ndef message into the Ndef Tag 37 * @param firstMessage Ndef message to write while format successful. it can be null, then only format the tag, not 38 * write tag 39 * @return Errorcode of operation. if return 0, means successful. 40 */ 41 int Format(std::weak_ptr<NdefMessage> firstMessage); 42 /** 43 * @Description format a tag as NDEF tag, then write Ndef message into the Ndef Tag, then set the tag readonly 44 * @param firstMessage Ndef message to write while format successful. it can be null, then only format the tag, not 45 * write tag 46 * @return Errorcode of operation. if return 0, means successful. 47 */ 48 int FormatReadOnly(std::weak_ptr<NdefMessage> firstMessage); 49 50 private: 51 int Format(std::weak_ptr<NdefMessage> firstMessage, bool bMakeReadOnly); 52 }; 53 } // namespace KITS 54 } // namespace NFC 55 } // namespace OHOS 56 #endif // NDEF_FORMATABLE_TAG_H 57