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_ABILITY_RUNTIME_DATA_ABILITY_RESULT_H 17 #define OHOS_ABILITY_RUNTIME_DATA_ABILITY_RESULT_H 18 19 #include "parcel.h" 20 #include "uri.h" 21 22 using Uri = OHOS::Uri; 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 class DataAbilityResult final : public Parcelable { 27 public: 28 /** 29 * @brief A constructor used to create a DataAbilityResult instance 30 * with the input parameter count specified. 31 */ 32 explicit DataAbilityResult(int count); 33 34 /** 35 * @brief A constructor used to create a DataAbilityResult instance 36 * with the input parameter uri specified 37 */ 38 explicit DataAbilityResult(const Uri &uri); 39 40 /** 41 * @brief A constructor used to create a DataAbilityResult instance 42 * with a Parcel object specified. 43 */ 44 explicit DataAbilityResult(Parcel &parcel); 45 46 /** 47 * @brief A constructor used to create a DataAbilityResult instance 48 * with input parameters uri, count, and failure specified. 49 */ 50 DataAbilityResult(const Uri &uri, int count); 51 52 ~DataAbilityResult(); 53 54 /** 55 * @brief Obtains the Uri object corresponding to the operation. 56 * @return Obtains the Uri object corresponding to the operation. 57 */ 58 Uri GetUri(); 59 60 /** 61 * @brief Obtains the number of rows affected by the operation. 62 * @return Returns the number of rows affected by the operation. 63 */ 64 int GetCount(); 65 66 /** 67 * @brief Prints out a string containing the class object information. 68 * @return Returns object information. 69 */ 70 std::string ToString(); 71 72 /** 73 * @brief Marshals a DataAbilityResult object into a Parcel. 74 * @param parcel Indicates the Parcel object for marshalling. 75 * @return Returns true if the marshalling is successful; returns false otherwise. 76 */ 77 virtual bool Marshalling(Parcel &parcel) const; 78 79 /** 80 * @brief Unmarshals a DataAbilityResult object from a Parcel. 81 * @param parcel Indicates the Parcel object for unmarshalling. 82 * @return Returns true if the unmarshalling is successful; returns false otherwise. 83 */ 84 static DataAbilityResult *Unmarshalling(Parcel &parcel); 85 86 /** 87 * @brief Creates a DataAbilityResult instance based on the given Parcel object. 88 * Used to transfer DataAbilityResult object using Parcel. 89 * @param parcel Indicates the Parcel object. 90 * @return Returns the DataAbilityResult object. 91 */ 92 static DataAbilityResult *CreateFromParcel(Parcel &parcel); 93 94 private: 95 Uri uri_; 96 int count_; 97 98 bool ReadFromParcel(Parcel &parcel); 99 // no object in parcel 100 static constexpr int VALUE_NULL = -1; 101 // object exist in parcel 102 static constexpr int VALUE_OBJECT = 1; 103 }; 104 } // namespace AppExecFwk 105 } // namespace OHOS 106 #endif // OHOS_ABILITY_RUNTIME_DATA_ABILITY_RESULT_H 107