bluetoothmgmt/btmgr/BTManServer/CSYSubSession.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2002-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 // Provides the implementation of the subsession that refers to virtual serial ports
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "BTManServer.h"
       
    19 #include "btmanserverutil.h"
       
    20 #include <bluetooth/logger.h>
       
    21 
       
    22 #ifdef __FLOG_ACTIVE
       
    23 _LIT8(KLogComponent, LOG_COMPONENT_BT_MANAGER_SERVER);
       
    24 #endif
       
    25 
       
    26 CBTCommPortSettingsSubSession* CBTCommPortSettingsSubSession::NewL(CBTManSession& aSession, CBTRegistry& aRegistry)
       
    27 	{
       
    28 	LOG_STATIC_FUNC
       
    29 	CBTCommPortSettingsSubSession* self = new(ELeave) CBTCommPortSettingsSubSession(aSession, aRegistry);
       
    30 	//Since its a CObject derived class so we should use CleanupClosePushL
       
    31 	CleanupClosePushL(*self);
       
    32 	self->ConstructL();
       
    33 	CleanupStack::Pop();
       
    34 	return self;	
       
    35 	}
       
    36 
       
    37 CBTCommPortSettingsSubSession::~CBTCommPortSettingsSubSession()
       
    38 	{
       
    39 	LOG_FUNC
       
    40 	}
       
    41 
       
    42 void CBTCommPortSettingsSubSession::ConstructL()
       
    43 	{
       
    44 	LOG_FUNC
       
    45 	}
       
    46 	
       
    47 CBTCommPortSettingsSubSession::CBTCommPortSettingsSubSession(CBTManSession& aSession, CBTRegistry& aRegistry)
       
    48 : CBTManSubSession(aSession,aRegistry)
       
    49 	{
       
    50 	LOG_FUNC
       
    51 	}
       
    52 
       
    53 void CBTCommPortSettingsSubSession::GetL(const TBTCommPortSettings& aSettings, const RMessage2& aMessage)
       
    54 /**
       
    55 	Find the virtual serial port specified by aSettings, and write the settings to client
       
    56 
       
    57 	@param	aSettings	the key to find the virtual serial port
       
    58 	@param	aMessage	the client message to complete
       
    59 **/
       
    60 	{
       
    61 	LOG_FUNC
       
    62 	// ask registry for row from the localdevice table
       
    63 	const TBTCommPortSettings* portSettings = iRegistry.GetCommPortSettingsLC(aSettings);
       
    64 
       
    65 	TPckg<TBTCommPortSettings> pckg(*portSettings);
       
    66 	
       
    67 	aMessage.WriteL(0, pckg); // write client descriptor
       
    68 	iSession.CompleteMessage(aMessage, KErrNone);
       
    69 
       
    70 	CleanupStack::PopAndDestroy(1); //portSettings;
       
    71 	}
       
    72 
       
    73 void CBTCommPortSettingsSubSession::UpdateL(const TBTCommPortSettings& aPortSettings, const RMessage2& aMessage)
       
    74 /**
       
    75 	Find the virtual serial port specified by aSettings, and update
       
    76 
       
    77 	@param	aPortSettings	the key to find the virtual serial port
       
    78 	@param	aMessage	the client message to complete
       
    79 **/
       
    80 	{
       
    81 	LOG_FUNC
       
    82 	RDbView* view = NULL;
       
    83 
       
    84 	TRAPD(err, view = iRegistry.OpenCommPortL(aPortSettings));
       
    85 	CleanupCloseDeletePushL(view); // we take ownsership
       
    86 
       
    87 	switch(err)
       
    88 		{
       
    89 		case KErrNone:
       
    90 			{
       
    91 			iRegistry.UpdateCommPortSettingsL(*view, aPortSettings);
       
    92 			break;
       
    93 			}
       
    94 		case KErrNotFound:
       
    95 			{
       
    96 			
       
    97 			//In EKA2 we can verify that the client uid is correct
       
    98 			iRegistry.AddCommPortSettingsL(aPortSettings, aMessage.SecureId());
       
    99 			
       
   100 			break;
       
   101 			}
       
   102 		default:
       
   103 			User::Leave(err);
       
   104 		}
       
   105 
       
   106 	// Got here OK, so complete message and tidy up
       
   107 	iSession.CompleteMessage(aMessage, KErrNone);
       
   108 	CleanupStack::PopAndDestroy(view);
       
   109 	NotifyChange(KRegistryChangeCSYTable);
       
   110 	}
       
   111 
       
   112 void CBTCommPortSettingsSubSession::DeleteL(const TBTCommPortSettings& aPortSettings, const RMessage2& aMessage)
       
   113 /**
       
   114 	Find the virtual serial port specified by aSettings, and delete
       
   115 
       
   116 	@param	aPortSettings	the key to find the virtual serial port
       
   117 	@param	aMessage	the client message to complete
       
   118 **/
       
   119 	{
       
   120 	LOG_FUNC
       
   121 	RDbView* view = NULL;
       
   122 
       
   123 	TRAPD(err, view = iRegistry.OpenCommPortL(aPortSettings));
       
   124 	CleanupCloseDeletePushL(view);
       
   125 	switch(err)
       
   126 		{
       
   127 		case KErrNone:
       
   128 			{
       
   129 			iRegistry.DeleteCommPortSettingsL(*view);
       
   130 			break;
       
   131 			}
       
   132 		default:
       
   133 			User::Leave(err);
       
   134 		}
       
   135 	// Got here OK, so complete message and tidy up
       
   136 	iSession.CompleteMessage(aMessage, KErrNone);
       
   137 	CleanupStack::PopAndDestroy(view);
       
   138 	NotifyChange(KRegistryChangeCSYTable);
       
   139 	}
       
   140 
       
   141 void CBTCommPortSettingsSubSession::Cleanup(TInt /*aError*/)
       
   142 	{
       
   143 	LOG_FUNC
       
   144 	// do nothing
       
   145 	}