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/. */
7 #include "mozilla/dom/TVSource.h"
8 #include "mozilla/dom/TVTuner.h"
9 #include "mozilla/dom/TVUtils.h"
10 #include "TVListeners.h"
15 NS_IMPL_CYCLE_COLLECTION(TVSourceListener
, mSources
)
17 NS_IMPL_CYCLE_COLLECTING_ADDREF(TVSourceListener
)
18 NS_IMPL_CYCLE_COLLECTING_RELEASE(TVSourceListener
)
20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TVSourceListener
)
21 NS_INTERFACE_MAP_ENTRY(nsITVSourceListener
)
22 NS_INTERFACE_MAP_ENTRY(nsISupports
)
26 TVSourceListener::RegisterSource(TVSource
* aSource
)
28 mSources
.AppendElement(aSource
);
32 TVSourceListener::UnregisterSource(TVSource
* aSource
)
34 for (uint32_t i
= 0; i
< mSources
.Length(); i
++) {
35 if (mSources
[i
] == aSource
) {
36 mSources
.RemoveElementsAt(i
, 1);
41 /* virtual */ NS_IMETHODIMP
42 TVSourceListener::NotifyChannelScanned(const nsAString
& aTunerId
,
43 const nsAString
& aSourceType
,
44 nsITVChannelData
* aChannelData
)
46 nsRefPtr
<TVSource
> source
= GetSource(aTunerId
, aSourceType
);
47 source
->NotifyChannelScanned(aChannelData
);
51 /* virtual */ NS_IMETHODIMP
52 TVSourceListener::NotifyChannelScanComplete(const nsAString
& aTunerId
,
53 const nsAString
& aSourceType
)
55 nsRefPtr
<TVSource
> source
= GetSource(aTunerId
, aSourceType
);
56 source
->NotifyChannelScanComplete();
60 /* virtual */ NS_IMETHODIMP
61 TVSourceListener::NotifyChannelScanStopped(const nsAString
& aTunerId
,
62 const nsAString
& aSourceType
)
64 nsRefPtr
<TVSource
> source
= GetSource(aTunerId
, aSourceType
);
65 source
->NotifyChannelScanStopped();
69 /* virtual */ NS_IMETHODIMP
70 TVSourceListener::NotifyEITBroadcasted(const nsAString
& aTunerId
,
71 const nsAString
& aSourceType
,
72 nsITVChannelData
* aChannelData
,
73 nsITVProgramData
** aProgramDataList
,
74 const uint32_t aCount
)
76 nsRefPtr
<TVSource
> source
= GetSource(aTunerId
, aSourceType
);
77 source
->NotifyEITBroadcasted(aChannelData
, aProgramDataList
, aCount
);
81 already_AddRefed
<TVSource
>
82 TVSourceListener::GetSource(const nsAString
& aTunerId
,
83 const nsAString
& aSourceType
)
85 for (uint32_t i
= 0; i
< mSources
.Length(); i
++) {
87 nsRefPtr
<TVTuner
> tuner
= mSources
[i
]->Tuner();
88 tuner
->GetId(tunerId
);
90 nsString sourceType
= ToTVSourceTypeStr(mSources
[i
]->Type());
92 if (aTunerId
.Equals(tunerId
) && aSourceType
.Equals(sourceType
)) {
93 nsRefPtr
<TVSource
> source
= mSources
[i
];
94 return source
.forget();
102 } // namespace mozilla