1 /* |
|
2 * Copyright (c) 2005 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: Session implementation class for Metadata Harvester Server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <e32base.h> |
|
25 #include <s32mem.h> |
|
26 #include "mdhserversession.h" |
|
27 #include "mdhcommon.h" |
|
28 #include "mdhserver.h" |
|
29 #include "mdhmediaservercontainer.h" |
|
30 |
|
31 #include "msdebug.h" |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS ============================= |
|
35 // --------------------------------------------------------------------------- |
|
36 // Two-phase API constructor |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CCmMdhSession* CCmMdhSession::NewL( |
|
40 CCmMdhMediaserverContainer* aMediaserverContainer, CCmMdhServer& aServer ) |
|
41 { |
|
42 LOG(_L("[CmMdh Server]\t CCmMdhSession::NewL")); |
|
43 CCmMdhSession* self = |
|
44 new (ELeave) CCmMdhSession( aMediaserverContainer, aServer ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // Constructor |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CCmMdhSession::CCmMdhSession( |
|
56 CCmMdhMediaserverContainer* aMediaserverContainer, |
|
57 CCmMdhServer& aServer ): iServer( aServer ) |
|
58 { |
|
59 iMediaserverContainer = aMediaserverContainer; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Constructor |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 void CCmMdhSession::ConstructL() |
|
67 { |
|
68 LOG(_L("[CmMdh Server]\t CCmMdhSession::ConstructL")) |
|
69 iServer.IncrementSessions(); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Destructor |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CCmMdhSession::~CCmMdhSession() |
|
77 { |
|
78 LOG(_L("[CmMdh Server]\t CCmMdhSession::~CCmMdhSession")); |
|
79 iServer.DecrementSessions(); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CCmMdhSession::Server |
|
84 // Returns a reference to server |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CCmMdhServer& CCmMdhSession::Server() |
|
88 { |
|
89 return *static_cast<CCmMdhServer*> |
|
90 (const_cast<CServer2*>(CSession2::Server())); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CCmMdhSession::CompleteIfBusy |
|
95 // Completes message with busy error code if server is busy |
|
96 // --------------------------------------------------------------------------- |
|
97 TBool CCmMdhSession::CompleteIfBusy(const RMessage2& aMessage) |
|
98 { |
|
99 if (iServer.ServerState()) // operation already in progress |
|
100 { |
|
101 aMessage.Complete(KErrInUse); |
|
102 return ETrue; |
|
103 } |
|
104 return EFalse; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CCmMdhSession::ServiceL |
|
109 // Implements CSession2 -derived ServiceL -method. |
|
110 // (other items were commented in a header). |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CCmMdhSession::ServiceL(const RMessage2& aMessage) |
|
114 { |
|
115 LOG(_L("[CmMdh Server]\t CCmMdhSession::ServiceL")); |
|
116 |
|
117 switch ( aMessage.Function() ) |
|
118 { |
|
119 case ECmMdhSearchMediaservers: |
|
120 { |
|
121 LOG(_L("[CmMdh Server]\t ECmMdhSearchMediaServers request")); |
|
122 if ( !CompleteIfBusy(aMessage) ) |
|
123 { |
|
124 iServer.SetCurrentAsyncMsg( aMessage ); |
|
125 iServer.CreateMediaserverContainerL(); |
|
126 iServer.MediaserverContainer().SearchMediaserversL(); |
|
127 } |
|
128 break; |
|
129 } |
|
130 case ECmMdhHarvest: |
|
131 { |
|
132 LOG(_L("[CmMdh Server]\t ECmMdhHarvest request")); |
|
133 iServer.SetCurrentAsyncMsg( aMessage ); |
|
134 iServer.CreateMediaserverContainerL(); |
|
135 iServer.MediaserverContainer().HarvestMediaserversL(); |
|
136 break; |
|
137 } |
|
138 case ECmMdhCancel: |
|
139 { |
|
140 LOG(_L("[CmMdh Server]\t ECmMdhCancel request")); |
|
141 switch ( iServer.ServerState() ) |
|
142 { |
|
143 case ECmMdhServerStateSearching: |
|
144 { |
|
145 iServer.MediaserverContainer().CancelSearchL(); |
|
146 iServer.DestroyMediaserverContainer(); |
|
147 |
|
148 aMessage.Complete( KErrNone ); |
|
149 break; |
|
150 } |
|
151 case ECmMdhServerStateHarvesting: |
|
152 { |
|
153 iServer.MediaserverContainer().CancelHarvestL(); |
|
154 iServer.DestroyMediaserverContainer(); |
|
155 |
|
156 aMessage.Complete( KErrNone ); |
|
157 break; |
|
158 } |
|
159 default: |
|
160 { |
|
161 aMessage.Complete( KErrNotReady ); |
|
162 break; |
|
163 } |
|
164 } |
|
165 break; |
|
166 } |
|
167 default: |
|
168 { |
|
169 // Unknown opcode --> panic client |
|
170 PanicClient( aMessage, ECmMdhClientBadRequest ); |
|
171 break; |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 // End of File |
|