networkprotocols/dnsproxy/dnsproxyserver/src/dnsproxyserver.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2008-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 // Source file for the DNS Proxy server side implementation.
       
    15 // DNS Proxy client session handler code.
       
    16 //
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent
       
    23 */
       
    24 
       
    25 #include "dnsproxyserver.h"
       
    26 #include "dnsproxysession.h"
       
    27 #include "dnsproxyclientconfigparams.h"
       
    28 //debug print
       
    29 #include <e32debug.h>
       
    30 #include "dnsproxylog.h"
       
    31 
       
    32 #ifdef SYMBIAN_NETWORKING_PLATSEC
       
    33 #include "dnsproxypolicy.h"
       
    34 #endif
       
    35 
       
    36 
       
    37 #ifdef SYMBIAN_NETWORKING_PLATSEC
       
    38 CDnsProxyServer::CDnsProxyServer(): CPolicyServer(EPriorityStandard,Policy,ESharableSessions), iCount(0)
       
    39 #elif defined(EKA2)
       
    40 CDnsProxyServer::CDnsProxyServer(): CServer2(EPriorityStandard), iCount(0)
       
    41 #else
       
    42 //On  EKA1, session is open in one thread and used in another
       
    43 CDnsProxyServer::CDnsProxyServer(): CServer2(EPriorityStandard, ESharableSessions), iCount(0)
       
    44 #endif
       
    45 /**
       
    46  * The CDnsProxyServer::CDnsProxyServer method
       
    47  *
       
    48  * Constructor
       
    49  *
       
    50  * @internalComponent
       
    51  */
       
    52     {
       
    53     __LOG("CDnsProxyServer::CDnsProxyServer Entry/Exit")
       
    54     }
       
    55 
       
    56 CDnsProxyServer::~CDnsProxyServer()
       
    57     {
       
    58     __LOG("CDnsProxyServer::~CDnsProxyServer Entry/Exit")
       
    59 
       
    60 	}
       
    61 
       
    62 CDnsProxyServer* CDnsProxyServer::NewL()
       
    63 /**
       
    64  * Creates an instance of DNS Proxy server class
       
    65  * @param - None
       
    66  * @return - None
       
    67  *
       
    68  * @internalTechnology
       
    69  **/
       
    70     {
       
    71     __LOG("\n CDnsProxyServer::NewL Entry\n");
       
    72     CDnsProxyServer* self = new(ELeave) CDnsProxyServer;
       
    73     self->Start(KServerName);
       
    74     __LOG("\n CDnsProxyServer::NewL Exit\n");
       
    75     return self;
       
    76     }
       
    77 
       
    78 CSession2* CDnsProxyServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMessage*/) const
       
    79 /**
       
    80  * Starts server session object.
       
    81  * @param aVersion
       
    82  * @param aMessage
       
    83  * @return - None
       
    84  *
       
    85  * @internalTechnology
       
    86  **/
       
    87     {
       
    88     __LOG("\n CDnsProxyServer::NewSessionL Entry \n");
       
    89     CDnsProxyServerSession* dnssession = CDnsProxyServerSession::NewL();
       
    90     if(dnssession)
       
    91     	{
       
    92     	const_cast<CDnsProxyServer*>(this)->iCount++;
       
    93     	}
       
    94     return dnssession;
       
    95     }
       
    96 
       
    97 /**
       
    98  * Starts server session object.
       
    99  * @param aVersion
       
   100  * @param aMessage
       
   101  * @return - None
       
   102  *
       
   103  * @internalTechnology
       
   104  **/
       
   105 void CDnsProxyServer::DecreaseSessionCount(CDnsProxyServerSession& aSession)const
       
   106     {
       
   107     __LOG("\n CDnsProxyServer::DecreseSession Entry\n");
       
   108     const_cast<CDnsProxyServer*>(this)->iCount--;
       
   109     __LOG1("\n CDnsProxyServer::DecreseSession session count = %d\n",iCount);
       
   110     if(0 == iCount)
       
   111         {
       
   112         aSession.StopDNSEngine();
       
   113         __LOG("\n *** cout zero stoping scheduler ***\n");
       
   114         CActiveScheduler::Stop();
       
   115         }
       
   116     __LOG("\n CDnsProxyServer::DecreseSession Exit\n");
       
   117     }
       
   118 
       
   119 static void RunTheServerL()
       
   120 /**
       
   121  * This method implements the CServer2 method and runs the server.
       
   122  * @param - None
       
   123  * @return - None
       
   124  *
       
   125  * @internalTechnology
       
   126  **/
       
   127     {
       
   128     __LOG("\n RunTheServerL \n");
       
   129     //create and install the active scheduler
       
   130     CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
   131     CleanupStack::PushL(scheduler);
       
   132     CActiveScheduler::Install(scheduler);
       
   133 
       
   134     //create the dns proxy server
       
   135     CDnsProxyServer *server = CDnsProxyServer::NewL();
       
   136     CleanupStack::PushL(server);
       
   137     //naming the server thread after the server start. This helps to debug panics.
       
   138     User::LeaveIfError(User::RenameThread(KServerExeName));
       
   139     RProcess::Rendezvous(KErrNone);
       
   140     //enter the wait loop
       
   141     CActiveScheduler::Start();
       
   142     __LOG("\n after start CActiveScheduler::Start \n");
       
   143     CleanupStack::PopAndDestroy(server);
       
   144     CleanupStack::PopAndDestroy(scheduler);
       
   145     __LOG("RunTheServerL Exit")
       
   146     }
       
   147 
       
   148 
       
   149 // Server process entry-point
       
   150 TInt E32Main()
       
   151 /**
       
   152  * The main thread function, the Ordinal 1!
       
   153  * @return - Standard Epoc error code on exit
       
   154  */
       
   155     {
       
   156     __UHEAP_MARK; // Heap checking
       
   157 
       
   158     CTrapCleanup* cleanup=CTrapCleanup::New();
       
   159     TInt r=KErrNoMemory;
       
   160     if (cleanup)
       
   161         {
       
   162         TRAP(r,RunTheServerL());
       
   163         delete cleanup;
       
   164         }
       
   165     __UHEAP_MARKEND;
       
   166     return r;
       
   167     }
       
   168