applayerpluginsandutils/uripermissionservices/inc/tldlistdef.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2008-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 
       
    15 
       
    16 /** @file
       
    17 @publishedAll
       
    18 @released
       
    19 */
       
    20 
       
    21 #ifndef __TLDLISTDEF_H__
       
    22 #define __TLDLISTDEF_H__
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <ineturilistdef.h>
       
    26 
       
    27 using namespace InetUriList;
       
    28 
       
    29 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    30 
       
    31 class TBase
       
    32 	{
       
    33   friend class TPolicyQueryArgs;
       
    34   friend class TQueryResults;
       
    35 
       
    36 public:			
       
    37 	/**
       
    38 	Default constructor
       
    39 	*/
       
    40 	inline TBase ()
       
    41 		:iFlags ( 0 )
       
    42 		{}
       
    43 
       
    44 private:
       
    45 	 /**
       
    46 	 Bit width of the type.	
       
    47 	 */
       
    48 	 enum 
       
    49 		{
       
    50 	    KBitsPerType = 3			
       
    51 		};
       
    52 		
       
    53 	 /**
       
    54 	 Maximum number of arguments. Currently set as 4.	
       
    55 	 */
       
    56 	 enum
       
    57 		{
       
    58 	    KMaxArguments = 4
       
    59 		};
       
    60 
       
    61 protected:	
       
    62 	TInt iArgs [KMaxArguments];
       
    63 	TInt iFlags;
       
    64 	};
       
    65 
       
    66 //-----------------------------------------------------------------
       
    67 class TPolicyQueryArgs:public TBase
       
    68 	{
       
    69 	public:
       
    70 		/**
       
    71 		The argument types.		
       
    72 		*/
       
    73 		enum TPolicyArgType
       
    74 			{
       
    75 			ETldUri = 1,
       
    76 			ETldListType,
       
    77 			ETldQueryType
       
    78 			};
       
    79 
       
    80 		/**
       
    81 		Default constructor
       
    82 		*/
       
    83 		inline TPolicyQueryArgs ()
       
    84 			:TBase()
       
    85 			{}
       
    86 
       
    87 		/**
       
    88 		A templated constructor that constructs the query argument.
       
    89 		It takes one argument.
       
    90 		*/
       
    91 		template < class T0 >
       
    92 		explicit inline TPolicyQueryArgs ( T0 a0 )
       
    93 			{
       
    94 			Assign ( a0 );
       
    95 			iFlags=(Type(a0)<<(( Type(a0))*KBitsPerType));
       
    96 			}
       
    97 
       
    98 		/**
       
    99 		A templated constructor that constructs the query argument.
       
   100 		It takes two arguments.
       
   101 		*/
       
   102 		template < class T0, class T1 >
       
   103 		inline TPolicyQueryArgs ( T0 a0, T1 a1 )
       
   104 			{
       
   105 			Assign ( a0 );
       
   106 			Assign ( a1 );
       
   107 			iFlags=(Type(a0)<<(( Type(a0))*KBitsPerType)) |
       
   108 					(Type(a1)<<(( Type(a1))*KBitsPerType));
       
   109 			}
       
   110 
       
   111 		/**
       
   112 		A templated constructor that constructs the query argument.
       
   113 		It takes three arguments.
       
   114 		*/
       
   115 		template < class T0, class T1, class T2 >
       
   116 		inline TPolicyQueryArgs ( T0 a0, T1 a1, T2 a2 )
       
   117 			{
       
   118 			Assign ( a0 );
       
   119 			Assign ( a1 );
       
   120 			Assign ( a2 );
       
   121 			iFlags=(Type(a0)<<(Type(a0)*KBitsPerType)) | 
       
   122 					(Type(a1)<<(Type(a1)*KBitsPerType)) |
       
   123 					(Type(a2)<<(Type(a2)*KBitsPerType));
       
   124 			}
       
   125 		/**
       
   126 		Returns the argument if set, otherwise returns KErrNotFound.	
       
   127 		*/		
       
   128 		TInt Get ( TPolicyArgType aType ) const
       
   129 			{
       
   130 			if ( IsSet ( aType ) )
       
   131 				return iArgs[aType - 1];
       
   132 			return KErrNotFound;			
       
   133 			}
       
   134 						
       
   135 	private:	   
       
   136 		/**
       
   137 		Checks whether the flag is set for the given argument type.		
       
   138 		*/
       
   139 		TBool IsSet ( TPolicyArgType aType ) const
       
   140 			{
       
   141 			TInt val = iFlags & ( aType << ( aType  * KBitsPerType ) );
       
   142 			return iFlags & ( aType << ( aType  * KBitsPerType ) );
       
   143 			}		
       
   144 		
       
   145 		TPolicyArgType Type ( const TDesC8* )
       
   146 			{
       
   147 			return ETldUri;				
       
   148 			}
       
   149 			
       
   150 		TPolicyArgType Type ( InetUriList::TListType )
       
   151 			{
       
   152 			return ETldListType;				
       
   153 			}
       
   154 
       
   155 		TPolicyArgType Type ( InetUriList::TTLDQueryType )
       
   156 			{
       
   157 			return ETldQueryType;				
       
   158 			}
       
   159 		
       
   160 		void Assign ( const TDesC8* aValue )
       
   161 			{
       
   162 			iArgs[Type(aValue)-1] = (TInt)aValue;
       
   163 			}
       
   164 			
       
   165 		void Assign ( InetUriList::TListType aValue )
       
   166 			{
       
   167 			iArgs[Type(aValue)-1] = aValue;
       
   168 			}
       
   169 			
       
   170 		void Assign ( InetUriList::TTLDQueryType aValue )
       
   171 			{
       
   172 			iArgs[Type(aValue)-1] = aValue;
       
   173 			}
       
   174 			
       
   175 	
       
   176 	};
       
   177 
       
   178 #else
       
   179 class TBase
       
   180 	{
       
   181 public:	
       
   182 	/**
       
   183 	Bit width of the type.
       
   184 	
       
   185 	@internalComponent
       
   186 	*/
       
   187 	enum 
       
   188 		{
       
   189 		KBitsPerType = 3			
       
   190 		};
       
   191 	
       
   192 	/**
       
   193 	Maximum number of arguments. Currently set as 4.
       
   194 
       
   195 	@internalComponent
       
   196 	*/
       
   197 	enum
       
   198 		{
       
   199 		KMaxArguments = 4
       
   200 		};
       
   201 	
       
   202 	/**
       
   203 	Default constructor
       
   204 	*/
       
   205 	inline TBase ()
       
   206 		:iFlags ( 0 )
       
   207 		{}
       
   208 
       
   209 protected:	
       
   210 	TInt iArgs [KMaxArguments];
       
   211 	TInt iFlags;
       
   212 	};
       
   213 
       
   214 //-----------------------------------------------------------------
       
   215 class TPolicyQueryArgs:public TBase
       
   216 	{
       
   217 	public:
       
   218 		/**
       
   219 		The argument types.
       
   220 		
       
   221 		@internalComponent
       
   222 		*/
       
   223 		enum TPolicyArgType
       
   224 			{
       
   225 			ETldUri = 1,
       
   226 			ETldListType,
       
   227 			ETldQueryType
       
   228 			};
       
   229 
       
   230 		/**
       
   231 		Default constructor
       
   232 		*/
       
   233 		inline TPolicyQueryArgs ()
       
   234 			:TBase()
       
   235 			{}
       
   236 
       
   237 
       
   238 		/**
       
   239 		A templated constructor that constructs the query argument.
       
   240 		It takes one argument.
       
   241 		*/
       
   242 		template < class T0 >
       
   243 		explicit inline TPolicyQueryArgs ( T0 a0 )
       
   244 			{
       
   245 			Assign ( a0 );
       
   246 			iFlags=(Type(a0)<<(( Type(a0))*KBitsPerType));
       
   247 			}
       
   248 
       
   249 		/**
       
   250 		A templated constructor that constructs the query argument.
       
   251 		It takes two arguments.
       
   252 		*/
       
   253 		template < class T0, class T1 >
       
   254 		inline TPolicyQueryArgs ( T0 a0, T1 a1 )
       
   255 			{
       
   256 			Assign ( a0 );
       
   257 			Assign ( a1 );
       
   258 			iFlags=(Type(a0)<<(( Type(a0))*KBitsPerType)) |
       
   259 					(Type(a1)<<(( Type(a1))*KBitsPerType));
       
   260 			}
       
   261 
       
   262 		/**
       
   263 		A templated constructor that constructs the query argument.
       
   264 		It takes three arguments.
       
   265 		*/
       
   266 		template < class T0, class T1, class T2 >
       
   267 		inline TPolicyQueryArgs ( T0 a0, T1 a1, T2 a2 )
       
   268 			{
       
   269 			Assign ( a0 );
       
   270 			Assign ( a1 );
       
   271 			Assign ( a2 );
       
   272 			iFlags=(Type(a0)<<(Type(a0)*KBitsPerType)) | 
       
   273 					(Type(a1)<<(Type(a1)*KBitsPerType)) |
       
   274 					(Type(a2)<<(Type(a2)*KBitsPerType));
       
   275 			}
       
   276 
       
   277 		/**
       
   278 		Checks whether the flag is set for the given argument type.
       
   279 				
       
   280 		@internalComponent
       
   281 		*/
       
   282 		TBool IsSet ( TPolicyArgType aType ) const
       
   283 			{
       
   284 			TInt val = iFlags & ( aType << ( aType  * KBitsPerType ) );
       
   285 			return iFlags & ( aType << ( aType  * KBitsPerType ) );
       
   286 			}
       
   287 		
       
   288 		/**
       
   289 		Returns the argument if set, otherwise returns KErrNotFound.
       
   290 		
       
   291 		@internalComponent
       
   292 		*/		
       
   293 		TInt Get ( TPolicyArgType aType ) const
       
   294 			{
       
   295 			if ( IsSet ( aType ) )
       
   296 				return iArgs[aType - 1];
       
   297 			return KErrNotFound;			
       
   298 			}
       
   299 		
       
   300 				
       
   301 	private:
       
   302 
       
   303 		/**
       
   304 		@internalComponent
       
   305 		*/			
       
   306 		TPolicyArgType Type ( const TDesC8* )
       
   307 			{
       
   308 			return ETldUri;				
       
   309 			}
       
   310 			
       
   311 		TPolicyArgType Type ( InetUriList::TListType )
       
   312 			{
       
   313 			return ETldListType;				
       
   314 			}
       
   315 
       
   316 		TPolicyArgType Type ( InetUriList::TTLDQueryType )
       
   317 			{
       
   318 			return ETldQueryType;				
       
   319 			}
       
   320 		
       
   321 		void Assign ( const TDesC8* aValue )
       
   322 			{
       
   323 			iArgs[Type(aValue)-1] = (TInt)aValue;
       
   324 			}
       
   325 			
       
   326 		void Assign ( InetUriList::TListType aValue )
       
   327 			{
       
   328 			iArgs[Type(aValue)-1] = aValue;
       
   329 			}
       
   330 			
       
   331 		void Assign ( InetUriList::TTLDQueryType aValue )
       
   332 			{
       
   333 			iArgs[Type(aValue)-1] = aValue;
       
   334 			}
       
   335 			
       
   336 	
       
   337 	};
       
   338 
       
   339 
       
   340 #endif	//SYMBIAN_ENABLE_SPLIT_HEADERS
       
   341 
       
   342 	
       
   343 //------------------------------------------------------------------------
       
   344 class TQueryResults: public TBase
       
   345 	{
       
   346 	public:
       
   347 		/**
       
   348 		Default constructor
       
   349 		*/
       
   350 		inline TQueryResults ()
       
   351 			:TBase()
       
   352 			{}
       
   353 		
       
   354 		~TQueryResults ()
       
   355 			{
       
   356 			if ( IsSet( TQueryResults::ETldCharSet ) )
       
   357 				{
       
   358 				//Delete memory on Heap.
       
   359 				HBufC8* uriBuf = (reinterpret_cast<HBufC8*> ( Get ( TQueryResults::ETldCharSet ) ));
       
   360 				delete uriBuf;
       
   361 				}
       
   362 			}
       
   363 			
       
   364 		/**
       
   365 		returns a pointer to policydata
       
   366 		*/
       
   367 		HBufC8* CharsetL()
       
   368 			{
       
   369 			__ASSERT_ALWAYS( IsSet(TQueryResults::ETldCharSet), User::Panic( KTldInvalidRequest, KErrPolicyDataNotPresent ));
       
   370 			const TDesC8& uri = *( reinterpret_cast<TDesC8*> (Get ( TQueryResults::ETldCharSet ) ) );
       
   371 			return uri.AllocL();
       
   372 			}
       
   373 
       
   374 		/**
       
   375 		returns a list type
       
   376 		*/
       
   377 		InetUriList::TListType ListType()
       
   378 			{
       
   379 			__ASSERT_ALWAYS( IsSet(TQueryResults::ETldListType), User::Panic( KTldInvalidRequest, KErrPolicyListTypeNotPresent ));
       
   380 			return (static_cast<InetUriList::TListType> (Get ( TQueryResults::ETldListType ) ));
       
   381 			}
       
   382 			
       
   383 		/**
       
   384 		A templated constructor that constructs the query argument.
       
   385 		It takes one argument. --Check this
       
   386 		*/
       
   387 		template < class T0 >
       
   388 		inline void Set ( T0 a0 )
       
   389 			{
       
   390 			Assign ( a0 );
       
   391 			iFlags=(Type(a0)<<(( Type(a0))*KBitsPerType));
       
   392 			}
       
   393 
       
   394 	private:
       
   395 		#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
   396 		/**
       
   397 		The argument types.	
       
   398 		*/
       
   399 		#else
       
   400 		/**
       
   401 		The argument types.
       
   402 		
       
   403 		@internalComponent
       
   404 		*/
       
   405 		#endif	//SYMBIAN_ENABLE_SPLIT_HEADERS
       
   406 		enum TResultsArgType
       
   407 			{
       
   408 			ETldCharSet = 1,
       
   409 			ETldListType
       
   410 			};	
       
   411 		
       
   412 		#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
   413        /**
       
   414 		Checks whether the flag is set for the given argument type.		
       
   415 		*/
       
   416 		#else
       
   417 		/**
       
   418 		Checks whether the flag is set for the given argument type.
       
   419 				
       
   420 		@internalComponent
       
   421 		*/
       
   422 		#endif	//SYMBIAN_ENABLE_SPLIT_HEADERS
       
   423 		TBool IsSet ( TResultsArgType aType ) const
       
   424 			{
       
   425 			TInt val = iFlags & ( aType << ( aType  * KBitsPerType ) );
       
   426 			return iFlags & ( aType << ( aType  * KBitsPerType ) );
       
   427 			}
       
   428 
       
   429 		#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
   430 		/**
       
   431 		Returns the argument if set, otherwise returns KErrNotFound.		
       
   432 		*/	
       
   433 		#else
       
   434 		/**
       
   435 		Returns the argument if set, otherwise returns KErrNotFound.
       
   436 		
       
   437 		@internalComponent
       
   438 		*/		
       
   439 		#endif	//SYMBIAN_ENABLE_SPLIT_HEADERS
       
   440 		TInt Get ( TResultsArgType aType ) const
       
   441 			{
       
   442 			if ( IsSet ( aType ) )
       
   443 				return iArgs[aType - 1];
       
   444 			return KErrNotFound;			
       
   445 			}		
       
   446 	
       
   447 	private:
       
   448 		#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
   449 		/**
       
   450 		@internalComponent
       
   451 		*/			
       
   452 		#endif	//SYMBIAN_ENABLE_SPLIT_HEADERS
       
   453 		
       
   454 		TResultsArgType Type ( const TDesC8* )
       
   455 			{
       
   456 			return ETldCharSet;				
       
   457 			}
       
   458 			
       
   459 		TResultsArgType Type ( InetUriList::TListType )
       
   460 			{
       
   461 			return ETldListType;				
       
   462 			}
       
   463 
       
   464 		void Assign ( const TDesC8* aValue )
       
   465 			{
       
   466 			iArgs[Type(aValue)-1] = (TInt)aValue;
       
   467 			}
       
   468 			
       
   469 		void Assign ( InetUriList::TListType aValue )
       
   470 			{
       
   471 			iArgs[Type(aValue)-1] = aValue;
       
   472 			}
       
   473 	};
       
   474 
       
   475 #endif // __TLDLISTDEF_H__
       
   476