|
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: Metadata Harvester server's client |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // INCLUDE FILES |
|
25 |
|
26 #include "mdhclient.h" |
|
27 #include "cmserviceobserver.h" |
|
28 #include "msdebug.h" |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // Two-phase API constructor |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CCmMdhClient* CCmMdhClient::NewL( MCmServiceObserver& aServer ) |
|
35 { |
|
36 CCmMdhClient* self = CCmMdhClient::NewLC( aServer ); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Two-phase API constructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CCmMdhClient* CCmMdhClient::NewLC( MCmServiceObserver& aServer ) |
|
46 { |
|
47 CCmMdhClient* self = new ( ELeave ) CCmMdhClient( aServer ); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Destructor |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CCmMdhClient::~CCmMdhClient() |
|
58 { |
|
59 LOG(_L("[CmMdh Server]\t CCmMdhClient::~CCmMdhClient\n")); |
|
60 Cancel(); |
|
61 iMdhSession.Close(); |
|
62 LOG(_L("[CmMdh Server]\t CCmMdhClient::~CCmMdhClient end\n")); |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // Default constructor |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CCmMdhClient::CCmMdhClient( MCmServiceObserver& aServer ) : |
|
70 CActive( EPriorityStandard ), |
|
71 iServer( aServer ), iState( ECmMdhClientIdle ) |
|
72 { |
|
73 LOG(_L("[CmMdh Server]\t CCmMdhClient::CCmMdhClient\n")); |
|
74 CActiveScheduler::Add( this ); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // ConstructL |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CCmMdhClient::ConstructL( ) |
|
82 { |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Harvest |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 TInt CCmMdhClient::Harvest() |
|
90 { |
|
91 LOG(_L("[CmMdh Server]\t CCmMdhClient::Harvest\n")); |
|
92 |
|
93 if ( IsActive() ) |
|
94 { |
|
95 return KErrNotReady; |
|
96 } |
|
97 |
|
98 TInt errCode = iMdhSession.Connect(); |
|
99 if (errCode != KErrNone) |
|
100 { |
|
101 return errCode; |
|
102 } |
|
103 iMdhSession.SearchMediaservers( iStatus ); |
|
104 SetActive(); |
|
105 iState = ECmMdhClientSearching; |
|
106 return KErrNone; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // Stop |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CCmMdhClient::Stop() |
|
114 { |
|
115 LOG(_L("[CmMdh Server]\t CCmMdhClient::Stop\n")); |
|
116 Cancel(); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Close |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 void CCmMdhClient::Close() |
|
124 { |
|
125 LOG(_L("[CmMdh Server]\t CCmMdhClient::Close\n")); |
|
126 delete this; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // DoCancel |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CCmMdhClient::DoCancel() |
|
134 { |
|
135 LOG(_L("[CmMdh Server]\t CCmMdhClient::DoCancel\n")); |
|
136 iMdhSession.Cancel(); |
|
137 iMdhSession.Close(); |
|
138 iState = ECmMdhClientIdle; |
|
139 iServer.ServiceExecuted( ECmServiceHarvest, KErrCancel ); |
|
140 LOG(_L("[CmMdh Server]\t CCmMdhClient::DoCancel end\n")); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // RunL |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CCmMdhClient::RunL() |
|
148 { |
|
149 LOG(_L("[CmMdh Server]\t CCmMdhClient::RunL\n")); |
|
150 if ( iState == ECmMdhClientSearching && |
|
151 iStatus == KErrNone ) |
|
152 { |
|
153 iMdhSession.Harvest( iStatus ); |
|
154 SetActive(); |
|
155 iState = ECmMdhClientHarvesting; |
|
156 } |
|
157 else // iState == ECmMdhClientHarvesting or error in search |
|
158 { |
|
159 iMdhSession.Close(); |
|
160 iState = ECmMdhClientIdle; |
|
161 iServer.ServiceExecuted ( ECmServiceHarvest, iStatus.Int() ); |
|
162 } |
|
163 } |
|
164 |
|
165 // End of file |
|
166 |
|
167 |
|
168 |