eapol/eapol_framework/eapol_symbian/eap_server/src/PacStoreIf.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
child 55 9c2aa05919d9
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
     1 /*
       
     2 * Copyright (c) 2001-2010 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 the License "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:  PAC-store interface inside the EAP-server.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 11 %
       
    20 */
       
    21 
       
    22 #include "eap_am_tools.h"
       
    23 #include "eap_am_export.h"
       
    24 #include "PacStoreIf.h"
       
    25 #include "eap_automatic_variable.h"
       
    26 #include "eap_config.h"
       
    27 #include "eap_file_config.h"
       
    28 #include "abs_eap_am_mutex.h"
       
    29 
       
    30 
       
    31 /** @file */
       
    32 
       
    33 //--------------------------------------------------
       
    34 
       
    35 /**
       
    36  * This is the timer ID used with abs_eap_am_tools_c::set_timer() and abs_eap_am_tools_c::cancel_timer().
       
    37  */
       
    38 enum pac_store_message_if_timer_id
       
    39 {
       
    40     pac_store_message_IF_TIMER_PROCESS_DATA_ID,
       
    41     pac_store_message_IF_TIMER_SEND_DATA_ID,
       
    42 };
       
    43 
       
    44 //--------------------------------------------------
       
    45 
       
    46 EAP_FUNC_EXPORT CPacStoreIf::CPacStoreIf(
       
    47     abs_eap_am_tools_c * const tools,
       
    48     eap_am_message_if_c * const server,
       
    49     AbsEapSendInterface * client)
       
    50     : m_am_tools(tools)
       
    51     , m_client_if(client)
       
    52     , m_server_if(server)
       
    53     , m_fileconfig(0)
       
    54     , m_use_asyncronous_test(false)
       
    55     , iIsValid(false)
       
    56 {
       
    57 	if (m_am_tools == 0 || m_am_tools->get_is_valid() == false)
       
    58 		{
       
    59 		return;
       
    60 		}
       
    61 	if (m_client_if == 0)
       
    62 		{
       
    63 		return;
       
    64 		}
       
    65 	if (m_server_if == 0 || m_server_if->get_is_valid() == false)
       
    66 		{
       
    67 		return;
       
    68 		}
       
    69 		 
       
    70 	iIsValid = true;
       
    71 }
       
    72 
       
    73 //--------------------------------------------------
       
    74 
       
    75 EAP_FUNC_EXPORT CPacStoreIf::~CPacStoreIf()
       
    76 {
       
    77 	if (m_server_if != 0)
       
    78 	{
       
    79 		m_server_if->shutdown();
       
    80 	}
       
    81     delete m_server_if;
       
    82     m_server_if = 0;
       
    83 
       
    84     delete m_fileconfig;
       
    85     m_fileconfig = 0;
       
    86 }
       
    87 
       
    88 //--------------------------------------------------
       
    89 
       
    90 EAP_FUNC_EXPORT bool CPacStoreIf::get_is_valid()
       
    91 {
       
    92     return iIsValid;
       
    93 }
       
    94 
       
    95 //--------------------------------------------------
       
    96 
       
    97 EAP_FUNC_EXPORT eap_status_e CPacStoreIf::configure(
       
    98 	const eap_variable_data_c * const client_configuration)
       
    99 {
       
   100 	return m_server_if->configure(client_configuration);
       
   101 }
       
   102 
       
   103 // ----------------------------------------------------------------
       
   104 
       
   105 EAP_FUNC_EXPORT eap_status_e CPacStoreIf::send_data(const void * const data, const u32_t length)
       
   106     {
       
   107     return m_client_if->SendData(data, length, EEapPacStoreSendData);
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------------
       
   111 
       
   112 EAP_FUNC_EXPORT eap_status_e CPacStoreIf::process_data(const void * const data, const u32_t length)
       
   113     {
       
   114     return m_server_if->process_data(data, length);
       
   115     }
       
   116 
       
   117 //--------------------------------------------------
       
   118 
       
   119 //
       
   120 EAP_FUNC_EXPORT eap_status_e CPacStoreIf::shutdown()
       
   121 {
       
   122     EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   123 
       
   124     EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   125 
       
   126     EAP_TRACE_DEBUG(
       
   127         m_am_tools, 
       
   128         EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
   129         (EAPL("CPacStoreIf::shutdown(): this = 0x%08x.\n"),
       
   130         this));
       
   131 
       
   132     eap_status_e status(eap_status_ok);
       
   133 
       
   134     if (m_server_if != 0)
       
   135     {
       
   136         status = m_server_if->shutdown();
       
   137     }
       
   138 
       
   139     EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   140     return EAP_STATUS_RETURN(m_am_tools, status);
       
   141 }
       
   142 
       
   143 //--------------------------------------------------
       
   144 //--------------------------------------------------
       
   145 
       
   146 EAP_FUNC_EXPORT eap_pac_store_server_message_if_c * eap_pac_store_server_message_if_c::new_eap_pac_store_server_message_if_c(
       
   147     abs_eap_am_tools_c * const tools)
       
   148 {
       
   149     EAP_TRACE_DEBUG(
       
   150         tools,
       
   151         TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   152         (EAPL("eap_pac_store_server_message_if_c::new_eap_pac_store_server_message_if_c()\n")));
       
   153 
       
   154     EAP_TRACE_RETURN_STRING(tools, "returns: eap_pac_store_server_message_if_c::new_eap_pac_store_server_message_if_c()");
       
   155 
       
   156     eap_pac_store_server_message_if_c * const server = new eap_pac_store_server_message_if_c(
       
   157         tools);
       
   158 
       
   159     eap_automatic_variable_c<eap_am_message_if_c> automatic_server(
       
   160         tools,
       
   161         server);
       
   162 
       
   163     if (server == 0
       
   164     || server->get_is_valid() == false)
       
   165     {
       
   166         // ERROR.
       
   167         if (server != 0)
       
   168         {
       
   169             EAP_TRACE_DEBUG(
       
   170             tools,
       
   171             TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   172             (EAPL("calls: CPacStoreIf::CPacStoreIf(): server->shutdown()\n")));
       
   173 
       
   174             (void) server->shutdown();
       
   175         }
       
   176         return 0;
       
   177     }
       
   178 
       
   179     eap_status_e status = server->configure(0);
       
   180     if (status != eap_status_ok)
       
   181     {
       
   182         (void) server->shutdown();
       
   183         return 0;
       
   184     }
       
   185 
       
   186     automatic_server.do_not_free_variable();
       
   187 
       
   188     return server;
       
   189 }
       
   190 
       
   191 //--------------------------------------------------
       
   192 
       
   193 EAP_FUNC_EXPORT CPacStoreIf* CPacStoreIf::new_CPacStoreIf(
       
   194     abs_eap_am_tools_c * const tools,
       
   195     const bool is_client_when_true,
       
   196     const u32_t MTU,
       
   197     AbsEapSendInterface * client)
       
   198     {
       
   199     EAP_UNREFERENCED_PARAMETER(is_client_when_true);
       
   200     EAP_UNREFERENCED_PARAMETER(MTU);
       
   201     eap_pac_store_server_message_if_c *server =  eap_pac_store_server_message_if_c::new_eap_pac_store_server_message_if_c(
       
   202         tools);
       
   203     
       
   204     eap_automatic_variable_c<eap_am_message_if_c> automatic_server(
       
   205         tools,
       
   206         server);
       
   207 
       
   208     if (server == 0
       
   209         || server->get_is_valid() == false)
       
   210         {
       
   211         // ERROR.
       
   212         if (server != 0)
       
   213             {
       
   214             EAP_TRACE_DEBUG(
       
   215                 tools,
       
   216                 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   217                 (EAPL("calls: CPacStoreIf(): server->shutdown(): %s.\n"),
       
   218                 (is_client_when_true == true) ? "client": "server"));
       
   219 
       
   220             (void) server->shutdown();
       
   221             }
       
   222         return 0;
       
   223         }
       
   224 
       
   225     CPacStoreIf * pacstore_if = new CPacStoreIf(
       
   226         tools,
       
   227         server,
       
   228         client);
       
   229 
       
   230     eap_automatic_variable_c<CPacStoreIf> automatic_pacstore_if(
       
   231         tools,
       
   232         pacstore_if);
       
   233 
       
   234     if (pacstore_if == 0
       
   235         || pacstore_if->get_is_valid() == false)
       
   236         {
       
   237         // ERROR.
       
   238         if (pacstore_if != 0)
       
   239             {
       
   240             EAP_TRACE_DEBUG(
       
   241                 tools,
       
   242                 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   243                 (EAPL("calls: CPacStoreIf(): pacstore_if->shutdown(): %s.\n"),
       
   244                 (is_client_when_true == true) ? "client": "server"));
       
   245 
       
   246 			// automatic_pacstore_if will delete pacstore_if and pacstore_if will delete server too.
       
   247 			automatic_server.do_not_free_variable();
       
   248 
       
   249             (void) pacstore_if->shutdown();
       
   250             }
       
   251         return 0;
       
   252         }
       
   253 
       
   254     server->set_partner(pacstore_if);
       
   255 
       
   256     automatic_server.do_not_free_variable();
       
   257     automatic_pacstore_if.do_not_free_variable();
       
   258     
       
   259     return pacstore_if;
       
   260     }
       
   261 
       
   262 //--------------------------------------------------
       
   263 // End