blob: e625afa626ec1fa1f84b218393f12f446d754eda [file] [log] [blame]
Yi Jin04625ad2017-10-17 18:29:33 -07001/*
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
23using namespace android::base;
Yi Jin04625ad2017-10-17 18:29:33 -070024
25// ================================================================================
26status_t NoopParser::Parse(const int in, const int out) const
27{
28 string content;
29 if (!ReadFdToString(in, &content)) {
Tomasz Wasilczyk3815d342023-08-10 23:54:44 +000030 fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.c_str());
Yi Jin04625ad2017-10-17 18:29:33 -070031 return -1;
32 }
33 if (!WriteStringToFd(content, out)) {
Tomasz Wasilczyk3815d342023-08-10 23:54:44 +000034 fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.c_str());
Yi Jin04625ad2017-10-17 18:29:33 -070035 return -1;
36 }
37 return NO_ERROR;
38}
39
40// ================================================================================
41status_t ReverseParser::Parse(const int in, const int out) const
42{
43 string content;
44 if (!ReadFdToString(in, &content)) {
Tomasz Wasilczyk3815d342023-08-10 23:54:44 +000045 fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.c_str());
Yi Jin04625ad2017-10-17 18:29:33 -070046 return -1;
47 }
48 // reverse the content
49 reverse(content.begin(), content.end());
50 if (!WriteStringToFd(content, out)) {
Tomasz Wasilczyk3815d342023-08-10 23:54:44 +000051 fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.c_str());
Yi Jin04625ad2017-10-17 18:29:33 -070052 return -1;
53 }
54 return NO_ERROR;
55}