eapol/eapol_framework/eapol_symbian/eap_server/src/EapPluginIf.cpp
branchRCL_3
changeset 19 c74b3d9f6b9e
parent 18 bad0cc58d154
equal deleted inserted replaced
18:bad0cc58d154 19: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:  EAP-plugin interface.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 17 %
       
    20 */
       
    21 
       
    22 #include "eap_am_tools.h"
       
    23 #include "eap_am_export.h"
       
    24 #include "EapPluginIf.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 #include "eap_am_plugin.h"
       
    30 #include "eap_am_plugin_symbian.h"
       
    31 #include "eap_plugin_server_message_if.h"
       
    32 
       
    33 /** @file */
       
    34 
       
    35 //--------------------------------------------------
       
    36 
       
    37 CEapPluginIf::CEapPluginIf(
       
    38     abs_eap_am_tools_c * const tools,
       
    39     eap_am_message_if_c * const server)
       
    40     : m_am_tools(tools)
       
    41     , m_client_if(0)
       
    42     , m_server_if(server)
       
    43     , m_use_asyncronous_test(false)
       
    44 		, m_is_valid(false)
       
    45 {
       
    46 	EAP_TRACE_DEBUG(
       
    47 		m_am_tools,
       
    48 		TRACE_FLAGS_DEFAULT, 
       
    49 		(EAPL("CEapPluginIf::CEapPluginIf()\n")));
       
    50 
       
    51 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: CEapPluginIf::CEapPluginIf()");
       
    52 
       
    53 	if (m_am_tools == 0 || m_am_tools->get_is_valid() == false)
       
    54 	{
       
    55 		return;
       
    56 	}
       
    57 
       
    58 	if (m_server_if == 0 || m_server_if->get_is_valid() == false)
       
    59 	{
       
    60 		return;
       
    61 	}
       
    62 
       
    63 	m_is_valid = true;
       
    64 
       
    65 
       
    66 }
       
    67 
       
    68 //--------------------------------------------------
       
    69 
       
    70 CEapPluginIf::~CEapPluginIf()
       
    71 {
       
    72 	EAP_TRACE_DEBUG(
       
    73 		m_am_tools,
       
    74 		TRACE_FLAGS_DEFAULT, 
       
    75 		(EAPL("CEapPluginIf::~CEapPluginIf()\n")));
       
    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 
       
    85 //--------------------------------------------------
       
    86 
       
    87 bool CEapPluginIf::get_is_valid()
       
    88 {
       
    89     return m_is_valid;
       
    90 }
       
    91 
       
    92 //--------------------------------------------------
       
    93 
       
    94 eap_status_e CEapPluginIf::configure(
       
    95 	const eap_variable_data_c * const client_configuration)
       
    96 {
       
    97 	EAP_TRACE_DEBUG(
       
    98 		m_am_tools,
       
    99 		TRACE_FLAGS_DEFAULT, 
       
   100 		(EAPL("CEapPluginIf::configure()\n")));
       
   101 
       
   102 	return m_server_if->configure(client_configuration);
       
   103 }
       
   104 
       
   105 //--------------------------------------------------
       
   106 
       
   107 void CEapPluginIf::set_partner(AbsEapSendInterface * const client)
       
   108 {
       
   109     m_client_if = client;
       
   110 }
       
   111 
       
   112 // ----------------------------------------------------------------
       
   113 
       
   114 eap_status_e CEapPluginIf::send_data(const void * const data, const u32_t length)
       
   115 {
       
   116 	EAP_TRACE_DEBUG(
       
   117 		m_am_tools,
       
   118 		TRACE_FLAGS_DEFAULT, 
       
   119 		(EAPL("CEapPluginIf::send_data()\n")));
       
   120 
       
   121 	return EAP_STATUS_RETURN(m_am_tools, m_client_if->SendData(data, length, EEapPluginSendData));
       
   122 }
       
   123 
       
   124 // ----------------------------------------------------------------
       
   125 
       
   126 eap_status_e CEapPluginIf::process_data(const void * const data, const u32_t length)
       
   127 {
       
   128 	EAP_TRACE_DEBUG(
       
   129 		m_am_tools,
       
   130 		TRACE_FLAGS_DEFAULT, 
       
   131 		(EAPL("CEapPluginIf::process_data()\n")));
       
   132 
       
   133 	return EAP_STATUS_RETURN(m_am_tools, m_server_if->process_data(data, length));
       
   134 }
       
   135 
       
   136 //--------------------------------------------------
       
   137 
       
   138 //
       
   139 eap_status_e CEapPluginIf::shutdown()
       
   140 {
       
   141     EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   142 
       
   143     EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   144 
       
   145     EAP_TRACE_DEBUG(
       
   146         m_am_tools, 
       
   147         EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
   148         (EAPL("CEapPluginIf::shutdown(): this = 0x%08x.\n"),
       
   149         this));
       
   150 
       
   151     eap_status_e status(eap_status_ok);
       
   152 
       
   153     if (m_server_if != 0)
       
   154     {
       
   155         status = m_server_if->shutdown();
       
   156     }
       
   157 
       
   158     EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   159     return EAP_STATUS_RETURN(m_am_tools, status);
       
   160 }
       
   161 
       
   162 //--------------------------------------------------
       
   163 
       
   164 eap_am_plugin_c * new_eap_am_plugin_c(
       
   165 	abs_eap_am_tools_c * const tools,
       
   166 	abs_eap_am_plugin_c * const partner)
       
   167 {
       
   168 	eap_am_plugin_c * const plugin = new eap_am_plugin_symbian_c(tools, partner);
       
   169 
       
   170 	eap_automatic_variable_c<eap_am_plugin_c> automatic_plugin(
       
   171 		tools,
       
   172 		plugin);
       
   173 
       
   174 	if (plugin == 0
       
   175 	|| plugin->get_is_valid() == false)
       
   176 	{
       
   177 		// ERROR.
       
   178 		if (plugin != 0)
       
   179 		{
       
   180 			EAP_TRACE_DEBUG(
       
   181 			tools,
       
   182 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   183 			(EAPL("calls: new_eap_am_plugin_c(): plugin->shutdown()\n")));
       
   184 
       
   185 			plugin->shutdown();
       
   186 		}
       
   187 		return 0;
       
   188 	}
       
   189 
       
   190 	eap_status_e status = plugin->configure();
       
   191 	if (status != eap_status_ok)
       
   192 	{
       
   193 		plugin->shutdown();
       
   194 		return 0;
       
   195 	}
       
   196 
       
   197 	automatic_plugin.do_not_free_variable();
       
   198 
       
   199 	return plugin;
       
   200 }
       
   201 
       
   202 //--------------------------------------------------
       
   203 
       
   204 eap_am_message_if_c * eap_am_message_if_c::new_eap_plugin_server_message_if_c(
       
   205 	abs_eap_am_tools_c * const tools)
       
   206 {
       
   207 	EAP_TRACE_DEBUG(
       
   208 		tools,
       
   209 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   210 		(EAPL("eap_am_message_if_c::new_eap_plugin_server_message_if_c()\n")));
       
   211 
       
   212 	EAP_TRACE_RETURN_STRING(tools, "returns: eap_am_message_if_c::new_eap_plugin_server_message_if_c()");
       
   213 
       
   214 	eap_am_message_if_c * const server = new eap_plugin_server_message_if_c(
       
   215 		tools);
       
   216 
       
   217 	eap_automatic_variable_c<eap_am_message_if_c> automatic_server(
       
   218 		tools,
       
   219 		server);
       
   220 
       
   221 	if (server == 0
       
   222 	|| server->get_is_valid() == false)
       
   223 	{
       
   224 		// ERROR.
       
   225 		if (server != 0)
       
   226 		{
       
   227 			EAP_TRACE_DEBUG(
       
   228 			tools,
       
   229 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   230 			(EAPL("calls: CEapPluginIf::new_CEapPluginIf(): server->shutdown()\n")));
       
   231 
       
   232 			server->shutdown();
       
   233 		}
       
   234 		return 0;
       
   235 	}
       
   236 
       
   237 	eap_status_e status = server->configure(0);
       
   238 	if (status != eap_status_ok)
       
   239 	{
       
   240 		server->shutdown();
       
   241 		return 0;
       
   242 	}
       
   243 
       
   244 	automatic_server.do_not_free_variable();
       
   245 
       
   246 	return server;
       
   247 }
       
   248 
       
   249 //--------------------------------------------------
       
   250 
       
   251 CEapPluginIf* CEapPluginIf::new_CEapPluginIf(
       
   252     abs_eap_am_tools_c * const tools)
       
   253 {
       
   254 	EAP_TRACE_DEBUG(
       
   255 		tools,
       
   256 		TRACE_FLAGS_DEFAULT, 
       
   257 		(EAPL("CEapPluginIf::new_CEapPluginIf()\n")));
       
   258 
       
   259 	EAP_TRACE_RETURN_STRING(tools, "returns: CEapPluginIf::new_CEapPluginIf()");
       
   260 
       
   261 	eap_am_message_if_c * const server = eap_am_message_if_c::new_eap_plugin_server_message_if_c(
       
   262 		tools);
       
   263 
       
   264 	eap_automatic_variable_c<eap_am_message_if_c> automatic_server(
       
   265 		tools,
       
   266 		server);
       
   267 
       
   268 	if (server == 0
       
   269 	|| server->get_is_valid() == false)
       
   270 	{
       
   271 		// ERROR.
       
   272 		if (server != 0)
       
   273 		{
       
   274 			EAP_TRACE_DEBUG(
       
   275 				tools,
       
   276 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   277 				(EAPL("calls: CEapPluginIf::new_CEapPluginIf(): server->shutdown()\n")));
       
   278 
       
   279 			server->shutdown();
       
   280 		}
       
   281 
       
   282 		return 0;
       
   283 	}
       
   284 
       
   285 	CEapPluginIf * const plugin_if = new CEapPluginIf(
       
   286 		tools,
       
   287 		server);
       
   288 
       
   289 	eap_automatic_variable_c<CEapPluginIf> automatic_plugin_if(
       
   290 		tools,
       
   291 		plugin_if);
       
   292 
       
   293 	if (plugin_if == 0
       
   294 	|| plugin_if->get_is_valid() == false)
       
   295 	{
       
   296 		// ERROR.
       
   297 		if (plugin_if != 0)
       
   298 		{
       
   299 			EAP_TRACE_DEBUG(
       
   300 			tools,
       
   301 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   302 			(EAPL("calls: CEapPluginIf::new_CEapPluginIf(): plugin_if->shutdown()\n")));
       
   303 
       
   304 			// automatic_plugin_if will delete plugin_if and plugin_if will delete server too.
       
   305 			automatic_server.do_not_free_variable();
       
   306 			plugin_if->shutdown();
       
   307 		}
       
   308 
       
   309 		return 0;
       
   310 	}
       
   311 
       
   312 	server->set_partner(plugin_if);
       
   313 
       
   314 	automatic_server.do_not_free_variable();
       
   315 	automatic_plugin_if.do_not_free_variable();
       
   316 
       
   317 	return plugin_if;
       
   318 }
       
   319 
       
   320 //--------------------------------------------------
       
   321 // End