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 #ifndef PPAPI_CPP_DEV_ALARMS_DEV_H_ | |
| 6 #define PPAPI_CPP_DEV_ALARMS_DEV_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "ppapi/c/dev/ppb_alarms_dev.h" | |
| 11 #include "ppapi/cpp/dev/may_own_ptr_dev.h" | |
| 12 #include "ppapi/cpp/dev/optional_dev.h" | |
| 13 #include "ppapi/cpp/dev/string_wrapper_dev.h" | |
| 14 #include "ppapi/cpp/dev/struct_wrapper_output_traits_dev.h" | |
| 15 #include "ppapi/cpp/instance_handle.h" | |
| 16 #include "ppapi/cpp/output_traits.h" | |
| 17 | |
| 18 namespace pp { | |
| 19 | |
| 20 template <typename T> | |
| 21 class CompletionCallbackWithOutput; | |
| 22 | |
| 23 template <typename T> | |
| 24 class Array; | |
| 25 | |
| 26 namespace alarms { | |
| 27 | |
| 28 // Data types ------------------------------------------------------------------ | |
| 29 class Alarm_Dev { | |
| 30 public: | |
| 31 typedef PP_Alarms_Alarm_Dev CType; | |
| 32 typedef PP_Alarms_Alarm_Array_Dev CArrayType; | |
| 33 | |
| 34 Alarm_Dev(); | |
| 35 | |
| 36 Alarm_Dev(const Alarm_Dev& other); | |
| 37 | |
| 38 explicit Alarm_Dev(const PP_Alarms_Alarm_Dev& other); | |
| 39 | |
| 40 // Creates an accessor to |storage| but doesn't take ownership of it. | |
| 41 // |storage| must live longer than this object. The contents pointed to by | |
| 42 // |storage| must be zero-initialized by the caller. | |
| 43 Alarm_Dev(PP_Alarms_Alarm_Dev* storage, NotOwned); | |
| 44 | |
| 45 ~Alarm_Dev(); | |
| 46 | |
| 47 Alarm_Dev& operator=(const Alarm_Dev& other); | |
| 48 Alarm_Dev& operator=(const PP_Alarms_Alarm_Dev& other); | |
| 49 | |
| 50 std::string name() const; | |
| 51 void set_name(const std::string& value); | |
| 52 | |
| 53 double scheduled_time() const; | |
| 54 void set_scheduled_time(double value); | |
| 55 | |
| 56 bool is_period_in_minutes_set() const; | |
|
Sam McNally
2013/12/22 22:44:33
I would prefer has_period_in_minutes() and clear_p
yzshen1
2013/12/26 19:19:51
IMO, it is good to match the definition of PP_Opti
Sam McNally
2014/01/05 23:45:12
They aren't related, but they have a similar feel
| |
| 57 void unset_period_in_minutes(); | |
| 58 double period_in_minutes() const; | |
| 59 void set_period_in_minutes(double value); | |
| 60 | |
| 61 const PP_Alarms_Alarm_Dev* ToStruct() const; | |
| 62 | |
| 63 // The returned pointer is still owned by this object. And after it is used, | |
| 64 // EndRawUpdate() must be called. | |
| 65 PP_Alarms_Alarm_Dev* StartRawUpdate(); | |
| 66 void EndRawUpdate(); | |
| 67 | |
| 68 private: | |
| 69 internal::MayOwnPtr<PP_Alarms_Alarm_Dev> storage_; | |
| 70 | |
| 71 internal::StringWrapper name_wrapper_; | |
| 72 Optional<double> period_in_minutes_wrapper_; | |
| 73 }; | |
| 74 | |
| 75 class AlarmCreateInfo_Dev { | |
| 76 public: | |
| 77 typedef PP_Alarms_AlarmCreateInfo_Dev CType; | |
| 78 | |
| 79 AlarmCreateInfo_Dev(); | |
| 80 | |
| 81 AlarmCreateInfo_Dev(const AlarmCreateInfo_Dev& other); | |
| 82 | |
| 83 explicit AlarmCreateInfo_Dev(const PP_Alarms_AlarmCreateInfo_Dev& other); | |
| 84 | |
| 85 // Creates an accessor to |storage| but doesn't take ownership of it. | |
| 86 // |storage| must live longer than this object. The contents pointed to by | |
| 87 // |storage| must be zero-initialized by the caller. | |
| 88 AlarmCreateInfo_Dev(PP_Alarms_AlarmCreateInfo_Dev* storage, NotOwned); | |
| 89 | |
| 90 ~AlarmCreateInfo_Dev(); | |
| 91 | |
| 92 AlarmCreateInfo_Dev& operator=(const AlarmCreateInfo_Dev& other); | |
| 93 AlarmCreateInfo_Dev& operator=(const PP_Alarms_AlarmCreateInfo_Dev& other); | |
| 94 | |
| 95 bool is_when_set() const; | |
| 96 void unset_when(); | |
| 97 double when() const; | |
| 98 void set_when(double value); | |
| 99 | |
| 100 bool is_delay_in_minutes_set() const; | |
| 101 void unset_delay_in_minutes(); | |
| 102 double delay_in_minutes() const; | |
| 103 void set_delay_in_minutes(double value); | |
| 104 | |
| 105 bool is_period_in_minutes_set() const; | |
| 106 void unset_period_in_minutes(); | |
| 107 double period_in_minutes() const; | |
| 108 void set_period_in_minutes(double value); | |
| 109 | |
| 110 const PP_Alarms_AlarmCreateInfo_Dev* ToStruct() const; | |
| 111 | |
| 112 // The returned pointer is still owned by this object. And after it is used, | |
| 113 // EndRawUpdate() must be called. | |
| 114 PP_Alarms_AlarmCreateInfo_Dev* StartRawUpdate(); | |
| 115 void EndRawUpdate(); | |
| 116 | |
| 117 private: | |
| 118 internal::MayOwnPtr<PP_Alarms_AlarmCreateInfo_Dev> storage_; | |
| 119 | |
| 120 Optional<double> when_wrapper_; | |
| 121 Optional<double> delay_in_minutes_wrapper_; | |
| 122 Optional<double> period_in_minutes_wrapper_; | |
| 123 }; | |
| 124 | |
| 125 // Functions ------------------------------------------------------------------- | |
| 126 class Alarms_Dev { | |
| 127 public: | |
| 128 explicit Alarms_Dev(const InstanceHandle& instance); | |
| 129 ~Alarms_Dev(); | |
| 130 | |
| 131 void Create(const Optional<std::string>& name, | |
| 132 const AlarmCreateInfo_Dev& alarm_info); | |
| 133 | |
| 134 typedef CompletionCallbackWithOutput<Alarm_Dev> GetCallback; | |
| 135 int32_t Get(const Optional<std::string>& name, const GetCallback& callback); | |
| 136 | |
| 137 typedef CompletionCallbackWithOutput<Array<Alarm_Dev> > GetAllCallback; | |
| 138 int32_t GetAll(const GetAllCallback& callback); | |
| 139 | |
| 140 void Clear(const Optional<std::string>& name); | |
| 141 | |
| 142 void ClearAll(); | |
| 143 | |
| 144 private: | |
| 145 InstanceHandle instance_; | |
| 146 }; | |
| 147 | |
| 148 // Events ---------------------------------------------------------------------- | |
| 149 // TODO(yzshen): add onAlarm event. | |
| 150 | |
| 151 } // namespace alarms | |
| 152 | |
| 153 namespace internal { | |
| 154 | |
| 155 template <> | |
| 156 struct CallbackOutputTraits<alarms::Alarm_Dev> | |
| 157 : public internal::StructWrapperOutputTraits<alarms::Alarm_Dev> { | |
| 158 }; | |
| 159 | |
| 160 template <> | |
| 161 struct CallbackOutputTraits<alarms::AlarmCreateInfo_Dev> | |
| 162 : public internal::StructWrapperOutputTraits<alarms::AlarmCreateInfo_Dev> { | |
| 163 }; | |
| 164 | |
| 165 } // namespace internal | |
| 166 } // namespace pp | |
| 167 | |
| 168 #endif // PPAPI_CPP_DEV_ALARMS_DEV_H_ | |
| OLD | NEW |