|
1 /* |
|
2 * Copyright (c) 2004-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "crealfactory.h" |
|
20 #include "cimageprintengine.h" |
|
21 #include "cdiscoverymanager.h" |
|
22 #include "cprintjobmanager.h" |
|
23 #include "cprinteventcatcher.h" |
|
24 #include "cidleprinteventcatcher.h" |
|
25 #include "csettingsmanager.h" |
|
26 #include "imageprint.h" |
|
27 #include "cimageprint.h" |
|
28 #include "clog.h" |
|
29 |
|
30 const TInt KMaxServerConnections( 3 ); |
|
31 |
|
32 // CONSTRUCTION |
|
33 CRealFactory* CRealFactory::NewL( |
|
34 CImagePrintEngine* aEngine ) |
|
35 { |
|
36 CRealFactory* self = new ( ELeave ) CRealFactory( aEngine ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // Default constructor |
|
44 CRealFactory::CRealFactory( CImagePrintEngine* aEngine ) |
|
45 : CIFFactory( aEngine ) |
|
46 { |
|
47 } |
|
48 |
|
49 // Destructor |
|
50 CRealFactory::~CRealFactory() |
|
51 { |
|
52 LOG("CRealFactory::~CRealFactory BEGIN"); |
|
53 if ( iEventCatcher ) |
|
54 { |
|
55 iEventCatcher->UnRegisterObserver( iPrintJobMgr ); |
|
56 } |
|
57 delete iPrintJobMgr; |
|
58 delete iDiscoveryMgr; |
|
59 delete iSettingsMgr; |
|
60 delete iEventCatcher; |
|
61 delete iIdleEventCatcher; |
|
62 |
|
63 if ( iImageServer ) |
|
64 { |
|
65 iImageServer->Close(); |
|
66 delete iImageServer; |
|
67 } |
|
68 |
|
69 iImagePrintClient.Close(); |
|
70 LOG("CRealFactory::~CRealFactory END"); |
|
71 } |
|
72 |
|
73 // 2nd phase constructor |
|
74 void CRealFactory::ConstructL() |
|
75 { |
|
76 iImageServer = new ( ELeave ) CImagePrint; |
|
77 iImageServer->ConnectL(); |
|
78 |
|
79 iEventCatcher = CPrintEventCatcher::NewL( this, iPrintEngine ); |
|
80 iIdleEventCatcher = CIdlePrintEventCatcher::NewL( this /*aIdleObserver*/ ); |
|
81 iDiscoveryMgr = CDiscoveryManager::NewL( this ); |
|
82 iPrintJobMgr = CPrintJobManager::NewL( this, iPrintEngine ); |
|
83 iSettingsMgr = CSettingsManager::NewL( this ); |
|
84 |
|
85 iEventCatcher->RegisterObserver( iPrintJobMgr ); |
|
86 iImageServer->RegisterIdleObserver( iIdleEventCatcher ); |
|
87 |
|
88 User::LeaveIfError( iImagePrintClient.ConnectL() ); |
|
89 } |
|
90 |
|
91 // Discovery interface |
|
92 MDiscovery* CRealFactory::DiscoveryIF() |
|
93 { |
|
94 return iDiscoveryMgr; |
|
95 } |
|
96 |
|
97 // Settings interface |
|
98 MPrintSettings* CRealFactory::SettingsIF() |
|
99 { |
|
100 return iSettingsMgr; |
|
101 } |
|
102 |
|
103 // Print job interface |
|
104 MPrintJob* CRealFactory::PrintJobIF() |
|
105 { |
|
106 return iPrintJobMgr; |
|
107 } |
|
108 |
|
109 // Returns event catcher |
|
110 MPrintEventObserver* CRealFactory::PrintEventObserverIF() |
|
111 { |
|
112 return iEventCatcher; |
|
113 } |
|
114 |
|
115 MPrintEventRegisterIF* CRealFactory::PrintEventRegisterIF() |
|
116 { |
|
117 return iEventCatcher; |
|
118 } |
|
119 |
|
120 // Restarts Engine |
|
121 void CRealFactory::RestartEngine() |
|
122 { |
|
123 // No implementation |
|
124 } |
|
125 |
|
126 // Returns Engine |
|
127 CImagePrint* CRealFactory::Engine() |
|
128 { |
|
129 return iImageServer; |
|
130 } |
|
131 |
|
132 TBool CRealFactory::IsPrinting() const |
|
133 { |
|
134 return iPrintJobMgr->IsPrinting(); |
|
135 } |
|
136 |
|
137 |
|
138 MIdlePrintEventRegisterIF* CRealFactory::IdlePrintEventRegisterIF() |
|
139 { |
|
140 return iIdleEventCatcher; |
|
141 } |
|
142 |
|
143 RImagePrintClient CRealFactory::ImagePrintClient() |
|
144 { |
|
145 return iImagePrintClient; |
|
146 } |
|
147 |
|
148 TBool CRealFactory::IsApplicationAlreadyInUse() |
|
149 { |
|
150 TBool retValue = EFalse; |
|
151 TInt serverConnections = 0; |
|
152 TInt err = iImagePrintClient.CountConnections( serverConnections ); |
|
153 if( err != KErrNone ) |
|
154 { |
|
155 return EFalse; |
|
156 } |
|
157 |
|
158 // if server has already two connections |
|
159 if( serverConnections == KMaxServerConnections ) |
|
160 { |
|
161 //if another connection IS NOT pictbridge |
|
162 TInt mode = iImagePrintClient.IsPictBridgeMode(); |
|
163 if( mode < 0 ) |
|
164 { |
|
165 retValue = EFalse; |
|
166 } |
|
167 } |
|
168 // too many connection |
|
169 if( serverConnections > KMaxServerConnections ) |
|
170 { |
|
171 retValue = EFalse; |
|
172 } |
|
173 return retValue; |
|
174 } |
|
175 |
|
176 // End of File |