diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/processserversession_8cpp_source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/processserversession_8cpp_source.html Tue Mar 30 16:16:55 2010 +0100 @@ -0,0 +1,206 @@ + + +
+ +00001 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +00002 // All rights reserved. +00003 // This component and the accompanying materials are made available +00004 // under the terms of "Eclipse Public License v1.0" +00005 // which accompanies this distribution, and is available +00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". +00007 // +00008 // Initial Contributors: +00009 // Nokia Corporation - initial contribution. +00010 // +00011 // Contributors: +00012 // +00013 // Description: +00014 // +00015 +00016 #include "processserversession.h" +00017 +00018 +00019 /*****************CProcessServerSession**********************/ +00023 CProcessServerSession* CProcessServerSession::NewL(CProcessServer& aServer) +00024 { +00025 CProcessServerSession* s = new(ELeave) CProcessServerSession(aServer); +00026 CleanupStack::PushL(s); +00027 s->ConstructL(); +00028 CleanupStack::Pop(); +00029 return s; +00030 } +00034 CProcessServerSession::CProcessServerSession(CProcessServer& aServer) +00035 :iServer(aServer) +00036 { +00037 +00038 } +00039 +00040 void CProcessServerSession::ConstructL() +00041 { +00042 } +00046 CProcessServerSession::~CProcessServerSession() +00047 { +00048 delete iAsyncRequestHandler; +00049 iServer.CloseLogicalChannel(); +00050 iServer.DecrementRefCount(); +00051 } +00056 void CProcessServerSession::CreateL() +00057 // +00058 // 2nd phase constructor for sessions - called by the CServer framework +00059 // +00060 { +00061 iServer.IncrementRefCount(); +00062 //load dummy ldd +00063 User::LeaveIfError(iServer.LoadDevice()); +00064 iAsyncRequestHandler = CAsyncHandler::NewL(iServer); +00065 } +00069 void CProcessServerSession::ServiceL(const RMessage2& aMessage) +00070 { +00071 TInt r = KErrNone; +00072 switch(aMessage.Function()) +00073 { +00074 case ELoadDeviceDriver: +00075 aMessage.Complete(iServer.LoadDevice()); +00076 break; +00077 +00078 case EOpenDriver: +00079 aMessage.Complete(iServer.OpenLogicalChannel()); +00080 break; +00081 +00082 case EDummyLDDSendData: //async +00083 r = iAsyncRequestHandler->ProcessRequest(aMessage); +00084 if (r!=KErrNone) +00085 aMessage.Complete(r); +00086 break; +00087 +00088 case EDummyLDDSendDataCancel: //cancel async +00089 iAsyncRequestHandler->Cancel(); +00090 aMessage.Complete(KErrNone); +00091 break; +00092 +00093 case EUnloadDeviceDriver: +00094 aMessage.Complete(iServer.UnloadDevice()); +00095 break; +00096 +00097 default: +00098 User::Leave(KErrNotSupported); +00099 break; +00100 } +00101 +00102 } +00103 +00104 +00105 +00106 /*****************CAsyncHandler**********************/ +00110 CProcessServerSession::CAsyncHandler* CProcessServerSession::CAsyncHandler::NewL(CProcessServer& aServer) +00111 { +00112 CAsyncHandler* self = new(ELeave) CAsyncHandler(aServer); +00113 CleanupStack::PushL(self); +00114 self ->ConstructL(); +00115 CleanupStack::Pop(); +00116 return self; +00117 } +00121 CProcessServerSession::CAsyncHandler::~CAsyncHandler() +00122 { +00123 Cancel(); +00124 iMessageArray.Close(); +00125 } +00129 void CProcessServerSession::CAsyncHandler::RunL() +00130 { +00131 // complete the request +00132 Complete(iStatus.Int()); +00133 +00134 //continue to execute next request if there is any +00135 ExecuteFirstRequestInArray(); +00136 } +00140 void CProcessServerSession::CAsyncHandler::DoCancel() +00141 { +00142 iServer.CancelSendData(); +00143 // complete the request +00144 Complete(iStatus.Int()); +00145 } +00149 CProcessServerSession::CAsyncHandler::CAsyncHandler(CProcessServer& aServer) +00150 :CActive(EPriorityStandard), iServer(aServer) +00151 { +00152 CActiveScheduler::Add(this); +00153 } +00154 +00155 void CProcessServerSession::CAsyncHandler::ConstructL() +00156 { +00157 +00158 } +00164 TInt CProcessServerSession::CAsyncHandler::ProcessRequest(const RMessage2& aMessage) +00165 { +00166 TInt ret; +00167 //store message +00168 TMessage newMessage; +00169 newMessage.Message() = aMessage; +00170 ret= iMessageArray.Append(newMessage); +00171 if (ret != KErrNone) +00172 return ret; +00173 +00174 // kick off the first request in the array when there is only one in the array +00175 if (iMessageArray.Count() == 1) +00176 ret= ExecuteFirstRequestInArray(); +00177 +00178 return ret; +00179 } +00184 TInt CProcessServerSession::CAsyncHandler::ExecuteFirstRequestInArray() +00185 { +00186 TInt r = KErrNone; +00187 if (iMessageArray.Count() != 0) +00188 { +00189 const RMessage2& message = iMessageArray[0].Message(); +00190 switch (message.Function()) +00191 { +00192 case EDummyLDDSendData: +00193 { +00194 TBuf8<KMaxMessageLen> sendObject; +00195 r= message.Read(0, sendObject); +00196 if (r == KErrNone) +00197 { +00198 r = iServer.SendDataToDevice(iStatus, sendObject); +00199 if (r==KErrNone) +00200 SetActive(); +00201 } +00202 } +00203 break; +00204 +00205 default: +00206 break; +00207 } +00208 +00209 } +00210 return r; +00211 } +00215 void CProcessServerSession::CAsyncHandler::Complete(TInt aResult) +00216 { +00217 iMessageArray[0].Message().Complete(aResult); +00218 iMessageArray.Remove(0); +00219 iServer.UpdateDriverState(CProcessServer::ELogicalChannelOpened); +00220 } +00221 +00222 /***************TMessage****************/ +00226 const RMessage2& CProcessServerSession::CAsyncHandler::TMessage::Message() const +00227 { +00228 return iMessage; +00229 } +00230 +00231 RMessage2& CProcessServerSession::CAsyncHandler::TMessage::Message() +00232 { +00233 return iMessage; +00234 } +00235 +00236 //EOF +