blob: 52a20de4f6ef5bd41d81fbd1e652deeb64ddf6a5 [file] [log] [blame]
Christopher Wiley996775a2015-11-19 07:03:45 -08001/*
2 * Copyright (C) 2015 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_H_
18#define AIDL_TESTS_SIMPLE_PARCELABLE_H_
19
20#include <cstdint>
21#include <string>
22
23#include <binder/Parcelable.h>
24#include <utils/Errors.h>
25#include <utils/String16.h>
26
27namespace android {
28namespace aidl {
29namespace tests {
30
31class SimpleParcelable : public Parcelable {
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 status_t writeToParcel(Parcel* parcel) const override;
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 status_t readFromParcel(const Parcel* parcel) override;
50
51 std::string toString() const;
52
53 friend bool operator==(const SimpleParcelable& lhs,
54 const SimpleParcelable& rhs) {
55 return (lhs.name_ == rhs.name_) && (lhs.number_ == rhs.number_);
56 }
57 friend bool operator!=(const SimpleParcelable& lhs,
58 const SimpleParcelable& rhs) {
59 return !(lhs == rhs);
60 }
61
62 private:
63 String16 name_;
64 int32_t number_ = 0;
65}; // class SimpleParcelable
66
67} // namespace tests
68} // namespace aidl
69} // namespace android
70
71#endif // AIDL_TESTS_SIMPLE_PARCELABLE_H_