blob: 7bced9b76a40e4530f30680da8dd27cb19a0bc88 [file] [log] [blame]
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001/*
2 * Copyright 2020 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#include <ui/DeviceProductInfo.h>
18
19#include <ui/FlattenableHelpers.h>
20
Marin Shalamanov896e6302020-04-06 16:11:25 +020021#define RETURN_IF_ERROR(op) \
22 if (const status_t status = (op); status != OK) return status;
23
Marin Shalamanov359a7e72020-02-17 17:03:07 +010024namespace android {
25
26size_t DeviceProductInfo::getFlattenedSize() const {
Marin Shalamanov896e6302020-04-06 16:11:25 +020027 return FlattenableHelpers::getFlattenedSize(name) +
28 FlattenableHelpers::getFlattenedSize(manufacturerPnpId) +
29 FlattenableHelpers::getFlattenedSize(productId) +
30 FlattenableHelpers::getFlattenedSize(manufactureOrModelDate) +
31 FlattenableHelpers::getFlattenedSize(relativeAddress);
Marin Shalamanov359a7e72020-02-17 17:03:07 +010032}
33
34status_t DeviceProductInfo::flatten(void* buffer, size_t size) const {
35 if (size < getFlattenedSize()) {
36 return NO_MEMORY;
37 }
Marin Shalamanov896e6302020-04-06 16:11:25 +020038 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, name));
39 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, manufacturerPnpId));
40 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, productId));
41 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, manufactureOrModelDate));
42 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, relativeAddress));
43 return OK;
Marin Shalamanov359a7e72020-02-17 17:03:07 +010044}
45
46status_t DeviceProductInfo::unflatten(void const* buffer, size_t size) {
Marin Shalamanov896e6302020-04-06 16:11:25 +020047 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &name));
48 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &manufacturerPnpId));
49 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &productId));
50 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &manufactureOrModelDate));
51 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &relativeAddress));
52 return OK;
Marin Shalamanov359a7e72020-02-17 17:03:07 +010053}
54
55} // namespace android