linklayerprotocols/ethernetnif/IRLAN/IRLANDAT.CPP
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 1997-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 // Irlan parameter data model code 
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include <e32base.h>
       
    23 #include "IRLANUTL.H"
       
    24 #include "IRLANDAT.H"
       
    25 
       
    26 /**
       
    27 current IrLAN version 1.1
       
    28 @internalComponent
       
    29 */
       
    30 
       
    31 /*
       
    32 CIrlanRegister::CIrlanRegister()
       
    33 	{
       
    34 	__DECLARE_NAME(_S("CIrlanRegister"));
       
    35     iParameterList.SetOffset(_FOFF(CIrlanCommand,iLink));
       
    36 	iUnique=1;
       
    37 	}
       
    38 
       
    39 CIrlanRegister::~CIrlanRegister()
       
    40 	{
       
    41 	CIrlanCommand *cl;
       
    42 	TDblQueIter<CIrlanCommand> i(iParameterList);
       
    43 
       
    44 	while (cl=i++,cl!=NULL)
       
    45 		{
       
    46 		cl->iLink.Deque();	   
       
    47 		delete cl;
       
    48 		}
       
    49 	}
       
    50 
       
    51 CIrlanRegister *CIrlanRegister::NewL()
       
    52 // Invoked to create a new instance of the IAS register object
       
    53 	{
       
    54 	CIrlanRegister *reg=new (ELeave) CIrlanRegister();
       
    55 	reg->InitL();
       
    56 	return reg;
       
    57 	}
       
    58 
       
    59 void CIrlanRegister::InitL()
       
    60 // register the compulsory device classes
       
    61 	{
       
    62 	TIASDatabaseEntry ent;
       
    63 	SetHostName(PROTEA_DEFAULT_NICKNAME);
       
    64 	ent.SetClassName(IRDA_IAS_DEVICE_CLASSNAME);
       
    65 	ent.SetAttributeName(IRDA_IAS_DEVICENAME_ATTR);
       
    66 	ent.SetToCharString(iHostName);
       
    67 	RegisterEntryL(ent);
       
    68 
       
    69 	ent.SetClassName(IRDA_IAS_DEVICE_CLASSNAME);
       
    70 	ent.SetAttributeName(IRDA_IAS_LMPSUPPORT_ATTR);
       
    71 	TBuf8<3> data;
       
    72 	data.SetLength(3);
       
    73 	data[0]=KIrLMPVersionMask;
       
    74 	data[1]=KIASSupportMask;
       
    75 	data[2]=KIrLMPSupportMask;
       
    76 	ent.SetToOctetSeq(data);
       
    77 	RegisterEntryL(ent);
       
    78 	return;
       
    79 	}
       
    80 
       
    81 void CIrlanRegister::RegisterEntryL(const TDesC8& aBuffer)
       
    82 // Add a new command to the data base
       
    83 	{
       
    84 	TIASDatabaseEntry ent;
       
    85 	ent.Copy(aBuffer);
       
    86 	CIASClass * cls=LookUpCommand(ent().iClassName);
       
    87 	if (cls==NULL)
       
    88 		{
       
    89 		TInt uniqueID=0; // "Device" is always id 0 - autoincrement for others.
       
    90 		if (ent().iClassName!=IRDA_IAS_DEVICE_CLASSNAME)		
       
    91 			uniqueID=iUnique++;
       
    92 		cls=CIASClass::NewL(ent().iClassName,uniqueID);
       
    93 		iIASClassList.AddLast(*cls);
       
    94 		}
       
    95 	cls->AddAttributeL(ent().iAttributeName,ent().iData);
       
    96 	}
       
    97 
       
    98 TInt CIrlanRegister::UnregisterEntry(const TDesC8& aBuffer)
       
    99 //
       
   100 // Remove a whole class from the database.
       
   101 //
       
   102 	{
       
   103 	TIrlanDatabaseEntry ent;
       
   104 	ent.Copy(aBuffer);
       
   105 	CIASClass * cls=LookUpClass(ent().iClassName);
       
   106 	if (cls==NULL)
       
   107 		return KErrNotFound;
       
   108 	return cls->RemoveAttribute(ent().iAttributeName);
       
   109 	}
       
   110 
       
   111 TIASQueryResult CIASRegister::Lookup(const TDesC8& aClassName,
       
   112   const TDesC8& anAttributeName,TUint16& anObjectId,TIASResponse& aResponse)
       
   113 	{
       
   114 	CIASClass* cls=LookUpClass(aClassName);
       
   115 	if (cls!=NULL)
       
   116 		{
       
   117 		anObjectId=cls->LookUpObjectID();
       
   118 
       
   119 		CIASAttribute* attr=cls->LookUpAttribute(anAttributeName);
       
   120 		if (attr!=NULL)
       
   121 			attr->GetAttributeData(aResponse);
       
   122 		else
       
   123 			return EIASNoSuchAttribute;
       
   124 		}
       
   125 	else
       
   126 		return EIASNoSuchClass;
       
   127 
       
   128 	return EIASSuccess;
       
   129 	}
       
   130 
       
   131 CIASClass* CIASRegister::LookUpClass(const TDesC8& aName)
       
   132 //
       
   133 // Go through the list of classes and see if any of them match
       
   134 // on names with aName.
       
   135 //
       
   136 	{
       
   137 	CIASClass *cl;
       
   138 	TDblQueIter<CIASClass> i(iIASClassList);
       
   139 
       
   140 	while (cl=i++,cl!=NULL)
       
   141 		{
       
   142 		if (cl->Match(aName))
       
   143 			return cl;
       
   144 		}
       
   145 	return NULL;
       
   146 	}
       
   147 
       
   148 void CIASRegister::SetHostName(const TDesC8 &aName)
       
   149 	{
       
   150 	iHostName.Copy(aName);
       
   151 	}
       
   152 
       
   153 void CIASRegister::GetHostName(TDes8 &aName)
       
   154 	{
       
   155 	aName.Copy(iHostName);
       
   156 	}
       
   157 
       
   158  */
       
   159 
       
   160 //*******************************************************************
       
   161 
       
   162 /**
       
   163 Constructor.
       
   164 */
       
   165 CIrlanParameter::CIrlanParameter()
       
   166 {
       
   167 	__DECLARE_NAME(_S("CIrlanParameter"));
       
   168 }
       
   169 
       
   170 /**
       
   171 Destructor.
       
   172 */
       
   173 CIrlanParameter::~CIrlanParameter()
       
   174 {
       
   175 	CIrlanParameterValue *val;
       
   176 	TDblQueIter<CIrlanParameterValue> i(iIrlanParameterValueList);
       
   177 
       
   178 	delete iParamName;
       
   179 	while (val=i++,val!=NULL)
       
   180 		{
       
   181 		val->iLink.Deque();	
       
   182 		delete val;
       
   183 		}
       
   184 }
       
   185 
       
   186 /**
       
   187 Invoked to create a new instance of an irlan parameter object.
       
   188 @param aName parameter name.
       
   189 @param aID   parameter ID.
       
   190 @return A pointer to CIrlanParameter object.
       
   191 */
       
   192 CIrlanParameter *CIrlanParameter::NewL(const TDesC8& aName,const TUint8 aID)
       
   193 {
       
   194 	CIrlanParameter *cl=new (ELeave) CIrlanParameter();
       
   195 	CleanupStack::PushL(cl);
       
   196 	cl->InitL(aName,aID);
       
   197 	CleanupStack::Pop();
       
   198 	return cl;
       
   199 }
       
   200 
       
   201 /**
       
   202 We don't initialise attributes here.  Must subsequently invoke.
       
   203 Add the newly created object to an parameter list.
       
   204 @param aName The parameter name.
       
   205 @param aCode The Command Code.
       
   206 */
       
   207 void CIrlanParameter::InitL(const TDesC8& aName,TUint8 aCode)
       
   208 {
       
   209 	iParamName=HBufC8::NewL(aName.Length());
       
   210 	TPtr8 temp=iParamName->Des();
       
   211 	temp=aName;
       
   212 
       
   213 	iCommandCode=aCode;
       
   214     iIrlanParameterValueList.SetOffset(_FOFF(CIrlanParameterValue,iLink));
       
   215 }
       
   216 
       
   217 /**
       
   218 Adds the parameter value to List.
       
   219 @param aName parameter name.
       
   220 @param aType parameter type.
       
   221 */
       
   222 void CIrlanParameter::AddParameterValueL(const TDesC8& aName,const TIrlanParameterType& aType)
       
   223 {
       
   224 	if (LookUpParameterValue(aName)!=NULL)
       
   225 		User::Leave(KErrAlreadyExists);
       
   226 	CIrlanParameterValue *val=CIrlanParameterValue::NewL(aName,aType);
       
   227 	iIrlanParameterValueList.AddFirst(*val);
       
   228 }
       
   229 
       
   230 /**
       
   231 Searchs a parameter in the parameter List.
       
   232 @return A pointer to CIrlanParameterValue class
       
   233 */
       
   234 CIrlanParameterValue* CIrlanParameter::LookUpParameterValue()
       
   235 {
       
   236 	CIrlanParameterValue *val=NULL;
       
   237 	CIrlanParameterValue *ret=NULL;
       
   238 	TDblQueIter<CIrlanParameterValue> i(iIrlanParameterValueList);
       
   239 
       
   240 	TInt count=0;
       
   241 	while (val=i++,val!=NULL)
       
   242 		{
       
   243 		ret=val;
       
   244 		count++;
       
   245 		}
       
   246 	__ASSERT_DEBUG(count<=1,IrlanUtil::Fault(EIrlanInvalidParameter));
       
   247 	return ret;
       
   248 }
       
   249 
       
   250 /**
       
   251 Searchs a parameter in the parameter List depending on the value.
       
   252 @param aValue A parameter value to be searched.
       
   253 @return A pointer to CIrlanParameterValue class
       
   254 */
       
   255 CIrlanParameterValue* CIrlanParameter::LookUpParameterValue(const TDesC8& aValue)
       
   256 {
       
   257 	CIrlanParameterValue *val;
       
   258 	TDblQueIter<CIrlanParameterValue> i(iIrlanParameterValueList);
       
   259 
       
   260 	while (val=i++,val!=NULL)
       
   261 		{
       
   262 		if (val->Match(aValue))
       
   263 			return val;
       
   264 		}
       
   265 	return NULL;
       
   266 }
       
   267 
       
   268 /**
       
   269 Remove the paramter value from the parameter list.
       
   270 @param aValue A parameter value to be removed.
       
   271 @return KErrNone if success else KErrNotFound.
       
   272 */
       
   273 TInt CIrlanParameter::RemoveParameterValue(const TDesC8& aValue)
       
   274 {
       
   275 	CIrlanParameterValue *val=LookUpParameterValue(aValue);
       
   276 	if (val==NULL)
       
   277 		return KErrNotFound;
       
   278 	val->iLink.Deque();
       
   279 	delete val;
       
   280 	if (iIrlanParameterValueList.IsEmpty())
       
   281 		{
       
   282 		iLink.Deque();
       
   283 		delete this;
       
   284 		}
       
   285 	return KErrNone;
       
   286 }
       
   287 
       
   288 /**
       
   289 Searches this descriptor's data for a match with the match pattern supplied in the specified 
       
   290 descriptor.
       
   291 @param aName A 8 bit non modifable descriptor containing the match pattern
       
   292 @return If a match is found, the offset within this descriptor's data where the match first 
       
   293 		occurs. 
       
   294 */
       
   295 TBool CIrlanParameter::Match(const TDesC8& aName)const
       
   296 {
       
   297 	return (iParamName->Compare(aName)==0);
       
   298 }
       
   299 
       
   300 /**
       
   301 Get the command code.
       
   302 @return The command code.
       
   303 */
       
   304 TUint8 CIrlanParameter::GetCommandCode()
       
   305 {
       
   306 	return iCommandCode;
       
   307 }
       
   308 
       
   309 //*******************************************************************
       
   310 
       
   311 /**
       
   312 Constructor.
       
   313 */
       
   314 CIrlanParameterValue::CIrlanParameterValue()
       
   315 {
       
   316 	__DECLARE_NAME(_S("CIrlanParameter"));
       
   317 }
       
   318 
       
   319 /**
       
   320 Destructor.
       
   321 */
       
   322 CIrlanParameterValue::~CIrlanParameterValue()
       
   323 {
       
   324 	delete iParamValue;
       
   325 }
       
   326 
       
   327 /**
       
   328 Invoked to create a new instance of an irlan parameter object.
       
   329 @param aValue parameter value.
       
   330 @param aType  parameter Type.
       
   331 @return A pointer to CIrlanParameterValue object.
       
   332 */
       
   333 CIrlanParameterValue* CIrlanParameterValue::NewL(const TDesC8& aValue,const TIrlanParameterType& aType)
       
   334 {
       
   335 	CIrlanParameterValue *val=new (ELeave) CIrlanParameterValue();
       
   336 	CleanupStack::PushL(val);
       
   337 	val->InitL(aValue,aType);
       
   338 	CleanupStack::Pop();
       
   339 	return val;
       
   340 }
       
   341 
       
   342 /**
       
   343 Add the newly created object to an parameter list.
       
   344 @param aValue parameter value.
       
   345 @param aType  parameter Type.
       
   346 */
       
   347 void CIrlanParameterValue::InitL(const TDesC8& aValue,const TIrlanParameterType& aType)
       
   348 {
       
   349 	iParamValue=HBufC8::NewL(aValue.Length());
       
   350 	TPtr8 temp=iParamValue->Des();
       
   351 	temp=aValue;
       
   352 	
       
   353 	iParamValueLength=TUint16(aValue.Length());
       
   354 	iParamValueType=aType;
       
   355 }
       
   356 
       
   357 /**
       
   358 Searches this descriptor's data for a match with the match pattern supplied in the specified 
       
   359 descriptor.
       
   360 @param aName A 8 bit non modifable descriptor containing the match pattern
       
   361 @return If a match is found, the offset within this descriptor's data where the match first 
       
   362 		occurs. 
       
   363 */
       
   364 TBool CIrlanParameterValue::Match(const TDesC8& aName) const
       
   365 {
       
   366 	return (iParamValue->Compare(aName)==0);
       
   367 }
       
   368 
       
   369 /**
       
   370 Gets a 8-bit integer value from the buffer.
       
   371 @param aDes On completion, the 8-bit value from the buffer
       
   372 */
       
   373 void CIrlanParameterValue::GetValue(TPtr8& aDes)
       
   374 {
       
   375 	TPtr8 val=iParamValue->Des();
       
   376 	aDes.Set(val);
       
   377 }
       
   378 
       
   379 /**
       
   380 Gets the length of the Parameter value.
       
   381 @return The 16-bit parameter value.
       
   382 */
       
   383 TUint16 CIrlanParameterValue::GetValueLength()
       
   384 {
       
   385 	return iParamValueLength;
       
   386 }