messagingfw/biomsgfw/BioWatchers/Src/NbsWatcher.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 //
       
    15 
       
    16 #include "NbsWatcher.h"
       
    17 #include <biodb.h>
       
    18 
       
    19 #include "NBSSocketWatcher.h"
       
    20 
       
    21 #include <e32test.h>
       
    22 #include <watcher.h>
       
    23 
       
    24 //
       
    25 // DLL Global Methods
       
    26 //
       
    27 
       
    28 
       
    29 #include <ecom/implementationproxy.h>
       
    30 
       
    31 const TImplementationProxy ImplementationTable[] = 
       
    32 	{
       
    33 		IMPLEMENTATION_PROXY_ENTRY(0x10008C66, CNbsWatcher::NewL)
       
    34 	};
       
    35 
       
    36 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    37 	{
       
    38 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    39 
       
    40 	return ImplementationTable;
       
    41 	}
       
    42 
       
    43 
       
    44 //
       
    45 // NbsWatcher
       
    46 //
       
    47 
       
    48 //
       
    49 // Construction
       
    50 //
       
    51 CNbsWatcher::CNbsWatcher(RFs& aFs, CWatcherLog& aLog)
       
    52 : CSmsBaseWatcher(aFs, aLog, EPriorityStandard + 1)
       
    53 	{
       
    54 	}
       
    55 	
       
    56 CNbsWatcher::~CNbsWatcher()
       
    57 	{
       
    58 	}
       
    59 
       
    60 //
       
    61 CNbsWatcher* CNbsWatcher::NewL(TAny* aWatcherParams)
       
    62 	{
       
    63 	TWatcherParams* params = reinterpret_cast<TWatcherParams*>(aWatcherParams);
       
    64 	CNbsWatcher* self= new (ELeave) CNbsWatcher(params->iFs, params->iLog);
       
    65 	CleanupStack::PushL(self);
       
    66 	self->ConstructL();
       
    67 	CleanupStack::Pop(self);
       
    68 	return self;
       
    69 	}
       
    70 	
       
    71 void CNbsWatcher::ConstructL()
       
    72 	{
       
    73 	// CSmsBaseWatcher::ConstructL calls SetActive
       
    74 	CSmsBaseWatcher::ConstructL();
       
    75 	}
       
    76 
       
    77 //
       
    78 // Construction/destruction
       
    79 
       
    80 void CNbsWatcher::StartL()
       
    81 	{
       
    82 	CSmsBaseWatcher::StartL();
       
    83 
       
    84 	GetBioServiceId(*iSession, iBioServiceId, iSmsServiceId);
       
    85 
       
    86 	CreateSocketWatchersFromBioDbL(EBioMsgIdNbs);
       
    87 
       
    88 	// Set up a SMS Watcher for Special Messages
       
    89 	SetupSpecialWatcherL(ESmsAddrMessageIndication);
       
    90 
       
    91 	// Set up a SMS Watcher for Status Reports
       
    92 	SetupSpecialWatcherL(ESmsAddrStatusReport);
       
    93 
       
    94 	// Set up the default NULL SMS message
       
    95 	CBaseSmsActiveSocketWatcher* nbsWatcher = CNbsSmsSocketWatcher::NewLC(iBioServiceId, iSmsServiceId, *iBioDb, iWatcherLog, Priority(), KNullUid, iFs, KNullDesC, ESmsAddrRecvAny);
       
    96 	TInt error = SetupAndAppendL(*nbsWatcher, *iSocketWatchers);
       
    97 	User::LeaveIfError(error); //need to make sure the ReceiveAny watcher is working
       
    98 	iReceiveAnySocket = nbsWatcher;
       
    99 	CleanupStack::Pop(); //nbsWatcher
       
   100 
       
   101 	StartSocketWatchersL();
       
   102 
       
   103 	ResetDb(); //these members are only required during construction
       
   104 
       
   105 	// delete the session with the message server
       
   106 	delete iSession;
       
   107 	iSession = NULL;	
       
   108 	}
       
   109 
       
   110 CBaseSmsActiveSocketWatcher* CNbsWatcher::CreateSocketWatcherLC(const TUid aBioUid, const TBioMsgId& aBioMsg)
       
   111 	{
       
   112 	if (!SupportBioMsgId(aBioMsg))
       
   113 		User::Leave(KErrNotSupported);
       
   114 
       
   115 	__ASSERT_DEBUG(iBioDb, PanicWatcher(EObjectNotConstructed));
       
   116 
       
   117 	return CNbsSmsSocketWatcher::NewLC(iBioServiceId, iSmsServiceId, *iBioDb, iWatcherLog, Priority(), aBioUid, iFs, aBioMsg.iText);
       
   118 	}
       
   119 
       
   120 TBool CNbsWatcher::SupportBioMsgId(const TBioMsgId& aBioMsg) const
       
   121 	{
       
   122 	return aBioMsg.iType == EBioMsgIdNbs && aBioMsg.iPort <= 0 && aBioMsg.iText.Length();
       
   123 	}
       
   124 
       
   125 void CNbsWatcher::AddBifL(TUid aBioID)
       
   126 	{
       
   127 	BIOWATCHERLOG(iWatcherLog.Printf(_L8("BioNbs: AddBifL(BioUid: %d)"), aBioID.iUid));
       
   128 
       
   129 	// Handle the case where the watchers are not working
       
   130 	if (!iReceiveAnySocket)
       
   131 		User::Leave(KErrNotSupported);
       
   132 
       
   133 	iReceiveAnySocket->Cancel();
       
   134 
       
   135 	TRAPD(err, AddBifWithTypeL(EBioMsgIdNbs, aBioID));
       
   136 
       
   137 	iReceiveAnySocket->SetupL();
       
   138 	iReceiveAnySocket->StartL();
       
   139 
       
   140 	ResetDb();
       
   141 
       
   142 	User::LeaveIfError(err);
       
   143 	}
       
   144 
       
   145 void CNbsWatcher::SetupSpecialWatcherL(TSmsAddrFamily aAddrFamily)
       
   146 	{
       
   147 	CBaseSmsActiveSocketWatcher* nbsWatcher = NULL;
       
   148 
       
   149 	//The following function will leave with KErrNotSupported
       
   150 	//if the CSmsSettings stored against the SMS Service indicates
       
   151 	//that this message type should not be watched
       
   152 
       
   153 	BIOWATCHERLOG(iWatcherLog.Printf(_L8("BioNbs: SetupSpecialWatcher [aAddrFamily=%d]"), aAddrFamily));
       
   154 	__ASSERT_DEBUG(iBioDb, PanicWatcher(EObjectNotConstructed));
       
   155 
       
   156 	TRAPD(error, nbsWatcher = CSpecialNbsSmsSocketWatcher::NewL(iBioServiceId, iSmsServiceId, *iBioDb, iWatcherLog, Priority(), KNullUid, iFs, KNullDesC, aAddrFamily));
       
   157 
       
   158 	if (error == KErrNone)
       
   159 		{
       
   160 		CleanupStack::PushL(nbsWatcher);
       
   161 		error = SetupAndAppendL(*nbsWatcher, *iSocketWatchers); //Returns either KErrNotFound or KErrAlreadyExists, otherwise leaves
       
   162 
       
   163 		if (error != KErrNone)
       
   164 			CleanupStack::PopAndDestroy(nbsWatcher);
       
   165 		else
       
   166 			CleanupStack::Pop(nbsWatcher);
       
   167 		}
       
   168 
       
   169 	if (error != KErrNone)
       
   170 		{
       
   171 		BIOWATCHERLOG(iWatcherLog.Printf(_L8("BioNbs: SetupSpecialWatcher Failed [error=%d]"), error));
       
   172 
       
   173 		if (error == KErrNoMemory)
       
   174 			User::Leave(error);
       
   175 		//else ignore the error
       
   176 		}
       
   177 	}