Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85d3cc02 authored by Yi Jin's avatar Yi Jin Committed by android-build-merger
Browse files

Merge "Use modern c++ code style for incidentd." into pi-dev

am: 56051569

Change-Id: Ifd36cb23ae185b8a37805deb6163e87a2e9ee1c9
parents 4f632a30 56051569
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@
#include <android-base/file.h>

using namespace android::base;
using namespace std;

// ================================================================================
status_t NoopParser::Parse(const int in, const int out) const
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <utils/String8.h>

using namespace android;
using namespace std;

/**
 * Base class for text parser
+9 −9
Original line number Diff line number Diff line
@@ -98,9 +98,9 @@ bool getColumnIndices(std::vector<int>& indices, const char** headerNames, const
    size_t lastIndex = 0;
    int i = 0;
    while (headerNames[i] != NULL) {
        string s = headerNames[i];
        std::string s = headerNames[i];
        lastIndex = line.find(s, lastIndex);
        if (lastIndex == string::npos) {
        if (lastIndex == std::string::npos) {
            fprintf(stderr, "Bad Task Header: %s\n", line.c_str());
            return false;
        }
@@ -271,7 +271,7 @@ Table::Table(const char* names[], const uint64_t ids[], const int count)
        :mEnums(),
         mEnumValuesByName()
{
    map<std::string, uint64_t> fields;
    std::map<std::string, uint64_t> fields;
    for (int i = 0; i < count; i++) {
        fields[names[i]] = ids[i];
    }
@@ -286,11 +286,11 @@ void
Table::addEnumTypeMap(const char* field, const char* enumNames[], const int enumValues[], const int enumSize)
{
    if (mFields.find(field) == mFields.end()) {
        fprintf(stderr, "Field '%s' not found", string(field).c_str());
        fprintf(stderr, "Field '%s' not found", field);
        return;
    }

    map<std::string, int> enu;
    std::map<std::string, int> enu;
    for (int i = 0; i < enumSize; i++) {
        enu[enumNames[i]] = enumValues[i];
    }
@@ -420,10 +420,10 @@ Message::insertField(ProtoOutputStream* proto, const std::string& name, const st

    // Try to find the message field which is the prefix of name, so the value would be inserted
    // recursively into the submessage.
    string mutableName = name;
    std::string mutableName = name;
    for (auto iter = mSubMessages.begin(); iter != mSubMessages.end(); iter++) {
        string fieldName = iter->first;
        string prefix = fieldName + "_"; // underscore is the delimiter in the name
        std::string fieldName = iter->first;
        std::string prefix = fieldName + "_"; // underscore is the delimiter in the name
        if (stripPrefix(&mutableName, prefix.c_str())) {
            if (mPreviousField != fieldName) {
                endSession(proto);
@@ -437,7 +437,7 @@ Message::insertField(ProtoOutputStream* proto, const std::string& name, const st
}

void
Message::startSession(ProtoOutputStream* proto, const string& name)
Message::startSession(ProtoOutputStream* proto, const std::string& name)
{
    uint64_t fieldId = mTable->mFields[name];
    uint64_t token = proto->start(fieldId);
+6 −6
Original line number Diff line number Diff line
@@ -150,9 +150,9 @@ public:
    // Return false if the given name can't be found.
    bool insertField(ProtoOutputStream* proto, const std::string& name, const std::string& value);
private:
    map<std::string, uint64_t> mFields;
    map<std::string, map<std::string, int>> mEnums;
    map<std::string, int> mEnumValuesByName;
    std::map<std::string, uint64_t> mFields;
    std::map<std::string, std::map<std::string, int>> mEnums;
    std::map<std::string, int> mEnumValuesByName;
};

/**
@@ -187,15 +187,15 @@ public:
    bool insertField(ProtoOutputStream* proto, const std::string& name, const std::string& value);

    // Starts a new message field proto session.
    void startSession(ProtoOutputStream* proto, const string& name);
    void startSession(ProtoOutputStream* proto, const std::string& name);

    // Ends the previous message field proto session.
    void endSession(ProtoOutputStream* proto);
private:
    Table* mTable;
    std::string mPreviousField;
    stack<uint64_t> mTokens;
    map<std::string, Message*> mSubMessages;
    std::stack<uint64_t> mTokens;
    std::map<std::string, Message*> mSubMessages;
};

#endif  // INCIDENT_HELPER_UTIL_H
+9 −1
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@
#include <unistd.h>
#include <wait.h>

namespace android {
namespace os {
namespace incidentd {

const ssize_t BUFFER_SIZE = 16 * 1024;  // 16 KB
const ssize_t MAX_BUFFER_COUNT = 256;   // 4 MB max

@@ -206,7 +210,7 @@ status_t FdBuffer::readProcessedDataInStream(int fd, unique_fd toFd, unique_fd f
            }
            if (amt < 0) {
                if (!(errno == EAGAIN || errno == EWOULDBLOCK)) {
                    VLOG("Fail to write toFd.get() %d: %s", toFd.get(), strerror(errno));
                    VLOG("Fail to write toFd %d: %s", toFd.get(), strerror(errno));
                    return -errno;
                }  // otherwise just continue
            } else {
@@ -252,3 +256,7 @@ status_t FdBuffer::readProcessedDataInStream(int fd, unique_fd toFd, unique_fd f
size_t FdBuffer::size() const { return mBuffer.size(); }

EncodedBuffer::iterator FdBuffer::data() const { return mBuffer.begin(); }

}  // namespace incidentd
}  // namespace os
}  // namespace android
Loading