syncmlfw/common/sosserver/src/nsmlsosserver.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Symbian OS Server source.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h>
       
    20 #include <e32math.h>
       
    21 
       
    22 #include <nsmldebug.h>
       
    23 #include "nsmlsosserver.h"
       
    24 
       
    25 GLDEF_C TInt E32Main() // main function called by E32
       
    26 	{
       
    27     return LaunchServer();
       
    28 	}
       
    29 
       
    30 // --------------------------------------------------------------------------
       
    31 // EXPORT_C TInt LaunchServer()
       
    32 // --------------------------------------------------------------------------
       
    33 //
       
    34 TInt LaunchServer()
       
    35     {
       
    36     // check server not already started
       
    37 	TFindServer findSOSServer( KSOSServerName );
       
    38 	TFullName name;
       
    39 	if ( findSOSServer.Next(name) == KErrNone )
       
    40 		{ // found server already 
       
    41 		return KErrGeneral;
       
    42 		}
       
    43 
       
    44 	// create server thread
       
    45 	RSemaphore signal;
       
    46     signal.CreateLocal(0);
       
    47 
       
    48 	// randomize server thread's name
       
    49     TName threadName( KSOSServerThread );
       
    50     threadName.AppendNum( Math::Random(), EHex );
       
    51     
       
    52     RThread thread;
       
    53 	TInt res = thread.Create( threadName, // name of thread
       
    54 		                      CNSmlSOSServer::ThreadFunction, // thread function
       
    55 		                      KDefaultStackSize, NULL,
       
    56 		                      &signal ); // parameter to thread function
       
    57 		
       
    58 	if ( res != KErrNone )
       
    59 		{
       
    60 		thread.Close();
       
    61 		return res;
       
    62 		}
       
    63 	// start thread
       
    64 	thread.SetPriority(EPriorityMuchMore); // set priority
       
    65 	thread.Resume(); 
       
    66     thread.Close();
       
    67     signal.Wait(); 
       
    68     signal.Close();
       
    69 
       
    70     return res;
       
    71     }
       
    72 
       
    73 // --------------------------------------------------------------------------
       
    74 // void CNSmlSOSServer::PanicServer( TNSmlSOSServerPanic aPanic )
       
    75 // --------------------------------------------------------------------------
       
    76 //
       
    77 void CNSmlSOSServer::PanicServer( TNSmlSOSServerPanic aPanic )
       
    78     {
       
    79 	_LIT(KTxtSOSServer,"SOSServer");
       
    80 	User::Panic(KTxtSOSServer,aPanic);
       
    81     }
       
    82 
       
    83 // --------------------------------------------------------------------------
       
    84 // TInt CNSmlSOSServer::ThreadFunction(TAny* aStarted)
       
    85 // --------------------------------------------------------------------------
       
    86 //
       
    87 TInt CNSmlSOSServer::ThreadFunction( TAny* aStarted )
       
    88 	{
       
    89 #ifdef __CLIENT_API_MT_
       
    90     __UHEAP_MARK;
       
    91 #endif // __CLIENT_API_MT_
       
    92 
       
    93 	// create cleanup stack
       
    94     CTrapCleanup* cleanup = CTrapCleanup::New();
       
    95 	if ( !cleanup )
       
    96 	    {
       
    97 	    PanicServer(ECleanupCreateError);
       
    98 	    }    
       
    99 	    
       
   100 	DBG_BEGIN();
       
   101 	_DBG_FILE("CNSmlSOSServer::ThreadFunction(): CleanupStack created.");
       
   102 	    
       
   103 	// convert argument to semaphore
       
   104 	RSemaphore& started= *(RSemaphore*) aStarted;
       
   105 	
       
   106 	// construct and install active scheduler
       
   107 	CActiveScheduler* scheduler = new CActiveScheduler;
       
   108 	__ASSERT_ALWAYS( scheduler,PanicServer(EMainSchedulerError) );
       
   109 	CActiveScheduler::Install( scheduler );
       
   110 
       
   111 	// construct server
       
   112     CNSmlSOSServer* server = NULL;
       
   113     TRAPD( err, server = CNSmlSOSServer::NewL());
       
   114 
       
   115 	RProcess::Rendezvous( err );
       
   116 
       
   117 	// start handling requests
       
   118 	CActiveScheduler::Start();
       
   119 	
       
   120     started.Signal();
       
   121 	
       
   122 	_DBG_FILE("CNSmlSOSServer::ThreadFunction(): CActiveScheduler stopped");
       
   123 
       
   124     delete server;
       
   125     delete scheduler;    
       
   126     delete cleanup;
       
   127 
       
   128 #ifdef __CLIENT_API_MT_
       
   129     __UHEAP_MARKEND;
       
   130 #endif // __CLIENT_API_MT_
       
   131 	
       
   132     return err;
       
   133 	}
       
   134 
       
   135 // --------------------------------------------------------------------------
       
   136 // CNSmlSOSServer* CNSmlSOSServer::NewL()
       
   137 // --------------------------------------------------------------------------
       
   138 //
       
   139 CNSmlSOSServer* CNSmlSOSServer::NewL()
       
   140 	{
       
   141 	_DBG_FILE("CNSmlSOSServer::NewL(): begin");
       
   142 	
       
   143 	CNSmlSOSServer* self = new (ELeave) CNSmlSOSServer();
       
   144 	CleanupStack::PushL(self);
       
   145     self->ConstructL();
       
   146 	self->StartL(KSOSServerName);
       
   147     CleanupStack::Pop(); // self
       
   148 
       
   149 	_DBG_FILE("CNSmlSOSServer::NewL(): end");
       
   150 	
       
   151 	return self;
       
   152 	}
       
   153 
       
   154 // --------------------------------------------------------------------------
       
   155 // CNSmlSOSServer::CNSmlSOSServer()
       
   156 // --------------------------------------------------------------------------
       
   157 //
       
   158 CNSmlSOSServer::CNSmlSOSServer() : CServer2(EPriorityStandard, ESharableSessions)
       
   159 	{
       
   160 	}
       
   161 
       
   162 // --------------------------------------------------------------------------
       
   163 // void CNSmlSOSServer::ConstructL()
       
   164 // --------------------------------------------------------------------------
       
   165 //
       
   166 void CNSmlSOSServer::ConstructL()
       
   167     {
       
   168     iHandler = CNSmlSOSHandler::NewL();
       
   169     iBackup = CNSmlSOSBackup::NewL(iHandler);
       
   170     iObjConIndex = CObjectConIx::NewL();
       
   171     }
       
   172 
       
   173 // --------------------------------------------------------------------------
       
   174 // CNSmlSOSServer::~CNSmlSOSServer()
       
   175 // --------------------------------------------------------------------------
       
   176 //
       
   177 CNSmlSOSServer::~CNSmlSOSServer()
       
   178 	{
       
   179     delete iBackup;
       
   180     delete iHandler;
       
   181     delete iObjConIndex;
       
   182     }
       
   183 
       
   184 // --------------------------------------------------------------------------
       
   185 // CSession2* CNSmlSOSServer::NewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 CSession2* CNSmlSOSServer::NewSessionL( const TVersion& aVersion, const RMessage2& /*aMessage*/ ) const
       
   189 	{
       
   190 	_DBG_FILE("CNSmlSOSServer::NewSessionL(): begin");
       
   191 	TVersion v(KNSmlSOSServerVersionMajor, KNSmlSOSServerVersionMinor, 0);
       
   192 	if( !User::QueryVersionSupported(v,aVersion) )
       
   193 		{
       
   194 		User::Leave(KErrNotSupported);
       
   195 		}
       
   196 
       
   197     iBackup->Subscribe();
       
   198     
       
   199     _DBG_FILE("CNSmlSOSServer::NewSessionL(): end");
       
   200 	return CNSmlSOSSession::NewL( (CNSmlSOSServer*)this, iHandler ); 
       
   201 	}
       
   202 
       
   203 // --------------------------------------------------------------------------
       
   204 // CObjectCon* CNSmlSOSServer::NewContainerL()
       
   205 // --------------------------------------------------------------------------
       
   206 //
       
   207 CObjectCon* CNSmlSOSServer::NewContainerL()
       
   208     {
       
   209     return iObjConIndex->CreateL();
       
   210     }
       
   211 
       
   212 //End of File
       
   213