• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-2025 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 "ans_status.h"
16 #include <string>
17 #include "ans_inner_errors.h"
18 #include "ans_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace Notification {
22 
AnsStatus(int32_t errCode,const std::string & msg)23 AnsStatus::AnsStatus(int32_t errCode, const std::string& msg)
24 {
25     errCode_ = errCode;
26     msg_ = msg;
27 }
28 
AnsStatus(int32_t errCode,const std::string & msg,int32_t sceneId,int32_t branchId)29 AnsStatus::AnsStatus(int32_t errCode, const std::string& msg, int32_t sceneId, int32_t branchId)
30 {
31     errCode_ = errCode;
32     msg_ = msg;
33     sceneId_ = sceneId;
34     branchId_ = branchId;
35     path_ = FormatSceneBranchStr(sceneId, branchId);
36 }
37 
Ok()38 bool AnsStatus::Ok()
39 {
40     return errCode_ == ERR_OK;
41 }
42 
FormatSceneBranchStr(int32_t sceneId,int32_t branchId)43 std::string AnsStatus::FormatSceneBranchStr(int32_t sceneId, int32_t branchId)
44 {
45     return std::to_string(sceneId) + "_" + std::to_string(branchId);
46 }
47 
AppendSceneBranch(int32_t sceneId,int32_t branchId)48 AnsStatus& AnsStatus::AppendSceneBranch(int32_t sceneId, int32_t branchId)
49 {
50     return AppendSceneBranch(sceneId, branchId, "");
51 }
52 
AppendSceneBranch(int32_t sceneId,int32_t branchId,const std::string & msg)53 AnsStatus& AnsStatus::AppendSceneBranch(int32_t sceneId, int32_t branchId, const std::string& msg)
54 {
55     std::string path = FormatSceneBranchStr(sceneId, branchId);
56     path_.append("#" + path);
57     msg_.append("#" + msg);
58     return *this;
59 }
60 
GetErrCode()61 int32_t AnsStatus::GetErrCode()
62 {
63     return errCode_;
64 }
65 
InvalidParam(int32_t sceneId,int32_t branchId)66 AnsStatus AnsStatus::InvalidParam(int32_t sceneId, int32_t branchId)
67 {
68     return AnsStatus::InvalidParam("Invalid param", sceneId, branchId);
69 }
70 
InvalidParam(const std::string & msg,int32_t sceneId,int32_t branchId)71 AnsStatus AnsStatus::InvalidParam(const std::string& msg, int32_t sceneId, int32_t branchId)
72 {
73     return AnsStatus(ERR_ANS_INVALID_PARAM, msg, sceneId, branchId);
74 }
75 
BuildMessage(bool isPrint)76 HaMetaMessage AnsStatus::BuildMessage(bool isPrint)
77 {
78     return HaMetaMessage(branchId_, sceneId_).Path(path_).Message(msg_, isPrint);
79 }
80 
81 }  // namespace Notification
82 }  // namespace OHOS
83