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