1 /*
2 * Copyright (C) 2018 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 #define LOG_TAG "StatsDimensionsValue"
18
19 #include "android/os/StatsDimensionsValue.h"
20
21 #include <cutils/log.h>
22
23 using android::Parcel;
24 using android::Parcelable;
25 using android::status_t;
26 using std::vector;
27
28 namespace android {
29 namespace os {
30
StatsDimensionsValue()31 StatsDimensionsValue::StatsDimensionsValue() {};
32
StatsDimensionsValue(int32_t field,String16 value)33 StatsDimensionsValue::StatsDimensionsValue(int32_t field, String16 value) :
34 mField(field),
35 mValueType(kStrValueType),
36 mStrValue(value) {
37 }
StatsDimensionsValue(int32_t field,int32_t value)38 StatsDimensionsValue::StatsDimensionsValue(int32_t field, int32_t value) :
39 mField(field),
40 mValueType(kIntValueType),
41 mIntValue(value) {
42 }
StatsDimensionsValue(int32_t field,int64_t value)43 StatsDimensionsValue::StatsDimensionsValue(int32_t field, int64_t value) :
44 mField(field),
45 mValueType(kLongValueType),
46 mLongValue(value) {
47 }
StatsDimensionsValue(int32_t field,bool value)48 StatsDimensionsValue::StatsDimensionsValue(int32_t field, bool value) :
49 mField(field),
50 mValueType(kBoolValueType),
51 mBoolValue(value) {
52 }
StatsDimensionsValue(int32_t field,float value)53 StatsDimensionsValue::StatsDimensionsValue(int32_t field, float value) :
54 mField(field),
55 mValueType(kFloatValueType),
56 mFloatValue(value) {
57 }
StatsDimensionsValue(int32_t field,vector<StatsDimensionsValue> value)58 StatsDimensionsValue::StatsDimensionsValue(int32_t field, vector<StatsDimensionsValue> value) :
59 mField(field),
60 mValueType(kTupleValueType),
61 mTupleValue(value) {
62 }
63
~StatsDimensionsValue()64 StatsDimensionsValue::~StatsDimensionsValue() {}
65
66 status_t
writeToParcel(Parcel * out) const67 StatsDimensionsValue::writeToParcel(Parcel* out) const {
68 status_t err ;
69
70 err = out->writeInt32(mField);
71 if (err != NO_ERROR) {
72 return err;
73 }
74 err = out->writeInt32(mValueType);
75 if (err != NO_ERROR) {
76 return err;
77 }
78 switch (mValueType) {
79 case kStrValueType:
80 err = out->writeString16(mStrValue);
81 break;
82 case kIntValueType:
83 err = out->writeInt32(mIntValue);
84 break;
85 case kLongValueType:
86 err = out->writeInt64(mLongValue);
87 break;
88 case kBoolValueType:
89 err = out->writeBool(mBoolValue);
90 break;
91 case kFloatValueType:
92 err = out->writeFloat(mFloatValue);
93 break;
94 case kTupleValueType:
95 {
96 int sz = mTupleValue.size();
97 err = out->writeInt32(sz);
98 if (err != NO_ERROR) {
99 return err;
100 }
101 for (int i = 0; i < sz; ++i) {
102 err = mTupleValue[i].writeToParcel(out);
103 if (err != NO_ERROR) {
104 return err;
105 }
106 }
107 }
108 break;
109 default:
110 err = UNKNOWN_ERROR;
111 break;
112 }
113 return err;
114 }
115
116 status_t
readFromParcel(const Parcel * in)117 StatsDimensionsValue::readFromParcel(const Parcel* in)
118 {
119 // Implement me if desired. We don't currently use this.
120 ALOGE("Cannot do c++ StatsDimensionsValue.readFromParcel(); it is not implemented.");
121 (void)in; // To prevent compile error of unused parameter 'in'
122 return UNKNOWN_ERROR;
123 }
124
125 } // namespace os
126 } // namespace android
127