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