tcpiputils/dnd/src/dndexe.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2004-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 // dnd.cpp - name resolver daemon main module
       
    15 //
       
    16 
       
    17 #include "demon.h"
       
    18 #include "inet6log.h"
       
    19 #include <cflog.h>
       
    20 
       
    21 //Logging name for the DND
       
    22 #define DND_COMPNAME "dnd"
       
    23 
       
    24 //
       
    25 // class CDndMain
       
    26 //
       
    27 class CDndMain : public CBase, public MDemonMain
       
    28     {
       
    29 public:
       
    30 	~CDndMain();
       
    31 	void ConstructL();
       
    32 	void Write(const TDesC &aDes);
       
    33 	void WriteList(const TDesC &aFmt, VA_LIST aList);
       
    34 	TInt CheckResult(const TDesC &aText, TInt aResult);
       
    35 	
       
    36 	MDemonEngine *iModel;
       
    37 
       
    38 
       
    39 private:
       
    40 #ifdef _LOG
       
    41 	TBuf<1024> iBuf;	//< A work buffer for formatting messages (WriteList)
       
    42 #endif
       
    43  __CFLOG_DECLARATION_MEMBER;
       
    44    };
       
    45 
       
    46 
       
    47 // **************
       
    48 // "Main Program"
       
    49 // **************
       
    50 //
       
    51 
       
    52 
       
    53 CDndMain::~CDndMain()
       
    54 	{
       
    55 	delete iModel;
       
    56 	 __CFLOG_CLOSE;
       
    57   	 __CFLOG_DELETE;
       
    58 	}
       
    59     
       
    60 
       
    61 void CDndMain::ConstructL()
       
    62 	{
       
    63 	__CFLOG_CREATEL;
       
    64   	__CFLOG_OPEN;
       
    65 	iModel = MDemonEngine::NewL(*this);
       
    66 	iModel->ConstructL();
       
    67 	}
       
    68 
       
    69 
       
    70 void CDndMain::Write(const TDesC &aMsg)
       
    71 	{
       
    72 #ifndef _LOG
       
    73 	(void)aMsg;	// ..just to silence compiler warning
       
    74 #else
       
    75 	Log::Write(aMsg);
       
    76 #endif
       
    77 	}
       
    78 
       
    79 void CDndMain::WriteList(const TDesC &aFmt, VA_LIST aList)
       
    80 	{
       
    81 #ifndef _LOG
       
    82 	(void)aFmt;	// ..just to silence compiler warning
       
    83 	(void)aList;
       
    84 #else
       
    85 	iBuf.FormatList(aFmt, aList);
       
    86 	Log::Write(iBuf);
       
    87 #endif
       
    88 	}
       
    89 
       
    90 TInt CDndMain::CheckResult(const TDesC &/*aText*/, TInt aResult)
       
    91 	{
       
    92 	return aResult;
       
    93 	}
       
    94 
       
    95 static void DaemonL()
       
    96 	{
       
    97 	CDndMain *main = new (ELeave) CDndMain;
       
    98 	CleanupStack::PushL(main);
       
    99 	CActiveScheduler::Install(new (ELeave) CActiveScheduler);
       
   100 	main->ConstructL();
       
   101 	CActiveScheduler::Start();
       
   102 	CleanupStack::PopAndDestroy();
       
   103 	delete CActiveScheduler::Current();
       
   104 	}
       
   105 
       
   106 #ifdef __DLL__
       
   107 GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
       
   108 	{
       
   109 	return(KErrNone);
       
   110 	}
       
   111 #endif
       
   112 
       
   113 EXPORT_C TInt E32Main()
       
   114 	{
       
   115 	_LIT(KDnd,"DND");
       
   116 	(void)RThread::RenameMe(KDnd);
       
   117 	CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
       
   118 	TRAPD(error, DaemonL());
       
   119 	delete cleanup; // destroy clean-up stack
       
   120 	__ASSERT_ALWAYS(!error,User::Panic(KDnd,error));
       
   121 	return KErrNone;
       
   122 	}