1 /* |
|
2 * Copyright (c) 2007 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: Generic handler to be used by Observables |
|
15 * |
|
16 * Copyright © 2007 Nokia. All rights reserved. |
|
17 * This material, including documentation and any related computer |
|
18 * programs, is protected by copyright controlled by Nokia. All |
|
19 * rights are reserved. Copying, including reproducing, storing, |
|
20 * adapting or translating, any or all of this material requires the |
|
21 * prior written consent of Nokia. This material also contains |
|
22 * confidential information which may not be disclosed to others |
|
23 * without the prior written consent of Nokia. |
|
24 |
|
25 * |
|
26 * |
|
27 */ |
|
28 |
|
29 |
|
30 |
|
31 // INCLUDE FILES |
|
32 #include "CamObservable.h" |
|
33 #include "CamObserver.h" |
|
34 #include "CamObserverHandler.h" |
|
35 #include "camlogging.h" |
|
36 |
|
37 // --------------------------------------------------------- |
|
38 // CCamObserverHandler::CCamObserverHandler |
|
39 // C++ constructor |
|
40 // --------------------------------------------------------- |
|
41 // |
|
42 CCamObserverHandler::CCamObserverHandler() |
|
43 { |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------- |
|
47 // CCamObserverHandler::~CCamObserverHandler |
|
48 // C++ Destructor |
|
49 // --------------------------------------------------------- |
|
50 // |
|
51 CCamObserverHandler::~CCamObserverHandler() |
|
52 { |
|
53 PRINT( _L("Camera => ~CCamObserverHandler") ); |
|
54 iObservers.Reset(); |
|
55 PRINT( _L("Camera <= ~CCamObserverHandler") ); |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------- |
|
59 // CCamObserverHandler::NewL |
|
60 // Symbian 2-phase constructor |
|
61 // --------------------------------------------------------- |
|
62 // |
|
63 CCamObserverHandler* CCamObserverHandler::NewL() |
|
64 { |
|
65 CCamObserverHandler* self = new( ELeave ) CCamObserverHandler(); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop( self ); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------- |
|
73 // CCamObserverHandler::ConstructL |
|
74 // Second phase constructor |
|
75 // --------------------------------------------------------- |
|
76 // |
|
77 void CCamObserverHandler::ConstructL() |
|
78 { |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CCamObserverHandler::RegisterObserverL |
|
83 // Registers observer if not previously registered |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 void CCamObserverHandler::RegisterObserverL(MCamObserver* aObserver) |
|
87 { |
|
88 if ( aObserver ) |
|
89 { |
|
90 if ( KErrNotFound == iObservers.Find( aObserver )) |
|
91 { |
|
92 User::LeaveIfError(iObservers.Append(aObserver)); |
|
93 } |
|
94 } |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------- |
|
98 // CCamObserverHandler::DeregisterObserver |
|
99 // Removes observer |
|
100 // --------------------------------------------------------- |
|
101 // |
|
102 void CCamObserverHandler::DeregisterObserver(MCamObserver* aObserver) |
|
103 { |
|
104 if ( aObserver ) |
|
105 { |
|
106 TInt index = iObservers.Find( aObserver ); |
|
107 if ( KErrNotFound != index ) |
|
108 { |
|
109 iObservers.Remove(index); |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------- |
|
115 // CCamObserverHandler::BroadcastEvent |
|
116 // Broadcasts an event code to all observers |
|
117 // --------------------------------------------------------- |
|
118 // |
|
119 void CCamObserverHandler::BroadcastEvent( TCamObserverEvent aEvent ) |
|
120 { |
|
121 TInt count = iObservers.Count(); |
|
122 TInt i; |
|
123 for ( i = 0; i < count; i++ ) |
|
124 { |
|
125 // Checked to be non-NULL when added to array. |
|
126 iObservers[i]->HandleObservedEvent( aEvent ); |
|
127 } |
|
128 } |
|
129 |
|
130 // End of File |
|