networkcontrol/commsuserpromptmgr/database/src/netupsthreadentry.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This file provides the implementation for the thread entry.
       
    15 // @internalComponent
       
    16 // @prototype
       
    17 // 
       
    18 //
       
    19 
       
    20 #include "e32base.h"				// defines CleanupStack
       
    21 
       
    22 #include "netupsthreadentry.h"
       
    23 #include "netupsdatabaseentry.h"
       
    24 #include "netupsprocessentry.h"
       
    25 #include "netupssubsession.h"
       
    26 #include "netupsthreadmonitor.h"
       
    27 #include "netupspolicycheckrequestqueue.h"
       
    28 #include "netupsassert.h"
       
    29 
       
    30 #include <ups/upsclient.h>
       
    31 
       
    32 #include <comms-infras/commsdebugutility.h> 		// defines the comms debug logging utility
       
    33 
       
    34 namespace NetUps
       
    35 {
       
    36 __FLOG_STMT(_LIT8(KNetUpsSubsys, 	"esock");)   
       
    37 __FLOG_STMT(_LIT8(KNetUpsComponent, "NetUps");) /*esockloader*/
       
    38 
       
    39 CThreadEntry* CThreadEntry::NewL(CDatabaseEntry& aDatabaseEntry, CProcessEntry& aProcessEntry, const TThreadId& aThreadId, UserPromptService::RUpsSession& aUpsSession)
       
    40 	{
       
    41 	CThreadEntry* self = new (ELeave) CThreadEntry(aThreadId);
       
    42 
       
    43 	CleanupStack::PushL(self);
       
    44 	self->ConstructL(aDatabaseEntry, aProcessEntry, aUpsSession);
       
    45 	CleanupStack::Pop(self);
       
    46 
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 CThreadEntry::CThreadEntry(const TThreadId& aThreadId) :  iIsDead(EFalse), iThreadId(aThreadId), iThreadMonitor(NULL)
       
    51 	{
       
    52 	}
       
    53 	
       
    54 void CThreadEntry::ConstructL(CDatabaseEntry& aDatabaseEntry, CProcessEntry& aProcessEntry, UserPromptService::RUpsSession& aUpsSession)
       
    55 	{
       
    56 	__FLOG_OPEN(KNetUpsSubsys, KNetUpsComponent);
       
    57 
       
    58 	iSubSession 	= CSubSession::NewL(aUpsSession, aDatabaseEntry, aProcessEntry, *this);
       
    59 	iQueue 			= CPolicyCheckRequestQueue::NewL(*iSubSession); 
       
    60 	iThreadMonitor 	= CThreadMonitor::NewL(aDatabaseEntry, aProcessEntry, *this);
       
    61 
       
    62 	__FLOG_6(_L("CThreadEntry %08x:\tConstructL(), iIsDead = %d, thread id = %d, iThreadMonitor = %08x, iSubSession = %08x, iQueue = %08x"), this, iIsDead, iThreadId.Id(), iThreadMonitor, iSubSession, iQueue);	
       
    63 	}
       
    64 
       
    65 CThreadEntry::~CThreadEntry() 
       
    66 	{
       
    67 	__FLOG_1(_L("CThreadEntry %08x:\t~CThreadEntry()"), this);
       
    68 
       
    69 	for (TInt i = iConnectionEntry.Count() - 1; i >=0; --i )
       
    70 		{
       
    71 		delete iConnectionEntry[i];
       
    72 		}	
       
    73 	iConnectionEntry.Reset();
       
    74 	iConnectionEntry.Close();
       
    75 
       
    76 	delete	iThreadMonitor;
       
    77 	delete	iSubSession;
       
    78 	delete  iQueue;
       
    79 
       
    80 	__FLOG_CLOSE;	
       
    81 	}
       
    82 
       
    83 TBool CThreadEntry::FindConnectionEntry(const Messages::TNodeId& aCommsId, TInt32& aIndex)
       
    84 	{
       
    85 	TBool found = EFalse;
       
    86 	for (TInt i = iConnectionEntry.Count() - 1; i >=0; --i)
       
    87 		{
       
    88 		if (iConnectionEntry[i]->CommsId() == aCommsId)
       
    89 			{
       
    90 			aIndex = i;
       
    91 			found = ETrue;
       
    92 			break;
       
    93 			}
       
    94 		}
       
    95 		
       
    96 	return found;	
       
    97 	}
       
    98 
       
    99 void CThreadEntry::AddCommsIdL(const Messages::TNodeId& aCommsId)
       
   100 	{
       
   101 	//__FLOG_2(_L("CThreadEntry %08x:\t AddCommsIdL(), aCommsId = %d"), this, aCommsId.Printable());
       
   102 	__FLOG_1(_L("CThreadEntry %08x:\tAddCommsIdL()"), this);
       
   103 
       
   104 	TInt32 index = 0;
       
   105 	TBool found = FindConnectionEntry(aCommsId, index);
       
   106 		
       
   107 	if (found == EFalse)
       
   108 		{
       
   109 		CConnectionEntry* connectionEntry = CConnectionEntry::NewL(aCommsId, (TInt) 0);
       
   110 		CleanupStack::PushL(connectionEntry);
       
   111 		iConnectionEntry.AppendL(connectionEntry);
       
   112 		CleanupStack::Pop(connectionEntry);
       
   113 		}		
       
   114 	}
       
   115 
       
   116 TBool CThreadEntry::RemoveCommsId(const Messages::TNodeId& aCommsId)
       
   117 	{
       
   118 	//__FLOG_2(_L("CThreadEntry %08x:\tRemoveCommsId(), aCommsId %08x"), this, aCommsId);
       
   119 	__FLOG_1(_L("CThreadEntry %08x:\tRemoveCommsId()"), this);
       
   120 
       
   121 	TInt32 index = 0;
       
   122 	TBool found = FindConnectionEntry(aCommsId, index);
       
   123 
       
   124 	TBool commsIdRemoved = EFalse;
       
   125 	if (found && (iConnectionEntry[index]->Count() == 0))
       
   126 		{
       
   127 		delete iConnectionEntry[index];
       
   128 		iConnectionEntry[index] = 0;
       
   129 		iConnectionEntry.Remove(index);			
       
   130 		commsIdRemoved = ETrue;
       
   131 		}
       
   132 
       
   133 	return commsIdRemoved;
       
   134 	}
       
   135 
       
   136 void CThreadEntry::IncrementConnectionCount(const Messages::TNodeId& aCommsId)
       
   137 	{
       
   138 	//__FLOG_2(_L("CThreadEntry %08x:\t IncrementConnectionCount(), aCommsId = %d"), this, aCommsId.Printable());
       
   139 	__FLOG_1(_L("CThreadEntry %08x:\t IncrementConnectionCount()"), this);
       
   140 
       
   141 	TInt32 index = 0;
       
   142 	TBool found = FindConnectionEntry(aCommsId, index);
       
   143 		
       
   144 	if (found == EFalse)
       
   145 		{
       
   146 		User::Panic(KNetUpsPanic, KPanicInvalidLogic);					
       
   147 		}	
       
   148 	else
       
   149 		{
       
   150 		iConnectionEntry[index]->IncrementCount();	
       
   151 		}
       
   152 	}
       
   153 
       
   154 void CThreadEntry::IncrementConnectionCountL(const Messages::TNodeId& aCommsId)
       
   155 	{
       
   156 	//__FLOG_2(_L("CThreadEntry %08x:\t IncrementConnectionCount(), aCommsId = %d"), this, aCommsId.Printable());
       
   157 	__FLOG_1(_L("CThreadEntry %08x:\tIncrementConnectionCountL()"), this);
       
   158 
       
   159 	TInt32 index = 0;
       
   160 	TBool found = FindConnectionEntry(aCommsId, index);
       
   161 		
       
   162 	if (found == EFalse)
       
   163 		{
       
   164 		CConnectionEntry* connectionEntry = CConnectionEntry::NewL(aCommsId, (TInt) 1);
       
   165 		CleanupStack::PushL(connectionEntry);
       
   166 		iConnectionEntry.AppendL(connectionEntry);
       
   167 		CleanupStack::Pop(connectionEntry);
       
   168 		}
       
   169 	else
       
   170 		{
       
   171 		iConnectionEntry[index]->IncrementCount();
       
   172 		}		
       
   173 	}
       
   174 
       
   175 void CThreadEntry::DecrementConnectionCount(const Messages::TNodeId& aCommsId)
       
   176 	{
       
   177 	//__FLOG_2(_L("CThreadEntry %08x:\t DecrementConnectionCount(), aCommsId = %d"), this, aCommsId.Printable());
       
   178 	__FLOG_1(_L("CThreadEntry %08x:\tDecrementConnectionCount()"), this);
       
   179 
       
   180 	TInt32 index = 0;
       
   181 	TBool found = FindConnectionEntry(aCommsId, index);
       
   182 
       
   183 	if (found == EFalse)
       
   184 		{
       
   185 		User::Panic(KNetUpsPanic, KPanicInvalidLogic);
       
   186 		}
       
   187 	else
       
   188 		{
       
   189 		iConnectionEntry[index]->DecrementCount();
       
   190 		if (iConnectionEntry[index]->Count() == 0)
       
   191 			{
       
   192 			delete iConnectionEntry[index];
       
   193 			iConnectionEntry[index] = 0;
       
   194 			iConnectionEntry.Remove(index);
       
   195 			}
       
   196 		}		
       
   197 	}
       
   198 
       
   199 TInt32 CThreadEntry::ConnectionCount()
       
   200 	{
       
   201 	__FLOG_1(_L("CThreadEntry %08x:\tConnectionCount()"), this);
       
   202 
       
   203 	TInt32 count = 0;
       
   204 	
       
   205 	for (TInt i = iConnectionEntry.Count() - 1; i >=0; --i )
       
   206 		{
       
   207 		count+= iConnectionEntry[i]->Count();
       
   208 		}	
       
   209 
       
   210 	__FLOG_2(_L("\tcount = %d"), this, count);
       
   211 	
       
   212 	return count;
       
   213 	}
       
   214 
       
   215 TInt32	CThreadEntry::ConnectionCount(const Messages::TNodeId& aCommsId)
       
   216 	{
       
   217 	//__FLOG_2(_L("CThreadEntry %08x:\t ConnectionCount(), aCommsId = %d"), this, aCommsId.Printable());
       
   218 	__FLOG_1(_L("CThreadEntry %08x:\t ConnectionCount()"), this);
       
   219 
       
   220 	TInt32 index = 0;
       
   221 	TInt32 count = 0;
       
   222 	TBool found = FindConnectionEntry(aCommsId, index);
       
   223 
       
   224 	if (found == EFalse)
       
   225 		{
       
   226 		User::Panic(KNetUpsPanic, KPanicInvalidLogic);
       
   227 		}
       
   228 	else
       
   229 		{
       
   230 		count = iConnectionEntry[index]->Count();			
       
   231 		}	
       
   232 
       
   233 	return count;
       
   234 	}
       
   235 
       
   236 RPointerArray<CConnectionEntry>& CThreadEntry::ConnectionEntry()
       
   237 	{
       
   238 	return iConnectionEntry;	
       
   239 	}
       
   240 
       
   241 const TThreadId& CThreadEntry::ThreadId() const
       
   242 	{
       
   243 	return iThreadId;
       
   244 	}
       
   245 
       
   246 void CThreadEntry::SetIsDead(TBool aDead)
       
   247 	{
       
   248 	iIsDead = aDead;
       
   249 	}
       
   250 
       
   251 TBool CThreadEntry::IsDead() const
       
   252 	{
       
   253 	return iIsDead;
       
   254 	}
       
   255 
       
   256 void CThreadEntry::SetThreadMonitor(CThreadMonitor* aThreadMonitor)
       
   257 	{
       
   258 	iThreadMonitor = aThreadMonitor;	
       
   259 	__FLOG_6(_L("CThreadEntry %08x:\t SetThreadMonitor(), iIsDead = %d, thread id = %d, iThreadMonitor = %08x, iSubSession = %08x, iQueue = %08x"), this, iIsDead, iThreadId.Id(), iThreadMonitor, iSubSession, iQueue);	
       
   260 	}
       
   261 
       
   262 CThreadMonitor* CThreadEntry::ThreadMonitor() const
       
   263 	{
       
   264 	return iThreadMonitor;
       
   265 	}
       
   266 
       
   267 void CThreadEntry::SetSubSession(CSubSession* aSubSession)
       
   268 	{
       
   269 	iSubSession = aSubSession;	
       
   270 	__FLOG_6(_L("CThreadEntry %08x:\t SetSubSession(), iIsDead = %d, iThreadId.Id() = %d, iThreadMonitor = %08x, iSubSession = %08x, iQueue = %08x"), this, iIsDead, iThreadId.Id(), iThreadMonitor, iSubSession, iQueue);
       
   271 	}
       
   272 
       
   273 CSubSession* CThreadEntry::SubSession() const
       
   274 	{
       
   275 	return iSubSession;
       
   276 	}
       
   277 
       
   278 CPolicyCheckRequestQueue& CThreadEntry::RequestQueue() const
       
   279 	{
       
   280 	return *iQueue;
       
   281 	}
       
   282 
       
   283 } // end of namespace