telephonyprotocols/secondarypdpcontextumtsdriver/spudman/src/spudfactory.cpp
changeset 69 b982c3e940f3
parent 59 ac20d6a0a19d
child 73 70d75957b98f
equal deleted inserted replaced
59:ac20d6a0a19d 69:b982c3e940f3
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // SPUD factory class and DLL entry point
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include "spudfactory.h"
       
    24 #include "spudman.h"
       
    25 
       
    26 /**
       
    27 Spud destructor.
       
    28 */
       
    29 CSpudFactory::~CSpudFactory()
       
    30 	{
       
    31 	}
       
    32 
       
    33 /**
       
    34 This function is pure virtual in CNifFactory, so we have to define it
       
    35 here. It is called by NifMan before NewInterfaceL().
       
    36 */
       
    37 void CSpudFactory::InstallL()
       
    38 	{
       
    39 	}
       
    40 
       
    41 /**
       
    42 Factory function which creates an instance of the SPUD.
       
    43 
       
    44 @param aName The name of the NIF
       
    45 @param aNotify supplies details from "IfParams" field in CommDb
       
    46 @return A newly-instantiated SPUD NIF
       
    47 */
       
    48 CNifIfBase* CSpudFactory::NewInterfaceL(const TDesC& aName, MNifIfNotify* aNotify)
       
    49 	{
       
    50 	__FLOG_STATIC0(KSpudFirstTag, KSpudLog, _L("CSpudFactory::NewInterfaceL"));
       
    51    _LIT(KSpudDesc, "spud");
       
    52 	if(aName.CompareF(KSpudDesc))
       
    53 		{
       
    54 		__FLOG_STATIC2(KSpudFirstTag, KSpudLog, _L("CSpudFactory::NewInterfaceL requested %S, not %S"), &aName, &KSpudDesc);
       
    55 		User::Leave(KErrNotSupported);
       
    56 		}
       
    57 	
       
    58 	// This is a complicated construction phase as many of the objects need to
       
    59 	// contain pointers to several of the others.
       
    60 	CSpudMan* spudMan = new (ELeave) CSpudMan(*this, aNotify);
       
    61 	CleanupStack::PushL(spudMan);
       
    62 
       
    63 	CSpudMux* mux = new (ELeave) CSpudMux(*spudMan);
       
    64 	CleanupStack::PushL(mux);
       
    65 
       
    66 	CSpudProtocol* protocol = new (ELeave) CSpudProtocol();
       
    67 	CleanupStack::PushL(protocol);
       
    68 
       
    69 	CBindMan* bindMan = new (ELeave) CBindMan(*spudMan, mux, protocol);
       
    70 	// Ownership of mux and protocol have been transferred to bindMan
       
    71 	CleanupStack::Pop(2);
       
    72 
       
    73 	CleanupStack::PushL(bindMan);
       
    74 	spudMan->ConstructL(bindMan);
       
    75 	// Ownership of bindMan has been transferred to spudMan
       
    76 	CleanupStack::Pop(bindMan);
       
    77 
       
    78 	protocol->Construct(*bindMan);
       
    79 	mux->Construct(*bindMan);
       
    80 
       
    81 	CSpudBinderRef& primaryCtxBinder = *bindMan->GetNewRefForPrimaryL();
       
    82 	
       
    83 	// Read the protocol name from CommDB
       
    84 	TName protoName;
       
    85 	aNotify->ReadDes(TPtrC(SERVICE_IF_NETWORKS), protoName); // ignore error; will be caught in LoadNifL
       
    86 
       
    87     // SPUD only handles one protocol at a time
       
    88     ASSERT(protoName.Length() && protoName.Locate(',') == KErrNotFound);
       
    89 	
       
    90 	// Load a NIF to handle the primary context
       
    91 	bindMan->LoadNifL(protoName, primaryCtxBinder);
       
    92 	CleanupStack::Pop(spudMan);
       
    93 
       
    94 	// Ownership of spudMan is passed to the caller
       
    95 	return spudMan;
       
    96 	}
       
    97 
       
    98 /**
       
    99 Factory function which creates an instance of the SPUD.
       
   100 This version doesn't have the required notify pointer, so we unconditionally leave.
       
   101 
       
   102 @param aName The name of the NIF
       
   103 @return Never
       
   104 @leave KErrNotSupported unconditionally
       
   105 */
       
   106 CNifIfBase* CSpudFactory::NewInterfaceL(const TDesC& /*aName*/)
       
   107 	{
       
   108 	__FLOG_STATIC0(KSpudFirstTag, KSpudLog, _L("CSpudFactory::NewInterfaceL not supported without MNifIfNotify"));
       
   109     User::Leave(KErrNotSupported);
       
   110 	return NULL;	// never reached
       
   111     }
       
   112 
       
   113 /**
       
   114 Return information about modules within this NIF.
       
   115 This function is pure virtual in CNifFactory, so we have to define it here.
       
   116 However, it doesn't do anything, and is never called by NifMan.
       
   117 
       
   118 @param aInfo On successful return, contains information about a module within the NIF
       
   119 @param aIndex An index into CNifIfBase/CNifIfLink-derived objects in the NIF, starting from 0.
       
   120  It is up to the NIF how it assigns indices to objects.
       
   121 @return KErrNotSupported
       
   122 */
       
   123 TInt CSpudFactory::Info(TNifIfInfo& /*aInfo*/, TInt /*aIndex*/) const
       
   124 	{
       
   125 	__FLOG_STATIC0(KSpudFirstTag, KSpudLog, _L("CSpudFactory::Info not supported"));
       
   126     ASSERT(EFalse);
       
   127 	return KErrNotSupported;
       
   128 	}
       
   129 
       
   130 
       
   131 // Force export of non-mangled name
       
   132 extern "C"
       
   133 	{
       
   134 
       
   135 /**
       
   136 Polymorphic DLL entry point
       
   137 */
       
   138 EXPORT_C CNifFactory *NewInterfaceFactoryL()
       
   139 	{
       
   140 	return new (ELeave) CSpudFactory;
       
   141 	}
       
   142 
       
   143 	}