eapol/eapol_framework/eapol_symbian/am/common/symbian/eap_am_semaphore_symbian.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-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 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 and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 146 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 
       
    29 // INCLUDES
       
    30 #include "eap_am_memory.h"
       
    31 #include "eap_am_trace_symbian.h"
       
    32 
       
    33 #include "eap_am_semaphore_symbian.h"
       
    34 
       
    35 //--------------------------------------------------
       
    36 
       
    37 //
       
    38 EAP_FUNC_EXPORT eap_am_semaphore_symbian_c::~eap_am_semaphore_symbian_c()
       
    39 {
       
    40 	m_semaphore.Close();
       
    41 	m_owner_thread.Close();
       
    42 }
       
    43 
       
    44 //--------------------------------------------------
       
    45 
       
    46 EAP_FUNC_EXPORT eap_am_semaphore_symbian_c::eap_am_semaphore_symbian_c(
       
    47 	const i32_t initial_count,
       
    48 	const i32_t maximum_count)
       
    49 	: m_count(initial_count)
       
    50 	, m_is_valid(false)
       
    51 {
       
    52 	if (eap_am_semaphore_base_c::get_is_valid() == false)
       
    53 	{
       
    54 		return;
       
    55 	}
       
    56 
       
    57 	TInt err = m_semaphore.CreateLocal(initial_count);
       
    58 	if (err != KErrNone)
       
    59 	{
       
    60 		EAP_TRACE_DEBUG_SYMBIAN((_L("\n ERROR: eap_am_semaphore_symbian_c::eap_am_semaphore_symbian_c : Semaphore CreateLocal returned err = %d"), err));
       
    61 		return;
       
    62 	}
       
    63 	
       
    64 	RThread thisThread; // Generic handle meaning "the current thread"
       
    65 
       
    66 	err = thisThread.Duplicate(thisThread);    // a specific handle
       
    67 	if (err != KErrNone)
       
    68 	{
       
    69 		EAP_TRACE_DEBUG_SYMBIAN((_L("\n ERROR: eap_am_semaphore_symbian_c::eap_am_semaphore_symbian_c : Thread Duplicate returned err = %d"), err));
       
    70 		return;
       
    71 	}
       
    72 
       
    73 	m_owner_thread = thisThread;
       
    74 	
       
    75 	m_is_valid = true;	
       
    76 }
       
    77 
       
    78 EAP_FUNC_EXPORT eap_am_semaphore_symbian_c::eap_am_semaphore_symbian_c(
       
    79 	const eap_am_semaphore_symbian_c * const owner)
       
    80 	: eap_am_semaphore_base_c(owner)
       
    81 	, m_count(0ul)
       
    82 	, m_is_valid(false)
       
    83 {
       
    84 	if (eap_am_semaphore_base_c::get_is_valid() == false)
       
    85 	{
       
    86 		return;
       
    87 	}
       
    88 	
       
    89 	m_semaphore = *(owner->get_semaphore());
       
    90 
       
    91 	TInt err = m_semaphore.Duplicate(*(owner->get_owner_thread()));
       
    92 	if (err != KErrNone)
       
    93 	{
       
    94 		EAP_TRACE_DEBUG_SYMBIAN((_L("\n ERROR: eap_am_semaphore_symbian_c::eap_am_semaphore_symbian_c(): Semaphore Duplicate returned err = %d"), err));
       
    95 		return;
       
    96 	}
       
    97 
       
    98 	RThread thisThread; // Generic handle meaning "the current thread"  
       
    99 
       
   100 	err = thisThread.Duplicate(thisThread);    // a specific handle 
       
   101 	if (err != KErrNone)
       
   102 	{
       
   103 		EAP_TRACE_DEBUG_SYMBIAN((_L("\n ERROR: eap_am_semaphore_symbian_c::eap_am_semaphore_symbian_c(): Thread Duplicate returned err = %d"), err));
       
   104 		return;
       
   105 	}
       
   106 
       
   107 	m_owner_thread = thisThread;
       
   108 	
       
   109 	m_is_valid = true;		
       
   110 }
       
   111 
       
   112 //--------------------------------------------------
       
   113 
       
   114 //
       
   115 EAP_FUNC_EXPORT const RSemaphore * eap_am_semaphore_symbian_c::get_semaphore() const
       
   116 {
       
   117 	return &m_semaphore;
       
   118 }
       
   119 
       
   120 //--------------------------------------------------
       
   121 
       
   122 //
       
   123 EAP_FUNC_EXPORT const RThread * eap_am_semaphore_symbian_c::get_owner_thread() const
       
   124 {
       
   125 	return &m_owner_thread;
       
   126 }
       
   127 
       
   128 //--------------------------------------------------
       
   129 
       
   130 
       
   131 
       
   132 EAP_FUNC_EXPORT eap_status_e eap_am_semaphore_symbian_c::semaphore_reserve()
       
   133 {
       
   134 	m_semaphore.Wait();
       
   135 	m_count--;
       
   136 	
       
   137 	return eap_status_ok;
       
   138 }
       
   139 
       
   140 EAP_FUNC_EXPORT eap_status_e eap_am_semaphore_symbian_c::semaphore_release()
       
   141 {
       
   142 	m_count++;
       
   143 	m_semaphore.Signal();
       
   144 	
       
   145 	return eap_status_ok;	
       
   146 }
       
   147 
       
   148 EAP_FUNC_EXPORT  abs_eap_am_semaphore_c * eap_am_semaphore_symbian_c::dublicate_semaphore()
       
   149 {
       
   150 	eap_am_semaphore_symbian_c *dublicate = new eap_am_semaphore_symbian_c(this);
       
   151 	return dublicate;	
       
   152 }
       
   153 
       
   154 EAP_FUNC_EXPORT u32_t eap_am_semaphore_symbian_c::get_count() const
       
   155 {
       
   156 	return 	m_count;
       
   157 }
       
   158 
       
   159 EAP_FUNC_EXPORT bool eap_am_semaphore_symbian_c::get_is_valid() const
       
   160 {
       
   161 	return m_is_valid;
       
   162 }
       
   163 
       
   164 //--------------------------------------------------
       
   165 //--------------------------------------------------
       
   166 //--------------------------------------------------
       
   167 
       
   168 
       
   169 
       
   170 
       
   171 // End of file