30 #include <nsIWritablePropertyBag2.h>
33 #include <sbIJobCancelable.h>
34 #include <sbIJobProgress.h>
35 #include <sbIDeviceEvent.h>
36 #include <sbIMediacoreEventListener.h>
37 #include <sbIMediacoreEvent.h>
38 #include <sbIMediacoreError.h>
39 #include <sbITranscodeError.h>
55 PRMonitor * aCompleteNotifyMonitor,
56 StatusProperty const & aStatusProperty,
61 aCompleteNotifyMonitor,
66 sbTranscodeProgressListener::sbTranscodeProgressListener(
70 PRMonitor * aCompleteNotifyMonitor,
71 StatusProperty
const & aStatusProperty,
73 mBaseDevice(aDeviceBase),
74 mStatus(aDeviceStatusHelper),
76 mCompleteNotifyMonitor(aCompleteNotifyMonitor),
79 mStatusProperty(aStatusProperty),
83 NS_ASSERTION(mBaseDevice,
84 "sbTranscodeProgressListener mBaseDevice can't be null");
86 "sbTranscodeProgressListener mStatus can't be null");
88 "sbTranscodeProgressListener mItem can't be null");
89 NS_ASSERTION(mCompleteNotifyMonitor,
90 "sbTranscodeProgressListener mCompleteNotifyMonitor "
93 NS_IF_ADDREF(static_cast<sbIDevice*>(mBaseDevice));
96 sbTranscodeProgressListener::~sbTranscodeProgressListener() {
98 NS_IF_RELEASE(disambiguate);
102 sbTranscodeProgressListener::Completed(
sbIJobProgress * aJobProgress) {
108 if (mCompleteNotifyMonitor) {
109 nsAutoMonitor monitor(mCompleteNotifyMonitor);
110 PR_AtomicSet(&mIsComplete, 1);
113 PR_AtomicSet(&mIsComplete, 1);
118 rv = aJobProgress->RemoveJobProgressListener(
this);
119 NS_ENSURE_SUCCESS(rv, rv);
127 sbTranscodeProgressListener::SetProgress(
sbIJobProgress * aJobProgress) {
130 NS_ENSURE_ARG_POINTER(aJobProgress);
133 rv = aJobProgress->GetTotal(&mTotal);
134 NS_ENSURE_SUCCESS(rv, rv);
138 rv = aJobProgress->GetProgress(&progress);
139 NS_ENSURE_SUCCESS(rv, rv);
141 double percentComplete = 0.0;
143 percentComplete =
static_cast<double>(progress) /
144 static_cast<double>(mTotal);
149 double const complete = percentComplete * 100.0;
152 SetStatusProperty(value);
158 sbTranscodeProgressListener::OnJobProgress(
sbIJobProgress *aJobProgress)
160 NS_ENSURE_ARG_POINTER(aJobProgress);
170 nsCOMPtr<sbIJobCancelable> cancel = mCancel;
177 rv = SetStatusProperty(value);
178 NS_ENSURE_SUCCESS(rv, rv);
180 rv = Completed(aJobProgress);
181 NS_ENSURE_SUCCESS(rv, rv);
186 nsresult rv = aJobProgress->GetStatus(&status);
187 NS_ENSURE_SUCCESS(rv, rv);
192 SetStatusProperty(value);
194 rv = Completed(aJobProgress);
195 NS_ENSURE_SUCCESS(rv, rv);
202 SetStatusProperty(value);
204 rv = Completed(aJobProgress);
205 NS_ENSURE_SUCCESS(rv, rv);
210 rv = SetProgress(aJobProgress);
211 NS_ENSURE_SUCCESS(rv, rv);
216 NS_WARNING(
"Unexpected progress state in "
217 "sbTranscodeProgressListener::OnJobProgress");
226 sbTranscodeProgressListener::SetStatusProperty(
230 NS_ENSURE_SUCCESS(rv, rv);
238 NS_ENSURE_STATE(mItem);
239 NS_ENSURE_ARG_POINTER(aEvent);
244 rv = aEvent->GetType(&type);
245 NS_ENSURE_SUCCESS(rv, rv);
248 nsCOMPtr<sbIMediacoreError> error;
249 rv = aEvent->GetError(getter_AddRefs(error));
250 NS_ENSURE_SUCCESS(rv, rv);
253 nsCOMPtr<nsIWritablePropertyBag2> bag =
254 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/sbpropertybag;1", &rv);
255 NS_ENSURE_SUCCESS(rv, rv);
258 rv = error->GetMessage(message);
259 if (NS_SUCCEEDED(rv)) {
260 rv = bag->SetPropertyAsAString(NS_LITERAL_STRING(
"message"),
262 NS_ENSURE_SUCCESS(rv, rv);
264 rv = bag->SetPropertyAsInterface(NS_LITERAL_STRING(
"mediacore-error"),
266 NS_ENSURE_SUCCESS(rv, rv);
270 if (NS_SUCCEEDED(rv)) {
271 nsCOMPtr<sbITranscodeError> transcodeError;
275 getter_AddRefs(transcodeError));
276 NS_ENSURE_SUCCESS(rv, rv);
277 rv = transcodeError->SetDestItem(mItem);
278 NS_ENSURE_SUCCESS(rv, rv);
279 rv = bag->SetPropertyAsInterface(NS_LITERAL_STRING(
"transcode-error"),
281 NS_ENSURE_SUCCESS(rv, rv);
nsresult CreateAndDispatchEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE, sbIDeviceEventTarget *aTarget=nsnull)
nsresult SB_NewTranscodeError(const nsAString &aMessageWithItem, const nsAString &aMessageWithoutItem, const nsAString &aDetails, const nsAString &aUri, sbIMediaItem *aMediaItem, sbITranscodeError **_retval)
Generic interface for exposing long running jobs to the UI.
NS_IMPL_THREADSAFE_ISUPPORTS2(sbTranscodeProgressListener, sbIJobProgressListener, sbIMediacoreEventListener) sbTranscodeProgressListener *sbTranscodeProgressListener
const unsigned short STATUS_SUCCEEDED
Constant indicating that the job has completed.
Songbird Variant Utility Definitions.
virtual PRBool IsRequestAborted()
nsString GetValue() const
const unsigned short STATUS_RUNNING
Constant indicating that the job is active.
const unsigned long EVENT_DEVICE_TRANSCODE_ERROR
void ItemProgress(double aProgress)
Songbird Device Status Services Definitions.
Implemented to receive notifications from sbIJobProgress interfaces.
void SetCurrent(PRUint32 aCurrent)
#define SB_PROPERTY_CONTENTURL
nsresult SetValue(nsAString const &aValue)
const unsigned short STATUS_FAILED
Constant indicating that the job has completed with errors.