00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "processserver.h"
00017 #include "processserverstart.h"
00018 #include "processserversession.h"
00019 #include<e32debug.h>
00020
00021 const TInt KProcessServerShutDownDelay = 50000000;
00022
00023
00024 void CProcessServer::NewLC()
00025 {
00026 CProcessServer* s = new(ELeave) CProcessServer();
00027 CleanupStack::PushL(s);
00028 s->ConstructL();
00029 }
00033 CProcessServer::CProcessServer()
00034 :CServer2(EPriorityStandard, ESharableSessions),iDriverState(EStateUnknown)
00035 {
00036 }
00040 void CProcessServer::ConstructL()
00041 {
00042
00043
00044 StartL(KProcessServerName);
00045 iDelayProcessServerShutDown = CDelayServerShutDown::NewL();
00046 }
00050 CProcessServer::~CProcessServer()
00051 {
00052 if (iDelayProcessServerShutDown)
00053 {
00054 iDelayProcessServerShutDown->Cancel();
00055 delete iDelayProcessServerShutDown;
00056 }
00057
00058
00059 UnloadDevice();
00060 }
00067 CSession2* CProcessServer::NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const
00068 {
00069
00070 TVersion v(KProcessServerVersion,KProcessServerMinorVersionNumber,KProcessServerBuildVersionNumber);
00071 if(!User::QueryVersionSupported(v, aVersion))
00072 User::Leave(KErrNotSupported);
00073
00074
00075 if(!aMessage.HasCapability(ECapabilityMultimediaDD))
00076 User::Leave(KErrPermissionDenied);
00077
00078
00079 CProcessServer& ncThis = const_cast<CProcessServer&>(*this);
00080 CProcessServerSession* serverSession = CProcessServerSession::NewL(ncThis);
00081 return serverSession;
00082 }
00086 void CProcessServer::IncrementRefCount()
00087 {
00088 iRefCount++;
00089 iDelayProcessServerShutDown->Cancel();
00090 }
00091
00095 void CProcessServer::DecrementRefCount()
00096 {
00097 iRefCount--;
00098 if ( iRefCount == 0 )
00099 {
00100 iDelayProcessServerShutDown->SetDelay(TTimeIntervalMicroSeconds32(KProcessServerShutDownDelay));
00101 }
00102 }
00107 TInt CProcessServer::LoadDevice()
00108 {
00109 if (iDriverState>=EDriverLoaded && iDriverState<EDriverUnloaded)
00110 return KErrNone;
00111
00112 TInt r=User::LoadPhysicalDevice(KDriver1PddFileName);
00113 if (r!=KErrNone && r!=KErrAlreadyExists)
00114 {
00115 return r;
00116 }
00117
00118 r = User::LoadLogicalDevice(KDriver1LddFileName);
00119 if (r!=KErrNone && r!=KErrAlreadyExists)
00120 {
00121 return r;
00122 }
00123
00124
00125 UpdateDriverState(EDriverLoaded);
00126 return KErrNone;
00127 }
00132 TInt CProcessServer::UnloadDevice()
00133 {
00134 if (iDriverState==EDriverUnloaded || iDriverState == EStateUnknown)
00135 return KErrNone;
00136
00137
00138 if (iDriver.Handle())
00139 iDriver.Close();
00140
00141 TInt r = User::FreeLogicalDevice(RDriver1::Name());
00142 if (r!=KErrNone)
00143 return r;
00144
00145 TName pddName(RDriver1::Name());
00146 _LIT(KVariantExtension,".template");
00147 pddName.Append(KVariantExtension);
00148 r=User::FreePhysicalDevice(pddName);
00149
00150 if (KErrNone==r)
00151 UpdateDriverState(EDriverUnloaded);
00152 return r;
00153 }
00158 TInt CProcessServer::OpenLogicalChannel()
00159 {
00160 if (iDriverState>=ELogicalChannelOpened && iDriverState<ELogicalChannelClosed)
00161 return KErrNone;
00162
00163 TInt r = iDriver.Open();
00164 if (KErrNone==r)
00165 UpdateDriverState(ELogicalChannelOpened);
00166
00167 return r;
00168 }
00172 void CProcessServer::CloseLogicalChannel()
00173 {
00174 if (iDriver.Handle())
00175 {
00176 iDriver.Close();
00177 UpdateDriverState(ELogicalChannelClosed);
00178 }
00179 }
00186 TInt CProcessServer::SendDataToDevice(TRequestStatus& aStatus, const TDesC8& aData)
00187 {
00188 TInt r = KErrNone;
00189 if (iDriverState>=ELogicalChannelOpened && iDriverState<ELogicalChannelClosed)
00190 {
00191 iDriver.SendData(aStatus, aData);
00192 UpdateDriverState(ESendingData);
00193 }
00194 else
00195 {
00196 r = KErrArgument;
00197 }
00198 return r;
00199 }
00203 void CProcessServer::CancelSendData()
00204 {
00205 iDriver.SendDataCancel();
00206 UpdateDriverState(ELogicalChannelOpened);
00207 }
00212 void CProcessServer::UpdateDriverState(TDriverState aState)
00213 {
00214 iDriverState = aState;
00215 }
00216
00217