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_EXTENSIONS_DEV_ALARMS_DEV_H_ | |
6 #define PPAPI_CPP_EXTENSIONS_DEV_ALARMS_DEV_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "ppapi/c/extensions/dev/ppb_ext_alarms_dev.h" | |
12 #include "ppapi/cpp/extensions/dict_field.h" | |
13 #include "ppapi/cpp/extensions/event_base.h" | |
14 #include "ppapi/cpp/extensions/ext_output_traits.h" | |
15 #include "ppapi/cpp/instance_handle.h" | |
16 #include "ppapi/cpp/var.h" | |
17 | |
18 namespace pp { | |
19 namespace ext { | |
20 | |
21 template <class T> | |
22 class ExtCompletionCallbackWithOutput; | |
23 | |
24 template <class T> | |
25 class Optional; | |
26 | |
27 namespace alarms { | |
28 | |
29 // Data types ------------------------------------------------------------------ | |
30 class Alarm_Dev { | |
31 public: | |
32 Alarm_Dev(); | |
33 ~Alarm_Dev(); | |
34 | |
35 bool Populate(const PP_Ext_Alarms_Alarm_Dev& value); | |
36 | |
37 Var CreateVar() const; | |
38 | |
39 static const char* const kName; | |
40 static const char* const kScheduledTime; | |
41 static const char* const kPeriodInMinutes; | |
42 | |
43 DictField<std::string> name; | |
44 DictField<double> scheduled_time; | |
45 OptionalDictField<double> period_in_minutes; | |
46 }; | |
47 | |
48 class AlarmCreateInfo_Dev { | |
49 public: | |
50 AlarmCreateInfo_Dev(); | |
51 ~AlarmCreateInfo_Dev(); | |
52 | |
53 bool Populate(const PP_Ext_Alarms_AlarmCreateInfo_Dev& value); | |
54 | |
55 Var CreateVar() const; | |
56 | |
57 static const char* const kWhen; | |
58 static const char* const kDelayInMinutes; | |
59 static const char* const kPeriodInMinutes; | |
60 | |
61 OptionalDictField<double> when; | |
62 OptionalDictField<double> delay_in_minutes; | |
63 OptionalDictField<double> period_in_minutes; | |
64 }; | |
65 | |
66 // Functions ------------------------------------------------------------------- | |
67 class Alarms_Dev { | |
68 public: | |
69 explicit Alarms_Dev(const InstanceHandle& instance); | |
70 ~Alarms_Dev(); | |
71 | |
72 void Create(const Optional<std::string>& name, | |
73 const AlarmCreateInfo_Dev& alarm_info); | |
74 | |
75 typedef ExtCompletionCallbackWithOutput<Alarm_Dev> GetCallback; | |
76 int32_t Get(const Optional<std::string>& name, const GetCallback& callback); | |
77 | |
78 typedef ExtCompletionCallbackWithOutput<std::vector<Alarm_Dev> > | |
79 GetAllCallback; | |
80 int32_t GetAll(const GetAllCallback& callback); | |
81 | |
82 void Clear(const Optional<std::string>& name); | |
83 | |
84 void ClearAll(); | |
85 | |
86 private: | |
87 InstanceHandle instance_; | |
88 }; | |
89 | |
90 // Events ---------------------------------------------------------------------- | |
91 // Please see ppapi/cpp/extensions/event_base.h for how to use an event class. | |
92 | |
93 class OnAlarmEvent_Dev | |
94 : public internal::EventBase1<PP_Ext_Alarms_OnAlarm_Dev, Alarm_Dev> { | |
95 public: | |
96 class Listener { | |
97 public: | |
98 virtual ~Listener() {} | |
99 | |
100 virtual void OnAlarm(Alarm_Dev& alarm) = 0; | |
101 }; | |
102 | |
103 // |listener| is not owned by this instance and must outlive it. | |
104 OnAlarmEvent_Dev(const InstanceHandle& instance, Listener* listener); | |
105 virtual ~OnAlarmEvent_Dev(); | |
106 | |
107 private: | |
108 virtual void Callback(Alarm_Dev& alarm); | |
109 | |
110 Listener* listener_; | |
111 }; | |
112 | |
113 } // namespace alarms | |
114 } // namespace ext | |
115 } // namespace pp | |
116 | |
117 #endif // PPAPI_CPP_EXTENSIONS_DEV_ALARMS_DEV_H_ | |
OLD | NEW |