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 OHOS_VCARD_DECODER_H 17 #define OHOS_VCARD_DECODER_H 18 #include <string> 19 #include <vector> 20 21 #include "vcard_contact.h" 22 #include "vcard_file_utils.h" 23 24 namespace OHOS { 25 namespace Telephony { 26 class VCardDecodeListener { 27 public: 28 virtual ~VCardDecodeListener() = default; 29 virtual void OnStarted() = 0; 30 virtual void OnEnded() = 0; 31 virtual void OnOneContactStarted() = 0; 32 virtual void OnOneContactEnded() = 0; 33 virtual void OnRawDataCreated(std::shared_ptr<VCardRawData> rawData) = 0; 34 }; 35 36 class VCardDecoder { 37 public: 38 VCardDecoder(); 39 static std::shared_ptr<VCardDecoder> Create(const std::string &path, int32_t &errorCode); 40 static std::shared_ptr<VCardDecoder> Create(std::shared_ptr<std::ifstream> file_, int32_t &errorCode); 41 static void Close(); 42 virtual void AddVCardDecodeListener(std::shared_ptr<VCardDecodeListener> listener); 43 virtual void Decode(int32_t &errorCode); 44 virtual bool DecodeOne(int32_t &errorCode); 45 bool IsEnd(); 46 virtual ~VCardDecoder(); 47 48 protected: 49 static VCardFileUtils fileUtils_; 50 static std::string GetVersion(); 51 static std::shared_ptr<VCardDecoder> GetDecoder(const std::string &version); 52 }; 53 } // namespace Telephony 54 } // namespace OHOS 55 #endif // OHOS_VCARD_DECODER_H 56