00001 /* 00002 Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 00003 00004 Redistribution and use in source and binary forms, with or without 00005 modification, are permitted provided that the following conditions are met: 00006 00007 * Redistributions of source code must retain the above copyright notice, this 00008 list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, 00010 this list of conditions and the following disclaimer in the documentation 00011 and/or other materials provided with the distribution. 00012 * Neither the name of Nokia Corporation nor the names of its contributors 00013 may be used to endorse or promote products derived from this software 00014 without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 00027 Description: 00028 */ 00029 00030 00031 00032 #include "processclient.h" 00033 #include "processclientserver.h" 00034 #include<e32debug.h> 00035 00036 #define KMaxServerNameLength 256 00037 00038 static const TUid KUidProcessServer = {0x10283037}; // Process Server UID 00039 const TInt KCreateSessionRetryCount = 2; //CreateSession retry count 00040 const TInt KServerDefaultMessageSlots = 2; //server async Message Slots 00041 00048 static TInt StartServer() 00049 { 00050 const TUidType serverUid(KNullUid,KNullUid,KUidProcessServer); 00051 00052 RProcess server; 00053 TInt r=server.Create(KProcessServerServerImg,KNullDesC,serverUid); 00054 if (r!=KErrNone) 00055 return r; 00056 TRequestStatus stat; 00057 server.Rendezvous(stat); 00058 00059 if (stat!=KRequestPending) 00060 server.Kill(KErrCouldNotConnect); // abort startup 00061 else 00062 server.Resume(); // logon OK - start the server 00063 00064 User::WaitForRequest(stat); // wait for start or death 00065 // The server exit type may be a panic value and a panic value can be zero, which is the same 00066 // value as KErrNone. So, the exit type is tested for a panic before being returned. 00067 if (server.ExitType()==EExitPanic) 00068 { 00069 r = KErrServerTerminated; 00070 } 00071 else 00072 { 00073 r = stat.Int(); 00074 } 00075 server.Close(); 00076 return r; 00077 } 00082 EXPORT_C TInt RProcessClient::Connect() 00083 { 00084 TInt retry=KCreateSessionRetryCount; //number of CreateSession retries 00085 FOREVER 00086 { 00087 // try to create a session with the server which has KServerDefaultMessageSlots async message slots. 00088 TInt r=CreateSession(KProcessServerName, 00089 TVersion(KProcessServerVersion, 00090 KProcessServerMinorVersionNumber, 00091 KProcessServerBuildVersionNumber), 00092 KServerDefaultMessageSlots); 00093 if (r!=KErrNotFound && r!=KErrServerTerminated) 00094 return r; 00095 if (--retry==0) 00096 return r; 00097 r=StartServer(); 00098 if (r!=KErrNone && r!=KErrAlreadyExists) 00099 return r; 00100 // 1. r=KErrNone means server starts up successfully. 00101 // 2. r=KErrAlreadyExists means a duplicate server was trying to start up. 00102 // Note: if there are other functions called before CServer2::StartL() during construction, 00103 // other errors might happen when the duplicate server is trying to start. 00104 // Therefore, we recommend CServer2::StartL() is the first function in server construction 00105 // @see CProcessServer::ConstructL() 00106 // 00107 // NOTE: If users would like to retry start up server after other scenarios happened, e.g. panic,then go 00108 // through the following steps: 00109 // 1. Increase the value of KCreateSessionRetryCount (only start up server once in this example) 00110 // 2. Need another variable, e.g. TExitType, together with error code returned in StartServer() 00111 // to distinguish these scenarios 00112 // 3. Modify the third if statement to stop exit when the required scenarios happens. 00113 // 00114 } 00115 } 00120 EXPORT_C TInt RProcessClient::OpenDriver() 00121 { 00122 return SendReceive(EOpenDriver); 00123 } 00129 EXPORT_C void RProcessClient::Send(const TDesC8& aBuf, TRequestStatus& aStatus) 00130 { 00131 SendReceive(EDummyLDDSendData, TIpcArgs(&aBuf), aStatus); 00132 } 00136 EXPORT_C void RProcessClient::SendCancel() 00137 { 00138 SendReceive(EDummyLDDSendDataCancel); 00139 } 00144 EXPORT_C TInt RProcessClient::UnloadDeviceDriver() 00145 { 00146 return SendReceive(EUnloadDeviceDriver); 00147 } 00152 EXPORT_C TInt RProcessClient::LoadDeviceDriver() 00153 { 00154 return SendReceive(ELoadDeviceDriver); 00155 } 00156 00157 //EOF