uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/alfpolicyrequesthandler.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Contains a class that is responsible for sending policy updates 
       
    15 *                to connected clients
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <s32mem.h>
       
    23 
       
    24 //======== USER INCLUDES ========
       
    25 #include "alfpolicyrequesthandler.h"
       
    26 #include "alfpolicyhandler.h"
       
    27 //#include "tfxserverdef.h"
       
    28 #include <alflogger.h>
       
    29 
       
    30 
       
    31 // ======== HELPER CLASS FUNCTIONS ========
       
    32 
       
    33 CPolicyEventReq::CPolicyEventReq()
       
    34     {
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // Destructor for CPolicyEventReq
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CPolicyEventReq::~CPolicyEventReq()
       
    42 	{
       
    43 	iOriginalControlPolicies.ResetAndDestroy();
       
    44 	iAddedPolicies.ResetAndDestroy();
       
    45 	iRemovedPolicies.ResetAndDestroy();
       
    46 
       
    47 	if(!iMessage.IsNull() && iMessage.Handle() != 0)	// We should release a a stored message. 
       
    48 		{
       
    49         __ALFFXLOGSTRING("CPolicyEventReq:: Message complete, Disconnected");
       
    50 		iMessage.Complete( KErrDisconnected );
       
    51 		}
       
    52 	}
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 TUint CPolicyEventReq::TotalPolicyCount() const
       
    58     {
       
    59     TUint count = 0;
       
    60     for ( TInt i = iOriginalControlPolicies.Count() - 1; i >= 0; --i )
       
    61         {
       
    62         count += iOriginalControlPolicies[i]->iControlPolicies.Count();
       
    63         }
       
    64     count += iAddedPolicies.Count();
       
    65     count += iRemovedPolicies.Count();
       
    66     return count;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // Constructor for CClientControlPolicy
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CClientControlPolicy::CClientControlPolicy()
       
    74 	{
       
    75 	}
       
    76 
       
    77 	
       
    78 // ---------------------------------------------------------------------------
       
    79 // Destructor for CClientControlPolicy
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CClientControlPolicy::~CClientControlPolicy()
       
    83 	{
       
    84 	
       
    85 	for( TInt i =  iControlPolicies.Count() - 1; i >= 0; i--)
       
    86 		{
       
    87 		iControlPolicies.Remove(i);
       
    88 		}
       
    89 		
       
    90 	iControlPolicies.Close();
       
    91 	iResourceDir.Close();
       
    92 	iFilename.Close();
       
    93 	}
       
    94 
       
    95 	
       
    96 // ======== MEMBER FUNCTIONS ========
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Constructor. 
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 CPolicyClientRequestHandler::CPolicyClientRequestHandler(CPolicyHandler* aParent) :
       
   103 		 iParent(aParent)
       
   104 	{
       
   105 	}
       
   106 	
       
   107 // ---------------------------------------------------------------------------
       
   108 // Destructor
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CPolicyClientRequestHandler::~CPolicyClientRequestHandler()
       
   112 	{
       
   113     RemoveDeadClients();
       
   114 	iControlPolicyClients.ResetAndDestroy();
       
   115 	}
       
   116 	
       
   117 	
       
   118 // ---------------------------------------------------------------------------
       
   119 // Iterates over all connected clients and appends a policy to each if necessary.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CPolicyClientRequestHandler::RegisterControlAction(const TUid aUid, TUint aAction)
       
   123 	{
       
   124 	CPolicyEventReq* pPolReq = NULL;
       
   125 	
       
   126 	// Look for existing clients. If none found, all is OK.
       
   127 	TInt contrCount = iControlPolicyClients.Count();
       
   128 	// We have some connected clients. Update the new policies for all of these.
       
   129 	for(TInt i = 0; i < contrCount; i++)
       
   130 		{
       
   131 		pPolReq = iControlPolicyClients[i];
       
   132 		// Checking if we already have stored the policy. Since we only have a copy of the pointer
       
   133 		// to the original object we need not update it. It has already been done in the policyhandler.
       
   134 		if(KErrNone == CheckStoredControlPolicy(pPolReq->iOriginalControlPolicies, aUid, aAction))
       
   135 			{
       
   136 			return;
       
   137 			}
       
   138 		// If it's not in the original list, see if we have it somewhere else. If so, complete
       
   139 		// the stored away message if possible.
       
   140 		if(KErrNone == AddControlPolicyAction(pPolReq->iAddedPolicies, pPolReq->iRemovedPolicies, aUid, aAction))
       
   141 			{
       
   142 			if(!pPolReq->iMessage.IsNull())
       
   143 				{
       
   144                 __ALFFXLOGSTRING("CPolicyEventReq:: Message complete, Register control action");
       
   145 				pPolReq->iMessage.Complete(KErrNone);
       
   146 				pPolReq->iMessage = RMessagePtr2();
       
   147 				}
       
   148 			}
       
   149 		}
       
   150 	}
       
   151 	
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 TInt CPolicyClientRequestHandler::RemoveControlPolicy(const TUid aUid, TUint aAction )
       
   158 	{
       
   159 	
       
   160 	TInt clientCount = iControlPolicyClients.Count();
       
   161 	TInt err = KErrNone;
       
   162 	// Lint will complain because the tPol pointer is not deleted here.
       
   163 	// The pointer is stored into a pointerarray and deleted when the array is destroyed.
       
   164 	// This is the reason why this warning/error is disabled.
       
   165 	/*lint -e429  -e830 */
       
   166 
       
   167 	for(TInt i = 0; i < clientCount; i++)
       
   168 		{
       
   169 		if( KErrNotFound == RemovePolicyUid(iControlPolicyClients[i]->iOriginalControlPolicies, 
       
   170 											aAction, aUid) 	&& 
       
   171 			KErrNotFound == RemovePolicyUid(iControlPolicyClients[i]->iAddedPolicies, aAction, aUid))
       
   172 			{
       
   173 			TControlPolicy* tPol = new TControlPolicy;
       
   174 			if(NULL == tPol)
       
   175 				{
       
   176 				return KErrNoMemory;
       
   177 				}
       
   178 			tPol->iAction = aAction;
       
   179 			tPol->iId = aUid;
       
   180 			tPol->iPolicy = ENotSupported;
       
   181 			
       
   182 			err = iControlPolicyClients[i]->iRemovedPolicies.Append(tPol); //Takes ownership
       
   183 			if( KErrNone != err)
       
   184 				{
       
   185 				delete tPol;
       
   186 				tPol = NULL;
       
   187 				return err;
       
   188 				}
       
   189 				
       
   190 			if(!iControlPolicyClients[i]->iMessage.IsNull())
       
   191 				{
       
   192                 __ALFFXLOGSTRING("CPolicyEventReq:: Message complete, Remove control policy");
       
   193 				iControlPolicyClients[i]->iMessage.Complete(KErrNone);
       
   194 				iControlPolicyClients[i]->iMessage = RMessagePtr2();
       
   195 				}
       
   196 			}
       
   197 		} 
       
   198 	/*lint +e429  +e830 */
       
   199 	return KErrNone;
       
   200 	}
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 TInt CPolicyClientRequestHandler::RequestPolicy( const RMessage2& aMessage )
       
   208 	{
       
   209 	TInt err = KErrNone;
       
   210 	CPolicyEventReq* req = NULL;
       
   211 	
       
   212 	RThread client;
       
   213 	err = aMessage.Client( client );
       
   214 	if( err != KErrNone )
       
   215 		{
       
   216 		client.Close();
       
   217 		return err;
       
   218 		}
       
   219 		
       
   220 	TThreadId currClient = client.Id();
       
   221 	client.Close();
       
   222 	
       
   223 	TInt clientCount = iControlPolicyClients.Count();
       
   224 	for( TInt i = 0; i < clientCount; i++ )
       
   225 		{
       
   226 		req = iControlPolicyClients[i];
       
   227 		if(req->iClientId == currClient)
       
   228 			{
       
   229 			if(	req->iAddedPolicies.Count() == 0 && req->iOriginalControlPolicies.Count() == 0
       
   230 				&& req->iRemovedPolicies.Count() == 0)
       
   231 				{
       
   232 				// Check if it's OK to add this request to the list.
       
   233 				// This is done by just storing the message. 
       
   234 				if( req->iMessage.IsNull() )
       
   235 					{
       
   236 					req->iMessage = aMessage;
       
   237 					return KErrNone;
       
   238 					}
       
   239 				// If message is not null, something is wrong.
       
   240 				return KErrGeneral;
       
   241 				}
       
   242 			// If we have a stored message, complete it. Should not happen!
       
   243 			if( !req->iMessage.IsNull() )
       
   244 				{
       
   245                 __ALFFXLOGSTRING("CPolicyEventReq:: Message complete, stored message, should not happen");
       
   246 				req->iMessage.Complete( KErrNone );
       
   247 	    		// NULLify the message pointer after it has been completed.
       
   248 	    		// If not done, we can't check if the message is valid or not.
       
   249 				req->iMessage = RMessagePtr2();
       
   250 				return KErrNone;
       
   251 				}
       
   252             // Otherwise complete this message.
       
   253             __ALFFXLOGSTRING("CPolicyEventReq:: Message complete, return policy count");
       
   254             aMessage.Complete( req->TotalPolicyCount() );
       
   255 			return KErrNone;
       
   256 			}
       
   257 		}
       
   258 	// Client not found. Insert it!
       
   259 	err = InsertClient( aMessage );
       
   260 	if( err != KErrNotFound )	
       
   261 		{
       
   262 		// If failed to insert the client, complete the message so it may try again.
       
   263 		// Also, if there are control policies, we report the number of them
       
   264 		// If error is KErrNotFound, we have stored the message, and it will be completed
       
   265 		// later (as soon as there are policies)
       
   266         __ALFFXLOGSTRING1("CPolicyEventReq:: insert client returned %d", err);
       
   267 		aMessage.Complete( err );
       
   268 		}
       
   269 	return KErrNone;
       
   270 	}
       
   271 	
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 TInt CPolicyClientRequestHandler::GetPolicyL( TThreadId aClientId, TInt aPolicyCount, TPtr8& aOutBuf )
       
   277     {
       
   278     CPolicyEventReq* 		req 	= NULL;
       
   279     TControlPolicy* 		tAddPol	= NULL;
       
   280     CActionPolicy*			tPol 	= NULL;
       
   281     CClientControlPolicy*	tOUid 	= NULL;	
       
   282     TControlPolicy* 		tRemPol = NULL;
       
   283         
       
   284     TThreadId id = aClientId;
       
   285     TInt count = 0;
       
   286     RDesWriteStream outstream( aOutBuf );
       
   287     CleanupClosePushL( outstream );
       
   288     
       
   289     for( TInt i = iControlPolicyClients.Count() - 1; i >= 0; --i )
       
   290         {
       
   291         req = iControlPolicyClients[i];
       
   292         
       
   293         if ( req->iClientId == id )
       
   294             {
       
   295             int added = 0;
       
   296 
       
   297             count = req->TotalPolicyCount();
       
   298             if ( count > aPolicyCount )
       
   299                 {
       
   300                 count = aPolicyCount;
       
   301                 }
       
   302             outstream.WriteUint32L( count );
       
   303 
       
   304             TInt addedPolicyCount       = req->iAddedPolicies.Count();
       
   305             TInt origPolicyCount        = req->iOriginalControlPolicies.Count();
       
   306             TInt removedPoliciesCount   = req->iRemovedPolicies.Count();
       
   307 
       
   308             for ( TInt q = origPolicyCount - 1; q >= 0 && added < count; --q )
       
   309                 {
       
   310                 tOUid = req->iOriginalControlPolicies[q];
       
   311                 TInt origPolicyInfoCount = tOUid->iControlPolicies.Count();
       
   312                 for ( TInt qi = origPolicyInfoCount - 1; qi >= 0 && added < count; --qi )
       
   313                     {
       
   314                     tPol = tOUid->iControlPolicies[qi];
       
   315                     outstream.WriteInt32L( tOUid->iUid.iUid );
       
   316                     outstream.WriteInt32L( tPol->iAction );
       
   317                     outstream.WriteUint8L( tPol->iPolicy );
       
   318                     added++;
       
   319 
       
   320                     // Here we only remove the policy from the local list of original policies.
       
   321                     // we don't delete it since it's a copy of the pointer to the
       
   322                     // original object and we don't want to remove it permanently!
       
   323                     tOUid->iControlPolicies.Remove( qi );
       
   324                     }
       
   325                 if ( tOUid->iControlPolicies.Count() == 0 )
       
   326                     {
       
   327                     // It's OK to delete tOUid. It doesn't destroy anything except itself!
       
   328                     req->iOriginalControlPolicies.Remove(q);
       
   329                     delete tOUid;
       
   330                     }
       
   331                 }
       
   332 
       
   333             for ( TInt z = addedPolicyCount - 1; z >= 0 && added < count; --z )
       
   334                 {
       
   335                 tAddPol = req->iAddedPolicies[z];
       
   336                 outstream.WriteInt32L( tAddPol->iId.iUid );
       
   337                 outstream.WriteInt32L( tAddPol->iAction );
       
   338                 outstream.WriteUint8L( tAddPol->iPolicy );
       
   339                   added++;
       
   340 
       
   341                 // Here we delete the actual object. This is possible since
       
   342                 // it has been created specifically for this client.
       
   343                 delete tAddPol;
       
   344                 req->iAddedPolicies.Remove( z );
       
   345                 }
       
   346             for(TInt s = removedPoliciesCount - 1; s >= 0 && added < count; s--)
       
   347                 {
       
   348                 tRemPol = req->iRemovedPolicies[s];
       
   349                 outstream.WriteInt32L( tRemPol->iId.iUid );
       
   350                 outstream.WriteInt32L( tRemPol->iAction );
       
   351                 outstream.WriteUint8L( tRemPol->iPolicy );
       
   352                    added++;
       
   353                 // Here we delete the actual object. This is possible since
       
   354                 // it has been created specifically for this client.
       
   355                 delete tRemPol;
       
   356                 req->iRemovedPolicies.Remove(s);
       
   357                 }
       
   358             outstream.CommitL();
       
   359             CleanupStack::PopAndDestroy(); // outstream
       
   360             
       
   361             return KErrNone;
       
   362             }
       
   363         }
       
   364         
       
   365     outstream.WriteUint32L( 0 );
       
   366     outstream.CommitL();
       
   367     CleanupStack::PopAndDestroy(); // outstream
       
   368     return KErrNotFound;
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CPolicyClientRequestHandler::RemoveClient( TThreadId aClientId )
       
   376 	{
       
   377 	for( TInt i = iControlPolicyClients.Count() - 1; i >= 0; i--)
       
   378 		{
       
   379 		if( iControlPolicyClients[i]->iClientId == aClientId )
       
   380 			{
       
   381 			if(!iControlPolicyClients[i]->iMessage.IsNull())
       
   382 			    {
       
   383                 __ALFFXLOGSTRING("CPolicyEventReq:: Message complete, remove client");
       
   384     			iControlPolicyClients[i]->iMessage.Complete( KErrCancel );
       
   385                 iControlPolicyClients[i]->iMessage = RMessage2(); //Null message so destructor wont try to complete.
       
   386 			    }
       
   387    			delete iControlPolicyClients[i];
       
   388 			iControlPolicyClients.Remove(i);
       
   389 			}
       
   390 		}
       
   391 	}
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // Removes all requests belonging to a terminated client.
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CPolicyClientRequestHandler::RemoveDeadClients()
       
   398 	{
       
   399 	// Lint seems to have some trouble identifying the TThreadId class.
       
   400 	// Due to this, Lint will report several errors here that are incorrect.
       
   401 	// These errors are disabled.
       
   402 	/*lint -e10 -e1013 -e1055 -e746 -e747 */
       
   403 	RThread client;
       
   404 	for( TInt i = iControlPolicyClients.Count() - 1; i >= 0; i--)
       
   405 		{
       
   406 		TInt err = client.Open(iControlPolicyClients[i]->iClientId.Id());
       
   407 		if(err == KErrNone)
       
   408 			{
       
   409 			if(client.ExitType() != EExitPending)
       
   410 				{
       
   411 				//Client is dead, remove from list.
       
   412 				iControlPolicyClients[i]->iMessage = RMessage2(); //Null message so destructor wont try to complete.
       
   413 				delete iControlPolicyClients[i];
       
   414 				iControlPolicyClients.Remove(i);
       
   415 				}
       
   416 		    client.Close();
       
   417 			}
       
   418 		else
       
   419 			{
       
   420 			//Could not open client, client handle was invalid.
       
   421 			//So clean it up from list too.
       
   422 			iControlPolicyClients[i]->iMessage = RMessage2(); //Null message so destructor wont try to complete.
       
   423 			delete iControlPolicyClients[i];
       
   424 			iControlPolicyClients.Remove(i);
       
   425 			}
       
   426 		}
       
   427 	/*lint +e10 +e1013 +e1055 +e746 +e747 */
       
   428 	}
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // ---------------------------------------------------------------------------
       
   432 //
       
   433 void CPolicyClientRequestHandler::DumpClientsL(RFileWriteStream& aFile)
       
   434 	{
       
   435 	// Lint seems to have some trouble identifying the TThreadId class.
       
   436 	// Due to this, Lint will report several errors here that are incorrect.
       
   437 	// These errors are disabled.
       
   438 	/*lint -e10 -e1013 -e1055 -e746 -e747 */
       
   439 	for(TInt i = iControlPolicyClients.Count() - 1; i >= 0; i--)
       
   440 		{
       
   441 		TPckgC<TThreadId> clientid(iControlPolicyClients[i]->iClientId.Id());
       
   442 		aFile.WriteL(clientid);
       
   443 		}
       
   444 	/*lint +e10 +e1013 +e1055 +e746 +e747 */
       
   445 	}
       
   446 
       
   447 	
       
   448 // =================== PRIVATE METHODS ==============
       
   449 
       
   450 // ---------------------------------------------------------------------------
       
   451 // ---------------------------------------------------------------------------
       
   452 //
       
   453 TInt CPolicyClientRequestHandler::InsertClient(const RMessage2& aMessage)
       
   454 	{
       
   455 	
       
   456 	TInt err = KErrNone;
       
   457 	
       
   458 	CPolicyEventReq* req = new CPolicyEventReq();
       
   459 	if (!req)
       
   460 		{
       
   461 		return KErrNoMemory;
       
   462 		}
       
   463 
       
   464 	// Getting the client ID and storing it.	
       
   465 	RThread client;
       
   466 	err = aMessage.Client(client);
       
   467 	if( err != KErrNone )
       
   468 		{
       
   469 		delete req;
       
   470 		return err;
       
   471 		}
       
   472 	req->iClientId = client.Id();
       
   473 	client.Close();
       
   474 	
       
   475     err = iControlPolicyClients.Append(req);
       
   476     if( err == KErrNone )
       
   477     	{
       
   478 		// Requesting all policies from the policy handler.
       
   479         err = iParent->GetAllControlPolicies( req->iOriginalControlPolicies );
       
   480 		if( err == KErrNotFound )
       
   481 			{
       
   482 			// If no polices found, store message for later.
       
   483 			req->iMessage = aMessage;
       
   484 			return err;
       
   485 			} 
       
   486         err = req->TotalPolicyCount();
       
   487     	}
       
   488     else
       
   489         {
       
   490         delete req;
       
   491         }
       
   492     return err;
       
   493 	}
       
   494 
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 TInt CPolicyClientRequestHandler::AddControlPolicyAction(	RPointerArray<TControlPolicy>& aAddedPolicies,
       
   500 															RPointerArray<TControlPolicy>& aRemovedPolicies,
       
   501 															const TUid aUid, TUint aAction)
       
   502 	{
       
   503 	
       
   504 	
       
   505 	// Lint will complain because the tPol pointer is not deleted here.
       
   506 	// The pointer is stored into a pointerarray and deleted when the array is destroyed.
       
   507 	// This is the reason why this warning/error is disabled.
       
   508 	/*lint -e429 -e830 */
       
   509 		
       
   510 	TControlPolicy* tPol = NULL;
       
   511 	TInt err = KErrNone;
       
   512 	
       
   513 	// Checking if we have any newly added policies.
       
   514 	TInt polUidCount = aAddedPolicies.Count();
       
   515 	for(TInt i = 0; i < polUidCount; i++)
       
   516 		{
       
   517 		tPol = aAddedPolicies[i];
       
   518 		if(tPol->iId == aUid && tPol->iAction == aAction)
       
   519 			{
       
   520 			return KErrNone;
       
   521 			}
       
   522 		}
       
   523 	// Checking if this policy has been set to be removed.
       
   524 	polUidCount = aRemovedPolicies.Count();
       
   525 	for(TInt i = 0; i < polUidCount; i++)
       
   526 		{
       
   527 		tPol = aRemovedPolicies[i];
       
   528 		if(tPol->iId == aUid && tPol->iAction == aAction)
       
   529 			{
       
   530 			aRemovedPolicies.Remove(i);
       
   531 			delete tPol;
       
   532 			tPol = NULL;
       
   533 			return KErrNone;
       
   534 			}
       
   535 		}
       
   536 	
       
   537 	// No policy found. Adding a new one.
       
   538 	// For some reason Lint doesn't like this if() clause. Perhaps Lint doesn't
       
   539 	// understand that new can return NULL. Disabling the "if always evaluates to False"
       
   540 	// error message.
       
   541 	/*lint -e774 -e831 */
       
   542 	tPol = NULL;
       
   543 	tPol = new TControlPolicy;
       
   544 	if(NULL == tPol)
       
   545 		{
       
   546 		return KErrNoMemory;
       
   547 		}
       
   548 	/*lint +e774 +e831 */
       
   549 
       
   550 	tPol->iAction = aAction;
       
   551 	tPol->iId = aUid;
       
   552 	tPol->iPolicy = ESupported;
       
   553 
       
   554 	err = aAddedPolicies.Append(tPol);
       
   555 	if(KErrNone == err)
       
   556 		{
       
   557 		return err;
       
   558 		}
       
   559 
       
   560 	// Clenup on failure
       
   561 	delete tPol;
       
   562 	tPol = NULL;
       
   563 	return err;			
       
   564 
       
   565 	/*lint +e429 +e830 */	
       
   566 	}
       
   567 
       
   568 // ---------------------------------------------------------------------------
       
   569 //
       
   570 // ---------------------------------------------------------------------------
       
   571 //
       
   572 TInt CPolicyClientRequestHandler::CheckStoredControlPolicy(	RPointerArray<CClientControlPolicy>& aPtr, 
       
   573 															TUid aUid, TUint aAction)
       
   574 	{
       
   575 	
       
   576 	TInt polUidCount = aPtr.Count();
       
   577 	for(TInt i = 0; i < polUidCount; i++)
       
   578 		{
       
   579 		if(aPtr[i]->iUid == aUid)
       
   580 			{
       
   581 			TInt actionCount = aPtr[i]->iControlPolicies.Count();
       
   582 			for(TInt j = 0; j < actionCount; j++)
       
   583 				{
       
   584 				if(aPtr[i]->iControlPolicies[j]->iAction == aAction)
       
   585 					{
       
   586 					return KErrNone;
       
   587 					}
       
   588 				}
       
   589 			}
       
   590 		}
       
   591 	return KErrNotFound;
       
   592 	}
       
   593 
       
   594 // ---------------------------------------------------------------------------
       
   595 //
       
   596 // ---------------------------------------------------------------------------
       
   597 // 
       
   598 
       
   599 TInt CPolicyClientRequestHandler::RemovePolicyUid(RPointerArray<TControlPolicy>& aAddedPolicies, TUint aAction, const TUid aUid)
       
   600 	{
       
   601 	TControlPolicy* tUid = NULL;
       
   602 
       
   603 	TInt policyCount = aAddedPolicies.Count();
       
   604 	for(TInt i = 0; i < policyCount; i++)
       
   605 		{
       
   606 		tUid = aAddedPolicies[i];
       
   607 		if(tUid->iId == aUid && tUid->iAction == aAction)
       
   608 			{
       
   609 			delete tUid;
       
   610 			tUid = NULL;
       
   611 			aAddedPolicies.Remove(i);
       
   612 			return KErrNone;
       
   613 			}
       
   614 		} 
       
   615 	return KErrNotFound;
       
   616 	}
       
   617 
       
   618 // ---------------------------------------------------------------------------
       
   619 //
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 TInt CPolicyClientRequestHandler::RemovePolicyUid(RPointerArray<CClientControlPolicy>& aPolUid, TUint aAction, const TUid aUid)
       
   623 	{
       
   624 	CClientControlPolicy* tUid = NULL;
       
   625 	
       
   626 	TInt policyCount = aPolUid.Count();
       
   627 	for(TInt i = 0; i < policyCount; i++)
       
   628 		{
       
   629 		tUid = aPolUid[i];
       
   630 		if(tUid->iUid == aUid)
       
   631 			{
       
   632 			TInt err = RemovePolicyInfo(tUid->iControlPolicies, aAction, EFalse);
       
   633 			if ( err == KErrNone)
       
   634 				{
       
   635 				if(tUid->iControlPolicies.Count() == 0)
       
   636 					{
       
   637 					delete tUid;
       
   638 					tUid = NULL;
       
   639 					aPolUid.Remove(i);
       
   640 					}
       
   641 				return err;
       
   642 				}
       
   643 			}
       
   644 		}
       
   645 	return KErrNotFound;
       
   646 	}
       
   647 
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 // ---------------------------------------------------------------------------
       
   651 //
       
   652 TInt CPolicyClientRequestHandler::RemovePolicyInfo(RPointerArray<CActionPolicy>& aPolInfo, TUint aAction, TBool aDelete)
       
   653 	{
       
   654 	CActionPolicy* tPol = NULL;
       
   655 	TInt polInfoCount = aPolInfo.Count();
       
   656 	
       
   657 	for(TInt i = 0; i < polInfoCount; i++)
       
   658 		{
       
   659 		tPol = aPolInfo[i];
       
   660 		if(tPol->iAction == aAction)
       
   661 			{
       
   662 			if(aDelete)
       
   663 				{
       
   664 				delete tPol;
       
   665 				tPol = NULL;
       
   666 				}
       
   667 			aPolInfo.Remove(i);
       
   668 			return KErrNone;
       
   669 			}
       
   670 		}
       
   671 	return KErrNotFound;
       
   672 	}
       
   673 
       
   674 
       
   675 
       
   676 // --- EOF ---
       
   677 
       
   678