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
16 #include "dm_hisysevent.h"
17
18 #include "dm_log.h" // for LOGE
19 #include "hisysevent.h" // for HiSysEvent, HiSysEvent::Domain, HiSysEvent...
20 #include "unistd.h" // for getpid, getuid
21
22 namespace OHOS {
23 namespace DistributedHardware {
24 constexpr int32_t DM_OK = 0;
SysEventWrite(const std::string & status,int32_t eventType,const std::string & msg)25 void SysEventWrite(const std::string &status, int32_t eventType, const std::string &msg)
26 {
27 HiSysEventParam params[] = {
28 {.name = "PID", .t = HISYSEVENT_INT32, .v = { .i32 = getpid() }, .arraySize = 0, },
29 {.name = "UID", .t = HISYSEVENT_INT32, .v = { .i32 = getuid() }, .arraySize = 0, },
30 {.name = "MSG", .t = HISYSEVENT_STRING, .v = { .s = (char *)msg.c_str() }, .arraySize = 0, },
31 };
32 size_t len = sizeof(params) / sizeof(params[0]);
33 int32_t res = OH_HiSysEvent_Write(
34 OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_DEVICE_MANAGER,
35 status.c_str(),
36 (HiSysEventEventType)eventType, params, len);
37 if (res != DM_OK) {
38 LOGE("%{public}s Write HiSysEvent error, res:%{public}d", status.c_str(), res);
39 }
40 }
41 } // namespace DistributedHardware
42 } // namespace OHOS
43