Yi Jin | 04625ad | 2017-10-17 18:29:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 "incident_helper" |
| 18 | |
| 19 | #include "TextParserBase.h" |
| 20 | |
| 21 | #include <android-base/file.h> |
| 22 | |
| 23 | using namespace android::base; |
Yi Jin | 04625ad | 2017-10-17 18:29:33 -0700 | [diff] [blame] | 24 | |
| 25 | // ================================================================================ |
| 26 | status_t NoopParser::Parse(const int in, const int out) const |
| 27 | { |
| 28 | string content; |
| 29 | if (!ReadFdToString(in, &content)) { |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame^] | 30 | fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.c_str()); |
Yi Jin | 04625ad | 2017-10-17 18:29:33 -0700 | [diff] [blame] | 31 | return -1; |
| 32 | } |
| 33 | if (!WriteStringToFd(content, out)) { |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame^] | 34 | fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.c_str()); |
Yi Jin | 04625ad | 2017-10-17 18:29:33 -0700 | [diff] [blame] | 35 | return -1; |
| 36 | } |
| 37 | return NO_ERROR; |
| 38 | } |
| 39 | |
| 40 | // ================================================================================ |
| 41 | status_t ReverseParser::Parse(const int in, const int out) const |
| 42 | { |
| 43 | string content; |
| 44 | if (!ReadFdToString(in, &content)) { |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame^] | 45 | fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.c_str()); |
Yi Jin | 04625ad | 2017-10-17 18:29:33 -0700 | [diff] [blame] | 46 | return -1; |
| 47 | } |
| 48 | // reverse the content |
| 49 | reverse(content.begin(), content.end()); |
| 50 | if (!WriteStringToFd(content, out)) { |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame^] | 51 | fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.c_str()); |
Yi Jin | 04625ad | 2017-10-17 18:29:33 -0700 | [diff] [blame] | 52 | return -1; |
| 53 | } |
| 54 | return NO_ERROR; |
| 55 | } |