• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2023 The Android Open Source Project
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *      http://www.apache.org/licenses/LICENSE-2.0
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  #ifndef AIDL_TESTS_SIMPLE_PARCELABLE_NDK_H_
18  #define AIDL_TESTS_SIMPLE_PARCELABLE_NDK_H_
19  
20  #include <cstdint>
21  #include <string>
22  
23  #include <android/binder_parcel.h>
24  #include <sys/cdefs.h>
25  
26  namespace aidl {
27  namespace android {
28  namespace aidl {
29  namespace tests {
30  
31  class SimpleParcelable {
32   public:
33    SimpleParcelable() = default;
34    SimpleParcelable(const std::string& name, int32_t number);
35    virtual ~SimpleParcelable() = default;
36  
37    // Write |this| parcelable to the given |parcel|.  Keep in mind that
38    // implementations of writeToParcel must be manually kept in sync
39    // with readFromParcel and the Java equivalent versions of these methods.
40    //
41    // Returns android::OK on success and an appropriate error otherwise.
42    binder_status_t writeToParcel(AParcel* _Nonnull parcel) const;
43  
44    // Read data from the given |parcel| into |this|.  After readFromParcel
45    // completes, |this| should have equivalent state to the object that
46    // wrote itself to the parcel.
47    //
48    // Returns android::OK on success and an appropriate error otherwise.
49    binder_status_t readFromParcel(const AParcel* _Nonnull parcel);
50  
51    std::string toString() const;
52  
53    friend bool operator==(const SimpleParcelable& lhs, const SimpleParcelable& rhs) {
54      return (lhs.name_ == rhs.name_) && (lhs.number_ == rhs.number_);
55    }
56    friend bool operator!=(const SimpleParcelable& lhs, const SimpleParcelable& rhs) {
57      return !(lhs == rhs);
58    }
59  
60   private:
61    std::string name_;
62    int32_t number_ = 0;
63  };  // class SimpleParcelable
64  
65  }  // namespace tests
66  }  // namespace aidl
67  }  // namespace android
68  }  // namespace aidl
69  
70  #endif  // AIDL_TESTS_SIMPLE_PARCELABLE_NDK_H_
71