bluetooth/btstack/eirman/eirmansession.cpp
changeset 32 f72906e669b4
parent 0 29b1cd4cb562
equal deleted inserted replaced
31:b9d1744dc449 32:f72906e669b4
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    30 
    30 
    31 #ifdef __FLOG_ACTIVE
    31 #ifdef __FLOG_ACTIVE
    32 _LIT8(KLogComponent, LOG_COMPONENT_EIRMANAGER);
    32 _LIT8(KLogComponent, LOG_COMPONENT_EIRMANAGER);
    33 #endif
    33 #endif
    34 
    34 
    35 CEirManSession* CEirManSession::NewL(CEirManServer& aServer)
    35 CEirManSession* CEirManSession::NewL(CEirManServer& aServer, MEirSessionNotifier& aParent, TBool aInternalSession)
    36 	{
    36 	{
    37 	LOG_STATIC_FUNC
    37 	LOG_STATIC_FUNC
    38 	CEirManSession* self = new(ELeave) CEirManSession(aServer);
    38 	CEirManSession* self = new(ELeave) CEirManSession(aServer, aParent, aInternalSession);
    39 	CleanupStack::PushL(self);
    39 	CleanupStack::PushL(self);
    40 	self->ConstructL();
    40 	self->ConstructL();
    41 	CleanupStack::Pop(self);
    41 	CleanupStack::Pop(self);
    42 	return self;
    42 	return self;
    43 	}
    43 	}
    44 
    44 
    45 CEirManSession::CEirManSession(CEirManServer& aServer)
    45 CEirManSession::CEirManSession(CEirManServer& aServer, MEirSessionNotifier& aParent, TBool aInternalSession)
    46 	: iEirManServer(aServer)
    46 	: iEirManServer(aServer)
       
    47 	, iParent(aParent)
    47 	, iEirTag(EEirTagRESERVED)
    48 	, iEirTag(EEirTagRESERVED)
       
    49 	, iInternalSession(aInternalSession)
    48 	{
    50 	{
    49 	LOG_FUNC
    51 	LOG_FUNC
    50 	}
    52 	}
    51 
    53 
    52 void CEirManSession::ConstructL()
    54 void CEirManSession::ConstructL()
    53 	{
    55 	{
    54 	LOG_FUNC
    56 	LOG_FUNC
    55 	iEirManServer.AddSession();
    57 	iEirManServer.AddSession(*this, iInternalSession);
    56 	}
    58 	}
    57 
    59 
    58 CEirManSession::~CEirManSession()
    60 CEirManSession::~CEirManSession()
    59 	{
    61 	{
    60 	LOG_FUNC
    62 	LOG_FUNC
    61 	// deregister any registered tag that may be registered
    63 	// deregister any registered tag that may be registered
    62 	DeregisterTag();
    64 	DeregisterTag();
    63 	if(!iDataAvailableListenerMessage.IsNull())
    65 	iLink.Deque();
    64 		{
    66 	iEirManServer.DropSession(iInternalSession);
    65 		// complete any outstanding messages.
    67 	}
    66 		iDataAvailableListenerMessage.Complete(KErrCancel);
    68 
    67 		}
    69 void CEirManSession::RegisterTag(TEirTag aTag)
    68 	iEirManServer.DropSession();
    70 	{
    69 	}
    71 	LOG_FUNC
    70 
    72 
    71 void CEirManSession::ServiceL(const RMessage2& aMessage)
    73 	LOG1(_L("CEirManSession::RegisterTag tag = %d"), aTag);
    72 	{
    74 
    73 	LOG_FUNC
    75 	if(!(aTag >= EEirTagName && aTag < EEirTagRESERVED))
    74 	LOG1(_L("CEirManSession::ServiceL aMessage.Function() = %d"), aMessage.Function());
    76 		{
    75 	TBool complete = ETrue;
    77 		iParent.MesnRegisterComplete(KErrArgument);
    76 	TInt ret = KErrNone;
       
    77 
       
    78 	switch (aMessage.Function())
       
    79 		{
       
    80 	case EEirManRegisterTag:
       
    81 		complete = EFalse; // always async.
       
    82 		RegisterTag(aMessage);
       
    83 		break;
       
    84 
       
    85 	case EEirManSpaceAvailableNotification:
       
    86 		ret = RegisterSpaceAvailableListener(aMessage, complete);
       
    87 		break;
       
    88 
       
    89 	case EEirManCancelSpaceAvailableNotification:
       
    90 		ret = CancelSpaceAvailableListener();
       
    91 		break;
       
    92 
       
    93 	case EEirManSetData:
       
    94 		ret = SetData(aMessage);
       
    95 		break;
       
    96 		
       
    97 	case EEirManNewData:
       
    98 		ret = NewData(aMessage);
       
    99 		break;
       
   100 
       
   101 	default:
       
   102 		aMessage.Panic(KEirManCliPncCat, EEirManPanicInvalidIPC);
       
   103 		break;
       
   104 		}
       
   105 
       
   106 	if (complete)
       
   107 		{
       
   108 		aMessage.Complete(ret);
       
   109 		}
       
   110 	}
       
   111 
       
   112 void CEirManSession::RegisterTag(const RMessage2& aMessage)
       
   113 	{
       
   114 	LOG_FUNC
       
   115 
       
   116 	TEirTag tag = static_cast<TEirTag>(aMessage.Int0());
       
   117 	LOG1(_L("CEirManSession::RegisterTag tag = %d"), tag);
       
   118 
       
   119 	if(!(tag >= EEirTagName && tag < EEirTagRESERVED))
       
   120 		{
       
   121 		__ASSERT_ALWAYS(EFalse, aMessage.Panic(KEirManCliPncCat, EEirManPanicInvalidTag));
       
   122 		}
    78 		}
   123 	else if(iEirTag != EEirTagRESERVED)
    79 	else if(iEirTag != EEirTagRESERVED)
   124 		{
    80 		{
   125 		LOG1(_L("CEirManSession::RegisterTag ERROR, Tag in use: %d"), iEirTag);
    81 		LOG1(_L("CEirManSession::RegisterTag ERROR, Tag in use: %d"), iEirTag);
   126 		aMessage.Complete(KErrInUse);
    82 		iParent.MesnRegisterComplete(KErrInUse);
   127 		}
    83 		}
   128 	else
    84 	else
   129 		{
    85 		{
   130 		// Register this tag for callbacks
    86 		// Register this tag for callbacks
   131 		if(iEirManServer.EirFeatureState() == EEirFeatureReady)
    87 		if(iEirManServer.EirFeatureState() == EEirFeatureReady)
   132 			{
    88 			{
   133 			// Eir is supported
    89 			// Eir is supported
   134 			TInt result = iEirManServer.EirManager().RegisterTag(tag, *this);
    90 			TInt result = iEirManServer.EirManager().RegisterTag(aTag, *this);
   135 			if(result == KErrNone)
    91 			if(result == KErrNone)
   136 				{
    92 				{
   137 				iEirTag = tag;
    93 				iEirTag = aTag;
   138 				}
    94 				}
   139 			aMessage.Complete(result);
    95 			iParent.MesnRegisterComplete(result);
   140 			}
    96 			}
   141 		else if(iEirManServer.EirFeatureState() == EEirFeaturePending)
    97 		else if(iEirManServer.EirFeatureState() == EEirFeaturePending)
   142 			{
    98 			{
   143 			// We don't know if eir is supported or not at this moment
    99 			// We don't know if eir is supported or not at this moment
   144 			iPendingEirTag = tag;
   100 			iRegisterPending = ETrue;
   145 			iRegisterMessage = aMessage;
   101 			iPendingEirTag = aTag;
   146 			}
   102 			}
   147 		else
   103 		else
   148 			{
   104 			{
   149 			// Eir is not supported
   105 			// Eir is not supported
   150 			aMessage.Complete(KErrNotSupported);
   106 			iParent.MesnRegisterComplete(KErrNotSupported);
   151 			}
   107 			}
   152 		}
   108 		}
   153 	}
   109 	}
   154 
   110 
   155 void CEirManSession::DeregisterTag()
   111 void CEirManSession::DeregisterTag()
   167 
   123 
   168 // Eir Server has tried to register tag
   124 // Eir Server has tried to register tag
   169 void CEirManSession::NotifyEirFeatureState(TInt aResult)
   125 void CEirManSession::NotifyEirFeatureState(TInt aResult)
   170 	{
   126 	{
   171 	LOG1(_L("Eir Server has been notified feature ready, result: %d"), aResult);
   127 	LOG1(_L("Eir Server has been notified feature ready, result: %d"), aResult);
   172 	if(aResult == KErrNone && !iRegisterMessage.IsNull())
   128 	if(aResult == KErrNone && iRegisterPending)
   173 		{
   129 		{
   174 		__ASSERT_DEBUG(iEirManServer.EirFeatureState() == EEirFeatureReady, EIR_SESSION_PANIC(EEirSessionEirFeatureNotSupported));
   130 		__ASSERT_DEBUG(iEirManServer.EirFeatureState() == EEirFeatureReady, EIR_SESSION_PANIC(EEirSessionEirFeatureNotSupported));
   175 		TInt result = iEirManServer.EirManager().RegisterTag(iPendingEirTag, *this);
   131 		TInt result = iEirManServer.EirManager().RegisterTag(iPendingEirTag, *this);
   176 		if(result == KErrNone)
   132 		if(result == KErrNone)
   177 			{
   133 			{
   178 			iEirTag = iPendingEirTag;
   134 			iEirTag = iPendingEirTag;
   179 			}
   135 			}
   180 		iRegisterMessage.Complete(result);
   136 		iRegisterPending = EFalse;
   181 		}
   137 		iParent.MesnRegisterComplete(result);
   182 	else if(!iRegisterMessage.IsNull())
   138 		}
       
   139 	else if(iRegisterPending)
       
   140 		{
       
   141 		iRegisterPending = EFalse;
       
   142 		iParent.MesnRegisterComplete(aResult);
       
   143 		}
       
   144 	}
       
   145 
       
   146 
       
   147 TInt CEirManSession::NewData(TInt aRequiredLength)
       
   148 	{
       
   149 	LOG_FUNC
       
   150 	return iEirManServer.EirManager().NewData(iEirTag, aRequiredLength);
       
   151 	}
       
   152 
       
   153 
       
   154 TInt CEirManSession::SetData(const TDesC8& aData, TEirDataMode aMode)
       
   155 	{
       
   156 	LOG_FUNC
       
   157 	return iEirManServer.EirManager().SetData(iEirTag, aData, aMode);
       
   158 	}
       
   159 
       
   160 // Callback from the EIR Manager
       
   161 void CEirManSession::MemnEirBlockAvailable(TEirTag aTag, TUint aSpaceForTag)
       
   162 	{
       
   163 	LOG_FUNC
       
   164 	LOG2(_L("CEirManSession::MemnEirBlockAvailable Tag: %d space: %d"), aTag, aSpaceForTag);
       
   165 
       
   166 	// Silently discard callbacks not containing our EIR Tag
       
   167 	if(aTag != iEirTag)
       
   168 		{
       
   169 		__ASSERT_DEBUG(EFalse, EIR_SESSION_PANIC(EEirSessionInvalidEirTag));
       
   170 		LOG3(_L("CEirManSession::MemnEirBlockAvailable early return: aTag: %d iEirTag: %d space: %d"), aTag, iEirTag, aSpaceForTag);
       
   171 		return;
       
   172 		}
       
   173 
       
   174 	iParent.MesnSpaceAvailable(aSpaceForTag);
       
   175 
       
   176 	}
       
   177 
       
   178 TEirTag CEirManSession::EirTag() const
       
   179 	{
       
   180 	return iEirTag;
       
   181 	}
       
   182 
       
   183 CEirManExternalSession* CEirManExternalSession::NewL(CEirManServer& aServer)
       
   184 	{
       
   185 	CEirManExternalSession* self = new(ELeave) CEirManExternalSession();
       
   186 	CleanupStack::PushL(self);
       
   187 	self->ConstructL(aServer);
       
   188 	CleanupStack::Pop(self);
       
   189 	return self;
       
   190 	}
       
   191 
       
   192 CEirManExternalSession::CEirManExternalSession()
       
   193 	{
       
   194 	
       
   195 	}
       
   196 
       
   197 void CEirManExternalSession::ConstructL(CEirManServer& aServer)
       
   198 	{
       
   199 	iSession = CEirManSession::NewL(aServer, *this, EFalse);
       
   200 	}
       
   201 
       
   202 CEirManExternalSession::~CEirManExternalSession()
       
   203 	{
       
   204 	if(!iDataAvailableListenerMessage.IsNull())
       
   205 		{
       
   206 		// complete any outstanding messages.
       
   207 		iDataAvailableListenerMessage.Complete(KErrCancel);
       
   208 		}
       
   209 	delete iSession;
       
   210 	}
       
   211 /*
       
   212  * Each of the individual methods is responsible for completing the message.
       
   213  * All 'leaves' are processed in CSession2::ServiceError() resulting in message completion
       
   214  * with the appropriate error code.
       
   215  * RegisterTagL() and RegisterSpaceAvailableListenerL() store aMessage parameter for the future use
       
   216  * when the callbacks are called.
       
   217  */
       
   218 void CEirManExternalSession::ServiceL(const RMessage2& aMessage)
       
   219 	{
       
   220 	LOG_FUNC
       
   221 	LOG1(_L("CEirManSession::ServiceL aMessage.Function() = %d"), aMessage.Function());
       
   222 
       
   223 	switch (aMessage.Function())
       
   224 		{
       
   225 	case EEirManRegisterTag:
       
   226 		RegisterTagL(aMessage);
       
   227 		break;
       
   228 
       
   229 	case EEirManSpaceAvailableNotification:
       
   230 		RegisterSpaceAvailableListenerL(aMessage);
       
   231 		break;
       
   232 
       
   233 	case EEirManCancelSpaceAvailableNotification:
       
   234 		CancelSpaceAvailableListenerL(aMessage);
       
   235 		break;
       
   236 
       
   237 	case EEirManSetData:
       
   238 		SetDataL(aMessage);
       
   239 		break;
       
   240 		
       
   241 	case EEirManNewData:
       
   242 		NewDataL(aMessage);
       
   243 		break;
       
   244 
       
   245 	default:
       
   246 		aMessage.Panic(KEirManCliPncCat, EEirManPanicInvalidIPC);
       
   247 		break;
       
   248 		}
       
   249 	}
       
   250 
       
   251 void CEirManExternalSession::RegisterTagL(const RMessage2& aMessage)
       
   252 	{
       
   253 	LOG_FUNC
       
   254 	TEirTag tag = static_cast<TEirTag>(aMessage.Int0());
       
   255 	LOG1(_L("CEirManSession::RegisterTag tag = %d"), tag);
       
   256 
       
   257 	iRegisterMessage = aMessage;
       
   258 	
       
   259 	iSession->RegisterTag(tag);
       
   260 	}
       
   261 
       
   262 void CEirManExternalSession::MesnRegisterComplete(TInt aResult)
       
   263 	{
       
   264 	if (aResult == KErrArgument)
       
   265 		{
       
   266 		iRegisterMessage.Panic(KEirManCliPncCat, EEirManPanicInvalidTag);
       
   267 		}
       
   268 	else
   183 		{
   269 		{
   184 		iRegisterMessage.Complete(aResult);
   270 		iRegisterMessage.Complete(aResult);
   185 		}
   271 		}
   186 	}
   272 	}
   187 
   273 
   188 TInt CEirManSession::RegisterSpaceAvailableListener(const RMessage2& aMessage, TBool& aComplete)
   274 void CEirManExternalSession::RegisterSpaceAvailableListenerL(const RMessage2& aMessage)
   189 	{
   275 	{
   190 	LOG_FUNC
   276 	LOG_FUNC
   191 
   277 
   192 	if(iDataAvailableListenerMessage.Handle())
   278 	if(iDataAvailableListenerMessage.Handle())
   193 		{
   279 		{
   194 		LOG(_L("CEirManSession:::RegisterSpaceAvailableListener ERROR IN USE"));
   280 		LOG(_L("CEirManSession:::RegisterSpaceAvailableListener ERROR IN USE"));
   195 		return KErrInUse;
   281 		LEAVEL(KErrInUse);
   196 		}
   282 		}
   197 
   283 
   198 	iDataAvailableListenerMessage = aMessage;
   284 	iDataAvailableListenerMessage = aMessage;
   199 
       
   200 	aComplete = EFalse;
       
   201 
   285 
   202 	if(iLastSpaceOffered != 0)
   286 	if(iLastSpaceOffered != 0)
   203 		{
   287 		{
   204 		LOG(_L("cached space present, completing immediately"));
   288 		LOG(_L("cached space present, completing immediately"));
   205 		CompleteSpaceAvailableRequest(iLastSpaceOffered);
   289 		CompleteSpaceAvailableRequest(iLastSpaceOffered);
   206 		iLastSpaceOffered = 0;
   290 		iLastSpaceOffered = 0;
   207 		return KErrNone;
   291 		return;
   208 		}
   292 		}
   209 	
   293 	
   210 	LOG(_L("waiting for callback..."));
   294 	LOG(_L("waiting for callback..."));
   211 	return KErrNone;
   295 	}
   212 	}
   296 	
   213 	
   297 void CEirManExternalSession::NewDataL(const RMessage2& aMessage)
   214 TInt CEirManSession::NewData(const RMessage2& aMessage)
   298 	{
   215 	{
   299 	LOG_FUNC
   216 	LOG_FUNC
   300 
   217 	__ASSERT_ALWAYS(iEirTag != EEirTagRESERVED, aMessage.Panic(KEirManCliPncCat, EEirManPanicInvalidTag));
   301 	if (iSession->EirTag() == EEirTagRESERVED)
       
   302 		{
       
   303 		aMessage.Panic(KEirManCliPncCat, EEirManPanicInvalidTag);
       
   304 		return;
       
   305 		}
       
   306 
   218 	TInt requiredLength = static_cast<TInt>(aMessage.Int0());
   307 	TInt requiredLength = static_cast<TInt>(aMessage.Int0());
   219 
   308 
   220 	return iEirManServer.EirManager().NewData(iEirTag, requiredLength);
   309 	LEAVEIFERRORL(iSession->NewData(requiredLength));
   221 	}
   310 	aMessage.Complete(KErrNone);
   222 
   311 	}
   223 TInt CEirManSession::CancelSpaceAvailableListener()
   312 
       
   313 void CEirManExternalSession::CancelSpaceAvailableListenerL(const RMessage2& aMessage)
   224 	{
   314 	{
   225 	LOG_FUNC
   315 	LOG_FUNC
   226 
   316 
   227 	if(!iDataAvailableListenerMessage.Handle())
   317 	if(!iDataAvailableListenerMessage.Handle())
   228 		{
   318 		{
   229 		return KErrNotFound;
   319 		LEAVEL(KErrNotFound);
   230 		}
   320 		}
   231 
   321 
   232 	iDataAvailableListenerMessage.Complete(KErrCancel);
   322 	iDataAvailableListenerMessage.Complete(KErrCancel);
   233 
   323 	aMessage.Complete(KErrNone);
   234 	return KErrNone;
   324 	}
   235 	}
   325 
   236 
   326 void CEirManExternalSession::SetDataL(const RMessage2& aMessage)
   237 TInt CEirManSession::SetData(const RMessage2& aMessage)
   327 	{
   238 	{
   328 	LOG_FUNC
   239 	LOG_FUNC
   329 	if (iSession->EirTag() == EEirTagRESERVED)
   240 	__ASSERT_ALWAYS(iEirTag != EEirTagRESERVED, aMessage.Panic(KEirManCliPncCat, EEirManPanicInvalidTag));
   330 		{
       
   331 		aMessage.Panic(KEirManCliPncCat, EEirManPanicInvalidTag);
       
   332 		return;
       
   333 		}
       
   334 
   241 	TEirDataMode eirDataMode = static_cast<TEirDataMode>(aMessage.Int1());
   335 	TEirDataMode eirDataMode = static_cast<TEirDataMode>(aMessage.Int1());
   242 	LOG2(_L("Tag: %d EirDataMode: %d"), iEirTag, eirDataMode);
   336 	LOG1(_L("EirDataMode: %d"),  eirDataMode);
   243 
   337 
   244 	// No need to allocate memory with an expensive malloc() call (via HBuf8::NewL or whatever), 
   338 	// No need to allocate memory with an expensive malloc() call (via HBuf8::NewL or whatever), 
   245 	// since the EIR contents fit in the stack, and the EIR Manager will cache the data anyway
   339 	// since the EIR contents fit in the stack, and the EIR Manager will cache the data anyway
   246 	TBuf8<KHCIExtendedInquiryResponseMaxLength> data;
   340 	TBuf8<KHCIExtendedInquiryResponseMaxLength> data;
   247 	TInt err = aMessage.Read(0, data);
   341 	LEAVEIFERRORL(aMessage.Read(0, data));
   248 	
   342 	
   249 	if(err == KErrNone)
   343 	LEAVEIFERRORL(iSession->SetData(data, eirDataMode));
   250 		{
   344 	aMessage.Complete(KErrNone);
   251 		err = iEirManServer.EirManager().SetData(iEirTag, data, eirDataMode);
   345 	}
   252 		}
   346 
   253 	return err;
   347 void CEirManExternalSession::MesnSpaceAvailable(TUint aSpaceForTag)
   254 	}
   348 	{
   255 
       
   256 // Callback from the EIR Manager
       
   257 void CEirManSession::MemnEirBlockAvailable(TEirTag aTag, TUint aSpaceForTag)
       
   258 	{
       
   259 	LOG_FUNC
       
   260 	LOG2(_L("CEirManSession::MemnEirBlockAvailable Tag: %d space: %d"), aTag, aSpaceForTag);
       
   261 
       
   262 	// Silently discard callbacks not containing our EIR Tag
       
   263 	if(aTag != iEirTag)
       
   264 		{
       
   265 		__ASSERT_DEBUG(EFalse, EIR_SESSION_PANIC(EEirSessionInvalidEirTag));
       
   266 		LOG3(_L("CEirManSession::MemnEirBlockAvailable early return: aTag: %d iEirTag: %d space: %d"), aTag, iEirTag, aSpaceForTag);
       
   267 		return;
       
   268 		}
       
   269 
       
   270 	if(iDataAvailableListenerMessage.Handle())
   349 	if(iDataAvailableListenerMessage.Handle())
   271 		{
   350 		{
   272 		LOG(_L("Listener outstanding, completing request"));
   351 		LOG(_L("Listener outstanding, completing request"));
   273 		// Clear stored value
   352 		// Clear stored value
   274 		iLastSpaceOffered = 0;
   353 		iLastSpaceOffered = 0;
   280 		// Store in case a client registers later. If this happens multiple times, only the last one will be remembered
   359 		// Store in case a client registers later. If this happens multiple times, only the last one will be remembered
   281 		iLastSpaceOffered = aSpaceForTag;
   360 		iLastSpaceOffered = aSpaceForTag;
   282 		}
   361 		}
   283 	}
   362 	}
   284 
   363 
   285 void CEirManSession::CompleteSpaceAvailableRequest(TUint aBytesAvailable)
   364 void CEirManExternalSession::CompleteSpaceAvailableRequest(TUint aBytesAvailable)
   286 	{
   365 	{
   287 	LOG_FUNC
   366 	LOG_FUNC
   288 	LOG1(_L("CEirManSession::CompleteSpaceAvailableRequest bytes: %d"), aBytesAvailable);
   367 	LOG1(_L("CEirManSession::CompleteSpaceAvailableRequest bytes: %d"), aBytesAvailable);
   289 	// Offer the space to the client
   368 	// Offer the space to the client
   290 	TPckg<TUint32> pckg(aBytesAvailable);
   369 	TPckgC<TUint32> pckg(aBytesAvailable);
   291 
   370 
   292 	TInt err = iDataAvailableListenerMessage.Write(0, pckg);
   371 	TInt err = iDataAvailableListenerMessage.Write(0, pckg);
   293 	iDataAvailableListenerMessage.Complete(err);
   372 	iDataAvailableListenerMessage.Complete(err);
   294 	}
   373 	}
   295 
   374 
       
   375 CEirManInternalSession* CEirManInternalSession::NewL(CEirManServer& aServer, MEirInternalSessionNotifier& aParent)
       
   376 	{
       
   377 	LOG_STATIC_FUNC
       
   378 	CEirManInternalSession* self = new(ELeave) CEirManInternalSession(aParent);
       
   379 	CleanupStack::PushL(self);
       
   380 	self->ConstructL(aServer);
       
   381 	CleanupStack::Pop(self);
       
   382 	return self;
       
   383 	}
       
   384 
       
   385 CEirManInternalSession::CEirManInternalSession(MEirInternalSessionNotifier& aParent)
       
   386 	: iParent(aParent)
       
   387 	{
       
   388 	
       
   389 	}
       
   390 
       
   391 void CEirManInternalSession::ConstructL(CEirManServer& aServer)
       
   392 	{
       
   393 	iSession = CEirManSession::NewL(aServer, *this, ETrue);
       
   394 	iSetDataCb = new (ELeave) CAsyncCallBack(CActive::EPriorityHigh);
       
   395 	TCallBack cb(&SetDataCb, this);
       
   396 	iSetDataCb->Set(cb);
       
   397 	}
       
   398 
       
   399 CEirManInternalSession::~CEirManInternalSession()
       
   400 	{
       
   401 	delete iSetDataCb;
       
   402 	delete iSession;
       
   403 	}
       
   404 	
       
   405 void CEirManInternalSession::RegisterTag(TEirTag aTag)
       
   406 	{
       
   407 	iSession->RegisterTag(aTag);
       
   408 	}
       
   409 
       
   410 void CEirManInternalSession::SetData(const TDesC8& aData, TEirDataMode aMode)
       
   411 	{
       
   412 	delete iPendingData;
       
   413 	iPendingData = NULL;
       
   414 	iSetDataCb->Cancel();
       
   415 	iPendingData = aData.Alloc();
       
   416 	iPendingMode = aMode;
       
   417 	if (iPendingData)
       
   418 		{
       
   419 		iSetDataCb->CallBack();
       
   420 		}
       
   421 	}
       
   422 
       
   423 TInt CEirManInternalSession::SetDataCb(TAny* aThis)
       
   424 	{
       
   425 	static_cast<CEirManInternalSession*>(aThis)->DoSetData();
       
   426 	return KErrNone;
       
   427 	}
       
   428 
       
   429 void CEirManInternalSession::DoSetData()
       
   430 	{
       
   431 	TInt err = iSession->SetData(*iPendingData, iPendingMode);
       
   432 	if (err != KErrNone)
       
   433 		{
       
   434 		iParent.MeisnSetDataError(err);
       
   435 		}
       
   436 	}
       
   437 
       
   438 TInt CEirManInternalSession::NewData(TInt aRequiredLength)
       
   439 	{
       
   440 	return iSession->NewData(aRequiredLength);
       
   441 	}
       
   442 
       
   443 
       
   444 void CEirManInternalSession::MesnRegisterComplete(TInt aResult)
       
   445 	{
       
   446 	iParent.MeisnRegisterComplete(aResult);
       
   447 	}
       
   448 
       
   449 void CEirManInternalSession::MesnSpaceAvailable(TUint aSpaceForTag)
       
   450 	{
       
   451 	iParent.MeisnSpaceAvailable(aSpaceForTag - KEirLengthTagLength);
       
   452 	}