35 |
35 |
36 // ---------------------------------------------------------------------------------------- |
36 // ---------------------------------------------------------------------------------------- |
37 // Server startup code |
37 // Server startup code |
38 // ---------------------------------------------------------------------------------------- |
38 // ---------------------------------------------------------------------------------------- |
39 |
39 |
40 static TInt StartAMServerL() |
40 static TInt StartServer() |
41 { |
41 { |
42 RDEBUG("RApplicationManagement: Starting server..."); |
42 RDEBUG("RApplicationManagement: Starting server..."); |
43 |
43 |
44 TInt err = KErrNone; |
44 const TUidType serverUid(KNullUid, KNullUid, |
45 const TUid nameUid = TUid::Uid(KUikonUidPluginInterfaceNotifiers); |
45 KApplicationManagementServerUid); |
46 |
46 |
47 const TUid appServerUid = TUid::Uid(KAppMgmtServerUid ); |
47 // EPOC and EKA 2 is easy, we just create a new server process. Simultaneous |
48 |
48 // launching of two such processes should be detected when the second one |
49 RApaLsSession apa; |
49 // attempts to create the server object, failing with KErrAlreadyExists. |
50 err = apa.Connect(); |
50 RProcess server; |
51 User::LeaveIfError(err); |
51 //TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid); |
52 CleanupClosePushL(apa); |
52 TInt r = server.Create(KApplicationManagementServerImg, KNullDesC); |
53 |
53 if (r != KErrNone) |
54 // Get application information |
|
55 TApaAppInfo info; |
|
56 |
|
57 for(TInt i = 20; ((err = apa.GetAppInfo(info, |
|
58 appServerUid)) == RApaLsSession::EAppListInvalid) && i > 0; i--) |
|
59 { |
54 { |
60 User::After(500000); |
55 RDEBUG_2("ApplicationManagementClient: server start failed %d",r); |
|
56 return r; |
61 } |
57 } |
62 User::LeaveIfError(err); |
58 TRequestStatus stat; |
63 |
59 server.Rendezvous(stat); |
64 TRequestStatus aRequestStatusForRendezvous; |
60 if (stat != KRequestPending) |
65 |
61 server.Kill(0); // abort startup |
66 // Start aplication server |
62 else |
67 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
63 server.Resume(); // logon OK - start the server |
68 cmdLine->SetExecutableNameL(info.iFullName); |
64 RDEBUG("ApplicationManagementClient: Started"); |
69 cmdLine->SetServerRequiredL(nameUid.iUid ); |
65 User::WaitForRequest(stat); |
70 cmdLine->SetCommandL(EApaCommandBackground); |
66 TInt err = RProperty::Define(KProperty, KInteger, RProperty::EInt); |
71 TThreadId srvid; |
67 RProperty ServerLaunch; |
72 err = apa.StartApp(*cmdLine, srvid, &aRequestStatusForRendezvous); |
68 ServerLaunch.Attach(KProperty, KInteger, EOwnerThread); |
73 User::LeaveIfError(err); |
69 TRequestStatus status; |
74 |
70 |
75 User::WaitForRequest(aRequestStatusForRendezvous); |
71 ServerLaunch.Subscribe(status); |
76 CleanupStack::PopAndDestroy(2, &apa); // cmdLine and apa |
72 //server.Resume(); |
77 |
73 User::WaitForRequest(status); |
78 return KErrNone; |
74 |
79 } |
75 ServerLaunch.Close(); |
80 |
76 RProperty::Delete(KProperty, KInteger); |
81 EXPORT_C RAppMgmtRfs::RAppMgmtRfs() |
77 |
82 { |
78 //User::WaitForRequest(stat); // wait for start or death |
|
79 // we can't use the 'exit reason' if the server panicked as this |
|
80 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
81 // from KErrNone |
|
82 r = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); |
|
83 // _LIT_SECURITY_POLICY_S0(KWritePolicy,KApplicationManagementServerUid.iUid); |
|
84 // _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData ); |
|
85 |
|
86 server.Close(); |
|
87 return r; |
83 } |
88 } |
|
89 |
|
90 |
84 EXPORT_C TInt RAppMgmtRfs::Connect() |
91 EXPORT_C TInt RAppMgmtRfs::Connect() |
85 { |
92 { |
86 TInt retry=2; |
93 TInt retry=2; |
87 TVersion ver( KAMVerMajor, KAMVerMinor, KAMVerBuild ); |
94 TVersion ver( KAMVerMajor, KAMVerMinor, KAMVerBuild ); |
88 for (;;) |
95 for (;;) |
89 { |
96 { |
90 |
97 |
91 TInt r; |
98 TInt r=CreateSession(KApplicationManagementServerName,ver,1); |
92 |
|
93 const TUid nameUid = TUid::Uid(KUikonUidPluginInterfaceNotifiers); |
|
94 |
|
95 const TUid appServerUid = TUid::Uid(KAppMgmtServerUid ); |
|
96 |
|
97 _LIT(KServerNameFormat, "%08x_%08x_AppServer"); |
|
98 TFullName serverName; |
|
99 serverName.Format(KServerNameFormat, |
|
100 nameUid, appServerUid); |
|
101 TRAP(r, ConnectExistingByNameL(serverName) ); |
|
102 if(r) |
|
103 { |
|
104 |
|
105 r = CreateSession (serverName, ver); |
|
106 |
|
107 } |
|
108 if (r!=KErrNotFound && r!=KErrServerTerminated) |
99 if (r!=KErrNotFound && r!=KErrServerTerminated) |
109 return r; |
100 return r; |
110 if (--retry==0) |
101 if (--retry==0) |
111 return r; |
102 return r; |
112 TRAP_IGNORE(r=StartAMServerL()); |
103 r=StartServer(); |
113 if (r!=KErrNone && r!=KErrAlreadyExists) |
104 if (r!=KErrNone && r!=KErrAlreadyExists) |
114 { |
105 { |
115 return r; |
106 return r; |
116 } |
107 } |
117 } |
108 } |
118 } |
109 } |
119 |
110 |
120 |
111 |
121 EXPORT_C void RAppMgmtRfs::Close() |
112 EXPORT_C void RAppMgmtRfs::Close() |
122 { |
113 { |
123 REikAppServiceBase::Close(); //basecall |
114 RSessionBase::Close(); //basecall |
124 } |
115 } |
125 |
116 |
126 // New methods |
117 // New methods |
127 EXPORT_C void RAppMgmtRfs::PerformRfsL() const |
118 EXPORT_C void RAppMgmtRfs::PerformRfsL() const |
128 { |
119 { |
129 User::LeaveIfError( SendReceive( EPerformRfs, TIpcArgs() ) ); |
120 User::LeaveIfError( SendReceive( EPerformRfs, TIpcArgs() ) ); |
130 } |
121 } |
131 |
122 |
132 TUid RAppMgmtRfs::ServiceUid() const |
123 |
133 { |
|
134 return TUid::Uid( KAMServiceUid); |
|
135 } |
|
136 |
|
137 |
|
138 EXPORT_C RApplicationManagement::RApplicationManagement() |
|
139 { |
|
140 } |
|
141 |
124 |
142 // This is the standard retry pattern for server connection |
125 // This is the standard retry pattern for server connection |
143 EXPORT_C TInt RApplicationManagement::Connect( ) |
126 EXPORT_C TInt RApplicationManagement::Connect( ) |
144 { |
127 { |
145 TInt retry=2; |
128 TInt retry=2; |
146 TVersion ver( KAMVerMajor, KAMVerMinor, KAMVerBuild ); |
129 TVersion ver( KAMVerMajor, KAMVerMinor, KAMVerBuild ); |
147 for (;;) |
130 for (;;) |
148 { |
131 { |
149 |
132 |
150 TInt r; |
133 TInt r=CreateSession(KApplicationManagementServerName,ver,1); |
151 |
|
152 const TUid nameUid = TUid::Uid(KUikonUidPluginInterfaceNotifiers); |
|
153 |
|
154 const TUid appServerUid = TUid::Uid(KAppMgmtServerUid ); |
|
155 |
|
156 _LIT(KServerNameFormat, "%08x_%08x_AppServer"); |
|
157 TFullName serverName; |
|
158 serverName.Format(KServerNameFormat, |
|
159 nameUid, appServerUid); |
|
160 TRAP(r, ConnectExistingByNameL(serverName) ); |
|
161 if(r) |
|
162 { |
|
163 |
|
164 r = CreateSession (serverName, ver); |
|
165 |
|
166 } |
|
167 if (r!=KErrNotFound && r!=KErrServerTerminated) |
134 if (r!=KErrNotFound && r!=KErrServerTerminated) |
168 return r; |
135 return r; |
169 if (--retry==0) |
136 if (--retry==0) |
170 return r; |
137 return r; |
171 TRAP_IGNORE(r=StartAMServerL()) |
138 r=StartServer(); |
172 if (r!=KErrNone && r!=KErrAlreadyExists) |
139 if (r!=KErrNone && r!=KErrAlreadyExists) |
173 { |
140 { |
174 return r; |
141 return r; |
175 } |
142 } |
176 } |
143 } |