Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/cpp/dev/alarms_dev.h" | |
| 6 | |
| 7 #include "ppapi/cpp/completion_callback.h" | |
| 8 #include "ppapi/cpp/dev/array_dev.h" | |
| 9 #include "ppapi/cpp/dev/to_c_type_converter_dev.h" | |
| 10 #include "ppapi/cpp/module_impl.h" | |
| 11 | |
| 12 namespace pp { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 template <> const char* interface_name<PPB_Alarms_Dev_0_1>() { | |
| 17 return PPB_ALARMS_DEV_INTERFACE_0_1; | |
| 18 } | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 namespace alarms { | |
| 23 | |
| 24 Alarm_Dev::Alarm_Dev() | |
| 25 : name_wrapper_(&storage_->name, NOT_OWNED), | |
| 26 period_in_minutes_wrapper_(&storage_->period_in_minutes, NOT_OWNED) { | |
| 27 } | |
| 28 | |
| 29 Alarm_Dev::Alarm_Dev(const Alarm_Dev& other) | |
| 30 : name_wrapper_(&storage_->name, NOT_OWNED), | |
| 31 period_in_minutes_wrapper_(&storage_->period_in_minutes, NOT_OWNED) { | |
| 32 operator=(other); | |
| 33 } | |
| 34 | |
| 35 Alarm_Dev::Alarm_Dev(const PP_Alarms_Alarm_Dev& other) | |
| 36 : name_wrapper_(&storage_->name, NOT_OWNED), | |
| 37 period_in_minutes_wrapper_(&storage_->period_in_minutes, NOT_OWNED) { | |
| 38 operator=(other); | |
| 39 } | |
| 40 | |
| 41 Alarm_Dev::Alarm_Dev(PP_Alarms_Alarm_Dev* storage, NotOwned) | |
| 42 : storage_(storage, NOT_OWNED), | |
| 43 name_wrapper_(&storage_->name, NOT_OWNED), | |
| 44 period_in_minutes_wrapper_(&storage_->period_in_minutes, NOT_OWNED) { | |
| 45 } | |
| 46 | |
| 47 Alarm_Dev::~Alarm_Dev() { | |
| 48 } | |
| 49 | |
| 50 Alarm_Dev& Alarm_Dev::operator=(const Alarm_Dev& other) { | |
| 51 return operator=(*other.storage_); | |
|
dmichael (off chromium)
2013/12/20 18:38:00
Hmm, this is kind of subtle (especially seeing as
yzshen1
2013/12/20 19:50:43
My thoughts when I designed this logic were:
- |st
dmichael (off chromium)
2013/12/20 22:01:09
I see, that's why it would be wrong to simply make
| |
| 52 } | |
| 53 | |
| 54 Alarm_Dev& Alarm_Dev::operator=(const PP_Alarms_Alarm_Dev& other) { | |
| 55 if (storage_.get() == &other) | |
| 56 return *this; | |
| 57 | |
| 58 name_wrapper_ = other.name; | |
| 59 storage_->scheduled_time = other.scheduled_time; | |
| 60 period_in_minutes_wrapper_ = other.period_in_minutes; | |
| 61 | |
| 62 return *this; | |
| 63 } | |
| 64 | |
| 65 std::string Alarm_Dev::name() const { | |
| 66 return name_wrapper_.get(); | |
| 67 } | |
| 68 | |
| 69 void Alarm_Dev::set_name(const std::string& value) { | |
| 70 name_wrapper_.set(value); | |
| 71 } | |
| 72 | |
| 73 double Alarm_Dev::scheduled_time() const { | |
| 74 return storage_->scheduled_time; | |
| 75 } | |
| 76 | |
| 77 void Alarm_Dev::set_scheduled_time(double value) { | |
| 78 storage_->scheduled_time = value; | |
| 79 } | |
| 80 | |
| 81 bool Alarm_Dev::is_period_in_minutes_set() const { | |
| 82 return period_in_minutes_wrapper_.is_set(); | |
| 83 } | |
| 84 | |
| 85 void Alarm_Dev::unset_period_in_minutes() { | |
| 86 period_in_minutes_wrapper_.unset(); | |
| 87 } | |
| 88 | |
| 89 double Alarm_Dev::period_in_minutes() const { | |
| 90 return period_in_minutes_wrapper_.get(); | |
| 91 } | |
| 92 | |
| 93 void Alarm_Dev::set_period_in_minutes(double value) { | |
| 94 period_in_minutes_wrapper_.set(value); | |
| 95 } | |
| 96 | |
| 97 const PP_Alarms_Alarm_Dev* Alarm_Dev::ToStruct() const { | |
| 98 return storage_.get(); | |
| 99 } | |
| 100 | |
| 101 PP_Alarms_Alarm_Dev* Alarm_Dev::StartRawUpdate() { | |
| 102 name_wrapper_.StartRawUpdate(); | |
| 103 period_in_minutes_wrapper_.StartRawUpdate(); | |
| 104 | |
| 105 return storage_.get(); | |
| 106 } | |
| 107 | |
| 108 void Alarm_Dev::EndRawUpdate() { | |
| 109 name_wrapper_.EndRawUpdate(); | |
| 110 period_in_minutes_wrapper_.EndRawUpdate(); | |
| 111 } | |
| 112 | |
| 113 AlarmCreateInfo_Dev::AlarmCreateInfo_Dev() | |
| 114 : when_wrapper_(&storage_->when, NOT_OWNED), | |
| 115 delay_in_minutes_wrapper_(&storage_->delay_in_minutes, NOT_OWNED), | |
| 116 period_in_minutes_wrapper_(&storage_->period_in_minutes, NOT_OWNED) { | |
| 117 } | |
| 118 | |
| 119 AlarmCreateInfo_Dev::AlarmCreateInfo_Dev(const AlarmCreateInfo_Dev& other) | |
| 120 : when_wrapper_(&storage_->when, NOT_OWNED), | |
| 121 delay_in_minutes_wrapper_(&storage_->delay_in_minutes, NOT_OWNED), | |
| 122 period_in_minutes_wrapper_(&storage_->period_in_minutes, NOT_OWNED) { | |
| 123 operator=(other); | |
| 124 } | |
| 125 | |
| 126 AlarmCreateInfo_Dev::AlarmCreateInfo_Dev( | |
| 127 const PP_Alarms_AlarmCreateInfo_Dev& other) | |
| 128 : when_wrapper_(&storage_->when, NOT_OWNED), | |
| 129 delay_in_minutes_wrapper_(&storage_->delay_in_minutes, NOT_OWNED), | |
| 130 period_in_minutes_wrapper_(&storage_->period_in_minutes, NOT_OWNED) { | |
| 131 operator=(other); | |
| 132 } | |
| 133 | |
| 134 AlarmCreateInfo_Dev::AlarmCreateInfo_Dev( | |
| 135 PP_Alarms_AlarmCreateInfo_Dev* storage, | |
| 136 NotOwned) | |
| 137 : storage_(storage, NOT_OWNED), | |
| 138 when_wrapper_(&storage_->when, NOT_OWNED), | |
| 139 delay_in_minutes_wrapper_(&storage_->delay_in_minutes, NOT_OWNED), | |
| 140 period_in_minutes_wrapper_(&storage_->period_in_minutes, NOT_OWNED) { | |
| 141 } | |
| 142 | |
| 143 AlarmCreateInfo_Dev::~AlarmCreateInfo_Dev() { | |
| 144 } | |
| 145 | |
| 146 AlarmCreateInfo_Dev& AlarmCreateInfo_Dev::operator=( | |
| 147 const AlarmCreateInfo_Dev& other) { | |
| 148 return operator=(*other.storage_); | |
| 149 } | |
| 150 | |
| 151 AlarmCreateInfo_Dev& AlarmCreateInfo_Dev::operator=( | |
| 152 const PP_Alarms_AlarmCreateInfo_Dev& other) { | |
| 153 if (storage_.get() == &other) | |
| 154 return *this; | |
| 155 | |
| 156 when_wrapper_ = other.when; | |
| 157 delay_in_minutes_wrapper_ = other.delay_in_minutes; | |
| 158 period_in_minutes_wrapper_ = other.period_in_minutes; | |
| 159 | |
| 160 return *this; | |
| 161 } | |
| 162 | |
| 163 bool AlarmCreateInfo_Dev::is_when_set() const { | |
| 164 return when_wrapper_.is_set(); | |
| 165 } | |
| 166 | |
| 167 void AlarmCreateInfo_Dev::unset_when() { | |
| 168 when_wrapper_.unset(); | |
| 169 } | |
| 170 | |
| 171 double AlarmCreateInfo_Dev::when() const { | |
| 172 return when_wrapper_.get(); | |
| 173 } | |
| 174 | |
| 175 void AlarmCreateInfo_Dev::set_when(double value) { | |
| 176 when_wrapper_.set(value); | |
| 177 } | |
| 178 | |
| 179 bool AlarmCreateInfo_Dev::is_delay_in_minutes_set() const { | |
| 180 return delay_in_minutes_wrapper_.is_set(); | |
| 181 } | |
| 182 | |
| 183 void AlarmCreateInfo_Dev::unset_delay_in_minutes() { | |
| 184 delay_in_minutes_wrapper_.unset(); | |
| 185 } | |
| 186 | |
| 187 double AlarmCreateInfo_Dev::delay_in_minutes() const { | |
| 188 return delay_in_minutes_wrapper_.get(); | |
| 189 } | |
| 190 | |
| 191 void AlarmCreateInfo_Dev::set_delay_in_minutes(double value) { | |
| 192 delay_in_minutes_wrapper_.set(value); | |
| 193 } | |
| 194 | |
| 195 bool AlarmCreateInfo_Dev::is_period_in_minutes_set() const { | |
| 196 return period_in_minutes_wrapper_.is_set(); | |
| 197 } | |
| 198 | |
| 199 void AlarmCreateInfo_Dev::unset_period_in_minutes() { | |
| 200 period_in_minutes_wrapper_.unset(); | |
| 201 } | |
| 202 | |
| 203 double AlarmCreateInfo_Dev::period_in_minutes() const { | |
| 204 return period_in_minutes_wrapper_.get(); | |
| 205 } | |
| 206 | |
| 207 void AlarmCreateInfo_Dev::set_period_in_minutes(double value) { | |
| 208 period_in_minutes_wrapper_.set(value); | |
| 209 } | |
| 210 | |
| 211 const PP_Alarms_AlarmCreateInfo_Dev* AlarmCreateInfo_Dev::ToStruct() const { | |
| 212 return storage_.get(); | |
| 213 } | |
| 214 | |
| 215 PP_Alarms_AlarmCreateInfo_Dev* AlarmCreateInfo_Dev::StartRawUpdate() { | |
| 216 when_wrapper_.StartRawUpdate(); | |
| 217 delay_in_minutes_wrapper_.StartRawUpdate(); | |
| 218 period_in_minutes_wrapper_.StartRawUpdate(); | |
| 219 | |
| 220 return storage_.get(); | |
| 221 } | |
| 222 | |
| 223 void AlarmCreateInfo_Dev::EndRawUpdate() { | |
| 224 when_wrapper_.EndRawUpdate(); | |
| 225 delay_in_minutes_wrapper_.EndRawUpdate(); | |
| 226 period_in_minutes_wrapper_.EndRawUpdate(); | |
| 227 } | |
| 228 | |
| 229 Alarms_Dev::Alarms_Dev(const InstanceHandle& instance) : instance_(instance) { | |
| 230 } | |
| 231 | |
| 232 Alarms_Dev::~Alarms_Dev() { | |
| 233 } | |
| 234 | |
| 235 void Alarms_Dev::Create(const Optional<std::string>& name, | |
| 236 const AlarmCreateInfo_Dev& alarm_info) { | |
| 237 if (!has_interface<PPB_Alarms_Dev_0_1>()) | |
| 238 return; | |
| 239 | |
| 240 internal::ToCTypeConverter<Optional<std::string> > name_converter(name); | |
| 241 internal::ToCTypeConverter<AlarmCreateInfo_Dev> alarm_info_converter( | |
| 242 alarm_info); | |
| 243 | |
| 244 return get_interface<PPB_Alarms_Dev_0_1>()->Create( | |
| 245 instance_.pp_instance(), | |
| 246 name_converter.ToCInput(), | |
| 247 alarm_info_converter.ToCInput()); | |
| 248 } | |
| 249 | |
| 250 int32_t Alarms_Dev::Get(const Optional<std::string>& name, | |
| 251 const GetCallback& callback) { | |
| 252 if (!has_interface<PPB_Alarms_Dev_0_1>()) | |
| 253 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
| 254 | |
| 255 internal::ToCTypeConverter<Optional<std::string> > name_converter(name); | |
| 256 | |
| 257 return get_interface<PPB_Alarms_Dev_0_1>()->Get( | |
| 258 instance_.pp_instance(), | |
| 259 name_converter.ToCInput(), | |
| 260 callback.output(), | |
| 261 callback.pp_completion_callback()); | |
| 262 } | |
| 263 | |
| 264 int32_t Alarms_Dev::GetAll(const GetAllCallback& callback) { | |
| 265 if (!has_interface<PPB_Alarms_Dev_0_1>()) | |
| 266 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
| 267 | |
| 268 return get_interface<PPB_Alarms_Dev_0_1>()->GetAll( | |
| 269 instance_.pp_instance(), | |
| 270 callback.output(), | |
| 271 internal::ArrayAllocator::Get(), | |
| 272 callback.pp_completion_callback()); | |
| 273 } | |
| 274 | |
| 275 void Alarms_Dev::Clear(const Optional<std::string>& name) { | |
| 276 if (!has_interface<PPB_Alarms_Dev_0_1>()) | |
| 277 return; | |
| 278 | |
| 279 internal::ToCTypeConverter<Optional<std::string> > name_converter(name); | |
| 280 | |
| 281 return get_interface<PPB_Alarms_Dev_0_1>()->Clear( | |
| 282 instance_.pp_instance(), | |
| 283 name_converter.ToCInput()); | |
| 284 } | |
| 285 | |
| 286 void Alarms_Dev::ClearAll() { | |
| 287 if (!has_interface<PPB_Alarms_Dev_0_1>()) | |
| 288 return; | |
| 289 | |
| 290 return get_interface<PPB_Alarms_Dev_0_1>()->ClearAll( | |
| 291 instance_.pp_instance()); | |
| 292 } | |
| 293 | |
| 294 } // namespace alarms | |
| 295 } // namespace pp | |
| OLD | NEW |