sbTranscodeError.cpp
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #include "sbTranscodeError.h"
26 
27 #include <nsIFile.h>
28 #include <nsIFileURL.h>
29 #include <nsIURI.h>
30 
31 #include <sbIMediaItem.h>
32 #include <sbITranscodeManager.h>
33 
34 #include <nsComponentManagerUtils.h>
35 #include <nsNetUtil.h>
36 #include <nsServiceManagerUtils.h>
37 #include <nsTArray.h>
38 
39 #include <sbStandardProperties.h>
40 #include <sbStringUtils.h>
41 
44  nsIScriptError,
45  nsIConsoleMessage,
47  nsISupportsPrimitive)
48 
50  :mLock(nsnull)
51 {
52  /* member initializers and constructor code */
53 }
54 
55 sbTranscodeError::~sbTranscodeError()
56 {
57  if (mLock) {
58  nsAutoLock::DestroyLock(mLock);
59  }
60  /* destructor code */
61 }
62 
63 /***** nsIConsoleMessage *****/
64 
65 /* [binaryname (MessageMoz)] readonly attribute wstring message; */
66 NS_IMETHODIMP
67 sbTranscodeError::GetMessageMoz(PRUnichar * *aMessage)
68 {
69  NS_ENSURE_ARG_POINTER(aMessage);
70  nsString message;
71  nsresult rv = GetData(message);
72  NS_ENSURE_SUCCESS(rv, rv);
73  *aMessage = ToNewUnicode(message);
74  NS_ENSURE_TRUE(*aMessage, NS_ERROR_OUT_OF_MEMORY);
75  return NS_OK;
76 }
77 
78 /***** nsIScriptError *****/
79 /* readonly attribute AString errorMessage; */
80 NS_IMETHODIMP
81 sbTranscodeError::GetErrorMessage(nsAString & aErrorMessage)
82 {
83  nsCString message;
84  nsresult rv = GetData(aErrorMessage);
85  NS_ENSURE_SUCCESS(rv, rv);
86  return NS_OK;
87 }
88 
89 /* readonly attribute AString sourceName; */
90 NS_IMETHODIMP
91 sbTranscodeError::GetSourceName(nsAString & aSourceName)
92 {
93  aSourceName.Assign(mSrcUri);
94  return NS_OK;
95 }
96 
97 /* readonly attribute AString sourceLine; */
98 NS_IMETHODIMP
99 sbTranscodeError::GetSourceLine(nsAString & aSourceLine)
100 {
101  return GetDetail(aSourceLine);
102 }
103 
104 /* readonly attribute PRUint32 lineNumber; */
105 NS_IMETHODIMP
106 sbTranscodeError::GetLineNumber(PRUint32 *aLineNumber)
107 {
108  NS_ENSURE_ARG_POINTER(aLineNumber);
109  *aLineNumber = 0;
110  return NS_OK;
111 }
112 
113 /* readonly attribute PRUint32 columnNumber; */
114 NS_IMETHODIMP
115 sbTranscodeError::GetColumnNumber(PRUint32 *aColumnNumber)
116 {
117  NS_ENSURE_ARG_POINTER(aColumnNumber);
118  *aColumnNumber = 0;
119  return NS_OK;
120 }
121 
122 /* readonly attribute PRUint32 flags; */
123 NS_IMETHODIMP
124 sbTranscodeError::GetFlags(PRUint32 *aFlags)
125 {
126  NS_ENSURE_ARG_POINTER(aFlags);
127  *aFlags = nsIScriptError::errorFlag;
128  return NS_OK;
129 }
130 
131 /* readonly attribute string category; */
132 NS_IMETHODIMP
133 sbTranscodeError::GetCategory(char * *aCategory)
134 {
135  NS_ENSURE_ARG_POINTER(aCategory);
136  *aCategory = ToNewCString(NS_LITERAL_CSTRING("songbird transcode"));
137  return NS_OK;
138 }
139 
140 /* void init (in wstring message,
141  * in wstring sourceName,
142  * in wstring sourceLine,
143  * in PRUint32 lineNumber,
144  * in PRUint32 columnNumber,
145  * in PRUint32 flags,
146  * in string category); */
147 NS_IMETHODIMP
148 sbTranscodeError::Init(const PRUnichar *message,
149  const PRUnichar *sourceName,
150  const PRUnichar *sourceLine,
151  PRUint32 lineNumber,
152  PRUint32 columnNumber,
153  PRUint32 flags,
154  const char *category)
155 {
156  /* This doesn't make sense for this object */
157  return NS_ERROR_NOT_IMPLEMENTED;
158 }
159 
160 /* AUTF8String toString (); */
161 NS_IMETHODIMP
162 sbTranscodeError::ToString(nsACString & _retval)
163 {
164  nsString result;
165  nsresult rv = GetData(result);
166  NS_ENSURE_SUCCESS(rv, rv);
167  CopyUTF16toUTF8(result, _retval);
168  return NS_OK;
169 }
170 
171 /***** nsISupportsString *****/
172 /* attribute AString data; */
173 NS_IMETHODIMP
174 sbTranscodeError::GetData(nsAString & aData)
175 {
176  nsresult rv;
177  nsString spec;
178  nsCOMPtr<nsIURI> uri;
179  nsCOMPtr<sbIMediaItem> item;
180  {
181  /* scope, avoid locking for too long */
182  nsAutoLock lock(mLock);
183  spec = mSrcUri;
184  item = mSrcItem;
185  if (!item) item = mDestItem;
186  }
187 
188  nsString title, key(mMessageWithoutItem);
189  if (item) {
190  rv = item->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_TRACKNAME),
191  title);
192  NS_ENSURE_SUCCESS(rv, rv);
193  CompressWhitespace(title);
194  if (!title.IsEmpty()) {
196  }
197  }
198 
199  if (title.IsEmpty() && !spec.IsEmpty()) {
200  rv = NS_NewURI(getter_AddRefs(uri), spec);
201  NS_ENSURE_SUCCESS(rv, rv);
202  nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(uri, &rv);
203  if (NS_SUCCEEDED(rv) && fileUrl) {
204  nsCOMPtr<nsIFile> file;
205  rv = fileUrl->GetFile(getter_AddRefs(file));
206  NS_ENSURE_SUCCESS(rv, rv);
207  rv = file->GetPath(title);
208  NS_ENSURE_SUCCESS(rv, rv);
209  }
210  else {
211  title = spec;
212  }
213  }
214 
215  if (title.IsEmpty()) {
216  title = SBLocalizedString("transcode.error.item.unknown");
217  }
218 
219  aData.Assign(SBLocalizedString(key));
220  NS_NAMED_LITERAL_STRING(REPLACE_KEY, "%(item)");
221  PRInt32 index = aData.Find(REPLACE_KEY);
222  if (index > -1) {
223  aData.Replace(index, REPLACE_KEY.Length(), title);
224  }
225  return NS_OK;
226 }
227 NS_IMETHODIMP
228 sbTranscodeError::SetData(const nsAString & aData)
229 {
230  /* setting the string doesn't make any sense */
231  return NS_ERROR_NOT_IMPLEMENTED;
232 }
233 
234 /* wstring toString (); */
235 NS_IMETHODIMP
236 sbTranscodeError::ToString(PRUnichar **_retval)
237 {
238  NS_ENSURE_ARG_POINTER(_retval);
239  nsString message;
240  nsresult rv = GetData(message);
241  NS_ENSURE_SUCCESS(rv, rv);
242  *_retval = ToNewUnicode(message);
243  NS_ENSURE_TRUE(*_retval, NS_ERROR_OUT_OF_MEMORY);
244  return NS_OK;
245 }
246 
247 /***** nsISupportsPrimitive *****/
248 
249 /* readonly attribute unsigned short type; */
250 NS_IMETHODIMP
251 sbTranscodeError::GetType(PRUint16 *aType)
252 {
253  NS_ENSURE_ARG_POINTER(aType);
254  *aType = nsISupportsPrimitive::TYPE_STRING;
255  return NS_OK;
256 }
257 
258 /***** sbITranscodeError *****/
259 
260 /* readonly attribute AString messageWithItem; */
261 NS_IMETHODIMP
262 sbTranscodeError::GetMessageWithItem(nsAString & aMessageWithItem)
263 {
264  nsAutoLock lock(mLock);
265  aMessageWithItem.Assign(mMessageWithItem);
266  return NS_OK;
267 }
268 
269 /* readonly attribute AString messageWithoutItem; */
270 NS_IMETHODIMP
271 sbTranscodeError::GetMessageWithoutItem(nsAString & aMessageWithoutItem)
272 {
273  nsAutoLock lock(mLock);
274  aMessageWithoutItem.Assign(mMessageWithoutItem);
275  return NS_OK;
276 }
277 
278 /* readonly attribute AString details; */
279 NS_IMETHODIMP
280 sbTranscodeError::GetDetail(nsAString & aDetails)
281 {
282  nsAutoLock lock(mLock);
283  aDetails.Assign(mDetails);
284  return NS_OK;
285 }
286 
287 /* attribute AString sourceUri; */
288 NS_IMETHODIMP
289 sbTranscodeError::GetSourceUri(nsAString & aSourceUri)
290 {
291  nsAutoLock lock(mLock);
292  aSourceUri.Assign(mSrcUri);
293  return NS_OK;
294 }
295 NS_IMETHODIMP
296 sbTranscodeError::SetSourceUri(const nsAString & aSourceUri)
297 {
298  nsAutoLock lock(mLock);
299  mSrcUri.Assign(aSourceUri);
300  return NS_OK;
301 }
302 
303 /* attribute sbIMediaItem sourceItem; */
304 NS_IMETHODIMP
305 sbTranscodeError::GetSourceItem(sbIMediaItem * *aSourceItem)
306 {
307  NS_ENSURE_ARG_POINTER(aSourceItem);
308  nsAutoLock lock(mLock);
309  NS_IF_ADDREF(*aSourceItem = mSrcItem);
310  return NS_OK;
311 }
312 NS_IMETHODIMP
313 sbTranscodeError::SetSourceItem(sbIMediaItem * aSourceItem)
314 {
315  nsAutoLock lock(mLock);
316  mSrcItem = aSourceItem;
317  return NS_OK;
318 }
319 
320 /* attribute AString destUri; */
321 NS_IMETHODIMP
322 sbTranscodeError::GetDestUri(nsAString & aDestUri)
323 {
324  nsAutoLock lock(mLock);
325  aDestUri.Assign(mDestUri);
326  return NS_OK;
327 }
328 NS_IMETHODIMP
329 sbTranscodeError::SetDestUri(const nsAString & aDestUri)
330 {
331  nsAutoLock lock(mLock);
332  mDestUri.Assign(aDestUri);
333  return NS_OK;
334 }
335 
336 /* attribute sbIMediaItem destItem; */
337 NS_IMETHODIMP
338 sbTranscodeError::GetDestItem(sbIMediaItem * *aDestItem)
339 {
340  NS_ENSURE_ARG_POINTER(aDestItem);
341  nsAutoLock lock(mLock);
342  NS_IF_ADDREF(*aDestItem = mDestItem);
343  return NS_OK;
344 }
345 NS_IMETHODIMP
346 sbTranscodeError::SetDestItem(sbIMediaItem * aDestItem)
347 {
348  nsAutoLock lock(mLock);
349  mDestItem = aDestItem;
350  return NS_OK;
351 }
352 
353 /* void init (in AString aMessageWithItem,
354  * in AString aMessageWithoutItem,
355  * in AString aDetails,
356  * in PRUint32 aSeverity); */
357 NS_IMETHODIMP
358 sbTranscodeError::Init(const nsAString & aMessageWithItem,
359  const nsAString & aMessageWithoutItem,
360  const nsAString & aDetails)
361 {
362  NS_ENSURE_FALSE(mLock, NS_ERROR_ALREADY_INITIALIZED);
363  mLock = nsAutoLock::NewLock("sbTranscodeError::mLock");
364  NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
365  nsAutoLock lock(mLock);
366  mMessageWithItem.Assign(aMessageWithItem);
367  mMessageWithoutItem.Assign(aMessageWithoutItem);
368  mDetails.Assign(aDetails);
369  return NS_OK;
370 }
return NS_OK
nsString mMessageWithItem
sbDeviceFirmwareAutoCheckForUpdate prototype flags
NS_IMPL_THREADSAFE_ISUPPORTS5(sbTranscodeError, sbITranscodeError, nsIScriptError, nsIConsoleMessage, nsISupportsString, nsISupportsPrimitive) sbTranscodeError
nsString mMessageWithoutItem
static nsresult ToString(const nsDiscriminatedUnion &data, nsACString &outString)
Definition: sbVariant.cpp:861
nsCOMPtr< sbIMediaItem > mDestItem
nsCOMPtr< sbIMediaItem > mSrcItem
function Init()
GstMessage * message
var uri
Definition: FeedWriter.js:1135
Interface that defines a single item of media in the system.
#define SB_PROPERTY_TRACKNAME
const nsISupportsString
_updateTextAndScrollDataForFrame aData
var file