eapol/eapol_framework/eapol_symbian/eap_server/src/EapServer.cpp
changeset 52 c23bdf5a328a
parent 39 fe6b6762fccd
equal deleted inserted replaced
51:e863583e6720 52:c23bdf5a328a
    14 * Description:  scheduler of EAP-server.
    14 * Description:  scheduler of EAP-server.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 35 %
    19 * %version: 41 %
    20 */
    20 */
    21 
    21 
    22 #include "EapServer.h"
    22 #include "EapServer.h"
    23 #include "EapTraceSymbian.h"
    23 #include "EapTraceSymbian.h"
    24 #include <ecom.h>
    24 #include <ecom.h>
    68 
    68 
    69 	EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::ConstructL()");
    69 	EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::ConstructL()");
    70 
    70 
    71 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    71 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    72 
    72 
       
    73 	eap_status_e status(eap_status_ok);
       
    74 
    73 	{
    75 	{
    74 		const u8_t DEFAULT_PREFIX[] = "EAP-SERVER";
    76 		const u8_t DEFAULT_PREFIX[] = "EAP-SERVER";
    75 		eap_variable_data_c tmp_prefix(iTools);
    77 		eap_variable_data_c tmp_prefix(iTools);
    76 
    78 
    77 		if (tmp_prefix.get_is_valid() == false)
    79 		if (tmp_prefix.get_is_valid() == false)
    78 		{
    80 		{
    79 			iTools->am_cancel_all_timers();
    81 			status = eap_status_allocation_error;
    80 			abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools);
    82 			(void) EAP_STATUS_RETURN(iTools, status);
    81 			User::Leave(KErrNoMemory);
       
    82 		}
    83 		}
    83 
    84 
    84 		eap_status_e status = tmp_prefix.set_copy_of_buffer(DEFAULT_PREFIX, sizeof(DEFAULT_PREFIX)-1ul);;
    85 		if (status == eap_status_ok)
    85 		if (status != eap_status_ok)
       
    86 		{
    86 		{
    87 			iTools->am_cancel_all_timers();
    87 			status = tmp_prefix.set_copy_of_buffer(DEFAULT_PREFIX, sizeof(DEFAULT_PREFIX)-1ul);;
    88 			abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools);
    88 			if (status != eap_status_ok)
    89 			User::Leave(KErrNoMemory);
    89 			{
       
    90 				(void) EAP_STATUS_RETURN(iTools, status);
       
    91 			}
    90 		}
    92 		}
    91 
    93 
    92 		status = tmp_prefix.add_end_null();
    94 		if (status == eap_status_ok)
    93 		if (status != eap_status_ok)
       
    94 		{
    95 		{
    95 			iTools->am_cancel_all_timers();
    96 			status = tmp_prefix.add_end_null();
    96 			abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools);
    97 			if (status != eap_status_ok)
    97 			User::Leave(KErrNoMemory);
    98 			{
       
    99 				(void) EAP_STATUS_RETURN(iTools, status);
       
   100 			}
    98 		}
   101 		}
    99 
   102 
   100 		status = iTools->set_trace_prefix(&tmp_prefix);
   103 		if (status == eap_status_ok)
   101 		if (status != eap_status_ok)
       
   102 		{
   104 		{
   103 			iTools->am_cancel_all_timers();
   105 			status = iTools->set_trace_prefix(&tmp_prefix);
   104 			abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools);
   106 			if (status != eap_status_ok)
   105 			User::Leave(KErrNoMemory);
   107 			{
       
   108 				(void) EAP_STATUS_RETURN(iTools, status);
       
   109 			}
   106 		}
   110 		}
       
   111 	}
       
   112 
       
   113 	if (status != eap_status_ok)
       
   114 	{
       
   115 		iTools->am_cancel_all_timers();
       
   116 		abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools);
       
   117 		User::Leave(KErrGeneral);
   107 	}
   118 	}
   108 
   119 
   109 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   120 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   110 
   121 
   111 	{
   122 	{
   227 		this));
   238 		this));
   228 
   239 
   229 	// Do not use iTools, because it will be destroyed before return.
   240 	// Do not use iTools, because it will be destroyed before return.
   230 	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapServer::~CEapServer()"));
   241 	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapServer::~CEapServer()"));
   231 
   242 
       
   243 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   244 
       
   245 	TInt aCount = iReadyHandlers.Count();
       
   246 
       
   247 	while (aCount > 0)
       
   248 	{
       
   249 		EAP_TRACE_DEBUG(
       
   250 			iTools,
       
   251 			TRACE_FLAGS_DEFAULT,
       
   252 			(EAPL("CEapServer::~CEapServer(): Removes iReadyHandlers[0]=0x%08x\n"),
       
   253 			iReadyHandlers[0]));
       
   254 
       
   255 		iReadyHandlers.Remove(0);
       
   256 
       
   257 		aCount = iReadyHandlers.Count();
       
   258 	}
       
   259 
       
   260 	iReadyHandlers.Close();
       
   261 
       
   262 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   263 
   232 	delete iShutdown;
   264 	delete iShutdown;
   233 	delete iBackupRestore;
   265 	delete iBackupRestore;
   234 	
   266 	
   235 	if (iTools) 
   267 	if (iTools) 
   236 	{
   268 	{
   428 	EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::BackupOrRestoreStartingL()");
   460 	EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::BackupOrRestoreStartingL()");
   429 
   461 
   430     StopL();
   462     StopL();
   431 }
   463 }
   432 
   464 
       
   465 // -----------------------------------------------------------------------------------------
       
   466 
       
   467 TInt CEapServer::AddReadyHandler(CEapServerProcessHandler * const handler)
       
   468 {
       
   469 	EAP_TRACE_DEBUG(
       
   470 		iTools,
       
   471 		TRACE_FLAGS_DEFAULT,
       
   472 		(EAPL("CEapServer::AddReadyHandler(): this=0x%08x: handler=0x%08x\n"),
       
   473 		this,
       
   474 		handler));
       
   475 	EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::AddReadyHandler()");
       
   476 
       
   477 	TInt aCount = iReadyHandlers.Count();
       
   478 
       
   479 	if (aCount > 0)
       
   480 	{
       
   481 		EAP_TRACE_DEBUG(
       
   482 			iTools,
       
   483 			TRACE_FLAGS_DEFAULT,
       
   484 			(EAPL("CEapServer::AddReadyHandler(): this=0x%08x: iReadyHandlers[0]=0x%08x\n"),
       
   485 			this,
       
   486 			iReadyHandlers[0]));
       
   487 	}
       
   488 
       
   489 	TInt error = iReadyHandlers.Append(handler);
       
   490 	if (error != KErrNone)
       
   491 	{
       
   492 		EAP_TRACE_DEBUG(
       
   493 			iTools,
       
   494 			TRACE_FLAGS_DEFAULT,
       
   495 			(EAPL("ERROR: CEapServer::AddReadyHandler(): Cannot append handler, error = %d\n"),
       
   496 			error));
       
   497 	}
       
   498 
       
   499 	if (aCount == 0
       
   500 		&& error == KErrNone)
       
   501 	{
       
   502 			EAP_TRACE_DEBUG(
       
   503 				iTools,
       
   504 				TRACE_FLAGS_DEFAULT,
       
   505 				(EAPL("CEapServer::AddReadyHandler(): this=0x%08x: Activates handler=0x%08x\n"),
       
   506 				this,
       
   507 				handler));
       
   508 
       
   509 		// Acticate the first handler.
       
   510 		handler->Activate(EapServerProcessHandlerState_All);
       
   511 	}
       
   512 
       
   513 	return error;
       
   514 }
       
   515 
       
   516 // -----------------------------------------------------------------------------------------
       
   517 
       
   518 TInt CEapServer::CompleteReadyHandler(CEapServerProcessHandler * const handler)
       
   519 {
       
   520 	EAP_TRACE_DEBUG(
       
   521 		iTools,
       
   522 		TRACE_FLAGS_DEFAULT,
       
   523 		(EAPL("CEapServer::CompleteReadyHandler(): this=0x%08x: handler=0x%08x\n"),
       
   524 		this,
       
   525 		handler));
       
   526 	EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::CompleteReadyHandler()");
       
   527 
       
   528 	TInt aCount = iReadyHandlers.Count();
       
   529 
       
   530 	TInt error(KErrNone);
       
   531 
       
   532 	if (aCount == 0)
       
   533 	{
       
   534 		EAP_TRACE_DEBUG(
       
   535 			iTools,
       
   536 			TRACE_FLAGS_DEFAULT,
       
   537 			(EAPL("CEapServer::CompleteReadyHandler(): this=0x%08x, no handlers ready.\n"),
       
   538 			this,
       
   539 			handler));
       
   540 	}
       
   541 	else if (iReadyHandlers[0] != handler)
       
   542 	{
       
   543 		EAP_TRACE_DEBUG(
       
   544 			iTools,
       
   545 			TRACE_FLAGS_DEFAULT,
       
   546 			(EAPL("ERROR: CEapServer::CompleteReadyHandler(): this=0x%08x, handler=0x%08x is not the first one 0x%08x\n"),
       
   547 			this,
       
   548 			handler,
       
   549 			iReadyHandlers[0]));
       
   550 
       
   551 		error = KErrGeneral;
       
   552 	}
       
   553 	else
       
   554 	{
       
   555 		iReadyHandlers.Remove(0);
       
   556 
       
   557 		aCount = iReadyHandlers.Count();
       
   558 
       
   559 		if (aCount > 0)
       
   560 		{
       
   561 			EAP_TRACE_DEBUG(
       
   562 				iTools,
       
   563 				TRACE_FLAGS_DEFAULT,
       
   564 				(EAPL("CEapServer::CompleteReadyHandler(): this=0x%08x, Activates handler=0x%08x\n"),
       
   565 				this,
       
   566 				iReadyHandlers[0]));
       
   567 
       
   568 			// Activate the next handler.
       
   569 			iReadyHandlers[0]->Activate(EapServerProcessHandlerState_All);
       
   570 		}
       
   571 	}
       
   572 
       
   573 	return error;
       
   574 }
       
   575 
       
   576 // -----------------------------------------------------------------------------------------
       
   577 
       
   578 TInt CEapServer::CancelReadyHandler(CEapServerProcessHandler * const handler)
       
   579 {
       
   580 	EAP_TRACE_DEBUG(
       
   581 		iTools,
       
   582 		TRACE_FLAGS_DEFAULT,
       
   583 		(EAPL("CEapServer::CancelReadyHandler(): this=0x%08x: handler=0x%08x\n"),
       
   584 		this,
       
   585 		handler));
       
   586 	EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::CancelReadyHandler()");
       
   587 
       
   588 	TInt index(0);
       
   589 	TInt aCount = iReadyHandlers.Count();
       
   590 
       
   591 	while (index < aCount)
       
   592 	{
       
   593 		if (iReadyHandlers[index] != handler)
       
   594 		{
       
   595 			EAP_TRACE_DEBUG(
       
   596 				iTools,
       
   597 				TRACE_FLAGS_DEFAULT,
       
   598 				(EAPL("CEapServer::CancelReadyHandler(): Removes iReadyHandlers[%d]=0x%08x\n"),
       
   599 				index,
       
   600 				iReadyHandlers[index]));
       
   601 
       
   602 			iReadyHandlers.Remove(index);
       
   603 
       
   604 			aCount = iReadyHandlers.Count();
       
   605 		}
       
   606 		else
       
   607 		{
       
   608 			++index;
       
   609 		}
       
   610 	} // while()
       
   611 
       
   612 	return KErrNone;
       
   613 }
       
   614 
       
   615 //----------------------------------------------------------------------------
       
   616 //----------------------------------------------------------------------------
   433 //----------------------------------------------------------------------------
   617 //----------------------------------------------------------------------------
   434 
   618 
   435 /*
   619 /*
   436     class CEapDelayedShutdown
   620     class CEapDelayedShutdown
   437 */
   621 */