commsfwtools/preparedefaultcommsdatabase/src/CommsDatNotifier.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-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 // Meta-database declarations 
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file 
       
    20 */
       
    21  
       
    22 #include "CommsDatInternalDefs.h"
       
    23 #include "CommsDatTypeInfoV1_1.h"
       
    24 #include "NotifierServ.H"
       
    25 #include <cdbcols.h>
       
    26 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    27 #include <commsdat_partner.h>
       
    28 #endif
       
    29 using namespace CommsDat;
       
    30 
       
    31 CCDNotifier::CCDNotifier(CMDBSessionImpl& aOwner)
       
    32  : iSuppressRollBackEvents(EFalse), iOwner(aOwner) 
       
    33     {
       
    34     }
       
    35 
       
    36 
       
    37 CCDNotifier::~CCDNotifier()
       
    38     {
       
    39     CancelAllNotifications();
       
    40    
       
    41     iNotifications.Close();    
       
    42     }
       
    43 
       
    44 
       
    45 CCDNotifier* CCDNotifier::NewL(CMDBSessionImpl& aOwner)
       
    46     {
       
    47 	CCDNotifier* r=new(ELeave) CCDNotifier(aOwner);
       
    48     CleanupStack::PushL(r);
       
    49     r->ConstructL();
       
    50     CleanupStack::Pop();
       
    51 	return r;
       
    52     }
       
    53 
       
    54 void CCDNotifier::ConstructL()
       
    55     {
       
    56     }
       
    57 
       
    58 
       
    59 TInt CCDNotifier::RegisterNotifyL(TRequestStatus& aStatus)
       
    60 /**
       
    61 @internalTechnology
       
    62 */
       
    63     {
       
    64     TInt ret(KErrNone);		
       
    65 	if(!iNotifier.Handle())
       
    66                 {
       
    67                 ret = iNotifier.Connect(); //Also starts the server if not running allready
       
    68                 }	
       
    69 	
       
    70 	if(ret == KErrNone)
       
    71                {
       
    72                iNotifier.RequestNotification(aStatus);
       
    73                }
       
    74                
       
    75         return ret;
       
    76     }
       
    77 
       
    78 
       
    79 
       
    80 TInt CCDNotifier::CancelAllNotifications()
       
    81 /**
       
    82 @internalComponent
       
    83 */
       
    84     {
       
    85     if(iNotifier.Handle())
       
    86     {    	
       
    87     iNotifier.CancelAllNotifications();
       
    88     iNotifier.Close();
       
    89     }
       
    90     
       
    91     return KErrNone;
       
    92     }
       
    93 
       
    94 
       
    95 
       
    96 TInt CCDNotifier::CancelNotify(TRequestStatus& aStatus)
       
    97 /**
       
    98 This function will cancel individual requests if given a particular TRequestStatus
       
    99   
       
   100 @internalComponent
       
   101 */
       
   102     {
       
   103     if(iNotifier.Handle())
       
   104     {    	
       
   105     iNotifier.CancelNotification(aStatus);
       
   106     return KErrNone;
       
   107     }        
       
   108     
       
   109     return KErrNotFound;
       
   110     }
       
   111 
       
   112 
       
   113 TInt CCDNotifier::NotifyClients(TInt aEventType)
       
   114 /**
       
   115 @internalTechnology
       
   116 */
       
   117     {
       
   118     // Discreetly drop the signalling of this event if our process lacks the necessary capabilities.
       
   119     //
       
   120     // For an EClose event, this means that readers finishing a session won't signal the fact that
       
   121     // they've closed a session. However, since they don't signal the fact that they've opened a 
       
   122     // session either, that's not such a concern.
       
   123     // 
       
   124     // For all other events, the client requires the same capability to Set the property as they
       
   125     // do for the associated CommsDat operation that it is signalling, so we presume that if they've
       
   126     // got this far, they have the necessary capabilities.
       
   127     //
       
   128     if (!RProcess().HasCapability(KCommsDatNotificationSetCapability, KSuppressPlatSecDiagnostic))
       
   129         {
       
   130         return KErrNone;
       
   131         }
       
   132         
       
   133     return RProperty::Set(KUidSystemCategory, KUidCommDbNotificationEvent.iUid, aEventType);
       
   134     }
       
   135     
       
   136 
       
   137 //
       
   138 // for Publish and Subscribe notifications
       
   139 
       
   140 
       
   141 void CCDNotifier::NotifyAllChanges()
       
   142 /*
       
   143 Does the notification for all the changes that are stored in the member variable iNotifications.
       
   144 
       
   145 @internalComponent
       
   146 */
       
   147 	{
       
   148 	TInt result(KErrNone);
       
   149 	// we attempt all notifications regardless of the failure of individual ones since
       
   150 	// different clients will be waiting on different notifications
       
   151 	for (TInt i=0; i < iNotifications.Count(); ++i)
       
   152    		{
       
   153    		//nithin: iValue maybe redundant...could be removed
       
   154  		result = RProperty::Set(KUidSystemCategory, iNotifications[i].iUid.iUid, iNotifications[i].iValue);
       
   155  		if ( result != KErrNone)
       
   156             {
       
   157             // Log error but nothing to do
       
   158             }
       
   159    		}
       
   160 	iNotifications.Reset();
       
   161 	}
       
   162 
       
   163 void CCDNotifier::ClearPubSubNotifications()
       
   164 /*
       
   165 Does the notification for all the changes that are stored in the member variable iNotifications.
       
   166 
       
   167 @internalComponent
       
   168 */
       
   169 	{
       
   170 	iNotifications.Close();
       
   171 	}
       
   172 
       
   173 /*
       
   174 Does the notification for all the changes that are stored in the member variable iNotifications.
       
   175 
       
   176 @internalComponent
       
   177 */
       
   178 void CCDNotifier::MaybeNotifyChange(TMDBElementId aElementId)
       
   179 	{
       
   180 	TCommsDatPubSubNotification notification;
       
   181 	ConvertToUid(aElementId, notification);
       
   182 	if (notification.iUid != KNullUid)
       
   183 		{
       
   184 	 	iNotifications.Append(notification); // nothing to do if fails
       
   185 		}	
       
   186 	}
       
   187 	
       
   188 /*
       
   189 Does the notification for delete operations and stores in member variable iNotifications.
       
   190 
       
   191 @internalComponent
       
   192 */
       
   193 void CCDNotifier::MaybeNotifyChangeForDelete(TMDBElementId aElementId, TBool aModemBearerDeleted)
       
   194 	{
       
   195 	MaybeNotifyChange(aElementId);
       
   196 
       
   197 	if (aModemBearerDeleted)
       
   198 		{
       
   199 		// there are three special notification when the modem bearer table is deleted
       
   200 		
       
   201 		TCommsDatPubSubNotification notification;
       
   202 
       
   203 		// TSY name change notification
       
   204 		const TUint32 rand1 = GetNewNumber(KUidCommDbModemTsyNameChange);
       
   205 		notification.Set(KUidCommDbModemTsyNameChange, rand1);
       
   206 		iNotifications.Append(notification);
       
   207 
       
   208 		// Data and fax change notification
       
   209 		const TUint32 rand2 = GetNewNumber(KUidCommDbModemDataAndFaxChange);
       
   210 		notification.Set(KUidCommDbModemDataAndFaxChange, rand2);
       
   211 		iNotifications.Append(notification);
       
   212 
       
   213 		// Phone services and SMS change notification
       
   214 		const TUint32 rand3 = GetNewNumber(KUidCommDbModemPhoneServicesAndSMSChange);
       
   215 		notification.Set(KUidCommDbModemPhoneServicesAndSMSChange, rand3);
       
   216 		iNotifications.Append(notification);		
       
   217 		}
       
   218 	}
       
   219 
       
   220 void CCDNotifier::ConvertToUid(TMDBElementId aId, TCommsDatPubSubNotification& aNotification)
       
   221 
       
   222 //Checks for the type of the setting passed and sets the value in the Commdb publish subscribe notification appropriately.
       
   223 
       
   224 //@param aSetting Setting to get
       
   225 //@param aVal Setting value.
       
   226 //@param aNotification A reference to TCommDbPublishSubscribeNotification
       
   227 	{
       
   228 	
       
   229 	if( (aId & KCDMaskShowRecordType) == KCDTIdDefaultWCDMARecord)
       
   230 		{
       
   231 		const TUint32 rand = GetNewNumber(KUidCommDbGPRSDefaultParamsChange);
       
   232 	    aNotification.Set(KUidCommDbGPRSDefaultParamsChange, rand);	
       
   233 		}
       
   234 	else if((aId & KCDMaskShowRecordType) == KCDTIdModemBearerRecord)
       
   235 		{
       
   236 		const TUint32 rand = GetNewNumber(KUidCommDbModemRecordChange);
       
   237 	    aNotification.Set(KUidCommDbModemRecordChange, rand);
       
   238 	    
       
   239 	    if((aId & KCDMaskShowType) == KCDTIdTsyName)
       
   240 	    	{
       
   241 	    	const TUint32 rand = GetNewNumber(KUidCommDbModemTsyNameChange);
       
   242 	        aNotification.Set(KUidCommDbModemTsyNameChange, rand);	
       
   243 	    	}    
       
   244 		}
       
   245 	else if((aId & KCDMaskShowRecordType) == KCDTIdProxiesRecord)
       
   246 		{
       
   247 		const TUint32 rand = GetNewNumber(KUidCommDbProxiesRecordChange);
       
   248 	    aNotification.Set(KUidCommDbProxiesRecordChange, rand);	
       
   249 		}
       
   250 	else if((aId & KCDMaskShowRecordType) == KCDTIdGlobalSettingsRecord)
       
   251 		{
       
   252 		switch(aId & KCDMaskShowType)
       
   253         	{
       
   254 	        case KCDTIdSMSBearer : // global settings field
       
   255 		        {
       
   256 		        aNotification.Set(KUidCommDbSMSBearerChange, 1);
       
   257 	            break;
       
   258 		        }
       
   259 	        case KCDTIdSMSReceiveMode :  // global settings field
       
   260 		        {
       
   261 		        aNotification.Set(KUidCommDbSMSReceiveModeChange, 1);
       
   262 		        break;
       
   263 	            }
       
   264 	        case KCDTIdGPRSAttachMode :  // global settings field
       
   265 		        {
       
   266 		        aNotification.Set(KUidCommDbGPRSAttachModeChange, 1);
       
   267 		        break;
       
   268 	            }      
       
   269 	        case KCDTIdModemDataFax :  // Global setting field
       
   270 		        {
       
   271 		        const TUint32 rand = GetNewNumber(KUidCommDbModemDataAndFaxChange);
       
   272 		        aNotification.Set(KUidCommDbModemDataAndFaxChange, rand);
       
   273 		        break;
       
   274 	            }
       
   275 	        case KCDTIdModemPhoneServicesSMS :  // Global setting field
       
   276 		        {
       
   277 		        const TUint32 rand = GetNewNumber(KUidCommDbModemPhoneServicesAndSMSChange);
       
   278 		        aNotification.Set(KUidCommDbModemPhoneServicesAndSMSChange, rand);
       
   279 		        break;
       
   280 	            }
       
   281         	};			
       
   282 		}
       
   283 				
       
   284 	// else not an error since we dont want to notify
       
   285 	}
       
   286 
       
   287 
       
   288 TUint32 CCDNotifier::GetNewNumber(TUid aUid)
       
   289 //Generates a new number for the given UID
       
   290 
       
   291 //@param aUid UID for which the new number is to be generated
       
   292 //@return The new number generated
       
   293 
       
   294 	{
       
   295  	TInt value;
       
   296  	TInt result = RProperty::Get(KUidSystemCategory, aUid.iUid, value);
       
   297  	return ++value;	//don't worry about overflow - it doesn't matter
       
   298 	}
       
   299 
       
   300 
       
   301 
       
   302 //
       
   303 
       
   304 
       
   305 TCommsDatPubSubNotification::TCommsDatPubSubNotification()
       
   306 	: iUid(KNullUid), iValue(0)
       
   307     {
       
   308     }
       
   309 
       
   310 	
       
   311 void TCommsDatPubSubNotification::Set(TUid aUid,TInt aVal)
       
   312 //Sets the given values of aUid and aVal to the members iUid and aVal.
       
   313 
       
   314 //@param aUid UID to be set
       
   315 //@param aVal Value to be set
       
   316 	{
       
   317 	iUid=aUid;
       
   318 	iValue=aVal;
       
   319 	}
       
   320 
       
   321 //
       
   322 
       
   323 
       
   324 RCommsdatNotifier::RCommsdatNotifier()
       
   325 	/** Constructor. */
       
   326 	{}
       
   327 
       
   328 		
       
   329 TInt RCommsdatNotifier::StartNotifierProcess()
       
   330 	{	
       
   331 	RProcess server;
       
   332 	
       
   333 	TInt ret=server.Create(KCommsdatNotifierExecutable, KNullDesC);
       
   334 	
       
   335 	if (ret!=KErrNone)
       
   336 		{
       
   337 		return ret;	
       
   338 		}
       
   339 	TRequestStatus stat;	
       
   340 	server.Rendezvous(stat);
       
   341 	server.Resume();
       
   342 	server.Close();
       
   343 	User::WaitForRequest(stat);
       
   344 	return stat.Int();		
       
   345 	}	
       
   346 	
       
   347 TInt RCommsdatNotifier::Connect()
       
   348 	/** Connects to the server.
       
   349 	*
       
   350 	* 
       
   351 	* @return	KErrNone if successful; otherwise, a system-wide error code. */
       
   352 	{
       
   353 	TInt ret = CreateSession(COMMSDATNOTIFIER_SERVER_NAME,Version(),-1);
       
   354 
       
   355 	if (ret!=KErrNone)
       
   356 		{		
       
   357 		ret=StartNotifierProcess();
       
   358 		if (ret==KErrNone || ret==KErrAlreadyExists)
       
   359 			{
       
   360 			ret = CreateSession(COMMSDATNOTIFIER_SERVER_NAME,Version(),-1);
       
   361 			}
       
   362 		}      
       
   363 	
       
   364 	if (ret==KErrNone)	
       
   365 	{		
       
   366 		ret = ShareProtected();
       
   367 	}
       
   368 		
       
   369 	return ret;
       
   370 	}
       
   371 
       
   372 TVersion RCommsdatNotifier::Version() const
       
   373 	/** Gets the client side version number.
       
   374 	*
       
   375 	* @return	The client version number. */
       
   376 	{
       
   377 	return(TVersion(KCommsdatNotifierMajorVersionNumber,KCommsdatNotifierMinorVersionNumber,KCommsdatNotifierSpecialBuildVersionNumber));
       
   378 	}
       
   379 
       
   380 void RCommsdatNotifier::RequestNotification(TRequestStatus& aStatus)
       
   381 	{
       
   382 	SendReceive(ERequestNotify, TIpcArgs(),aStatus);
       
   383 	}
       
   384 
       
   385 void RCommsdatNotifier::CancelNotification(TRequestStatus& aStatus)
       
   386 /**
       
   387 Cancel a previously registered notification.
       
   388 
       
   389 @param aStatus the TRequestStatus of the notification.  This will be completed with KErrCancel.
       
   390 */
       
   391 	{
       
   392 	SendReceive(ECancelNotify, TIpcArgs(&aStatus));
       
   393 	}	
       
   394 
       
   395 void RCommsdatNotifier::CancelAllNotifications()
       
   396 	{
       
   397 	SendReceive(ECancelAllNotify, TIpcArgs());
       
   398 	}		
       
   399 
       
   400 void RCommsdatNotifier::Close()
       
   401 	{
       
   402 	RHandleBase::Close();
       
   403 	}	
       
   404 
       
   405 // EOF