|
1 /* |
|
2 * Copyright (c) 2004 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: Methods for Ncn subsystem base class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // Include Files |
|
21 #include "NcnDebug.h" |
|
22 #include "NcnModelBase.h" |
|
23 #include "Ncn.h" |
|
24 #include "CNcnSession.h" |
|
25 #include "NcnCommsDefs.h" |
|
26 #include "MNcnNotificationObserver.h" |
|
27 #include <defaultcaps.hrh> |
|
28 #include <e32svr.h> |
|
29 #include <e32base.h> |
|
30 #include <e32math.h> |
|
31 #include <e32uid.h> |
|
32 |
|
33 // CONSTANTS |
|
34 /// Unnamed namespace for local definitions |
|
35 namespace { |
|
36 |
|
37 // thread name with secure api |
|
38 _LIT( KNcnThreadName, "ncnlist" ); |
|
39 |
|
40 const TUint myRangeCount = 3; |
|
41 const TInt myRanges[myRangeCount] = |
|
42 { |
|
43 0, //range is all s60-internal API requests |
|
44 ENewMessages1, //range is all public API requests |
|
45 EMarkUnread1 + 1 //range is non-supported requests |
|
46 }; |
|
47 const TUint8 myElementsIndex[myRangeCount] = |
|
48 { |
|
49 0, //applies to 0th range |
|
50 1, //applies to 1st range |
|
51 CPolicyServer::ENotSupported //applies to 2nd range |
|
52 }; |
|
53 const CPolicyServer::TPolicyElement myElements[] = |
|
54 { |
|
55 { |
|
56 _INIT_SECURITY_POLICY_V1( VID_DEFAULT, ECapabilityWriteUserData ), |
|
57 CPolicyServer::EFailClient |
|
58 }, |
|
59 { |
|
60 _INIT_SECURITY_POLICY_C1( ECapabilityWriteUserData ), |
|
61 CPolicyServer::EFailClient |
|
62 } |
|
63 }; |
|
64 const CPolicyServer::TPolicy myPolicy = |
|
65 { |
|
66 1, //connect attempt checks write user data capability |
|
67 myRangeCount, |
|
68 myRanges, |
|
69 myElementsIndex, |
|
70 myElements |
|
71 }; |
|
72 |
|
73 } // namespace |
|
74 |
|
75 // ================= MEMBER FUNCTIONS ======================= |
|
76 |
|
77 CNcn::CNcn( TInt aPriority, const TPolicy& aPolicy ) |
|
78 : CPolicyServer( aPriority, aPolicy ) |
|
79 { |
|
80 } |
|
81 |
|
82 CNcn::~CNcn() |
|
83 { |
|
84 delete iNcnModel; |
|
85 } |
|
86 |
|
87 // Create and start a new server. |
|
88 void CNcn::NewLC() |
|
89 { |
|
90 NCN_RDEBUG(_L("CREATING NCNLIST")); |
|
91 CNcn* server = new CNcn( CActive::EPriorityHigh, myPolicy ); |
|
92 CleanupStack::PushL( server ); |
|
93 server->ConstructL(); |
|
94 server->StartL( KNcnServerName ); |
|
95 } |
|
96 |
|
97 // Symbian OS default constructor can leave. |
|
98 void CNcn::ConstructL() |
|
99 { |
|
100 // Create an instance of CNcnModel (which initialises the Ncnlist environment) |
|
101 iNcnModel = CNcnModelBase::NewL(); |
|
102 } |
|
103 |
|
104 // Create a new server session. |
|
105 CSession2* CNcn::NewSessionL( |
|
106 const TVersion& aVersion, |
|
107 const RMessage2& /*aMessage*/ ) const |
|
108 { |
|
109 // check we're the right version |
|
110 TVersion v( KNcnNotificationServerMajor, |
|
111 KNcnNotificationServerMinor, |
|
112 KNcnNotificationServerBuild ); |
|
113 if( !User::QueryVersionSupported( v, aVersion ) ) |
|
114 User::Leave( KErrNotSupported ); |
|
115 // make new session |
|
116 return CNcnSession::NewL( iNcnModel->NotificationObserver() ); |
|
117 } |
|
118 |
|
119 TInt CNcn::RunServer() |
|
120 { |
|
121 __UHEAP_MARK; |
|
122 // |
|
123 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
124 TInt ret = KErrNoMemory; |
|
125 if( cleanup ) |
|
126 { |
|
127 TRAP( ret, CNcn::RunServerL() ); |
|
128 delete cleanup; |
|
129 } |
|
130 // |
|
131 __UHEAP_MARKEND; |
|
132 if( ret != KErrNone ) |
|
133 { |
|
134 // Signal the client that server creation failed |
|
135 RProcess::Rendezvous( ret ); |
|
136 } |
|
137 return ret; |
|
138 } |
|
139 |
|
140 void CNcn::RunServerL() |
|
141 { |
|
142 // rename thread if secure api is defined |
|
143 TInt err = User::RenameThread( KNcnThreadName ); |
|
144 |
|
145 if( err != KErrNone ) |
|
146 { |
|
147 User::Leave( err ); |
|
148 } |
|
149 |
|
150 // Create and install the active scheduler we need |
|
151 CActiveScheduler *as = new ( ELeave ) CActiveScheduler; |
|
152 CleanupStack::PushL( as ); |
|
153 CActiveScheduler::Install( as ); |
|
154 |
|
155 // Create server |
|
156 CNcn::NewLC(); |
|
157 |
|
158 // Initialisation complete, now signal the client |
|
159 RProcess::Rendezvous( KErrNone ); |
|
160 |
|
161 // Ready to run |
|
162 CActiveScheduler::Start(); |
|
163 |
|
164 // Cleanup the server and scheduler |
|
165 CleanupStack::PopAndDestroy( 2, as ); |
|
166 } |
|
167 |
|
168 TInt E32Main() |
|
169 { |
|
170 TInt error( KErrNone ); |
|
171 error = CNcn::RunServer(); |
|
172 return error; |
|
173 } |
|
174 |
|
175 // End of File |