• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "notification_normal_content.h"
17 
18 #include <string>                         // for operator+, basic_string
19 
20 #include "ans_log_wrapper.h"
21 #include "nlohmann/json.hpp"              // for json
22 #include "notification_basic_content.h"   // for NotificationBasicContent
23 
24 namespace OHOS {
25 namespace Notification {
Dump()26 std::string NotificationNormalContent::Dump()
27 {
28     return "NotificationNormalContent{ " + NotificationBasicContent::Dump() + " }";
29 }
30 
ToJson(nlohmann::json & jsonObject) const31 bool NotificationNormalContent::ToJson(nlohmann::json &jsonObject) const
32 {
33     return NotificationBasicContent::ToJson(jsonObject);
34 }
35 
FromJson(const nlohmann::json & jsonObject)36 NotificationNormalContent *NotificationNormalContent::FromJson(const nlohmann::json &jsonObject)
37 {
38     if (jsonObject.is_null() or !jsonObject.is_object()) {
39         ANS_LOGE("Invalid JSON object");
40         return nullptr;
41     }
42 
43     auto pContent = new (std::nothrow) NotificationNormalContent();
44     if (pContent == nullptr) {
45         ANS_LOGE("null pContent");
46         return nullptr;
47     }
48 
49     pContent->ReadFromJson(jsonObject);
50 
51     return pContent;
52 }
53 
Marshalling(Parcel & parcel) const54 bool NotificationNormalContent::Marshalling(Parcel &parcel) const
55 {
56     return NotificationBasicContent::Marshalling(parcel);
57 }
58 
Unmarshalling(Parcel & parcel)59 NotificationNormalContent *NotificationNormalContent::Unmarshalling(Parcel &parcel)
60 {
61     auto pContent = new (std::nothrow) NotificationNormalContent();
62     if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) {
63         delete pContent;
64         pContent = nullptr;
65     }
66 
67     return pContent;
68 }
69 }  // namespace Notification
70 }  // namespace OHOS
71