datacommsserver/esockserver/ssock/ss_parameterfamilybundle.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2007-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 // Implementation for CCFParameterFamilyBundle and RCFParameterFamilyBundle
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 #include "ss_parameterfamilybundle.h"
       
    24 #include <comms-infras/es_parameterfamily.h> 
       
    25 
       
    26 
       
    27 #ifdef _DEBUG
       
    28 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    29 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    30 _LIT(KSpecAssert_ESockSSocksprmtr, "ESockSSocksprmtr");
       
    31 #endif
       
    32 
       
    33 
       
    34 #ifdef _DEBUG
       
    35 _LIT (KBundlePanic,"BundlePanic");
       
    36 #endif
       
    37 
       
    38 namespace BundlePanics
       
    39 {
       
    40 enum
       
    41 	{
       
    42 	KPanicNotReallyANodeYet = 1
       
    43 	};
       
    44 }
       
    45 
       
    46 using namespace ESock;
       
    47 
       
    48 namespace ESock
       
    49 	{
       
    50 	
       
    51 	
       
    52 class CCFParameterFamilyBundle :	public CBase,
       
    53 									public RParameterFamilyBundle,
       
    54 									protected Messages::ASimpleNodeIdBase
       
    55 	{
       
    56 	friend class RCFParameterFamilyBundle;
       
    57 	friend class RCFParameterFamilyBundleC;
       
    58 public:
       
    59 	static CCFParameterFamilyBundle* NewL()
       
    60 		{
       
    61 		CCFParameterFamilyBundle* newObj = new(ELeave)CCFParameterFamilyBundle;
       
    62 		CleanupStack::PushL(newObj);
       
    63 		static_cast<RParameterFamilyBundle&>(*newObj).CreateL();
       
    64 		CleanupStack::Pop();
       
    65 		return newObj;
       
    66 		}
       
    67 
       
    68 	static CCFParameterFamilyBundle* LoadL(TDesC8& aDes)
       
    69 		{
       
    70 		CCFParameterFamilyBundle* newObj = new(ELeave)CCFParameterFamilyBundle;
       
    71 		CleanupStack::PushL(newObj);
       
    72 		static_cast<RParameterFamilyBundle&>(*newObj).LoadL(aDes);
       
    73 		CleanupStack::Pop();
       
    74 		return newObj;		
       
    75 		}
       
    76 
       
    77 	void Open() // increase refcount.. returns new refcount
       
    78 		{
       
    79 		User::LockedInc(iRefCount);
       
    80 		}
       
    81 
       
    82 	void Close() // decrease refcount or destroy
       
    83 		{
       
    84 		 __ASSERT_DEBUG(iRefCount >= 0, User::Panic(KSpecAssert_ESockSSocksprmtr, 1));
       
    85 		if(User::LockedDec(iRefCount) <= 1)
       
    86 			{
       
    87 			static_cast<RParameterFamilyBundle&>(*this).Destroy();
       
    88 			delete this;
       
    89 			}
       
    90 		}
       
    91 	
       
    92 protected:
       
    93 	CCFParameterFamilyBundle():
       
    94 		iRefCount(0) 
       
    95 		{
       
    96 		}
       
    97 
       
    98     virtual ~CCFParameterFamilyBundle()
       
    99     	{
       
   100     	}
       
   101 
       
   102    	virtual void ReceivedL(const Messages::TRuntimeCtxId& aSender, const Messages::TNodeId& aRecipient, Messages::TSignatureBase& aMessage)
       
   103    		{
       
   104 		__ASSERT_DEBUG(0,User::Panic(KBundlePanic,BundlePanics::KPanicNotReallyANodeYet));
       
   105 		(void)aSender;
       
   106 		(void)aRecipient;
       
   107 		(void)aMessage;
       
   108    		}
       
   109 
       
   110 
       
   111 	
       
   112 private:
       
   113 	TInt iRefCount;
       
   114 	};
       
   115 
       
   116 } // namespace ESock
       
   117 	
       
   118 EXPORT_C void RCFParameterFamilyBundleC::Open()
       
   119 /** Increases the refcount of the target family bundle. Ensure it
       
   120  *   stays in existence til at least after we call Close() on this instance
       
   121  *   of the handle.
       
   122 
       
   123 @param none
       
   124 @return none
       
   125 */
       
   126 	{
       
   127 	CCFParameterFamilyBundle* tBundle=TargetBundle();
       
   128 	if(tBundle)
       
   129 		{
       
   130 		tBundle->Open();
       
   131 		}
       
   132 	}
       
   133 
       
   134 
       
   135 EXPORT_C void RCFParameterFamilyBundleC::Open(const RCFParameterFamilyBundleC& aExistingHandle)
       
   136 /** Initialises this handle from an existing handle, whilst increasing the
       
   137  *   refcount. This ensures that the target
       
   138  *   stays in existence til at least after we call Close() on this instance
       
   139  *   of the handle.
       
   140 
       
   141 @param none
       
   142 @return none
       
   143 */
       
   144 	{
       
   145 	CCFParameterFamilyBundle* tBundle=TargetBundle();
       
   146 	if (tBundle)
       
   147 		{
       
   148 		tBundle->Close();
       
   149 		}
       
   150 	iBundleId = aExistingHandle.iBundleId;
       
   151 	tBundle=TargetBundle();
       
   152 	if (tBundle)
       
   153 		{
       
   154 		tBundle->Open();
       
   155 		}
       
   156 	}
       
   157 
       
   158 EXPORT_C void RCFParameterFamilyBundleC::Close()
       
   159 /** Opens a new RConnection instance.
       
   160 
       
   161 @param aSocketServer Socket Server session.
       
   162 @param aConnectionType Reserved.
       
   163 @return KErrNone if successful, otherwise another of the system wide error
       
   164 codes. */
       
   165 	{
       
   166 	CCFParameterFamilyBundle* tBundle=TargetBundle();
       
   167 	if(tBundle)
       
   168 		{
       
   169 		tBundle->Close();
       
   170 		}
       
   171 	iBundleId = Messages::TNodeId::NullId();
       
   172 	}
       
   173 
       
   174 EXPORT_C void RCFParameterFamilyBundleC::CreateL()
       
   175 	{
       
   176 	CCFParameterFamilyBundle* tBundle = CCFParameterFamilyBundle::NewL();
       
   177 	iBundleId = tBundle->NodeId();
       
   178 	}
       
   179 
       
   180 EXPORT_C void RCFParameterFamilyBundleC::LoadL(TDesC8& aDes)
       
   181 	{
       
   182 	CCFParameterFamilyBundle* tBundle = CCFParameterFamilyBundle::LoadL(aDes);
       
   183 	iBundleId = tBundle->NodeId();
       
   184 	}
       
   185 
       
   186 EXPORT_C TUint RCFParameterFamilyBundleC::Length() const
       
   187 	{
       
   188 	CCFParameterFamilyBundle* tBundle=const_cast<RCFParameterFamilyBundleC&>(*this).TargetBundle();
       
   189 	return tBundle?tBundle->Length():0;
       
   190 	}
       
   191 
       
   192 EXPORT_C TUint RCFParameterFamilyBundleC::CountParameterSets() const
       
   193 	{
       
   194 	CCFParameterFamilyBundle* tBundle=const_cast<RCFParameterFamilyBundleC&>(*this).TargetBundle();
       
   195 	return tBundle?tBundle->CountParameterFamilies():0;
       
   196 	}
       
   197 EXPORT_C TInt RCFParameterFamilyBundleC::Store(TDes8& aDes) const
       
   198 	{
       
   199 	CCFParameterFamilyBundle* tBundle=const_cast<RCFParameterFamilyBundleC&>(*this).TargetBundle();
       
   200 	return tBundle?tBundle->Store(aDes):KErrNotReady;
       
   201 	}
       
   202 
       
   203 EXPORT_C const RParameterFamily RCFParameterFamilyBundleC::GetFamilyAtIndex(TUint aIndex) const
       
   204 	{
       
   205 	CCFParameterFamilyBundle* tBundle=const_cast<RCFParameterFamilyBundleC&>(*this).TargetBundle();
       
   206 	return tBundle?tBundle->GetFamilyAtIndex(aIndex):RParameterFamily();
       
   207 	}
       
   208 
       
   209 EXPORT_C const RParameterFamily RCFParameterFamilyBundleC::FindFamily(TUint32 aFamilyId) const
       
   210 	{
       
   211 	CCFParameterFamilyBundle* tBundle=const_cast<RCFParameterFamilyBundleC&>(*this).TargetBundle();
       
   212 	return tBundle?tBundle->FindFamily(aFamilyId):RParameterFamily();
       
   213 	}
       
   214 
       
   215 
       
   216 EXPORT_C CCFParameterFamilyBundle* RCFParameterFamilyBundleC::TargetBundle()
       
   217 	{
       
   218 	return (iBundleId != Messages::TNodeId::NullId() ?
       
   219 		static_cast<CCFParameterFamilyBundle*>(static_cast<Messages::ASimpleNodeIdBase*>(iBundleId.Ptr())) :
       
   220 		NULL);
       
   221 	}
       
   222 
       
   223 EXPORT_C RParameterFamily RCFParameterFamilyBundle::CreateFamilyL(TUint32 aFamilyId)
       
   224 	{
       
   225 	return TargetBundleL().CreateFamilyL(aFamilyId);
       
   226 	}
       
   227 
       
   228 EXPORT_C RParameterFamily RCFParameterFamilyBundle::GetFamilyAtIndex(TUint aIndex)
       
   229 	{
       
   230 	CCFParameterFamilyBundle* tBundle=TargetBundle();
       
   231 	return tBundle?tBundle->GetFamilyAtIndex(aIndex):RParameterFamily();
       
   232 	}
       
   233 
       
   234 EXPORT_C RParameterFamily RCFParameterFamilyBundle::FindFamily(TUint32 aFamilyId)
       
   235 	{
       
   236 	CCFParameterFamilyBundle* tBundle=TargetBundle();
       
   237 	return tBundle?tBundle->FindFamily(aFamilyId):RParameterFamily();
       
   238 	}
       
   239 
       
   240 EXPORT_C void RCFParameterFamilyBundle::ClearAllParameters(RParameterFamily::TParameterSetType aType)
       
   241 	{
       
   242 	CCFParameterFamilyBundle* tBundle=TargetBundle();
       
   243 	if(tBundle)
       
   244 		{
       
   245 		tBundle->ClearAllParameters(aType);
       
   246 		}
       
   247 	}
       
   248 
       
   249