|
1 /** @file |
|
2 * Copyright (c) 2008 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: Declaration of CUpnpSymbianServerBase |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CUPNPSYMBIANSERVERBASE_H |
|
19 #define CUPNPSYMBIANSERVERBASE_H |
|
20 |
|
21 #include <e32base.h> |
|
22 #include "upnpnotifytimer.h" |
|
23 |
|
24 class CUpnpSymbianServerBase; |
|
25 |
|
26 typedef CUpnpSymbianServerBase* (*TServerFactoryMethodLC)(); |
|
27 |
|
28 /** |
|
29 * Base class for all symbian server classes used in upnp stack project |
|
30 * This implementation provides: |
|
31 * - proper server starting, |
|
32 * - 2 seconds stoping timeout, |
|
33 * - stopping server if ( no connected clients && CanBeStopped() ) |
|
34 * @see CanBeStopped() |
|
35 * @see SuggestShutdown() |
|
36 * - session connection version checking, |
|
37 * - basic panics utility functions, |
|
38 * - basic errors handling |
|
39 * Note that it should be used with client part implementation that use |
|
40 * RUpnpSessionBase class. |
|
41 * |
|
42 * @lib upnpipserversutils |
|
43 */ |
|
44 class CUpnpSymbianServerBase : public CServer2, public MUpnpNotifyTimerObserver |
|
45 { |
|
46 public: |
|
47 enum TUpnpSymbianServerPanics |
|
48 { |
|
49 ECreateTrapCleanup, |
|
50 EBadRequest, |
|
51 EBadDescriptor, |
|
52 EFirstUnusedPanicNumber //this should be always last enum as this is |
|
53 //used by derived server to start their panic enums |
|
54 }; |
|
55 |
|
56 public: |
|
57 /** |
|
58 * Fully initialise thread, and start the server. |
|
59 * Method is intended to be called from E32Main method without any earlier |
|
60 * initialisation. |
|
61 * @param aThreadName name to which thread will be renamed. |
|
62 * @param aServerFactoryMethodLC two phase constructor of server object that |
|
63 * leaves it on cleanup stack. |
|
64 * @return error code |
|
65 */ |
|
66 IMPORT_C static TInt StartServer( const TDesC& aThreadName, |
|
67 TServerFactoryMethodLC aServerFactoryMethodLC ); |
|
68 |
|
69 /** |
|
70 * Destructor |
|
71 */ |
|
72 IMPORT_C ~CUpnpSymbianServerBase(); |
|
73 |
|
74 /** |
|
75 * Panic the client. |
|
76 * @param aMessage the message channel to the client. |
|
77 * @param aReason the reason code for the panic. |
|
78 */ |
|
79 IMPORT_C void PanicClient( const RMessage2& aMessage, TInt aReason ) const; |
|
80 |
|
81 protected: |
|
82 /** |
|
83 * Constructor. |
|
84 */ |
|
85 IMPORT_C CUpnpSymbianServerBase(); |
|
86 |
|
87 /** |
|
88 * Second phase base constructor. It must be called by derived class. |
|
89 */ |
|
90 IMPORT_C void BaseConstructL(); |
|
91 |
|
92 /** |
|
93 * Panic the server. |
|
94 * @param aPanic the panic code. |
|
95 */ |
|
96 IMPORT_C void PanicServer( TInt aPanic ) const; |
|
97 |
|
98 private: |
|
99 /** |
|
100 * Returns new CSession2 object. |
|
101 * This method don't have to bother about version checking |
|
102 * as this is done by implementation of |
|
103 * CUpnpSymbianServerBase::NewSessionL |
|
104 * (const TVersion& aVersion, const RMessage2& aMessage) |
|
105 * that is wrapping this method. |
|
106 */ |
|
107 virtual CSession2* NewSessionL( const RMessage2& aMessage ) const = 0; |
|
108 |
|
109 /** |
|
110 * Returns version that is supported by this server. |
|
111 */ |
|
112 virtual TVersion SupportedVersion() const = 0; |
|
113 |
|
114 /** |
|
115 * Return name of a server. |
|
116 * @return name of a server. |
|
117 */ |
|
118 virtual const TDesC& ServerName() const = 0; |
|
119 |
|
120 /** |
|
121 * Derived classes can implement in the method additional condidions |
|
122 * of stopping server process that will be checked in SuggestShutdown |
|
123 * method and befor actual server stopping. Default implementation |
|
124 * provides no additional condidions. |
|
125 * |
|
126 * @return ETrue if server proccess can be stopped at the moment |
|
127 */ |
|
128 IMPORT_C virtual TBool CanBeStopped() const; |
|
129 |
|
130 protected: |
|
131 /** |
|
132 * Method should be called when derived class wants to suggest |
|
133 * closing of the media server. This method checks every stop |
|
134 * condidion and starts closing server timeout if all of them are |
|
135 * fulfilled. |
|
136 */ |
|
137 IMPORT_C void SuggestShutdown(); |
|
138 |
|
139 protected: |
|
140 //from MUpnpNotifyTimerObserver |
|
141 /** |
|
142 * Invoked by shutdown timer when event TimerEventL occured. |
|
143 */ |
|
144 IMPORT_C virtual void TimerEventL( CUpnpNotifyTimer* aTimer ); |
|
145 |
|
146 protected: |
|
147 //from CServer2 |
|
148 /** |
|
149 * This method wraps pure virtual NewSessionL(const RMessage2&) |
|
150 * and leaves with KErrNotSupported if aVersion is different |
|
151 * from version provided by pure virtual SupportedVersion. |
|
152 */ |
|
153 IMPORT_C CSession2* NewSessionL( |
|
154 const TVersion& aVersion, const RMessage2& aMessage ) const; |
|
155 |
|
156 protected: |
|
157 //from CActive |
|
158 |
|
159 /** |
|
160 * Invoked by active object framework to handle ending events |
|
161 */ |
|
162 IMPORT_C void RunL(); |
|
163 |
|
164 /** |
|
165 * Process any errors. |
|
166 * @param aError the leave code reported. |
|
167 * @result return KErrNone if leave is handled. |
|
168 */ |
|
169 IMPORT_C TInt RunError( TInt aError ); |
|
170 |
|
171 private: |
|
172 /** |
|
173 * Internal method that initialises thread, and starts the server. |
|
174 * Precondition is that cleanup stack is correctly initialised |
|
175 * and method is called from within a TRAP. |
|
176 * @param aThreadName name to which thread will be renamed. |
|
177 * @param aServerFactoryMethodLC two phase constructor of server object that |
|
178 * leaves it on cleanup stack. |
|
179 */ |
|
180 static void StartServerL( const TDesC& aThreadName, |
|
181 TServerFactoryMethodLC aServerFactoryMethodLC ); |
|
182 |
|
183 /** |
|
184 * Increment the count of the active sessions for this server. |
|
185 */ |
|
186 void IncrementSessionCount(); |
|
187 |
|
188 /** |
|
189 * Decrement the count of the active sessions for this server. |
|
190 */ |
|
191 void DecrementSessionCount(); |
|
192 |
|
193 private: |
|
194 /** @var iSessionCount the number of session owned by this server */ |
|
195 TInt iSessionCount; |
|
196 |
|
197 /** shutdown timer */ |
|
198 CUpnpNotifyTimer* iShutdownTimer; |
|
199 }; |
|
200 |
|
201 #endif // CUPNPSYMBIANSERVERBASE_H |