30 #include <nsComponentManagerUtils.h>
31 #include <sbIDataRemote.h>
32 #include <sbIDevice.h>
33 #include <nsIProxyObjectManager.h>
34 #include <nsServiceManagerUtils.h>
35 #include <nsThreadUtils.h>
45 mCurrentProgress = -1;
49 sbDeviceStatus::~sbDeviceStatus()
56 sbDeviceStatus::GetCurrentState(PRUint32 *aCurrentState)
58 NS_ENSURE_ARG_POINTER(aCurrentState);
59 *aCurrentState = mCurrentState;
63 sbDeviceStatus::SetCurrentState(PRUint32 aCurrentState)
68 mTimestamp = PR_IntervalNow();
71 mCurrentState = aCurrentState;
76 nsresult rv = SetWorkItemProgress(0);
77 NS_ENSURE_SUCCESS(rv, rv);
84 sbDeviceStatus::GetCurrentSubState(PRUint32 *aCurrentSubState)
86 NS_ENSURE_ARG_POINTER(aCurrentSubState);
87 *aCurrentSubState = mCurrentSubState;
91 sbDeviceStatus::SetCurrentSubState(PRUint32 aCurrentSubState)
93 mCurrentSubState = aCurrentSubState;
99 sbDeviceStatus::GetStateMessage(nsAString & aStateMessage)
101 return mStatusRemote->GetStringValue(aStateMessage);
104 sbDeviceStatus::SetStateMessage(
const nsAString & aStateMessage)
106 return mStatusRemote->SetStringValue(aStateMessage);
111 sbDeviceStatus::GetCurrentOperation(nsAString & aCurrentOperation)
113 return mOperationRemote->GetStringValue(aCurrentOperation);
116 sbDeviceStatus::SetCurrentOperation(
const nsAString & aCurrentOperation)
118 return mOperationRemote->SetStringValue(aCurrentOperation);
123 sbDeviceStatus::GetProgress(
double *aProgress)
127 rv = mProgressRemote->GetIntValue(&curProgress);
128 NS_ENSURE_SUCCESS(rv, rv);
130 *aProgress = (curProgress / 100.0 - 0.5);
135 sbDeviceStatus::SetProgress(
double aProgress)
137 PRInt64
const newProgress = (PRUint64)(aProgress * 100.00 + 0.5);
138 if (newProgress != mCurrentProgress) {
139 mCurrentProgress = newProgress;
140 return mProgressRemote->SetIntValue(newProgress);
147 sbDeviceStatus::GetWorkItemProgress(PRInt64 *aWorkItemProgress)
149 NS_ENSURE_ARG_POINTER(aWorkItemProgress);
150 return mWorkCurrentCountRemote->GetIntValue(aWorkItemProgress);
153 sbDeviceStatus::SetWorkItemProgress(PRInt64 aWorkItemProgress)
155 return mWorkCurrentCountRemote->SetIntValue(aWorkItemProgress);
160 sbDeviceStatus::GetWorkItemType(PRInt32 *aCurrentItemType)
162 NS_ENSURE_ARG_POINTER(aCurrentItemType);
163 mWorkCurrentTypeRemote->GetIntValue((PRInt64 *)aCurrentItemType);
167 sbDeviceStatus::SetWorkItemType(PRInt32 aCurrentItemType)
169 mWorkCurrentTypeRemote->SetIntValue(aCurrentItemType);
175 sbDeviceStatus::GetWorkItemProgressEndCount(PRInt64 *aWorkItemProgressEndCount)
177 NS_ENSURE_ARG_POINTER(aWorkItemProgressEndCount);
178 return mWorkTotalCountRemote->GetIntValue(aWorkItemProgressEndCount);
181 sbDeviceStatus::SetWorkItemProgressEndCount(PRInt64 aWorkItemProgressEndCount)
183 return mWorkTotalCountRemote->SetIntValue(aWorkItemProgressEndCount);
188 sbDeviceStatus::GetMediaItem(
sbIMediaItem * *aMediaItem)
191 NS_IF_ADDREF(*aMediaItem = mItem);
204 sbDeviceStatus::GetMediaList(
sbIMediaList * *aMediaList)
207 NS_IF_ADDREF(*aMediaList = mList);
219 NS_IMETHODIMP sbDeviceStatus::GetElapsedTime(PRUint32 *aElapsedTime)
221 NS_ENSURE_ARG_POINTER(aElapsedTime);
222 *aElapsedTime = PR_IntervalToMilliseconds((PRIntervalTime)(PR_IntervalNow() - mTimestamp));
227 NS_IMETHODIMP sbDeviceStatus::GetIsNewBatch(PRBool *aIsNewBatch)
229 *aIsNewBatch = mNewBatch;
232 NS_IMETHODIMP sbDeviceStatus::SetIsNewBatch(PRBool aIsNewBatch)
234 mNewBatch = aIsNewBatch;
236 mTimestamp = PR_IntervalNow();
243 mDeviceID.Assign(aDeviceID);
244 mTimestamp = PR_IntervalNow();
246 NS_NAMED_LITERAL_STRING(STATE,
"status.state");
247 NS_NAMED_LITERAL_STRING(OPERATION,
"status.operation");
248 NS_NAMED_LITERAL_STRING(PROGRESS,
"status.progress");
249 NS_NAMED_LITERAL_STRING(WORK_CURRENT_TYPE,
"status.type");
250 NS_NAMED_LITERAL_STRING(WORK_CURRENT_COUNT,
"status.workcount");
251 NS_NAMED_LITERAL_STRING(WORK_TOTAL_COUNT,
"status.totalcount");
254 nsCOMPtr<nsIProxyObjectManager> pom =
255 do_GetService(
"@mozilla.org/xpcomproxy;1", &rv);
256 NS_ENSURE_SUCCESS(rv, rv);
258 rv = GetDataRemote(pom,
261 getter_AddRefs(mStatusRemote));
262 NS_ENSURE_SUCCESS(rv, rv);
264 rv = GetDataRemote(pom,
267 getter_AddRefs(mOperationRemote));
268 NS_ENSURE_SUCCESS(rv, rv);
270 rv = GetDataRemote(pom,
273 getter_AddRefs(mProgressRemote));
274 NS_ENSURE_SUCCESS(rv, rv);
276 rv = GetDataRemote(pom,
279 getter_AddRefs(mWorkCurrentTypeRemote));
280 NS_ENSURE_SUCCESS(rv, rv);
282 rv = GetDataRemote(pom,
285 getter_AddRefs(mWorkCurrentCountRemote));
286 NS_ENSURE_SUCCESS(rv, rv);
288 rv = GetDataRemote(pom,
291 getter_AddRefs(mWorkTotalCountRemote));
292 NS_ENSURE_SUCCESS(rv, rv);
297 nsresult sbDeviceStatus::GetDataRemote(nsIProxyObjectManager* aProxyObjectManager,
298 const nsAString& aDataRemoteName,
299 const nsAString& aDataRemotePrefix,
300 void** appDataRemote)
302 nsAutoString fullDataRemoteName;
303 nsCOMPtr<sbIDataRemote> pDataRemote;
307 nullString.SetIsVoid(PR_TRUE);
310 if (!aDataRemotePrefix.IsEmpty())
312 fullDataRemoteName.Assign(aDataRemotePrefix);
313 fullDataRemoteName.AppendLiteral(
".");
315 fullDataRemoteName.Append(aDataRemoteName);
318 pDataRemote = do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1",
320 NS_ENSURE_SUCCESS(rv, rv);
321 rv = pDataRemote->Init(fullDataRemoteName, nullString);
322 NS_ENSURE_SUCCESS(rv, rv);
326 rv = aProxyObjectManager->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
329 nsIProxyObjectManager::INVOKE_ASYNC |
330 nsIProxyObjectManager::FORCE_PROXY_CREATION,
332 NS_ENSURE_SUCCESS(rv, rv);
An interface for accessing, and binding to, stored data.
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceCapsCompatibility, sbIDeviceCapsCompatibility) sbDeviceCapsCompatibility
const unsigned long STATE_IDLE