|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef USBUIMODELACTIVE_H |
|
19 #define USBUIMODELACTIVE_H |
|
20 |
|
21 #include <QObject> |
|
22 #include <e32base.h> |
|
23 #include <usbwatcher.h> |
|
24 |
|
25 class UsbUiModelActivePrivate; |
|
26 |
|
27 /*! |
|
28 \class UsbUiModelActive |
|
29 \brief Helper class for using active objects in Qt classes. |
|
30 |
|
31 UsbUiModelActive is a helper class for using active objects |
|
32 from any Qt class. It wraps a CActive-derived class in an interface |
|
33 that uses Qt's signal-slot mechanism for communicating status changes |
|
34 of the active object. |
|
35 |
|
36 */ |
|
37 class UsbUiModelActive : public QObject |
|
38 { |
|
39 Q_OBJECT |
|
40 friend class UsbUiModelActivePrivate; |
|
41 |
|
42 public: |
|
43 explicit UsbUiModelActive( int priority = CActive::EPriorityStandard, |
|
44 QObject *parent = NULL ); |
|
45 ~UsbUiModelActive(); |
|
46 |
|
47 inline TRequestStatus &RequestStatus(); |
|
48 inline void SetActive(); |
|
49 inline void Cancel(); |
|
50 inline bool IsActive(); |
|
51 |
|
52 public: |
|
53 int SetUsbPersonality(int personality); |
|
54 void CancelSetPersonality(); |
|
55 |
|
56 signals: |
|
57 void requestCompleted( int status ); |
|
58 |
|
59 private: |
|
60 /*! |
|
61 * emits a signal when the request is completed |
|
62 * @param status is the error |
|
63 */ |
|
64 void emitRequestCompleted( int status ); |
|
65 |
|
66 private: |
|
67 UsbUiModelActivePrivate *d; |
|
68 |
|
69 /** Handle to USBWatcher for setting the personality */ |
|
70 RUsbWatcher iUsbWatcher; |
|
71 }; |
|
72 |
|
73 |
|
74 /*! |
|
75 \class UsbUiModelActivePrivate |
|
76 \brief Private class of UsbUiModelActive, for using active objects in Qt classes. |
|
77 |
|
78 UsbUiModelActivePrivate is a helper class for using active objects |
|
79 from any Qt class. It derives from CActive and allows other classes to use |
|
80 it for passing to asynchronous function calls through its RequestStatus method. |
|
81 |
|
82 */ |
|
83 class UsbUiModelActivePrivate : public CActive |
|
84 { |
|
85 friend class UsbUiModelActive; |
|
86 |
|
87 public: |
|
88 explicit UsbUiModelActivePrivate( UsbUiModelActive *parent, int priority ); |
|
89 ~UsbUiModelActivePrivate(); |
|
90 |
|
91 private: |
|
92 virtual void RunL(); |
|
93 virtual void DoCancel(); |
|
94 virtual TInt RunError( TInt aError ); |
|
95 |
|
96 private: |
|
97 UsbUiModelActive *q; |
|
98 |
|
99 }; |
|
100 |
|
101 inline bool UsbUiModelActive::IsActive() |
|
102 { |
|
103 return d->IsActive(); |
|
104 } |
|
105 |
|
106 inline TRequestStatus &UsbUiModelActive::RequestStatus() |
|
107 { |
|
108 return d->iStatus; |
|
109 } |
|
110 |
|
111 inline void UsbUiModelActive::SetActive() |
|
112 { |
|
113 d->SetActive(); |
|
114 } |
|
115 |
|
116 inline void UsbUiModelActive::Cancel() |
|
117 { |
|
118 d->Cancel(); |
|
119 } |
|
120 |
|
121 #endif /* USBUIMODELACTIVE_H */ |