Index: pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp
===================================================================
--- pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp	(revision 2174)
+++ pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp	(revision 2379)
@@ -38,5 +38,5 @@
 // Account
 //
-#define HAS_SIP_ACCOUNT	1	// 0 to disable registration
+#define HAS_SIP_ACCOUNT	0	// 1 to enable registration
 #define SIP_DOMAIN	"pjsip.lab"
 #define SIP_USER	"400"
@@ -54,6 +54,6 @@
 // or STUN (for STUN see other settings below)
 //
-//#define NAMESERVER	NULL
-#define NAMESERVER	"192.168.0.2"
+#define NAMESERVER	NULL
+//#define NAMESERVER	"192.168.0.2"
 
 //
@@ -250,4 +250,6 @@
 
 
+//#include<e32debug.h>
+
 /* Logging callback */
 static void log_writer(int level, const char *buf, int len)
@@ -260,4 +262,5 @@
 
     TPtrC16 aBuf((const TUint16*)buf16, (TInt)len);
+    //RDebug::Print(aBuf);
     console->Write(aBuf);
     
@@ -436,5 +439,5 @@
 {
 public:
-    ConsoleUI(CActiveSchedulerWait *asw, CConsoleBase *con);
+    ConsoleUI(CConsoleBase *con);
 
     // Run console UI
@@ -452,11 +455,10 @@
     
 private:
-    CActiveSchedulerWait *asw_;
     CConsoleBase *con_;
 };
 
 
-ConsoleUI::ConsoleUI(CActiveSchedulerWait *asw, CConsoleBase *con) 
-: CActive(EPriorityStandard), asw_(asw), con_(con)
+ConsoleUI::ConsoleUI(CConsoleBase *con) 
+: CActive(EPriorityStandard), con_(con)
 {
     CActiveScheduler::Add(this);
@@ -509,5 +511,5 @@
     switch (kc) {
     case 'w':
-	    asw_->AsyncStop();
+	    CActiveScheduler::Stop();
 	    reschedule = PJ_FALSE;
 	    break;
@@ -686,12 +688,55 @@
 #include <es_sock.h>
 
+#if 0
+// Force network connection to use the first IAP, 
+// this is useful for debugging on emulator without GUI. 
+// Include commdb.lib & apengine.lib in symbian_ua.mmp file
+// if this is enabled.
+
+#include <apdatahandler.h>
+
+inline void ForceUseFirstIAP() 
+{
+    TUint32 rank = 1;
+    TUint32 bearers;
+    TUint32 prompt;
+    TUint32 iap;
+
+    CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
+    CleanupStack::PushL(commDb);
+
+    CApDataHandler* apDataHandler = CApDataHandler::NewLC(*commDb);
+    
+    TCommDbConnectionDirection direction = ECommDbConnectionDirectionOutgoing;
+    apDataHandler->GetPreferredIfDbIapTypeL(rank, direction, bearers, prompt, iap);
+    prompt = ECommDbDialogPrefDoNotPrompt;
+    apDataHandler->SetPreferredIfDbIapTypeL(rank, direction, bearers, (TCommDbDialogPref)prompt, iap, ETrue);
+    CleanupStack::PopAndDestroy(2); // apDataHandler, commDb
+}
+
+static void SelectIAP() 
+{
+    ForceUseFirstIAP();
+}
+
+#else
+
+static void SelectIAP() 
+{
+}
+
+#endif
+
+
 ////////////////////////////////////////////////////////////////////////////
 int ua_main() 
 {
-	RSocketServ aSocketServer;
-	RConnection aConn;
-	TInt err;
-	pj_symbianos_params sym_params;
+    RSocketServ aSocketServer;
+    RConnection aConn;
+    TInt err;
+    pj_symbianos_params sym_params;
     pj_status_t status;
+
+    SelectIAP();
     
     // Initialize RSocketServ
@@ -701,6 +746,6 @@
     // Open up a connection
     if ((err=aConn.Open(aSocketServer)) != KErrNone) {
-	    aSocketServer.Close();
-		return PJ_STATUS_FROM_OS(err);
+	aSocketServer.Close();
+	return PJ_STATUS_FROM_OS(err);
     }
     
@@ -723,23 +768,21 @@
     	aConn.Close();
     	aSocketServer.Close();
-	    return status;
+	return status;
     }
 
     // Run the UI
-    CActiveSchedulerWait *asw = new CActiveSchedulerWait;
-    ConsoleUI *con = new ConsoleUI(asw, console);
+    ConsoleUI *con = new ConsoleUI(console);
     
     con->Run();
-    
     PrintMenu();
-    asw->Start();
+
+    CActiveScheduler::Start();
     
     delete con;
-    delete asw;
 
     // Dump memory statistics
     PJ_LOG(3,(THIS_FILE, "Max heap usage: %u.%03uMB",
-    		  pjsua_var.cp.peak_used_size / 1000000,
-    		  (pjsua_var.cp.peak_used_size % 1000000)/1000));
+	      pjsua_var.cp.peak_used_size / 1000000,
+	      (pjsua_var.cp.peak_used_size % 1000000)/1000));
     
     // check max stack usage
@@ -747,5 +790,5 @@
 	pj_thread_t* this_thread = pj_thread_this();
 	if (!this_thread)
-		return status;
+	    return status;
 	
 	const char* max_stack_file;
@@ -754,6 +797,6 @@
 	
 	PJ_LOG(3,(THIS_FILE, "Max stack usage: %u at %s:%d", 
-			pj_thread_get_stack_max_usage(this_thread), 
-			max_stack_file, max_stack_line));
+		  pj_thread_get_stack_max_usage(this_thread), 
+		  max_stack_file, max_stack_line));
 #endif
 	
@@ -763,5 +806,5 @@
     // Close connection and socket server
     aConn.Close();
-	aSocketServer.Close();
+    aSocketServer.Close();
 	
     return status;
