Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/Observer.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_Observer_h
8
#define mozilla_Observer_h
9
10
#include "nsTObserverArray.h"
11
12
namespace mozilla {
13
14
/**
15
 * Observer<T> provides a way for a class to observe something.
16
 * When an event has to be broadcasted to all Observer<T>, Notify() method
17
 * is called.
18
 * T represents the type of the object passed in argument to Notify().
19
 *
20
 * @see ObserverList.
21
 */
22
template<class T>
23
class Observer
24
{
25
public:
26
0
  virtual ~Observer() {}
Unexecuted instantiation: mozilla::Observer<mozilla::hal::BatteryInformation>::~Observer()
Unexecuted instantiation: mozilla::Observer<mozilla::hal::NetworkInformation>::~Observer()
Unexecuted instantiation: mozilla::Observer<mozilla::hal::SensorData>::~Observer()
Unexecuted instantiation: mozilla::Observer<mozilla::hal::WakeLockInformation>::~Observer()
Unexecuted instantiation: mozilla::Observer<mozilla::hal::ScreenConfiguration>::~Observer()
Unexecuted instantiation: mozilla::Observer<mozilla::dom::MIDIPortList>::~Observer()
Unexecuted instantiation: mozilla::Observer<mozilla::void_t>::~Observer()
27
  virtual void Notify(const T& aParam) = 0;
28
};
29
30
/**
31
 * ObserverList<T> tracks Observer<T> and can notify them when Broadcast() is
32
 * called.
33
 * T represents the type of the object passed in argument to Broadcast() and
34
 * sent to Observer<T> objects through Notify().
35
 *
36
 * @see Observer.
37
 */
38
template<class T>
39
class ObserverList
40
{
41
public:
42
  /**
43
   * Note: When calling AddObserver, it's up to the caller to make sure the
44
   * object isn't going to be release as long as RemoveObserver hasn't been
45
   * called.
46
   *
47
   * @see RemoveObserver()
48
   */
49
  void AddObserver(Observer<T>* aObserver)
50
0
  {
51
0
    mObservers.AppendElementUnlessExists(aObserver);
52
0
  }
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::BatteryInformation>::AddObserver(mozilla::Observer<mozilla::hal::BatteryInformation>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::SensorData>::AddObserver(mozilla::Observer<mozilla::hal::SensorData>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::NetworkInformation>::AddObserver(mozilla::Observer<mozilla::hal::NetworkInformation>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::WakeLockInformation>::AddObserver(mozilla::Observer<mozilla::hal::WakeLockInformation>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::ScreenConfiguration>::AddObserver(mozilla::Observer<mozilla::hal::ScreenConfiguration>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::void_t>::AddObserver(mozilla::Observer<mozilla::void_t>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::dom::MIDIPortList>::AddObserver(mozilla::Observer<mozilla::dom::MIDIPortList>*)
53
54
  /**
55
   * Remove the observer from the observer list.
56
   * @return Whether the observer has been found in the list.
57
   */
58
  bool RemoveObserver(Observer<T>* aObserver)
59
0
  {
60
0
    return mObservers.RemoveElement(aObserver);
61
0
  }
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::BatteryInformation>::RemoveObserver(mozilla::Observer<mozilla::hal::BatteryInformation>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::SensorData>::RemoveObserver(mozilla::Observer<mozilla::hal::SensorData>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::NetworkInformation>::RemoveObserver(mozilla::Observer<mozilla::hal::NetworkInformation>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::WakeLockInformation>::RemoveObserver(mozilla::Observer<mozilla::hal::WakeLockInformation>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::ScreenConfiguration>::RemoveObserver(mozilla::Observer<mozilla::hal::ScreenConfiguration>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::void_t>::RemoveObserver(mozilla::Observer<mozilla::void_t>*)
Unexecuted instantiation: mozilla::ObserverList<mozilla::dom::MIDIPortList>::RemoveObserver(mozilla::Observer<mozilla::dom::MIDIPortList>*)
62
63
  uint32_t Length()
64
0
  {
65
0
    return mObservers.Length();
66
0
  }
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::BatteryInformation>::Length()
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::SensorData>::Length()
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::NetworkInformation>::Length()
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::WakeLockInformation>::Length()
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::ScreenConfiguration>::Length()
Unexecuted instantiation: mozilla::ObserverList<mozilla::dom::MIDIPortList>::Length()
67
68
  /**
69
   * Call Notify() on each item in the list.
70
   */
71
  void Broadcast(const T& aParam)
72
0
  {
73
0
    typename nsTObserverArray<Observer<T>*>::ForwardIterator iter(mObservers);
74
0
    while (iter.HasMore()) {
75
0
      Observer<T>* obs = iter.GetNext();
76
0
      obs->Notify(aParam);
77
0
    }
78
0
  }
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::BatteryInformation>::Broadcast(mozilla::hal::BatteryInformation const&)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::SensorData>::Broadcast(mozilla::hal::SensorData const&)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::NetworkInformation>::Broadcast(mozilla::hal::NetworkInformation const&)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::WakeLockInformation>::Broadcast(mozilla::hal::WakeLockInformation const&)
Unexecuted instantiation: mozilla::ObserverList<mozilla::hal::ScreenConfiguration>::Broadcast(mozilla::hal::ScreenConfiguration const&)
Unexecuted instantiation: mozilla::ObserverList<mozilla::void_t>::Broadcast(mozilla::void_t const&)
Unexecuted instantiation: mozilla::ObserverList<mozilla::dom::MIDIPortList>::Broadcast(mozilla::dom::MIDIPortList const&)
79
80
protected:
81
  nsTObserverArray<Observer<T>*> mObservers;
82
};
83
84
} // namespace mozilla
85
86
#endif // mozilla_Observer_h