syncmlfw/common/obex/obexdmplugin/src/NSmlObexDMplugin.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:  SyncML Obex plugin for Device Management
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <nsmlconstants.h>
       
    20 #include <NSmlPrivateAPI.h>
       
    21 #include <nsmlsyncalerthandlerif.h>
       
    22 #include "NSmlObexDMplugin.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CNSmlObexDMplugin::NewL()
       
    28 // 
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CNSmlObexDMplugin* CNSmlObexDMplugin::NewL()
       
    32     {
       
    33     DBG_FILE( _S8("CNSmlObexDMplugin::NewL: begin") );
       
    34     CNSmlObexDMplugin* self = new (ELeave) CNSmlObexDMplugin();
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop( self );
       
    38     DBG_FILE( _S8("CNSmlObexDMplugin::NewL: end") );
       
    39     return self;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CNSmlObexDMplugin::CNSmlObexDMplugin()
       
    44 // 
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CNSmlObexDMplugin::CNSmlObexDMplugin(): iPtr( 0, 0), iSendPtr( 0, 0 )
       
    48 	{
       
    49 	}
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CNSmlObexDMplugin::ConstructL()
       
    53 // 
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CNSmlObexDMplugin::ConstructL()
       
    57     {
       
    58 	iZeroPkg = ETrue;
       
    59 	iObexContent =  ENSmlDeviceManagement;
       
    60 	iState = EIdle;
       
    61     // create OBEX object to receive obex transfer
       
    62     iObexBufData = CBufFlat::NewL( 10*KBufferSize );
       
    63     iObexBufObject = CObexBufObject::NewL( iObexBufData );
       
    64 	iSessCancelled = ETrue;
       
    65 	iSessionActive = EFalse;
       
    66 
       
    67 	iServiceTimer = new (ELeave) CPluginServiceTimer( this, KPluginTimeOutValue );
       
    68 	iServiceTimer->ConstructL();
       
    69 	CActiveScheduler::Add( iServiceTimer );
       
    70 
       
    71 	iGetPacketWaiter = new(ELeave) CNSmlObexPacketWaiter( iSs ); 
       
    72 	iGetPacketWaiter->ConstructL();
       
    73 	}
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CNSmlObexDMplugin::GetServerCallback()
       
    77 // Get MObexServerNotify object to bind to CObexServer
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 MObexServerNotify* CNSmlObexDMplugin::GetServerCallback()
       
    81     {
       
    82 	return this;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CNSmlObexDMplugin::IsOBEXActive()
       
    87 // 
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 TBool CNSmlObexDMplugin::IsOBEXActive()
       
    91     {
       
    92 	return iSessionActive;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CNSmlObexDMplugin::~CNSmlObexDMplugin()
       
    97 // 
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CNSmlObexDMplugin::~CNSmlObexDMplugin()
       
   101     {
       
   102 	DBG_FILE( _S8("CNSmlObexDMplugin::~CNSmlObexDMplugin(): begin") );
       
   103 	Disconnect();
       
   104 
       
   105     delete iObexBufData;
       
   106     iObexBufData = NULL;
       
   107 
       
   108     delete iObexBufObject;
       
   109     iObexBufObject = NULL;
       
   110 
       
   111 	if( iListener )
       
   112 		{
       
   113 		iListener->iSessCancelled = iSessCancelled;
       
   114 		delete iListener;
       
   115 		iListener = NULL;
       
   116 		}
       
   117 
       
   118 	delete iData;
       
   119 	iData = NULL;
       
   120 
       
   121 	if( iServiceTimer )
       
   122 		{
       
   123 		iServiceTimer->Cancel();
       
   124 		}
       
   125 	
       
   126 	delete iServiceTimer;
       
   127 	iServiceTimer = NULL;
       
   128 
       
   129 	delete iGetPacketWaiter;
       
   130 	iGetPacketWaiter = NULL;
       
   131 
       
   132 	DBG_FILE( _S8("CNSmlObexDMplugin::~CNSmlObexDMplugin(): end") );
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CNSmlObexDMplugin::ErrorIndication( TInt aError )
       
   137 // 
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CNSmlObexDMplugin::ErrorIndication( TInt aError )
       
   141     {
       
   142 	iZeroPkg = ETrue;
       
   143 	DBG_FILE_CODE( aError, _S8("CNSmlObexDMplugin::ErrorIndication...") );
       
   144 	Disconnect();
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CNSmlObexDMplugin::TransportUpIndication()
       
   149 // 
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CNSmlObexDMplugin::TransportUpIndication()
       
   153     {
       
   154 	DBG_FILE( _S8("CNSmlObexDMplugin::TransportUpIndication...") );
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CNSmlObexDMplugin::TransportDownIndication()
       
   159 // 
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CNSmlObexDMplugin::TransportDownIndication()
       
   163     {
       
   164 	DBG_FILE( _S8("CNSmlObexDMplugin::TransportDownIndication...") );
       
   165 	Disconnect();
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CNSmlObexDMplugin::ObexConnectIndication( const TObexConnectInfo& /*aRemoteInfo*/, const TDesC8& /*aInfo*/ )
       
   170 // 
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TInt CNSmlObexDMplugin::ObexConnectIndication( const TObexConnectInfo& /*aRemoteInfo*/, const TDesC8& /*aInfo*/ )
       
   174     {
       
   175 	_DBG_FILE("CNSmlObexDMplugin::ObexConnectIndication [w45 14.11.2003]");	
       
   176 	TInt err( KErrNone );
       
   177 	iStopped = EFalse;
       
   178 
       
   179 	iStartTimer = ETrue;
       
   180 
       
   181 	if( iListener )
       
   182 		{
       
   183 		_DBG_FILE("delete iListener");	
       
   184 		delete iListener;
       
   185 		iListener = NULL;
       
   186 		}
       
   187 	
       
   188 	err = iSs.Connect();
       
   189 	if( err == KErrNotFound )
       
   190 		{
       
   191 		// obexcommserver was not running, creating one into a new thread
       
   192 		RSemaphore signal;
       
   193 		signal.CreateLocal(0);
       
   194 		RThread t;
       
   195 		TRAP( err, t.Create(_L("ObexCommServerThread"), CreateServer, 1024*6, KMinHeapSize, KMinHeapSize*250, &signal) );
       
   196 		t.Resume();
       
   197 		t.Close();
       
   198 		signal.Wait();
       
   199 		signal.Close();
       
   200 
       
   201 		err = iSs.Connect();
       
   202 		}
       
   203 	
       
   204 	if( err == KErrNone )
       
   205 		{
       
   206 		iSessCancelled = EFalse;
       
   207 		iListener = new CDisListener( iSs, this );
       
   208 		if ( !iListener )
       
   209 			{
       
   210 			err = KErrNoMemory;
       
   211 			}
       
   212 			
       
   213 		if( err == KErrNone )
       
   214 			{
       
   215 			iListener->ListenDisconnect();
       
   216 			DBG_FILE( _S8("CNSmlObexDMplugin iServiceTimer->StopTimer()") );
       
   217 			iServiceTimer->Cancel();
       
   218 			iServiceTimer->StopTimer();
       
   219 			}
       
   220 		}
       
   221     return ConvertError( err );
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CNSmlObexDMplugin::ObexDisconnectIndication( const TDesC8& /*aInfo*/ )
       
   226 // 
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CNSmlObexDMplugin::ObexDisconnectIndication( const TDesC8& /*aInfo*/ )
       
   230     {
       
   231 	_DBG_FILE("CNSmlObexDMplugin::ObexDisconnectIndication");
       
   232 	Disconnect();
       
   233 	}
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CNSmlObexDMplugin::PutRequestIndication()
       
   237 // 
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 CObexBufObject* CNSmlObexDMplugin::PutRequestIndication()
       
   241     {
       
   242 	_DBG_FILE("CNSmlObexDMplugin::PutRequestIndication");
       
   243 	iState = EIdle;
       
   244 	if ( iObexBufObject )
       
   245 		{
       
   246 		iObexBufData->Reset();
       
   247 		iObexBufObject->Reset();
       
   248 		}
       
   249 	if( iStopped )
       
   250 		{
       
   251 		_DBG_FILE("CNSmlObexDMplugin service unavailable");
       
   252 		return NULL;
       
   253 		}
       
   254     return iObexBufObject;
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CNSmlObexDMplugin::PutPacketIndication()
       
   259 // 
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 TInt CNSmlObexDMplugin::PutPacketIndication()
       
   263     {
       
   264 	_DBG_FILE("CNSmlObexDMplugin::PutPacketIndication");
       
   265 	TInt bytes = this->iObexBufObject->BytesReceived();
       
   266 	DBG_FILE_CODE( bytes, _S8("reveived bytes") );
       
   267 	if( iStopped )
       
   268 		{
       
   269 		_DBG_FILE("CNSmlObexDMplugin service unavailable");
       
   270 		return KErrIrObexRespServiceUnavail;
       
   271 		}
       
   272 	return KErrNone;
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CNSmlObexDMplugin::PutCompleteIndication()
       
   277 // 
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TInt CNSmlObexDMplugin::PutCompleteIndication()
       
   281     {
       
   282 	_DBG_FILE("CNSmlObexDMplugin::PutCompleteIndication");
       
   283 	TInt err( KErrNone );
       
   284 
       
   285 	err = CheckMimeType();
       
   286 
       
   287 	_DBG_FILE("CNSmlObexDMplugin After CheckMimeType");
       
   288 
       
   289 	if( err == KErrNone )
       
   290 		{
       
   291 		if ( iObexBufData->Size() > KNSmlLocalSyncWorkspaceSize )
       
   292 		    {
       
   293         	_DBG_FILE("CNSmlObexDMplugin: Received package too large!");
       
   294 		    return KErrIrObexRespReqEntityTooLarge;
       
   295 		    }
       
   296 		
       
   297 		if ( iZeroPkg )
       
   298 			{
       
   299 			_DBG_FILE("CNSmlObexDMplugin..Forwarding Zero Pkg");
       
   300 			DBG_DUMP((void*)iObexBufData->Ptr(0).Ptr(), iObexBufData->Size(), _S8("Zero Pkg") );
       
   301 
       
   302 			#ifdef __NSML_DEBUG__
       
   303 			_DBG_FILE("CNSmlObexDMplugin..Zero Pkg: CWbxml2XmlConverter::ConvertL() begin");
       
   304 			CWbxml2XmlConverter* c = NULL;
       
   305 			TRAP( err, c = CWbxml2XmlConverter::NewL() );
       
   306 			if (c)
       
   307 				{
       
   308 				TRAP( err, c->ConvertL(iObexBufData->Ptr(0).Ptr(), iObexBufData->Size()) );
       
   309 				DBG_DUMP((void*)c->Document().Ptr(), c->Document().Length(), _S8("Zero Pkg (XML)") );
       
   310 				delete c;
       
   311 				}
       
   312 			_DBG_FILE("CNSmlObexDMplugin..Zero Pkg: CWbxml2XmlConverter::ConvertL() end");
       
   313 			#endif // __NSML_DEBUG__
       
   314 	
       
   315 			TRAP( err, err = ForwardZeroPkgL( iObexContent ) );
       
   316 			iZeroPkg = EFalse;
       
   317 			}
       
   318 		else
       
   319 			{
       
   320 			_DBG_FILE("CNSmlObexDMplugin..SetReceivedPacket");
       
   321 			DBG_DUMP((void*)iObexBufData->Ptr(0).Ptr(), iObexBufData->Size(), _S8("CNSmlObexDMplugin SetReceivedPacket") );
       
   322 
       
   323 			#ifdef __NSML_DEBUG__
       
   324 			_DBG_FILE("CNSmlObexDMplugin..SetReceivedPacket: CWbxml2XmlConverter::ConvertL() begin");
       
   325 			CWbxml2XmlConverter* c = NULL;
       
   326 			TRAP( err, c = CWbxml2XmlConverter::NewL() );
       
   327 			if (c)
       
   328 				{
       
   329 				TRAP( err, c->ConvertL(iObexBufData->Ptr(0).Ptr(), iObexBufData->Size()) );
       
   330 				DBG_DUMP((void*)c->Document().Ptr(), c->Document().Length(), _S8("SetReceivedPacket (XML)") );
       
   331 				delete c;
       
   332 				}
       
   333 			_DBG_FILE("CNSmlObexDMplugin..SetReceivedPacket: CWbxml2XmlConverter::ConvertL() end");
       
   334 			#endif // __NSML_DEBUG__
       
   335 			
       
   336 			if( !iStopped )
       
   337 				{
       
   338 				this->iObexBufObject->BytesReceived();
       
   339 				this->iSs.SetReceivedPacket( this->iObexBufData->Ptr( 0 ) );
       
   340 				}
       
   341 			else{
       
   342 				err = KErrAccessDenied;
       
   343 				}
       
   344 			}
       
   345 		}
       
   346 	else if ( err == KErrNotSupported )
       
   347 	    {
       
   348     	_DBG_FILE("CNSmlObexDMplugin: Mimetype not supported!");
       
   349 	    return KErrIrObexRespUnsupMediaType;
       
   350 	    }
       
   351 	
       
   352 	return ConvertError( err );
       
   353     }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CNSmlObexDMplugin::GetRequestIndication( CObexBaseObject* /*aRequiredObject*/ )
       
   357 // 
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 CObexBufObject* CNSmlObexDMplugin::GetRequestIndication( CObexBaseObject* /*aRequiredObject*/ )
       
   361     {
       
   362 	_DBG_FILE("CNSmlObexDMplugin::GetRequestIndication");
       
   363 
       
   364 	TInt err( KErrNone );
       
   365 	iObexBufObject->Reset();
       
   366 
       
   367 	iState = EGetSendPacket;
       
   368 	err = iGetPacketWaiter->WaitForGetData();
       
   369 	iState = EIdle;
       
   370 
       
   371 	if ( err == KErrNone )
       
   372 		{
       
   373 		iObexBufData->Reset();
       
   374 		TRAP( err, iObexBufData->InsertL( 0, iGetPacketWaiter->Data() ) );
       
   375 		}
       
   376 	if ( err != KErrNone )
       
   377 		{
       
   378 		return NULL;
       
   379 		}
       
   380 
       
   381 	#ifdef __NSML_DEBUG__
       
   382 	_DBG_FILE("CNSmlObexDMplugin GetRequestIndication: CWbxml2XmlConverter begin");
       
   383 	CWbxml2XmlConverter* c = NULL;
       
   384 	TRAP( err, c = CWbxml2XmlConverter::NewL() );
       
   385 	if (c)
       
   386 		{
       
   387 		TRAP( err, c->ConvertL(iObexBufData->Ptr(0).Ptr(), iObexBufData->Size()) );
       
   388 		DBG_DUMP((void*)c->Document().Ptr(), c->Document().Length(), _S8("CNSmlObexDMplugin GetRequestIndication (XML)") );
       
   389 		delete c;
       
   390 		c = NULL;
       
   391 		}
       
   392 	_DBG_FILE("CNSmlObexDMplugin GetRequestIndication: CWbxml2XmlConverter end");
       
   393 	#endif // __NSML_DEBUG__
       
   394 
       
   395 
       
   396 	TRAP( err, iObexBufObject->SetDataBufL( iObexBufData ) );
       
   397 	if ( err != KErrNone )
       
   398 		{
       
   399 		return NULL;
       
   400 		}
       
   401     return iObexBufObject;
       
   402    }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // CNSmlObexDMplugin::GetPacketIndication()
       
   406 // 
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 TInt CNSmlObexDMplugin::GetPacketIndication()
       
   410     {
       
   411 	_DBG_FILE("CNSmlObexDMplugin::GetPacketIndication");
       
   412 	if( iStopped )
       
   413 		{
       
   414 		_DBG_FILE("CNSmlObexDMplugin service unavailable");
       
   415 		return KErrIrObexRespServiceUnavail;
       
   416 		}
       
   417     return KErrNone;
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CNSmlObexDMplugin::GetCompleteIndication()
       
   422 // 
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 TInt CNSmlObexDMplugin::GetCompleteIndication()
       
   426     {
       
   427 	_DBG_FILE("CNSmlObexDMplugin::GetCompleteIndication");
       
   428     return KErrNone;
       
   429     }
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // CNSmlObexDMplugin::SetPathIndication(const CObex::TSetPathInfo& /*aPathInfo*/, const TDesC8& /*aInfo*/)
       
   433 // 
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 TInt CNSmlObexDMplugin::SetPathIndication(const CObex::TSetPathInfo& /*aPathInfo*/, const TDesC8& /*aInfo*/)
       
   437     {
       
   438     return KErrNone;
       
   439     }
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // CNSmlObexDMplugin::AbortIndication()
       
   443 // 
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 void CNSmlObexDMplugin::AbortIndication()
       
   447     {
       
   448 	_DBG_FILE("CNSmlObexDMplugin::AbortIndication");
       
   449 	Disconnect();
       
   450     }
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CNSmlObexDMplugin::Disconnect()
       
   454 // 
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 void CNSmlObexDMplugin::Disconnect()
       
   458     {
       
   459 	_DBG_FILE("CNSmlObexDMplugin::Disconnect");
       
   460 	iZeroPkg = ETrue;
       
   461 
       
   462 	if( iStartTimer != EFalse )
       
   463 		{
       
   464 		DBG_FILE( _S8("CNSmlObexDMplugin iServiceTimer->StartTimer()") );
       
   465 		iServiceTimer->Cancel();
       
   466 		iServiceTimer->StartTimer();
       
   467 		}
       
   468 	
       
   469 	iState = EIdle;
       
   470 	if( !iSessCancelled )
       
   471 		{
       
   472 		_DBG_FILE("calling iSs.Disconnect()");
       
   473 		iSs.Disconnect();
       
   474 		iSs.Close();
       
   475 		iSessCancelled = ETrue;
       
   476 		}
       
   477     }
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CNSmlObexDMplugin::CheckMimeType()
       
   481 // 
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 TInt CNSmlObexDMplugin::CheckMimeType()
       
   485 	{ 	
       
   486 	_DBG_FILE("CNSmlObexDMplugin::CheckMimeType() - mimetype in dump...");
       
   487 	
       
   488 	TBuf8<256> mimeType;
       
   489 	mimeType.Copy( this->iObexBufObject->Type() );
       
   490 	mimeType.LowerCase();
       
   491 	TrimRightSpaceAndNull( mimeType );
       
   492 
       
   493 	DBG_DUMP( (void*)mimeType.Ptr(), mimeType.Length(), _S8("Received mimetype") );
       
   494 
       
   495 	if ( (mimeType.Compare( KDataSyncDM ) == 0) ||
       
   496 		 (mimeType.Compare( KDataSyncDMAlertNotification ) == 0) )
       
   497 		{		
       
   498 		_DBG_FILE("CNSmlObexDMplugin... KDataSyncDM OBEX content");
       
   499 		iObexContent = ENSmlDeviceManagement;	
       
   500 		return KErrNone;
       
   501 		}
       
   502 	else
       
   503 		{
       
   504 		_DBG_FILE("Unsupported mime type");
       
   505 		return KErrNotSupported;
       
   506 		}
       
   507 	}
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // CNSmlObexDMplugin::TrimRightSpaceAndNull()
       
   511 // 
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 void CNSmlObexDMplugin::TrimRightSpaceAndNull( TDes8& aDes ) const
       
   515 {
       
   516 	aDes.TrimRight();
       
   517 	if ( aDes.Length() > 0 )
       
   518 		{
       
   519 		if ( aDes[aDes.Length() - 1] == NULL )
       
   520 			{
       
   521 			aDes.SetLength( aDes.Length() - 1 );
       
   522 			} 
       
   523 		}
       
   524 }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // CNSmlObexDMplugin::ForwardZeroPkgL( TNSmlObexContent aSyncSelection )
       
   528 // 
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 TInt CNSmlObexDMplugin::ForwardZeroPkgL( TNSmlObexContent aSyncSelection )
       
   532 	{
       
   533 	_DBG_FILE("CNSmlObexDMplugin::ForwardZeroPkgL()");
       
   534 	TInt err( KErrNone );
       
   535 
       
   536 	if ( aSyncSelection == ENSmlDeviceManagement )
       
   537 		{
       
   538 		_DBG_FILE("CNSmlObexDMplugin... Before StartSync");
       
   539 		
       
   540 		RNSmlPrivateAPI privateApi;
       
   541 		TRAPD(openErr, privateApi.OpenL());
       
   542 	
       
   543 		if ( openErr != KErrNone )
       
   544 			{
       
   545 			return ENSmlErrUndefined;
       
   546 			}
       
   547 	
       
   548 		TRAPD(connErr, privateApi.SendL(this->iObexBufData->Ptr(0), ESmlDevMan,
       
   549 		    ESmlVersion1_1_2,KUidNSmlMediumTypeBluetooth ));
       
   550 	
       
   551 		if ( connErr != KErrNone )
       
   552 			{
       
   553 			privateApi.Close();
       
   554 			return ENSmlErrUndefined;
       
   555 			}
       
   556 		
       
   557 		privateApi.Close();
       
   558 				
       
   559 		}
       
   560 	else
       
   561 		{
       
   562 		err = KErrNotSupported;
       
   563 		}
       
   564 	return err;
       
   565 	}
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 // CNSmlObexDMplugin::SetMediaType( TSrcsMediaType aMediaType )
       
   569 // 
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 void CNSmlObexDMplugin::SetMediaType( TSrcsMediaType aMediaType )
       
   573     {
       
   574 	DBG_FILE( _S8("CNSmlObexDMplugin::SetMediaType()") );
       
   575 	iMediaType = aMediaType;
       
   576     }
       
   577 
       
   578 // -----------------------------------------------------------------------------
       
   579 // CNSmlObexDMplugin::CreateServer( TAny* aPtr )
       
   580 // 
       
   581 // -----------------------------------------------------------------------------
       
   582 //
       
   583 TInt CNSmlObexDMplugin::CreateServer( TAny* aPtr )
       
   584 	{
       
   585 	__UHEAP_MARK;
       
   586 	CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
       
   587 	CActiveScheduler* scheduler = new CActiveScheduler();
       
   588 	CActiveScheduler::Install(scheduler);	
       
   589 	TRAPD( err, StartServerL( aPtr ) );
       
   590 	__ASSERT_ALWAYS(err == KErrNone, User::Panic(_L("OBEXCommServer"), err));
       
   591 	delete scheduler;
       
   592 	delete cleanup; // destroy clean-up stack
       
   593 	__UHEAP_MARKEND;
       
   594 	return KErrNone;
       
   595 	}
       
   596 
       
   597 // -----------------------------------------------------------------------------
       
   598 // CNSmlObexDMplugin::StartServer( TAny* aPtr )
       
   599 // 
       
   600 // -----------------------------------------------------------------------------
       
   601 //
       
   602 void CNSmlObexDMplugin::StartServerL( TAny* aPtr )
       
   603 	{
       
   604 	CNSmlObexCommServer* server = CNSmlObexCommServer::NewL( KNSmlDMObexCommServerName() );
       
   605 	RSemaphore* s = (RSemaphore*)aPtr;
       
   606 	s->Signal();
       
   607 	CActiveScheduler::Start();
       
   608 	delete server;
       
   609 	}
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CNSmlObexDMplugin::ConvertError( TInt aError )
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 TInt CNSmlObexDMplugin::ConvertError( TInt aError )
       
   616 	{
       
   617 	DBG_FILE_CODE( aError, _S8("ConvertError...") );
       
   618 	TInt obexErr ( KErrIrObexRespInternalError );
       
   619 
       
   620 	switch (aError)
       
   621 	{
       
   622 	case KErrNone:
       
   623 		obexErr = KErrNone;
       
   624 		break;
       
   625 
       
   626 	case KErrNotFound:
       
   627 		obexErr = KErrIrObexRespNotFound;
       
   628 		break;
       
   629 
       
   630 	case KErrGeneral:
       
   631 	case KErrCancel:
       
   632 	case KErrNoMemory:
       
   633 		obexErr = KErrIrObexRespInternalError;
       
   634 		break;
       
   635 
       
   636 	case KErrNotSupported:
       
   637 		obexErr = KErrIrObexRespBadRequest;
       
   638 		break;
       
   639 
       
   640 	case KErrArgument:
       
   641 	case KErrTotalLossOfPrecision:
       
   642 	case KErrBadHandle:
       
   643 	case KErrOverflow:
       
   644 	case KErrUnderflow:
       
   645 	case KErrAlreadyExists:
       
   646 	case KErrPathNotFound:
       
   647 	case KErrDied:
       
   648 	case KErrInUse:
       
   649 	case KErrServerTerminated:
       
   650 		obexErr = KErrIrObexRespInternalError;
       
   651 		break;
       
   652 
       
   653 	case KErrServerBusy:
       
   654 		obexErr = KErrIrObexRespServiceUnavail;
       
   655 		break;
       
   656 
       
   657 	case KErrCompletion:
       
   658 	case KErrNotReady:
       
   659 	case KErrUnknown:
       
   660 	case KErrCorrupt:
       
   661 	case KErrAccessDenied:
       
   662 	case KErrLocked:
       
   663 	case KErrWrite:
       
   664 	case KErrDisMounted:
       
   665 	case KErrEof:
       
   666 	case KErrDiskFull:
       
   667 	case KErrBadDriver:
       
   668 	case KErrBadName:
       
   669 	case KErrCommsLineFail:
       
   670 	case KErrCommsFrame:
       
   671 	case KErrCommsOverrun:
       
   672 	case KErrCommsParity:
       
   673 	case KErrTimedOut:
       
   674 	case KErrCouldNotConnect:
       
   675 	case KErrCouldNotDisconnect:
       
   676 	case KErrBadLibraryEntryPoint:
       
   677 	case KErrBadDescriptor:
       
   678 	case KErrAbort:
       
   679 	case KErrTooBig:
       
   680 	case KErrDivideByZero:
       
   681 	case KErrBadPower:
       
   682 	case KErrDirFull:
       
   683 	case KErrHardwareNotAvailable:
       
   684 		obexErr = KErrIrObexRespInternalError;
       
   685 		break;
       
   686 	default:
       
   687 		obexErr = KErrIrObexRespInternalError;
       
   688 		break;
       
   689 	};
       
   690 	DBG_FILE_CODE( obexErr, _S8("ConvertError returned...") );
       
   691 	return obexErr;
       
   692 };
       
   693 
       
   694 // -----------------------------------------------------------------------------
       
   695 // CNSmlObexDMplugin::SetObexServer( CObexServer* aObexServer )
       
   696 // -----------------------------------------------------------------------------
       
   697 //
       
   698 TInt CNSmlObexDMplugin::SetObexServer( CObexServer* aObexServer )
       
   699     {
       
   700     DBG_FILE(_S8("CNSmlObexDMplugin::SetObexServer - Begin"));                          
       
   701     iObexServer = aObexServer;      
       
   702     return iObexServer->Start(this) ;
       
   703     }
       
   704 
       
   705 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   706 
       
   707 //End of File
       
   708