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;
24
25 // ================================================================================
Parse(const int in,const int out) const26 status_t NoopParser::Parse(const int in, const int out) const
27 {
28 string content;
29 if (!ReadFdToString(in, &content)) {
30 fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.string());
31 return -1;
32 }
33 if (!WriteStringToFd(content, out)) {
34 fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.string());
35 return -1;
36 }
37 return NO_ERROR;
38 }
39
40 // ================================================================================
Parse(const int in,const int out) const41 status_t ReverseParser::Parse(const int in, const int out) const
42 {
43 string content;
44 if (!ReadFdToString(in, &content)) {
45 fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.string());
46 return -1;
47 }
48 // reverse the content
49 reverse(content.begin(), content.end());
50 if (!WriteStringToFd(content, out)) {
51 fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.string());
52 return -1;
53 }
54 return NO_ERROR;
55 }