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 "hisysevent_adapter.h"
16#include "hisysevent.h"
17#include "hilog_wrapper.h"
18
19namespace OHOS {
20namespace Global {
21namespace Resource {
22using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent;
23
24void ReportInitResourceManagerFail(const std::string& bundleName, const std::string& errMsg)
25{
26    int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::GLOBAL_RESMGR, "INIT_RESMGR_FAILED",
27        HiSysEventNameSpace::EventType::FAULT,
28        "BUNDLENAME", bundleName,
29        "ERROR_MSG", errMsg);
30    if (ret != 0) {
31        RESMGR_HILOGE(RESMGR_TAG, "HiSysEventWrite failed! ret %{public}d, bundleName %{public}s, errMsg %{public}s",
32            ret, bundleName.c_str(), errMsg.c_str());
33    }
34}
35
36void ReportGetResourceByIdFail(int32_t resId, const std::string& result, const std::string& errMsg)
37{
38    int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::GLOBAL_RESMGR, "GET_RES_BY_ID_FAILED",
39        HiSysEventNameSpace::EventType::BEHAVIOR,
40        "ID", resId,
41        "RESULT", result,
42        "ERROR_MSG", errMsg);
43    if (ret != 0) {
44        RESMGR_HILOGE(RESMGR_TAG,
45            "HiSysEventWrite failed! ret %{public}d, resId %{public}d, result %{public}s, errMsg %{public}s.",
46            ret, resId, result.c_str(), errMsg.c_str());
47    }
48}
49
50void ReportGetResourceByNameFail(const std::string& resName, const std::string& result, const std::string& errMsg)
51{
52    int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::GLOBAL_RESMGR, "GET_RES_BY_NAME_FAILED",
53        HiSysEventNameSpace::EventType::BEHAVIOR,
54        "NAME", resName,
55        "RESULT", result,
56        "ERROR_MSG", errMsg);
57    if (ret != 0) {
58        RESMGR_HILOGE(RESMGR_TAG,
59            "HiSysEventWrite failed! ret %{public}d, resName %{public}s, result %{public}s, errMsg %{public}s",
60            ret, resName.c_str(), result.c_str(), errMsg.c_str());
61    }
62}
63
64void ReportAddResourcePathFail(const char* resourcePath, const std::string& errMsg)
65{
66    int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::GLOBAL_RESMGR, "ADD_RES_PATH_FAILED",
67        HiSysEventNameSpace::EventType::BEHAVIOR,
68        "PATH", resourcePath,
69        "ERROR_MSG", errMsg);
70    if (ret != 0) {
71        RESMGR_HILOGE(RESMGR_TAG,
72            "HiSysEventWrite failed! ret %{public}d, resourcePath %{public}s, errMsg %{public}s.",
73            ret, resourcePath, errMsg.c_str());
74    }
75}
76} // Resource
77} // Global
78} // OHOS