• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "simple_timer_info.h"
17 #include "time_hilog.h"
18 
19 namespace OHOS {
20 namespace MiscServices {
SimpleTimerInfo(std::string _name,int _type,bool _repeat,bool _disposable,bool _autoRestore,uint64_t _interval,std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent)21 SimpleTimerInfo::SimpleTimerInfo(std::string _name,
22                                  int _type,
23                                  bool _repeat,
24                                  bool _disposable,
25                                  bool _autoRestore,
26                                  uint64_t _interval,
27                                  std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent)
28 {
29     name = _name;
30     type = _type;
31     repeat = _repeat;
32     disposable = _disposable;
33     autoRestore = _autoRestore;
34     interval = _interval;
35     wantAgent = _wantAgent;
36 }
~SimpleTimerInfo()37 SimpleTimerInfo::~SimpleTimerInfo()
38 {
39 }
SetType(const int & _type)40 void SimpleTimerInfo::SetType(const int &_type)
41 {
42     type = _type;
43 }
44 
SetRepeat(bool _repeat)45 void SimpleTimerInfo::SetRepeat(bool _repeat)
46 {
47     repeat = _repeat;
48 }
SetInterval(const uint64_t & _interval)49 void SimpleTimerInfo::SetInterval(const uint64_t &_interval)
50 {
51     interval = _interval;
52 }
SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent)53 void SimpleTimerInfo::SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent)
54 {
55     wantAgent = _wantAgent;
56 }
OnTrigger()57 void SimpleTimerInfo::OnTrigger()
58 {
59 }
60 
Marshalling(Parcel & parcel) const61 bool SimpleTimerInfo::Marshalling(Parcel& parcel) const
62 {
63     if (!parcel.WriteString(name)) {
64         TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write name");
65         return false;
66     }
67     if (!parcel.WriteInt32(type)) {
68         TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write type");
69         return false;
70     }
71     if (!parcel.WriteBool(repeat)) {
72         TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write repeat");
73         return false;
74     }
75     if (!parcel.WriteBool(disposable)) {
76         TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write disposable");
77         return false;
78     }
79     if (!parcel.WriteBool(autoRestore)) {
80         TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write autoRestore");
81         return false;
82     }
83     if (!parcel.WriteUint64(interval)) {
84         TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write interval");
85         return false;
86     }
87     if (!parcel.WriteBool(wantAgent != nullptr)) {
88         TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write wantAgent status");
89         return false;
90     }
91     if (wantAgent != nullptr && !parcel.WriteParcelable(&(*wantAgent))) {
92         TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write wantAgent");
93         return false;
94     }
95     return true;
96 }
97 
Unmarshalling(Parcel & parcel)98 SimpleTimerInfo *SimpleTimerInfo::Unmarshalling(Parcel& parcel)
99 {
100     auto name = parcel.ReadString();
101     auto type = parcel.ReadInt32();
102     auto repeat = parcel.ReadBool();
103     auto disposable = parcel.ReadBool();
104     auto autoRestore = parcel.ReadBool();
105     auto interval = parcel.ReadUint64();
106     std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent{ nullptr };
107     if (parcel.ReadBool()) {
108         wantAgent = std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent>(
109                 parcel.ReadParcelable<OHOS::AbilityRuntime::WantAgent::WantAgent>());
110         if (!wantAgent) {
111             TIME_HILOGE(TIME_MODULE_SERVICE, "Input wantagent nullptr");
112             return nullptr;
113         }
114     }
115     SimpleTimerInfo *simpleTimerInfo = new (std::nothrow) SimpleTimerInfo(name, type, repeat, disposable, autoRestore,
116                                                                           interval, wantAgent);
117     if (simpleTimerInfo == nullptr) {
118         TIME_HILOGE(TIME_MODULE_SERVICE, "SimpleTimerInfo nullptr");
119         return nullptr;
120     }
121     return simpleTimerInfo;
122 }
123 } // namespace MiscServices
124 } // namespace OHOS