equal
deleted
inserted
replaced
106 |
106 |
107 // --------------------------------------------------------------------------- |
107 // --------------------------------------------------------------------------- |
108 // |
108 // |
109 // --------------------------------------------------------------------------- |
109 // --------------------------------------------------------------------------- |
110 // |
110 // |
111 void CUsbOtgStateObserver::SubscribeL(MUsbOtgStateObserver* aObserver) |
111 void CUsbOtgStateObserver::SubscribeL(MUsbOtgStateObserver& aObserver) |
112 { |
112 { |
113 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::SubscribeL" ) ); |
113 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::SubscribeL" ) ); |
114 |
114 // check if the same observer already exist in a list |
115 User::LeaveIfError(iObservers.Append(aObserver)); |
115 if(KErrNotFound != iObservers.Find(&aObserver)) |
|
116 { |
|
117 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL Observer already exists." ) ); |
|
118 Panic(EObserverAlreadyExists); |
|
119 return; |
|
120 } |
|
121 iObservers.AppendL(&aObserver); |
116 |
122 |
117 if (KFirst == iObservers.Count()) // first item |
123 if (KFirst == iObservers.Count()) // first item |
118 { |
124 { |
119 iOtgState.Subscribe(iStatus); |
125 iOtgState.Subscribe(iStatus); |
120 SetActive(); |
126 SetActive(); |
124 |
130 |
125 // --------------------------------------------------------------------------- |
131 // --------------------------------------------------------------------------- |
126 // |
132 // |
127 // --------------------------------------------------------------------------- |
133 // --------------------------------------------------------------------------- |
128 // |
134 // |
129 void CUsbOtgStateObserver::UnsubscribeL(MUsbOtgStateObserver* aObserver) |
135 void CUsbOtgStateObserver::UnsubscribeL(MUsbOtgStateObserver& aObserver) |
130 { |
136 { |
131 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::UnsubscribeL" ) ); |
137 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::UnsubscribeL" ) ); |
132 |
138 |
133 if (0 == iObservers.Count()) // no items |
139 TInt i(iObservers.Find(&aObserver)); |
134 { |
140 if(KErrNotFound == i) |
135 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::UnsubscribeL No observers" ) ); |
141 { |
136 return; |
142 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL Observer not found." ) ); |
137 } |
|
138 |
|
139 TInt i(0); |
|
140 while (i < iObservers.Count() && aObserver != iObservers[i]) |
|
141 ++i; |
|
142 |
|
143 if (aObserver == iObservers[i]) // found |
|
144 { |
|
145 iObservers.Remove(i); |
|
146 } |
|
147 else |
|
148 { |
|
149 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::UnsubscribeL CanNotFindOtgStateObserver" ) ); |
|
150 Panic(ECanNotFindOtgStateObserver); |
143 Panic(ECanNotFindOtgStateObserver); |
151 } |
144 return; |
152 |
145 } |
153 if (0 == iObservers.Count()) // no items |
146 |
|
147 iObservers.Remove(i); |
|
148 |
|
149 if (0 == iObservers.Count()) // no observers anymore |
154 { |
150 { |
155 // cancel pending request |
151 // cancel pending request |
156 Cancel(); |
152 Cancel(); |
157 } |
153 } |
158 } |
154 } |