linklayercontrol/tundriveragt/src/tundriveragent.cpp
branchRCL_3
changeset 63 425d8f4f7fa5
equal deleted inserted replaced
58:8d540f55e491 63:425d8f4f7fa5
       
     1 /**
       
     2 *   Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 *   All rights reserved.
       
     4 *   This component and the accompanying materials are made available
       
     5 *   under the terms of "Eclipse Public License v1.0"
       
     6 *   which accompanies this distribution, and is available
       
     7 *   at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *   
       
     9 *   Initial Contributors:
       
    10 *   Nokia Corporation - initial contribution.
       
    11 *   
       
    12 *   Contributors:
       
    13 *
       
    14 *   Description:
       
    15 *   Source file for tundriver agent.
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 /**
       
    21  @file tundriveragent.cpp
       
    22  @internalTechnology
       
    23 */
       
    24 
       
    25 #include "tundriveragent.h"
       
    26 extern "C" EXPORT_C CNifAgentFactory* NewAgentFactoryL()
       
    27 /**
       
    28 Agent Factory
       
    29 First ordinal export
       
    30 
       
    31 @internalComponent
       
    32 @return an object to class CTunAgentFactory,which Perform Agent initialisation.
       
    33 */
       
    34 	{	
       
    35 	return new(ELeave) CTunDriverAgentFactory;
       
    36 	}
       
    37 
       
    38 void CTunDriverAgentFactory::InstallL() 
       
    39 /**
       
    40 Performs a new Agent initialisation
       
    41 */
       
    42 	{}
       
    43  
       
    44 CNifAgentBase* CTunDriverAgentFactory::NewAgentL(const TDesC& /*aName*/)
       
    45 /**
       
    46 Creates a new TunDriverAgent to TunDriver
       
    47 
       
    48 @param aName , name of the TunDriverAgent
       
    49 @return a new instance of class TunDriverAgent
       
    50 */
       
    51 	{
       
    52 	return CTunDriverAgent::NewL();
       
    53 	}
       
    54 
       
    55 TInt CTunDriverAgentFactory::Info(TNifAgentInfo& aInfo, TInt /*aIndex*/) const
       
    56 /**
       
    57 Retrieves information about the Agent
       
    58 
       
    59 @param aInfo,a reference of class TNifAgentInfo which contains information about TunDriverAgent
       
    60 @return KErrNone if information retrieved successfully.
       
    61 */
       
    62 	{
       
    63 	aInfo.iName = KTunDriverAgentName;
       
    64 	aInfo.iVersion = TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
       
    65 	return KErrNone;
       
    66 	}
       
    67 
       
    68 CTunDriverAgent::CTunDriverAgent() :	iServiceStartedCallback(CActive::EPriorityStandard),
       
    69 							iConnectCompleteCallback(CActive::EPriorityStandard), 
       
    70 							iDisconnectCallback(CActive::EPriorityStandard)
       
    71 /**
       
    72 Default Constructor
       
    73 */
       
    74 	{
       
    75 	TCallBack serviceStartedCallback(ServiceStartedCb, this);
       
    76 	iServiceStartedCallback.Set(serviceStartedCallback);
       
    77 	
       
    78 	TCallBack connectionCompleteCallback(ConnectCompleteCb, this);
       
    79 	iConnectCompleteCallback.Set(connectionCompleteCallback);
       
    80 
       
    81 	TCallBack disconnectionCompleteCallback(DisconnectCompleteCb, this);
       
    82 	iDisconnectCallback.Set(disconnectionCompleteCallback);
       
    83 	}
       
    84  
       
    85 CTunDriverAgent::~CTunDriverAgent()
       
    86 /**
       
    87 Destructor
       
    88 */
       
    89 	{
       
    90 	iServiceStartedCallback.Cancel();
       
    91 	iConnectCompleteCallback.Cancel();
       
    92 	iDisconnectCallback.Cancel();
       
    93 	}
       
    94 
       
    95 
       
    96 CTunDriverAgent* CTunDriverAgent::NewL()
       
    97 /**
       
    98 Static NewL function constructing an object of class CTunDriverAgent
       
    99 
       
   100 @return self,pointer to class TunDriverAgent,that owns a CAsyncCallback used to 
       
   101 control the asynchronous ServiceStarted() and DisconnectComplete() call from the Agent to TunDriver. 
       
   102 */
       
   103 	{
       
   104 	CTunDriverAgent* self = new (ELeave) CTunDriverAgent();
       
   105 	CleanupStack::PushL(self);
       
   106 	self->ConstructL();
       
   107 	CleanupStack::Pop();
       
   108 	return self;
       
   109 	}
       
   110 
       
   111 void CTunDriverAgent::ConstructL()
       
   112 /**
       
   113 2nd Phase Constructor
       
   114 Calls CAgentBase::ConstructL()
       
   115 construct the database and dialog processor
       
   116 */
       
   117 	{
       
   118 	CAgentBase::ConstructL();
       
   119 	iCancelled = EFalse;
       
   120 	iAgentProgress = ETunDriverAgtIdle;
       
   121 	}
       
   122 
       
   123 void CTunDriverAgent::Info(TNifAgentInfo& aInfo) const
       
   124 /**
       
   125 Information about this Agent
       
   126 
       
   127 @param aInfo on return contains information about the agent
       
   128 */
       
   129 	{
       
   130 	aInfo.iName = KTunDriverAgentName;
       
   131 	aInfo.iName.AppendFormat(_L("-AgentFactory[0x%08x]"), this);
       
   132 	aInfo.iVersion = TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
       
   133 	}
       
   134 
       
   135 void CTunDriverAgent::Connect(TAgentConnectType aType)
       
   136 /**
       
   137 Connects this TunDriverAgent to TunDriver
       
   138 
       
   139 @internalComponent  
       
   140 @param aType, a variable of enum TAgentConnectType describing connection types.
       
   141 */
       
   142 	{
       
   143 	if (EAgentReconnect == aType)
       
   144 		{
       
   145 		iConnectCompleteCallback.CallBack();
       
   146 		}
       
   147 	else
       
   148 		{
       
   149 		iCancelled = EFalse;
       
   150 		iServiceStartedCallback.CallBack();		
       
   151 		}
       
   152 	}
       
   153 
       
   154 void CTunDriverAgent::Connect(TAgentConnectType aType, CStoreableOverrideSettings* /*aOverrideSettings*/)
       
   155 /**
       
   156 Connects this TunDriverAgent to TunDriver with store and retrieve commDB override sets to and from both
       
   157 streams and buffers.
       
   158 
       
   159 @param aType,a variable of enum TAgentConnectType describing connection types.
       
   160 @param aOverrideSettings, a pointer to class CStoreableOverrideSettings which store CommDB overrides.
       
   161 */
       
   162 	{
       
   163 	Connect(aType);
       
   164 	}
       
   165 
       
   166 void CTunDriverAgent::CancelConnect()
       
   167 /**
       
   168 Cancels Connection of the TunDriverAgent to TunDriver 
       
   169 */
       
   170 	{
       
   171 	iServiceStartedCallback.Cancel();
       
   172 	iConnectCompleteCallback.Cancel();
       
   173 	iConnected = EFalse;
       
   174 	iCancelled = ETrue;
       
   175 	}
       
   176 
       
   177 void CTunDriverAgent::Disconnect(TInt aReason)
       
   178 /**
       
   179 Disconnects from the TunDriverAgent to TunDriver with reason 
       
   180 
       
   181 @param aReason, reason for disconnection to the agent.
       
   182 */
       
   183 	{	   
       
   184 	iLastErrorCode = aReason;
       
   185 	iDisconnectCallback.CallBack();
       
   186 	}
       
   187 
       
   188 void CTunDriverAgent::ServiceStarted(TInt /*aError*/)
       
   189 /**
       
   190 ConnectionComplete from TunDriverAgent to TunDriver
       
   191 This function is calling CallBack() function if connect is not cancelled
       
   192 
       
   193 @param aError, error number for which service needs to be started.
       
   194 */
       
   195 	{
       
   196 	iAgentProgress = ETunDriverAgtConnecting;
       
   197 	iNotify->AgentProgress(iAgentProgress, KErrNone);
       
   198 	iNotify->ServiceStarted();
       
   199 	
       
   200 	/* if the connect has been cancelled during ServiceStarted() then we need to avoid 
       
   201 	 * calling ConnectComplete() - done in this next callback - otherwise we get a panic */
       
   202 	if (!iCancelled)
       
   203 		iConnectCompleteCallback.CallBack();
       
   204 	}
       
   205 
       
   206 void CTunDriverAgent::ConnectionComplete(TInt aError)
       
   207 /**
       
   208 Second phase of completing connection of TunDriveragent to TunDriver
       
   209 
       
   210 @param aError,error number for which connection is complete.
       
   211 */
       
   212     {
       
   213     if(aError==KErrNone)
       
   214 	    {
       
   215         iAgentProgress = ETunDriverAgtConnected;
       
   216         iNotify->AgentProgress(ETunDriverAgtConnected, aError);
       
   217         iNotify->ConnectComplete(aError);
       
   218         iConnected = ETrue;
       
   219         return;
       
   220 	    }
       
   221 	iNotify->AgentProgress(iAgentProgress,aError);
       
   222 	iNotify->ConnectComplete(aError);
       
   223 	iConnected = EFalse;
       
   224     }
       
   225 
       
   226 void CTunDriverAgent::DisconnectionComplete()
       
   227 /**
       
   228 Completes the disconnection of TunDriveragent from TunDriver
       
   229 */
       
   230 	{
       
   231 	
       
   232 	if ( iDisconnecting )
       
   233 	        {
       
   234             iNotify->AgentProgress(iAgentProgress, KErrNone);
       
   235 	        }
       
   236 	    else
       
   237 	        {
       
   238             iAgentProgress = ETunDriverAgtDisconnected;
       
   239             iDisconnecting = ETrue;
       
   240 	        iNotify->AgentProgress(iAgentProgress, KErrNone);
       
   241 	        iNotify->DisconnectComplete();
       
   242 	        iConnected = EFalse;
       
   243 	        }
       
   244 	}
       
   245 
       
   246 TInt CTunDriverAgent::GetExcessData(TDes8& /*aBuffer*/)
       
   247 /**
       
   248 Gets excessData from TunDriveragent to TunDriver
       
   249 
       
   250 @param aBuffer, variable containing the name of TunDriveragent
       
   251 @return KErrNotSupported,error code if it does not get excess data from TunDriveragent.
       
   252 */
       
   253 	{
       
   254 	return KErrNotSupported;
       
   255 	}
       
   256 
       
   257 
       
   258 TInt CTunDriverAgent::Notification(TNifToAgentEventType /*aEvent*/, TAny* /*aInfo*/)
       
   259  /*
       
   260 Establishes the Notification types from Nif to Agent for the TunDriveragent
       
   261 
       
   262 @param aEvent,a variable of enum TNifToAgentEventType, which contains Notification types from TunDriver to TunDriverAgent
       
   263 @param aInfo, information about the agent
       
   264 @return KErrNotSupported,error code if the notification type does not exist.
       
   265 */
       
   266 	{
       
   267 	return KErrNone;		
       
   268 	}
       
   269 
       
   270 void CTunDriverAgent::GetLastError(TInt& aError)
       
   271 /**
       
   272 Gets the LastError
       
   273 */
       
   274 	{
       
   275 	aError = iLastErrorCode;
       
   276 	}
       
   277 
       
   278 
       
   279 
       
   280 TInt CTunDriverAgent::IncomingConnectionReceived()
       
   281 /**
       
   282 IncomingConnectionReceived
       
   283 
       
   284 @return KErrNotSupported, error code if incoming connection is not received.
       
   285 */
       
   286 	{
       
   287 	return KErrNotSupported;
       
   288 	}
       
   289 
       
   290 TInt CTunDriverAgent::ServiceStartedCb(TAny* aThisPtr)
       
   291 /**
       
   292  * Connection Callback static function 
       
   293  *
       
   294  */
       
   295 	{
       
   296 	CTunDriverAgent* self = (CTunDriverAgent*)aThisPtr;
       
   297 	self->ServiceStarted(KErrNone);
       
   298 	return KErrNone;
       
   299 	}
       
   300 
       
   301 TInt CTunDriverAgent::ConnectCompleteCb(TAny* aThisPtr)
       
   302 /**
       
   303  * Second callback used during connection creation
       
   304  *
       
   305  */
       
   306     {
       
   307 	CTunDriverAgent* self = (CTunDriverAgent*) aThisPtr;
       
   308 	self->ConnectionComplete(KErrNone);
       
   309 	return KErrNone;
       
   310     }
       
   311 
       
   312 TInt CTunDriverAgent::DisconnectCompleteCb(TAny* aThisPtr)
       
   313 /**
       
   314  * Disconnection callback static function
       
   315  *
       
   316  */
       
   317     {
       
   318 	CTunDriverAgent* self = (CTunDriverAgent*) aThisPtr;
       
   319 	self->DisconnectionComplete();
       
   320 	return KErrNone;
       
   321     }