1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include "switch_config.h"
16#include "memmgr_log.h"
17#include "xml_helper.h"
18
19namespace OHOS {
20namespace Memory {
21namespace {
22    const std::string TAG = "SwitchConfig";
23}
24
25void SwitchConfig::SetBigMemKillSwitch(unsigned long long bigMemKillSwitch)
26{
27    bigMemKillSwitch_ = bigMemKillSwitch;
28}
29
30unsigned long long SwitchConfig::GetBigMemKillSwitch(void)
31{
32    return bigMemKillSwitch_;
33}
34
35void SwitchConfig::ParseConfig(const xmlNodePtr &rootNodePtr)
36{
37    if (!XmlHelper::CheckNode(rootNodePtr) || !XmlHelper::HasChild(rootNodePtr)) {
38        HILOGD("Node exsist:%{public}d,has child node:%{public}d",
39               XmlHelper::CheckNode(rootNodePtr), XmlHelper::HasChild(rootNodePtr));
40        return;
41    }
42
43    for (xmlNodePtr currNode = rootNodePtr->xmlChildrenNode; currNode != nullptr; currNode = currNode->next) {
44        std::string key = std::string(reinterpret_cast<const char *>(currNode->name));
45        if (key == "bigMemKillSwitch") {
46            if (!XmlHelper::ParseUnsignedLongLongContent(currNode, bigMemKillSwitch_)) {
47                HILOGE("parse key :<%{public}s> error", key.c_str());
48                return;
49            }
50            HILOGI("bigMemKillSwitch_=%{public}llu", bigMemKillSwitch_);
51        } else {
52            HILOGW("unknown key :<%{public}s>", key.c_str());
53        }
54    }
55}
56
57void SwitchConfig::Dump(int fd)
58{
59    dprintf(fd, "SwitchConfig:   \n");
60    dprintf(fd, "                   bigMemKillSwitch: %llu\n", bigMemKillSwitch_);
61}
62} // namespace Memory
63} // namespace OHOS