cbsref/telephonyrefplugins/atltsy/atcommand/generic/src/unsolicitedeventmonitor.cpp
branchRCL_3
changeset 65 630d2f34d719
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
       
     1 // Copyright (c) 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 contains CUnsolicitedEventMonitor which mornitor the arriving unsocilited event and then notify this to all observers.
       
    15 // 
       
    16 
       
    17 //user include
       
    18 #include "unsolicitedeventmonitor.h"
       
    19 #include "atunsolicited.h"
       
    20 #include "mslogger.h"
       
    21 #include "atmanager.h"
       
    22 #include "activecommandstore.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // CUnsolicitedEventMonitor::NewL
       
    26 // other items were commented in a header
       
    27 // ---------------------------------------------------------------------------
       
    28 CUnsolicitedEventMonitor* CUnsolicitedEventMonitor::NewL(CGlobalPhonemanager& aPhoneglobals,
       
    29 										    CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    30 	{
       
    31 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::NewL()"));
       
    32 	CUnsolicitedEventMonitor* self = CUnsolicitedEventMonitor::NewLC(aPhoneglobals, aCtsyDispatcherCallback);
       
    33 	CleanupStack::Pop(self);
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CUnsolicitedEventMonitor::NewLC
       
    39 // other items were commented in a header
       
    40 // ---------------------------------------------------------------------------
       
    41 CUnsolicitedEventMonitor* CUnsolicitedEventMonitor::NewLC(CGlobalPhonemanager& aPhoneglobals,
       
    42 											CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    43 	{
       
    44 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::NewLC()"));
       
    45 	CUnsolicitedEventMonitor* self = new (ELeave) CUnsolicitedEventMonitor(aPhoneglobals, 
       
    46 																 aCtsyDispatcherCallback);
       
    47 	CleanupStack::PushL(self);
       
    48 	self->ConstructL();
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CUnsolicitedEventMonitor::~CUnsolicitedEventMonitor
       
    54 // other items were commented in a header
       
    55 // ---------------------------------------------------------------------------
       
    56 CUnsolicitedEventMonitor::~CUnsolicitedEventMonitor()
       
    57 	{
       
    58 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::~CUnsolicitedEventMonitor()"));
       
    59 	iArray.Close();
       
    60 	}
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CUnsolicitedEventMonitor::CUnsolicitedEventMonitor
       
    64 // other items were commented in a header
       
    65 // ---------------------------------------------------------------------------
       
    66 CUnsolicitedEventMonitor::CUnsolicitedEventMonitor(CGlobalPhonemanager& aPhoneglobals,
       
    67 		                             CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    68 						             :CATCommandControlBase(aPhoneglobals, aCtsyDispatcherCallback)
       
    69 	{
       
    70 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::CUnsolicitedEventMonitor()"));
       
    71 	}
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CUnsolicitedEventMonitor::ConstructL
       
    75 // other items were commented in a header
       
    76 // ---------------------------------------------------------------------------
       
    77 void CUnsolicitedEventMonitor::ConstructL()
       
    78 	{
       
    79 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::ConstructL()"));
       
    80 	
       
    81 	CATUnsolicited* command = CATUnsolicited::NewL(iPhoneGlobals, iCtsyDispatcherCallback);
       
    82 	command->SetAtCommandObserver(this);
       
    83 	AddAtCommand(command);
       
    84 	}
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CUnsolicitedEventMonitor::AddUnsolicitedObserver
       
    88 // other items were commented in a header
       
    89 // ---------------------------------------------------------------------------
       
    90 void CUnsolicitedEventMonitor::AddUnsolicitedObserver(const MLtsyUnsolicitedCommandObserver* aObserver)
       
    91 	{
       
    92 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::AddUnsolicitedObserver()"));
       
    93 	
       
    94 	if (aObserver != NULL)
       
    95 		{
       
    96 		TInt nRes = iArray.Append(aObserver);
       
    97 		if (nRes == KErrNone)
       
    98 			{
       
    99 			LOGTEXT(_L8("[Ltsy] Append unsolicited Observer Success"));
       
   100 			}
       
   101 		else
       
   102 			{
       
   103 			LOGTEXT2(_L8("[Ltsy] Append unsolicited Observer fail Because result code = %d"), nRes);
       
   104 			}
       
   105 		}
       
   106 	else
       
   107 		{
       
   108 		LOGTEXT(_L8("[Ltsy] Unsolicited observer is NULL"));
       
   109 		}
       
   110 	}
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CUnsolicitedEventMonitor::RemoveUnsolicitedObserver
       
   114 // other items were commented in a header
       
   115 // ---------------------------------------------------------------------------
       
   116 void CUnsolicitedEventMonitor::RemoveUnsolicitedObserver(const MLtsyUnsolicitedCommandObserver* aObserver)
       
   117 	{
       
   118 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::RemoveUnsolicitedObserver()"));
       
   119 	if (aObserver != NULL)
       
   120 		{
       
   121 		TInt nFound = iArray.Find(aObserver);
       
   122 		if (KErrNotFound != nFound)
       
   123 			{
       
   124 			LOGTEXT(_L8("[Ltsy] Array have removed observer"));
       
   125 			iArray.Remove(nFound);
       
   126 			}
       
   127 		else
       
   128 			{
       
   129 			LOGTEXT(_L8("[Ltsy] Array not found observer"));
       
   130 			}
       
   131 		}
       
   132 	else
       
   133 		{
       
   134 		LOGTEXT(_L8("[Ltsy] Wind Observer is NULL"));
       
   135 		}
       
   136 	}
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CUnsolicitedEventMonitor::NotifyEveryObserver
       
   140 // other items were commented in a header
       
   141 // ---------------------------------------------------------------------------
       
   142 void CUnsolicitedEventMonitor::NotifyEveryObserver()
       
   143 	{
       
   144 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::NotifyEveryObserver()"));
       
   145 	
       
   146 	CAtCommandBase *cAtBase(NULL);
       
   147 	TRAPD(err, cAtBase = &GetAtCommandByAtTypeL(ELtsyAT_General_WIND));
       
   148 	if (err == KErrNoMemory)
       
   149 		{
       
   150 		return;
       
   151 		}
       
   152 	
       
   153 	CATUnsolicited*  unsolicited = dynamic_cast<CATUnsolicited*>(cAtBase);
       
   154 	if (unsolicited == NULL)
       
   155 		{
       
   156 		LOGTEXT(_L8("[Ltsy] Dynamic cast class CAtCommandBase to class CATUnsolicited failing"));
       
   157 		return;
       
   158 		}
       
   159 	
       
   160 	if (unsolicited->GetParserResult() != KErrNone)
       
   161 		{
       
   162 		LOGTEXT(_L8("[Ltsy] parse unsolicited command error"));
       
   163 		return;
       
   164 		}
       
   165 	
       
   166 	TUnsolicitedParams::TUnsolicitedParamsPckgBuf* pckg = (TUnsolicitedParams::TUnsolicitedParamsPckgBuf*)(&(unsolicited->GetUnsolicitedParams()));
       
   167 	TInt nEvent = (*pckg)().iEvent;
       
   168 	
       
   169 	TInt count = iArray.Count();
       
   170 	for (TInt n = 0; n < count;  n++)
       
   171 		{
       
   172 		MLtsyUnsolicitedCommandObserver* observer = iArray[n];
       
   173 		observer->UnsolicitedCommandArriving(nEvent, (*pckg));
       
   174 		}
       
   175 	}
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CUnsolicitedEventMonitor::StartUnsolicitedObserver
       
   179 // other items were commented in a header
       
   180 // ---------------------------------------------------------------------------
       
   181 void CUnsolicitedEventMonitor::StartUnsolicitedObserver()
       
   182 	{
       
   183 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::NotifyEveryObserver()"));
       
   184 	
       
   185 	CAtCommandBase *cAtBase(NULL);
       
   186 	TRAPD(err, cAtBase = &GetAtCommandByAtTypeL(ELtsyAT_General_WIND));
       
   187 	if (err == KErrNoMemory)
       
   188 		{
       
   189 		return;
       
   190 		}
       
   191 	
       
   192 	iPhoneGlobals.iAtManager->GetActiveCommandStore()->AddUnsolicitedAtCommand(cAtBase);
       
   193 	}
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CUnsolicitedEventMonitor::StopUnsolicitedObserver
       
   197 // other items were commented in a header
       
   198 // ---------------------------------------------------------------------------
       
   199 void CUnsolicitedEventMonitor::StopUnsolicitedObserver()
       
   200 	{
       
   201 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::StopUnsolicitedObserver()"));
       
   202 	
       
   203 	CAtCommandBase *cAtBase(NULL);
       
   204 	TRAPD(err, cAtBase = &GetAtCommandByAtTypeL(ELtsyAT_General_WIND));
       
   205 	if (err == KErrNoMemory)
       
   206 		{
       
   207 		return;
       
   208 		}
       
   209 	
       
   210 	iPhoneGlobals.iAtManager->GetActiveCommandStore()->RemoveActiveAtCommand(cAtBase);
       
   211 	}
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CUnsolicitedEventMonitor::AtCommandExecuteComplete
       
   215 // other items were commented in a header
       
   216 // ---------------------------------------------------------------------------
       
   217 void CUnsolicitedEventMonitor::AtCommandExecuteComplete(TAtEventSource /*aEventSource*/, TInt aStatus)
       
   218 	{
       
   219 	LOGTEXT(_L8("[Ltsy] Starting CUnsolicitedEventMonitor::AtCommandExecuteComplete()"));
       
   220 	if (aStatus == KErrNone)
       
   221 		{
       
   222 		NotifyEveryObserver();
       
   223 		}
       
   224 	
       
   225 	CAtCommandBase *cAtBase(NULL);
       
   226 	TRAPD(err, cAtBase = &GetAtCommandByAtTypeL(ELtsyAT_General_WIND));
       
   227 	if (err == KErrNoMemory)
       
   228 		{
       
   229 		return;
       
   230 		}
       
   231 	
       
   232 	cAtBase->ClearCurrentLine();
       
   233 	
       
   234 	LOGTEXT(_L8("[Ltsy] End CUnsolicitedEventMonitor::AtCommandExecuteComplete()"));
       
   235 	}
       
   236 
       
   237 //End of file