sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@internalComponent
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
#include "mmcameraclientinterface.h"
|
sl@0
|
22 |
#include <e32uid.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
* Starts the server process.
|
sl@0
|
27 |
*
|
sl@0
|
28 |
* Simultaneous launching of two such processes should be detected when the second
|
sl@0
|
29 |
* one attempts to create the server object, failing with KErrAlreadyExists.
|
sl@0
|
30 |
*/
|
sl@0
|
31 |
static TInt StartServer()
|
sl@0
|
32 |
{
|
sl@0
|
33 |
const TUidType serverUid(KNullUid, KExecutableImageUid, KECamServerUid3);
|
sl@0
|
34 |
RProcess server;
|
sl@0
|
35 |
TInt err = server.Create(KMMCameraServerExe, KNullDesC, serverUid);
|
sl@0
|
36 |
if (err != KErrNone)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
return err;
|
sl@0
|
39 |
}
|
sl@0
|
40 |
TRequestStatus stat;
|
sl@0
|
41 |
server.Rendezvous(stat);
|
sl@0
|
42 |
if (stat != KRequestPending)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
server.Kill(0); // abort startup
|
sl@0
|
45 |
}
|
sl@0
|
46 |
else
|
sl@0
|
47 |
{
|
sl@0
|
48 |
server.Resume(); // logon OK - start the server
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
User::WaitForRequest(stat); // wait for start or death
|
sl@0
|
52 |
// we can't use the 'exit reason' if the server panicked as this
|
sl@0
|
53 |
// is the panic 'reason' and may be '0' which cannot be distinguished
|
sl@0
|
54 |
// from KErrNone
|
sl@0
|
55 |
err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
|
sl@0
|
56 |
server.Close();
|
sl@0
|
57 |
|
sl@0
|
58 |
return err;
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
|
sl@0
|
62 |
/**
|
sl@0
|
63 |
* Connect to the server.
|
sl@0
|
64 |
*
|
sl@0
|
65 |
* Will attempt to start the server if it has not yet been started or has been shut down.
|
sl@0
|
66 |
*/
|
sl@0
|
67 |
TInt RMMCameraSession::Connect()
|
sl@0
|
68 |
{
|
sl@0
|
69 |
TInt serverStartRetries = 2;
|
sl@0
|
70 |
for (;;)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
// Attempt to create a session to the server
|
sl@0
|
73 |
TInt err = CreateSession(KMMCameraServerName, TVersion(0, 0, 0), KECamNumAsynchMsg);
|
sl@0
|
74 |
if (err != KErrNotFound && err != KErrServerTerminated)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
return err;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
if (--serverStartRetries == 0)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
return err;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
// Server not found or shut down so (re)start the server
|
sl@0
|
85 |
err = StartServer();
|
sl@0
|
86 |
if (err != KErrNone && err != KErrAlreadyExists)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
return err;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
}
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
|
sl@0
|
94 |
//
|
sl@0
|
95 |
// Synchronous interface APIs
|
sl@0
|
96 |
//
|
sl@0
|
97 |
|
sl@0
|
98 |
TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
if (aMessage.Length() > KECamMaxMessage)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
return KErrArgument;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage));
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage));
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TDes8& aMessage)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
if (aMessage.Length() > KECamMaxMessage)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
return KErrArgument;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
return SendReceive(aMsgId, TIpcArgs(&aMessage));
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TInt aMessage)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
return SendReceive(aMsgId, TIpcArgs(aMessage));
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
return SendReceive(aMsgId);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage) const
|
sl@0
|
134 |
{
|
sl@0
|
135 |
if (aMessage.Length() > KECamMaxMessage)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
return KErrArgument;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage));
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage) const
|
sl@0
|
144 |
{
|
sl@0
|
145 |
return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage));
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TDes8& aMessage) const
|
sl@0
|
149 |
{
|
sl@0
|
150 |
if (aMessage.Length() > KECamMaxMessage)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
return KErrArgument;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
return SendReceive(aMsgId, TIpcArgs(&aMessage));
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
|
sl@0
|
159 |
//
|
sl@0
|
160 |
// Asynchronous interface APIs
|
sl@0
|
161 |
//
|
sl@0
|
162 |
|
sl@0
|
163 |
TInt RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TDes8& aMessage, TRequestStatus& aStatus)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
if (aMessage.Length() > KECamMaxMessage)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
return KErrArgument;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
SendReceive(aMsgId, TIpcArgs(&aMessage), aStatus);
|
sl@0
|
171 |
|
sl@0
|
172 |
return KErrNone;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
void RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TInt aMessage, TRequestStatus& aStatus)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
SendReceive(aMsgId, TIpcArgs(aMessage), aStatus);
|
sl@0
|
178 |
}
|