locationtriggering/ltserver/ltserverlogic/src/lbtnotificationmap.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2007 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 "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:  Defines the notification map data structure used by Location 
       
    15 *				 Triggering Server Logic to store notification request messages
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include "lbtnotificationmap.h"
       
    23 #include "lbtglobal.h"
       
    24 #include "lbtlogger.h"
       
    25 
       
    26 // ======== LOCAL FUNCTIONS ========
       
    27 
       
    28 TInt OrderNotifReqs(
       
    29     const CLbtNotificationMap::TLbtNotificationReq& aLhs, 
       
    30     const CLbtNotificationMap::TLbtNotificationReq& aRhs)
       
    31 	{
       
    32 	FUNC_ENTER("CLbtNotificationMap::OrderNotifReqs");
       
    33 	const RMessage2& lhs = aLhs.iMsg;
       
    34 	const RMessage2& rhs = aRhs.iMsg;
       
    35 
       
    36 	if(lhs.SecureId() == rhs.SecureId())
       
    37 		{
       
    38 		return 0;
       
    39 		}
       
    40 	if(lhs.SecureId() < rhs.SecureId())
       
    41 		{
       
    42 		return -1;
       
    43 		}
       
    44 	else
       
    45 		{
       
    46 		return 1;
       
    47 		}
       
    48 	}
       
    49 
       
    50 
       
    51 TInt SecureIdCompare(CSession2** aSession, RMessage2& aMessage)
       
    52 	{
       
    53 	FUNC_ENTER("CLbtNotificationMap::SecureIdCompare");
       
    54 	if(aMessage.Session() == (*aSession))
       
    55 		{
       
    56 		return 0;
       
    57 		}
       
    58 	if(aMessage.Session() < (*aSession))
       
    59 		{
       
    60 		return -1;
       
    61 		}
       
    62 	else
       
    63 		{
       
    64 		return 1;
       
    65 		}
       
    66 	}
       
    67 
       
    68 // ======== MEMBER FUNCTIONS ========
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CLbtNotificationMap::NewL
       
    72 // Symbian Two - phase constructor
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CLbtNotificationMap* CLbtNotificationMap::NewL()
       
    76 	{
       
    77 	FUNC_ENTER("CLbtNotificationMap::NewL");
       
    78 	CLbtNotificationMap* self = new ( ELeave ) CLbtNotificationMap;
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();    
       
    81     CleanupStack::Pop();
       
    82     return self;
       
    83 	}
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CLbtNotificationMap::~CLbtNotificationMap
       
    87 // Destructor
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CLbtNotificationMap::~CLbtNotificationMap()
       
    91 	{
       
    92 	FUNC_ENTER("CLbtNotificationMap::~CLbtNotificationMap");
       
    93 	Reset(KErrServerBusy);
       
    94 	iMessageArray.Close();
       
    95 	}
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CLbtNotificationMap::InsertL
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CLbtNotificationMap::InsertL(
       
   102     const RMessage2& aMessage,
       
   103     CLbtServerLogicBase::TSubSessionType aType)	
       
   104 	{
       
   105 	FUNC_ENTER("CLbtNotificationMap::InsertL");
       
   106 	TLbtNotificationReq req = { aMessage, aType };
       
   107 
       
   108 	//Insert in sorted order into to the message array
       
   109 	TLinearOrder<TLbtNotificationReq> OrderPredicate(OrderNotifReqs);
       
   110 	iMessageArray.InsertInOrderAllowRepeats(req, OrderPredicate);
       
   111 //	iMessageArray.Append(req);
       
   112 	}
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CLbtNotificationMap::Retreive
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 TInt CLbtNotificationMap::Retreive(RMessage2& aMessage, 
       
   119 				    			   TUint32 aSubSessionHandle, 
       
   120 				    			   TSecureId aSecureId,
       
   121 				    			   TInt aServiceId,
       
   122 				    			   CSession2* aSession)
       
   123 	{
       
   124 	FUNC_ENTER("CLbtNotificationMap::Retreive");
       
   125 	for(TInt i=0; i<iMessageArray.Count(); ++i)
       
   126 		{
       
   127 		
       
   128 		RMessage2& msg = iMessageArray[i].iMsg;
       
   129 		if( msg.SecureId() == aSecureId &&
       
   130 		    msg.Int3() == aSubSessionHandle && 
       
   131 		    msg.Function() == aServiceId && 
       
   132 		    msg.Session() == aSession )
       
   133 			{
       
   134 			aMessage = msg;
       
   135 			iMessageArray.Remove(i);
       
   136 			return KErrNone;
       
   137 			}
       
   138 		}
       
   139 
       
   140 	return KErrNotFound;
       
   141 	}
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CLbtNotificationMap::Retreive
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 TInt CLbtNotificationMap::Retreive(RMessage2& aMessage, 
       
   148 				    			   TSecureId aSecureId,
       
   149 				    			   TInt aServiceId)
       
   150 	{
       
   151 	FUNC_ENTER("CLbtNotificationMap::Retreive");
       
   152 	for(TInt i=0; i<iMessageArray.Count(); ++i)
       
   153 		{
       
   154 		RMessage2& msg = iMessageArray[i].iMsg;
       
   155 		if( msg.SecureId() == aSecureId &&
       
   156 			msg.Function() == aServiceId )
       
   157 			{
       
   158 			aMessage = msg;
       
   159 			iMessageArray.Remove(i);
       
   160 			return KErrNone;
       
   161 			}
       
   162 		}
       
   163 	return KErrNotFound;
       
   164 	}
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CLbtNotificationMap::Retreive
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 TInt CLbtNotificationMap::Retreive(RMessage2& aMessage, 
       
   171                                    TInt aSubSessionHandle,
       
   172                                    TSecureId aSecureId)
       
   173     {
       
   174     FUNC_ENTER("CLbtNotificationMap::Retreive");
       
   175     for(TInt i=0; i<iMessageArray.Count(); ++i)
       
   176         {
       
   177         RMessage2& msg = iMessageArray[i].iMsg;
       
   178         if( msg.SecureId() == aSecureId && 
       
   179             msg.Int3() == aSubSessionHandle )
       
   180             {
       
   181             aMessage = msg;
       
   182             iMessageArray.Remove(i);
       
   183             return KErrNone;
       
   184             }
       
   185         }
       
   186     return KErrNotFound;
       
   187     }
       
   188 
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CLbtNotificationMap::Retreive
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 TInt CLbtNotificationMap::Retreive(RMessage2& aMessage, 
       
   195 				    			   TInt aServiceId,
       
   196 				    			   CLbtServerLogicBase::TSubSessionType aType)
       
   197 	{
       
   198 	FUNC_ENTER("CLbtNotificationMap::Retreive");
       
   199 	for(TInt i=0; i<iMessageArray.Count(); ++i)
       
   200 		{
       
   201 		RMessage2& msg = iMessageArray[i].iMsg;
       
   202 		if( msg.Function() == aServiceId &&
       
   203 			iMessageArray[i].iType == aType )
       
   204 			{
       
   205 			aMessage = msg;
       
   206 			iMessageArray.Remove(i);
       
   207 			return KErrNone;
       
   208 			}
       
   209 		}
       
   210 	return KErrNotFound;
       
   211 	}
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CLbtNotificationMap::CompleteMessagesOfSubsession
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CLbtNotificationMap::CompleteMessagesOfSubsession(const CSession2* aSession, const TInt aSubSessionHandle, TInt aErrorCode)
       
   218 	{
       
   219 	FUNC_ENTER("CLbtNotificationMap::CompleteMessagesOfSubsession");
       
   220 	for(TInt i=0;i<iMessageArray.Count();++i)
       
   221 		{
       
   222 		RMessage2& message = iMessageArray[i].iMsg;
       
   223 		if(message.Session() == aSession && 
       
   224 		   message.Int3() == aSubSessionHandle)
       
   225 			{
       
   226 			LbtGlobal::RequestComplete(message, aErrorCode);
       
   227 			iMessageArray.Remove(i);
       
   228 			}
       
   229 		}
       
   230 	}
       
   231 // ---------------------------------------------------------------------------
       
   232 // CLbtNotificationMap::CompleteMessagesOfSubsession
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CLbtNotificationMap::RemoveAllClientMessages(TSecureId aSecureId)	
       
   236 	{
       
   237 	FUNC_ENTER("CLbtNotificationMap::RemoveAllClientMessages");
       
   238 	for(TInt i=0;i<iMessageArray.Count();i++)
       
   239 		{
       
   240 		RMessage2& message = iMessageArray[i].iMsg;
       
   241 		if(message.SecureId() == aSecureId)
       
   242 			{
       
   243 			LbtGlobal::RequestComplete(message,KErrDied);
       
   244 			iMessageArray.Remove(i);
       
   245 			}
       
   246 		}
       
   247 	}
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // CLbtNotificationMap::Reset
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void CLbtNotificationMap::Reset(TInt aErrorCode)
       
   254 	{
       
   255 	FUNC_ENTER("CLbtNotificationMap::Reset");
       
   256 	for(TInt i=0;i<iMessageArray.Count();++i)
       
   257 		{
       
   258 		const RMessage2& message = iMessageArray[i].iMsg;
       
   259 		LbtGlobal::RequestComplete(message, aErrorCode);
       
   260 		}
       
   261 	iMessageArray.Reset();
       
   262 	}
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CLbtNotificationMap::ConstructL
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CLbtNotificationMap::ConstructL()
       
   269 	{
       
   270 	FUNC_ENTER("CLbtNotificationMap::ConstructL");
       
   271 	}
       
   272 
       
   273 // end of file