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 "networkshare_hisysevent.h"
17 
18 #include "net_event_report.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 
GetInstance()23 NetworkShareHisysEvent &NetworkShareHisysEvent::GetInstance()
24 {
25     static NetworkShareHisysEvent instance;
26     return instance;
27 }
28 
SendFaultEvent(const NetworkShareEventOperator & operatorType,const NetworkShareEventErrorType & errorCode,const std::string & errorMsg,const NetworkShareEventType & eventType)29 void NetworkShareHisysEvent::SendFaultEvent(const NetworkShareEventOperator &operatorType,
30                                             const NetworkShareEventErrorType &errorCode, const std::string &errorMsg,
31                                             const NetworkShareEventType &eventType)
32 {
33     EventInfo eventInfo;
34     eventInfo.operatorType = static_cast<int32_t>(operatorType);
35     eventInfo.errorType = static_cast<int32_t>(errorCode);
36     eventInfo.errorMsg = errorMsg;
37     eventInfo.sharingType = -1;
38     if (eventType == NetworkShareEventType::SETUP_EVENT) {
39         NetEventReport::SendSetupFaultEvent(eventInfo);
40     } else if (eventType == NetworkShareEventType::CANCEL_EVENT) {
41         NetEventReport::SendCancleFaultEvent(eventInfo);
42     }
43 }
44 
SendFaultEvent(const SharingIfaceType & sharingType,const NetworkShareEventOperator & operatorType,const NetworkShareEventErrorType & errorCode,const std::string & errorMsg,const NetworkShareEventType & eventType)45 void NetworkShareHisysEvent::SendFaultEvent(const SharingIfaceType &sharingType,
46                                             const NetworkShareEventOperator &operatorType,
47                                             const NetworkShareEventErrorType &errorCode, const std::string &errorMsg,
48                                             const NetworkShareEventType &eventType)
49 {
50     EventInfo eventInfo;
51     eventInfo.sharingType = static_cast<int32_t>(sharingType);
52     eventInfo.operatorType = static_cast<int32_t>(operatorType);
53     eventInfo.errorType = static_cast<int32_t>(errorCode);
54     eventInfo.errorMsg = errorMsg;
55     if (eventType == NetworkShareEventType::SETUP_EVENT) {
56         NetEventReport::SendSetupFaultEvent(eventInfo);
57     } else if (eventType == NetworkShareEventType::CANCEL_EVENT) {
58         NetEventReport::SendCancleFaultEvent(eventInfo);
59     }
60 }
61 
SendBehaviorEvent(int32_t sharingCount,const SharingIfaceType & sharingType)62 void NetworkShareHisysEvent::SendBehaviorEvent(int32_t sharingCount, const SharingIfaceType &sharingType)
63 {
64     EventInfo eventInfo;
65     eventInfo.sharingCount = sharingCount;
66     eventInfo.sharingType = static_cast<int32_t>(sharingType);
67     NetEventReport::SendTimeBehaviorEvent(eventInfo);
68 }
69 
70 } // namespace NetManagerStandard
71 } // namespace OHOS