83 |
83 |
84 // --------------------------------------------------------------------------- |
84 // --------------------------------------------------------------------------- |
85 // |
85 // |
86 // --------------------------------------------------------------------------- |
86 // --------------------------------------------------------------------------- |
87 // |
87 // |
88 CUsbVBusObserver::TState CUsbVBusObserver::VBus() /* not const, because for some reason RProperty::Get is not const! */ |
88 CUsbVBusObserver::TState CUsbVBusObserver::VBus() /* not const, because for some reason RProperty::Get is not const */ |
89 { |
89 { |
90 |
90 |
91 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus" ) ); |
91 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus" ) ); |
92 |
92 |
93 TInt val(0); |
93 TInt val(0); |
94 |
94 |
95 TInt err = iVBus.Get(val); |
95 TInt err = iVBus.Get(val); |
96 |
96 |
97 if (KErrNone != err) |
97 if (KErrNone != err) |
98 { |
98 { |
99 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus CanNotGetVBusProperty" ) ); |
99 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus CanNotGetVBusProperty" ) ); |
100 Panic(ECanNotGetVBusProperty); |
100 Panic(ECanNotGetVBusProperty); |
101 } |
101 } |
102 |
102 |
103 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus = %d" ), val )); |
103 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus = %d" ), val )); |
104 |
104 |
105 // not found in docs clear definition of this property. Verification is needed |
|
106 return (0 == val ? EVBusDown : EVBusUp); |
105 return (0 == val ? EVBusDown : EVBusUp); |
107 } |
106 } |
108 |
107 |
109 // --------------------------------------------------------------------------- |
108 // --------------------------------------------------------------------------- |
110 // |
109 // |
111 // --------------------------------------------------------------------------- |
110 // --------------------------------------------------------------------------- |
112 // |
111 // |
113 void CUsbVBusObserver::SubscribeL(MUsbVBusObserver* aObserver) |
112 void CUsbVBusObserver::SubscribeL(MUsbVBusObserver& aObserver) |
114 { |
113 { |
115 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::SubscribeL" ) ); |
114 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::SubscribeL" ) ); |
116 |
115 |
117 User::LeaveIfError(iObservers.Append(aObserver)); |
116 // check if the same observer already exist in a list |
118 |
117 if(KErrNotFound != iObservers.Find(&aObserver)) |
119 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::SubscribeL Observer appended." ) ); |
118 { |
120 |
119 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::SubscribeL Observer already exists." ) ); |
|
120 Panic(EObserverAlreadyExists); |
|
121 return; |
|
122 } |
|
123 |
|
124 iObservers.AppendL(&aObserver); |
|
125 |
121 if (KFirst == iObservers.Count()) // first item |
126 if (KFirst == iObservers.Count()) // first item |
122 { |
127 { |
123 iVBus.Subscribe(iStatus); |
128 iVBus.Subscribe(iStatus); |
124 SetActive(); |
129 SetActive(); |
125 } |
130 } |
127 |
132 |
128 // --------------------------------------------------------------------------- |
133 // --------------------------------------------------------------------------- |
129 // |
134 // |
130 // --------------------------------------------------------------------------- |
135 // --------------------------------------------------------------------------- |
131 // |
136 // |
132 void CUsbVBusObserver::UnsubscribeL(MUsbVBusObserver* aObserver) |
137 void CUsbVBusObserver::UnsubscribeL(MUsbVBusObserver& aObserver) |
133 { |
138 { |
134 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL" ) ); |
139 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL" ) ); |
135 |
140 |
136 if (0 == iObservers.Count()) // no items |
141 TInt i(iObservers.Find(&aObserver)); |
137 { |
142 if(KErrNotFound == i) |
138 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL No observers" ) ); |
143 { |
|
144 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL Observer not found." ) ); |
|
145 Panic(ECanNotFindVBusObserver); |
139 return; |
146 return; |
140 } |
147 } |
141 |
148 |
142 TInt i(0); |
149 iObservers.Remove(i); |
143 while (i < iObservers.Count() && aObserver != iObservers[i]) |
|
144 { |
|
145 ++i; |
|
146 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL i = %d" ), i )); |
|
147 } |
|
148 |
|
149 if (aObserver == iObservers[i]) // found |
|
150 { |
|
151 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL Removing item" ) ); |
|
152 iObservers.Remove(i); |
|
153 } |
|
154 else |
|
155 { |
|
156 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL CanNotFindVBusObserver" ) ); |
|
157 Panic(ECanNotFindVBusObserver); |
|
158 } |
|
159 |
150 |
160 if (0 == iObservers.Count()) // no observers anymore |
151 if (0 == iObservers.Count()) // no observers anymore |
161 { |
152 { |
162 // cancel pending request, if any |
153 // cancel pending request, if any |
163 Cancel(); |
154 Cancel(); |
164 return; |
|
165 } |
155 } |
166 } |
156 } |
167 |
157 |
168 // --------------------------------------------------------------------------- |
158 // --------------------------------------------------------------------------- |
169 // |
159 // |