summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/extensions/event_base.cc
blob: 210b213d0e35353bcd451622fd3f737a8758132a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/cpp/extensions/event_base.h"

#include "ppapi/cpp/extensions/dev/events_dev.h"

namespace pp {
namespace ext {
namespace internal {

GenericEventBase::GenericEventBase(
    const InstanceHandle& instance,
    const PP_Ext_EventListener& pp_listener)
    : instance_(instance),
      listener_id_(0),
      pp_listener_(pp_listener) {
}

GenericEventBase::~GenericEventBase() {
  StopListening();
}

bool GenericEventBase::StartListening() {
  if (IsListening())
    return true;

  listener_id_ = events::Events_Dev::AddListener(instance_.pp_instance(),
                                                 pp_listener_);
  return IsListening();
}

void GenericEventBase::StopListening() {
  if (!IsListening())
    return;

  events::Events_Dev::RemoveListener(instance_.pp_instance(), listener_id_);
  listener_id_ = 0;
}

}  // namespace internal
}  // namespace ext
}  // namespace pp