sbDeviceStatusHelper.h
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2011 POTI, Inc.
8  * http://www.songbirdnest.com
9  *
10  * This file may be licensed under the terms of of the
11  * GNU General Public License Version 2 (the ``GPL'').
12  *
13  * Software distributed under the License is distributed
14  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
15  * express or implied. See the GPL for the specific language
16  * governing rights and limitations.
17  *
18  * You should have received a copy of the GPL along with this
19  * program. If not, go to http://www.gnu.org/licenses/gpl.html
20  * or write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  *=END SONGBIRD GPL
24  */
25 
26 #ifndef sbDeviceStatus_h
27 #define sbDeviceStatus_h
28 
34 // Songbird imports.
35 #include "sbBaseDevice.h"
36 #include <sbIDeviceStatus.h>
37 #include <sbMemoryUtils.h>
38 
39 // Mozilla imports.
40 #include <nsCOMPtr.h>
41 
48 {
49  //----------------------------------------------------------------------------
50  //
51  // Public interface.
52  //
53  //----------------------------------------------------------------------------
54 
55 public:
56 
57  //
58  // Operation types.
59  //
60  // OPERATION_TYPE_NONE No operation type defined.
61  // OPERATION_TYPE_MOUNT Mount operation.
62  // OPERATION_TYPE_WRITE Write operation.
63  // OPERATION_TYPE_TRANSCODE Transcode operation
64  // OPERATION_TYPE_DELETE Delete operation.
65  // OPERATION_TYPE_READ Read operation
66  // OPERATION_TYPE_FORMAT Format operation.
67  // OPERATION_TYPE_DOWNLOAD Download operation.
68  //
69  enum Operation {
78  };
79 
80 
81  //
82  // Operation services.
83  //
84 
85  void OperationStart(Operation aOperationType,
86  PRInt32 aItemNum,
87  PRInt32 aItemCount,
88  PRInt32 aItemType,
89  sbIMediaList* aMediaList = nsnull,
90  sbIMediaItem* aMediaItem = nsnull,
91  PRBool aNewBatch = PR_TRUE);
92 
93  void OperationComplete(nsresult aResult);
94 
95 
96  //
97  // Item services.
98  //
99 
100  void ItemStart(PRInt32 aItemNum,
101  PRInt32 aItemCount,
102  PRInt32 aItemType);
103 
104  void ItemStart(sbIMediaList* aMediaList,
105  sbIMediaItem* aMediaItem,
106  PRInt32 aItemNum,
107  PRInt32 aItemCount,
108  PRInt32 aItemType = 0);
109 
110  void ItemProgress(double aProgress);
111 
112  void ItemComplete(nsresult aResult);
113 
114 
115  //
116  // Public services.
117  //
119 
121 
122  nsresult Initialize();
123 
124  nsresult ChangeState(PRUint32 aState);
125 
126  nsresult GetCurrentStatus(sbIDeviceStatus** aCurrentStatus);
127 
128  nsresult UpdateStatus(const nsAString& aOperation,
129  const nsAString& aStateMessage,
130  PRInt32 aItemNum,
131  PRInt32 aItemCount,
132  double aProgress,
133  PRInt32 aItemType = 0);
134 
135  PRUint32 GetSubState() {
136  PRUint32 subState;
137  nsresult rv = mStatus->GetCurrentSubState(&subState);
138  NS_ENSURE_SUCCESS(rv, sbIDevice::STATE_IDLE);
139  return subState;
140  }
141 
142  //----------------------------------------------------------------------------
143  //
144  // Private interface.
145  //
146  //----------------------------------------------------------------------------
147 
148 private:
149 
150  //
151  // Internal services fields.
152  //
153  // mDevice Device object. Don't refcount to avoid a cycle.
154  // mStatus Base device status object.
155  // mOperationType Current operation type.
156  // mMediaList Current operation media list.
157  // mMediaItem Current operation media item.
158  // mItemNum Current operation item number.
159  // mItemCount Current operation item count.
160  // mItemType Current item type.
161  //
162 
163  sbBaseDevice* mDevice;
164  nsCOMPtr<sbIDeviceStatus> mStatus;
165  Operation mOperationType;
166  nsCOMPtr<sbIMediaList> mMediaList;
167  nsCOMPtr<sbIMediaItem> mMediaItem;
168  PRInt32 mItemNum;
169  PRInt32 mItemCount;
170  PRInt32 mItemType;
171 };
172 
173 
182 SB_AUTO_CLASS2(sbDeviceStatusAutoState,
184  PRUint32,
185  (mValue != nsnull),
186  mValue->ChangeState(mValue2),
187  mValue = nsnull);
188 
195 {
196 public:
198  static bool IsItemOp(sbDeviceStatusHelper::Operation aOperation) {
199  NS_ASSERTION(aOperation != sbDeviceStatusHelper::OPERATION_TYPE_NONE,
200  "sbMSCStatusAutoOperationComplete::isItemOp pass 'none'");
201  // Make sure we're updated and know about all the types
202  NS_ASSERTION(aOperation == sbDeviceStatusHelper::OPERATION_TYPE_MOUNT ||
209  "sbDeviceStatusAutoOperationComplete::isItemOp is not current");
210 
211  return (aOperation != sbDeviceStatusHelper::OPERATION_TYPE_MOUNT) &&
213  }
218  mRequest(nsnull),
219  mStatus(nsnull),
220  mResult(NS_ERROR_FAILURE),
221  mOperation(sbDeviceStatusHelper::OPERATION_TYPE_NONE) {}
227  sbDeviceStatusHelper * aStatus,
229  TransferRequest * aRequest,
230  PRUint32 aBatchCount);
232  sbDeviceStatusHelper * aStatus,
240  sbDeviceStatusHelper * aStatus,
242  TransferRequest * aRequest,
243  PRInt32 aBatchCount);
252  void Complete();
253 
258  void SetResult(nsresult aResult) {
259  mResult = aResult;
260  }
264  void Transfer(sbDeviceStatusAutoOperationComplete & aDestination);
265 private:
266  // This will live in the request queue as long as we're alive
267  nsRefPtr<TransferRequest> mRequest;
268  PRUint32 mBatchCount;
269  sbDeviceStatusHelper * mStatus;
270  nsresult mResult;
272 
277  operator = (sbDeviceStatusAutoOperationComplete const & aOther);
278 
282  nsresult ExtractDataFromRequest(
283  PRUint32 & aType,
284  PRInt32 & aBatchIndex,
285  PRInt32 & aBatchCount,
286  sbBaseDevice::TransferRequest ** aRequestData);
287 
288  // Prevent copying
291 };
292 
293 #endif /* __SB_MSC_STATUS_H__ */
294 
nsresult UpdateStatus(const nsAString &aOperation, const nsAString &aStateMessage, PRInt32 aItemNum, PRInt32 aItemCount, double aProgress, PRInt32 aItemType=0)
void Transfer(sbDeviceStatusAutoOperationComplete &aDestination)
nsresult GetCurrentStatus(sbIDeviceStatus **aCurrentStatus)
SB_AUTO_CLASS2(sbDeviceStatusAutoState, sbDeviceStatusHelper *, PRUint32,(mValue!=nsnull), mValue->ChangeState(mValue2), mValue=nsnull)
nsresult ChangeState(PRUint32 aState)
A brief description of the contents of this interface.
void OperationStart(Operation aOperationType, PRInt32 aItemNum, PRInt32 aItemCount, PRInt32 aItemType, sbIMediaList *aMediaList=nsnull, sbIMediaItem *aMediaItem=nsnull, PRBool aNewBatch=PR_TRUE)
void OperationComplete(nsresult aResult)
sbDeviceStatusHelper(sbBaseDevice *aDevice)
static bool IsItemOp(sbDeviceStatusHelper::Operation aOperation)
void ItemComplete(nsresult aResult)
const unsigned long STATE_IDLE
Definition: sbIDevice.idl:220
void ItemStart(PRInt32 aItemNum, PRInt32 aItemCount, PRInt32 aItemType)
void ItemProgress(double aProgress)
Interface that defines a single item of media in the system.
restoreWindow aState
sbBaseDevice::TransferRequest TransferRequest