27 #ifndef _SB_JOB_UTILS_H_
28 #define _SB_JOB_UTILS_H_
50 #include <nsISimpleEnumerator.h>
51 #include <nsIStringEnumerator.h>
52 #include <nsISupportsPrimitives.h>
55 #include <sbIJobCancelable.h>
74 template <
class Interface>
79 typedef nsTArray<nsCOMPtr<Interface> > ArrayType;
81 explicit sbJobErrorEnumerator() : mIndex(0){}
83 sbJobErrorEnumerator(ArrayType& aArray)
84 : mArray(aArray), mIndex(0) {}
92 PRBool Adopt(ArrayType& aArray)
96 return mArray.SwapElements(aArray);
100 NS_IMETHODIMP HasMore(PRBool *_retval)
102 NS_ENSURE_ARG_POINTER(_retval);
103 *_retval = mIndex < mArray.Length();
107 NS_IMETHODIMP GetNext(nsAString & _retval)
111 if (!(mIndex < mArray.Length())) {
112 return NS_ERROR_FAILURE;
114 nsCOMPtr<Interface>
next(mArray[mIndex]);
115 NS_ENSURE_TRUE(
next, NS_ERROR_FAILURE);
117 nsCOMPtr<nsISupportsString>
string = do_QueryInterface(
next, &rv);
118 NS_ENSURE_SUCCESS(rv, rv);
120 rv =
string->GetData(_retval);
121 NS_ENSURE_SUCCESS(rv, rv);
128 NS_IMETHODIMP HasMoreElements(PRBool *_retval)
130 return HasMore(_retval);
136 if (!(mIndex < mArray.Length())) {
137 return NS_ERROR_FAILURE;
139 nsCOMPtr<Interface>
next(mArray[mIndex]);
140 NS_ENSURE_TRUE(
next, NS_ERROR_FAILURE);
142 rv = CallQueryInterface(
next, _retval);
143 NS_ENSURE_SUCCESS(rv, rv);
152 NS_PRECONDITION(PRInt32(mRefCnt) >= 0,
"illegal refcnt");
154 count = PR_AtomicIncrement((PRInt32*)&mRefCnt);
155 NS_LOG_ADDREF(
this, count,
"sbJobErrorEnumerator<>",
sizeof(*
this));
162 NS_PRECONDITION(0 != mRefCnt,
"dup release");
163 count = PR_AtomicDecrement((PRInt32 *)&mRefCnt);
164 NS_LOG_RELEASE(
this, count,
"sbJobErrorEnumerator<>");
167 NS_DELETEXPCOM(
this);
174 NS_ASSERTION(aInstancePtr,
175 "QueryInterface requires a non-NULL destination!");
176 nsresult rv = NS_ERROR_FAILURE;
177 NS_INTERFACE_TABLE2(sbJobErrorEnumerator<Interface>,
180 NS_INTERFACE_TABLE_TAIL
183 nsAutoRefCnt mRefCnt;
sbOSDControlService prototype QueryInterface
NS_IMETHODIMP_(nsresult) sbVariant
SB_AUTO_NULL_CLASS(sbAutoJobCancel, sbIJobCancelable *, mValue->Cancel())