1 /*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 "sharing_log.h"
17 #include "sharing_hisysevent.h"
18 #include "hisysevent.h"
19 #include "securec.h"
20
21 constexpr uint32_t MAX_STRING_SIZE = 256;
22 static constexpr char SHARING[] = "SHARING";
23
24 namespace OHOS {
25 namespace Sharing {
26
ReportOptFailReportOptFail(int32_t errCode,const std::string & operation,const std::string & errMsg)27 void ReportOptFailReportOptFail(int32_t errCode, const std::string &operation, const std::string &errMsg)
28 {
29 HiSysEventWrite(
30 SHARING,
31 SHARING_OPERATION_FAIL,
32 OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
33 "ERRCODE", errCode,
34 "OPERATION", operation,
35 "MSG", errMsg);
36 }
37
ReportSaFail(int32_t errCode,int32_t saId,const std::string & errMsg)38 void ReportSaFail(int32_t errCode, int32_t saId, const std::string &errMsg)
39 {
40 HiSysEventWrite(
41 SHARING,
42 SHARING_INIT,
43 OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
44 "ERRCODE", errCode,
45 "SAID", saId,
46 "MSG", errMsg);
47 }
48
ReportSaEvent(int32_t saId,const std::string & errMsg)49 void ReportSaEvent(int32_t saId, const std::string &errMsg)
50 {
51 HiSysEventWrite(
52 SHARING,
53 SHARING_INIT,
54 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
55 "SAID", saId,
56 "MSG", errMsg);
57 }
58
ReportForwardSharingEvent(const std::string & sharingEvent,const std::string & errMsg)59 void ReportForwardSharingEvent(const std::string &sharingEvent, const std::string &errMsg)
60 {
61 HiSysEventWrite(
62 SHARING,
63 SHARING_FORWARD_EVENT,
64 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
65 "EVENT", sharingEvent,
66 "MSG", errMsg);
67 }
68
CreateMsg(const char * format,...)69 std::string CreateMsg(const char *format, ...)
70 {
71 va_list args;
72 va_start(args, format);
73 char msg[MAX_STRING_SIZE] = {0};
74 if (vsnprintf_s(msg, sizeof(msg), sizeof(msg) - 1, format, args) < 0) {
75 SHARING_LOGE("failed to call vsnprintf_s.");
76 va_end(args);
77 }
78
79 va_end(args);
80 return std::string(msg);
81 }
82
83 } // namespace Sharing
84 } // namespace OHOS
85