datacommsserver/networkingdialogapi/agentnotifier/src/agentshellnotifier.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2003-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 <e32cons.h>
       
    17 
       
    18 #include <es_sock.h>
       
    19 
       
    20 #include "agentnotifierdefs.h"
       
    21 #include "agentshellnotifier.h"
       
    22 
       
    23 EXPORT_C CArrayPtr<MNotifierBase2>* NotifierArray()
       
    24 //
       
    25 // Lib main entry point
       
    26 //
       
    27 	{
       
    28 	CArrayPtrFlat<MNotifierBase2>* subjects=new (ELeave)CArrayPtrFlat<MNotifierBase2>(1);
       
    29 	CleanupStack::PushL(subjects);
       
    30 	subjects->AppendL(CAgentShellNotifier::NewL());
       
    31 	CleanupStack::Pop();//subjects
       
    32 	return(subjects);
       
    33 	}
       
    34 
       
    35 
       
    36 
       
    37 const TInt KAgentDialogWidth=38;
       
    38 const TInt KAgentDialogHeight=4;
       
    39 __FLOG_STMT(_LIT8(KDlgLogSubsys, "agentdialog");)
       
    40 __FLOG_STMT(_LIT8(KDlgLogComponent, "notifier");)
       
    41 
       
    42 CAgentDialogUpdate* CAgentDialogUpdate::NewL(const RMessagePtr2& aMessage)
       
    43 	{
       
    44 	CAgentDialogUpdate* self=new (ELeave) CAgentDialogUpdate(aMessage);
       
    45 	CleanupStack::PushL(self);
       
    46 	self->ConstructL(aMessage);
       
    47 	CleanupStack::Pop();
       
    48 	return self;
       
    49 	}
       
    50 	
       
    51 void CAgentDialogUpdate::Update(const RMessagePtr2& aMessage)
       
    52 	{
       
    53 	__FLOG(_L("CAgentDialogUpdate::Update Starting Agent Shell Dialog"));
       
    54 	iMessagePtr = aMessage;
       
    55 	TAgentDialogInputBuf agentDialogInputBuf;
       
    56 	aMessage.ReadL(1, agentDialogInputBuf);
       
    57 	TAgentDialogInput& agentdialogInput = agentDialogInputBuf();
       
    58 
       
    59 	iConsole->ClearScreen();
       
    60 	iConsole->SetTitle(agentdialogInput.iTitle);
       
    61 
       
    62 	TBuf<KAgentDialogWidth> buf1;
       
    63 	TBuf<KAgentDialogWidth> buf2;
       
    64 	buf1.Append(agentdialogInput.iLabel);
       
    65 	if(buf1.Length() >= 44 )
       
    66 	{
       
    67 		buf1.SetLength(40);
       
    68 		buf1.AppendFill('*',3);
       
    69 	}
       
    70 	buf1.Append(' ');
       
    71 
       
    72 	_LIT(KYesNoChoice, "Yes [y] No [n] Cancel[c]");
       
    73 	_LIT(KContinuePrompt, "Continue Yes [y]");
       
    74 
       
    75 	TInt operation = agentdialogInput.getDialogOperation();    
       
    76 	switch ( operation )
       
    77 		{
       
    78 		case ENoYesDialog:
       
    79 			buf2.Append(KYesNoChoice);
       
    80 			break;
       
    81 		case EContinueDialog:
       
    82 			buf2.Append(KContinuePrompt);
       
    83 			break;
       
    84 		default:
       
    85 		__ASSERT_DEBUG(EFalse, _L("Illegal Agent UI operation type"));
       
    86 		}
       
    87 
       
    88 	TPoint point;
       
    89 	TInt x = (iConsole->ScreenSize().iWidth - buf1.Length()) / 2; // put the string in the middle
       
    90 	point.SetXY(x, 0);
       
    91 	iConsole->SetCursorPosAbs(point);
       
    92 
       
    93 	iConsole->Printf(buf1);
       
    94 	x = (iConsole->ScreenSize().iWidth - buf2.Length()) / 2; // put the string in the middle
       
    95 	point.SetXY(x, 1);
       
    96 	iConsole->SetCursorPosAbs(point);
       
    97 	iConsole->Printf(buf2);
       
    98 	}
       
    99 	
       
   100 void CAgentDialogUpdate::DoCancel()
       
   101 	{
       
   102 	if (IsActive())
       
   103 		{
       
   104 		if (!iMessagePtr.IsNull())
       
   105 			{
       
   106 			iMessagePtr.Complete(KErrCancel);
       
   107 			}
       
   108 		iConsole->ReadCancel();
       
   109 		iConsole->Printf(_L("\ndialog cancelled.\nPress any key to continue...\n"));
       
   110 		}
       
   111 
       
   112 	}
       
   113 
       
   114 void CAgentDialogUpdate::RunL()
       
   115 	{
       
   116 	TInt key = iConsole->KeyCode();
       
   117 	__FLOG_1(_L("KeyPressed : %c"),key);
       
   118 	switch (key)
       
   119 		{
       
   120 		case 'y':
       
   121 		case 'Y':
       
   122 			iMessagePtr.Complete(EAgentYesPressed);
       
   123 			break;
       
   124 		case 'n':
       
   125 		case 'N':
       
   126 			iMessagePtr.Complete(EAgentNoPressed);
       
   127 			break;
       
   128 		case 'c':
       
   129 		case 'C':
       
   130 			iMessagePtr.Complete(KErrCancel);
       
   131 			break;
       
   132 		default:
       
   133 			iConsole->Printf(_L("\n Press 'y' 'n' or 'c'\n"));
       
   134 			iConsole->Read(iStatus);
       
   135 			SetActive();
       
   136 		}
       
   137 	}
       
   138 
       
   139 CAgentDialogUpdate::CAgentDialogUpdate(const RMessagePtr2& aMessage)
       
   140 :	CActive(EPriorityStandard),
       
   141 	iMessagePtr(aMessage)
       
   142 	{
       
   143 	__FLOG_OPEN(KDlgLogSubsys, KDlgLogComponent);
       
   144 	}
       
   145 
       
   146 void CAgentDialogUpdate::ConstructL(const RMessagePtr2& /*aMessage*/)
       
   147 	{
       
   148 	TRAPD(r,iConsole = Console::NewL(_L("AgentDialog"), TSize(KAgentDialogWidth,KAgentDialogHeight)));
       
   149 	__FLOG_1(_L("CAgentDialogUpdate::ConstructL - Console::NewL returned %d"),r);
       
   150 	
       
   151 	if (r < KErrNone) //So why not User::LeaveIfError - well Console::NewL is know to return 2
       
   152 		{
       
   153 		User::Leave(r);
       
   154 		}
       
   155 		if (iConsole == NULL)
       
   156 		{
       
   157 		User::Leave(KErrGeneral);
       
   158 		}
       
   159 	CActiveScheduler::Add(this);
       
   160 
       
   161 	// Read back the response
       
   162 	iConsole->Read(iStatus);
       
   163 	SetActive();
       
   164 	__FLOG_1(_L("Performed read for response should still be KRequestPending - %x"),iStatus.Int());
       
   165 
       
   166 	}
       
   167 
       
   168 CAgentDialogUpdate::~CAgentDialogUpdate()
       
   169 	{
       
   170 	Cancel();
       
   171 	delete iConsole;
       
   172 	__FLOG_CLOSE;
       
   173 	}
       
   174 	
       
   175 
       
   176 
       
   177 CAgentShellNotifier* CAgentShellNotifier::NewL()
       
   178 	{
       
   179 	CAgentShellNotifier* self=new (ELeave) CAgentShellNotifier();
       
   180 	CleanupStack::PushL(self);
       
   181 	self->ConstructL();
       
   182 	CleanupStack::Pop();
       
   183 	return self;
       
   184 	}
       
   185 	
       
   186 void CAgentShellNotifier::ConstructL()
       
   187 	{
       
   188 	}
       
   189 
       
   190 CAgentShellNotifier::~CAgentShellNotifier()
       
   191 	{
       
   192 	delete iAgentShellDialog;
       
   193 	}
       
   194 	//	From MNotifierBase
       
   195 
       
   196 void CAgentShellNotifier::Release()
       
   197 	{
       
   198 	delete this;
       
   199 	}
       
   200 
       
   201 CAgentShellNotifier::TNotifierInfo CAgentShellNotifier::RegisterL()
       
   202 	/**
       
   203 	 * Called when a notifier is first loaded to allow any initial construction that is required.
       
   204 	 */
       
   205 	{
       
   206 	iInfo.iUid=KUidAgentDialogNotifier;
       
   207 	iInfo.iChannel=KUidAgentDialogNotifier;
       
   208 	iInfo.iPriority=ENotifierPriorityLow;
       
   209 	return iInfo;
       
   210 	}
       
   211 
       
   212 CAgentShellNotifier::TNotifierInfo CAgentShellNotifier::Info() const
       
   213 	/**
       
   214 	 * Start the notifier with data aBuffer and return an initial response.
       
   215 	 */
       
   216 	{
       
   217 	return iInfo;
       
   218 	}
       
   219 
       
   220 TPtrC8 CAgentShellNotifier::StartL(const TDesC8& /*aBuffer*/)
       
   221 	/**
       
   222 	 * Start the notifier with data aBuffer.  aMessage should be completed when the notifier is deactivated.
       
   223 	 * May be called multiple times if more than one client starts the notifier.  The notifier is immediately
       
   224 	 * responsible for completing aMessage.
       
   225 	 */
       
   226 	{
       
   227 	TPtrC8 ret(KNullDesC8);
       
   228 	return (ret);
       
   229 	}
       
   230 	
       
   231 void CAgentShellNotifier::StartL(const TDesC8& /*aBuffer*/, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   232 	/**
       
   233 	 * Start the notifier with data aBuffer.  aMessage should be completed when the notifier is deactivated.
       
   234 	 * May be called multiple times if more than one client starts the notifier.  The notifier is immediately
       
   235 	 * responsible for completing aMessage.
       
   236 	 */
       
   237 	{
       
   238 	//	Keep this short! Must schedule an update and return immediately
       
   239 	if (!aMessage.IsNull())
       
   240 		{
       
   241 		if (iAgentShellDialog)
       
   242 			{
       
   243 			delete iAgentShellDialog;
       
   244 			iAgentShellDialog = NULL;
       
   245 			}
       
   246 		iAgentShellDialog = CAgentDialogUpdate::NewL(aMessage);
       
   247 
       
   248 		iAgentShellDialog->Update(aMessage);
       
   249 		}
       
   250 	}
       
   251 
       
   252 
       
   253 void CAgentShellNotifier::Cancel()
       
   254 	/**
       
   255 	 * The notifier has been deactivated so resources can be freed and outstanding messages completed.
       
   256 	 */
       
   257 	{
       
   258 	if (iAgentShellDialog)
       
   259 		{
       
   260 		iAgentShellDialog->Cancel();
       
   261 		delete iAgentShellDialog;
       
   262 		iAgentShellDialog=NULL;
       
   263 		}
       
   264 	}
       
   265 
       
   266 TPtrC8 CAgentShellNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   267 	/**
       
   268 	 * Update a currently active notifier with data aBuffer.
       
   269 	 */
       
   270 	{
       
   271 	//	Keep this short! Must schedule an update and return immediately
       
   272 	TPtrC8 ret(KNullDesC8);
       
   273 	return (ret);
       
   274 	}
       
   275 
       
   276 
       
   277