1 // Copyright (C) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use hisysevent::{write, EventType, HiSysEventParam}; 15 16 const DOMAIN: &str = "REQUEST"; 17 18 pub(crate) const ERROR_INFO: &str = "ERROR_INFO"; 19 pub(crate) const TASKS_TYPE: &str = "TASKS_TYPE"; 20 pub(crate) const TOTAL_FILE_NUM: &str = "TOTAL_FILE_NUM"; 21 pub(crate) const FAIL_FILE_NUM: &str = "FAIL_FILE_NUM"; 22 pub(crate) const SUCCESS_FILE_NUM: &str = "SUCCESS_FILE_NUM"; 23 24 /// System events structure which base on `Hisysevent`. 25 pub(crate) struct SysEvent<'a> { 26 event_kind: EventKind, 27 inner_type: EventType, 28 params: Vec<HiSysEventParam<'a>>, 29 } 30 31 impl<'a> SysEvent<'a> { task_fault() -> Self32 pub(crate) fn task_fault() -> Self { 33 Self { 34 event_kind: EventKind::TaskFault, 35 inner_type: EventType::Fault, 36 params: Vec::new(), 37 } 38 } 39 param(mut self, param: HiSysEventParam<'a>) -> Self40 pub(crate) fn param(mut self, param: HiSysEventParam<'a>) -> Self { 41 self.params.push(param); 42 self 43 } 44 write(self)45 pub(crate) fn write(self) { 46 write( 47 DOMAIN, 48 self.event_kind.as_str(), 49 self.inner_type, 50 self.params.as_slice(), 51 ); 52 } 53 } 54 55 enum EventKind { 56 TaskFault, 57 } 58 59 impl EventKind { as_str(&self) -> &str60 fn as_str(&self) -> &str { 61 match self { 62 EventKind::TaskFault => "TASK_FAULT", 63 } 64 } 65 } 66