datacommsserver/esockserver/csock/cs_connectionserv.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedPartner
       
    19  @released since 399
       
    20 */
       
    21 
       
    22 #include <ecom/ecom.h>
       
    23 #include <es_sock.h>
       
    24 #include <comms-infras/es_connectionserv.h>
       
    25 #include "cs_connectionservimpl.h"
       
    26 #include <comms-infras/es_connectionservermessages.h>
       
    27 #include <connpref.h>
       
    28 #include <comms-infras/ss_log.h>
       
    29 #include <rsshared.h>
       
    30 #include <es_ver.h>
       
    31 
       
    32 
       
    33 #ifdef _DEBUG
       
    34 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    35 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    36 _LIT(KSpecAssert_ESockCSockcscnct, "ESockCSockcscnct");
       
    37 #endif
       
    38 
       
    39 
       
    40 using namespace ConnectionServ;
       
    41 
       
    42 
       
    43 _LIT(KConnectionServerName, "!ConnectionServer");
       
    44 
       
    45 EXPORT_C RConnectionServ::RConnectionServ() :
       
    46 	iConnectionServImpl(0)
       
    47 /**
       
    48  Empty ctor
       
    49  */
       
    50 	{
       
    51 	LOG( ESockLog::Printf(_L8("RConnectionServ %08x:\tRConnectionServ() tid %d"), this, (TUint)RThread().Id()); );
       
    52 	}
       
    53 
       
    54 
       
    55 EXPORT_C TInt RConnectionServ::Connect(TUint aTierId)
       
    56 /** Opens a session to the connection server.
       
    57 
       
    58 RHandleBase::Close() should be called once the session is no longer required.
       
    59 All resources which are opened using the session will be automatically closed
       
    60 when the session terminates.
       
    61 
       
    62 @return KErrNone if successful, otherwise another of the system-wide error
       
    63 codes. */
       
    64 	{
       
    65 	LOG( ESockLog::Printf(_L8("RConnectionServ %08x:\tConnect() tid %d tier %d"), this, (TUint)RThread().Id(), aTierId ));
       
    66 #ifndef __ESOCK_SUPPRESS_ESOCK_HANDLE_OVERWRITE_PANICS
       
    67 	__ASSERT_DEBUG(Handle() == 0, User::Panic(KSpecAssert_ESockCSockcscnct, 1));
       
    68 	__ASSERT_DEBUG(iConnectionServImpl == 0, User::Panic(KSpecAssert_ESockCSockcscnct, 2));
       
    69 #endif
       
    70 
       
    71 	if(Handle())
       
    72 		{
       
    73 		return KErrInUse;
       
    74 		}
       
    75 
       
    76 	TVersion ver(KES32MajorVersionNumber,KES32MinorVersionNumber,KES32BuildVersionNumber);
       
    77 	TInt result = CreateSession(KConnectionServerName,ver,8,EIpcSession_Sharable);
       
    78 
       
    79 	if (result==KErrNotFound)
       
    80 		{
       
    81 		result=StartC32Full();
       
    82 		if (result==KErrNone || result==KErrAlreadyExists)
       
    83 			{
       
    84 			const TUint numberOfConcurrentRequests = 8;
       
    85 
       
    86 			// If this connection attempt also fails then most likely the connection server is
       
    87 			// not enabled in the current configuration.
       
    88 			result=CreateSession(KConnectionServerName,ver,numberOfConcurrentRequests,EIpcSession_Sharable);
       
    89 			}
       
    90 		}
       
    91 
       
    92 	if(result != KErrNone)
       
    93 		{
       
    94 		this->Close();
       
    95 		return result;
       
    96 		}
       
    97 
       
    98 	__ASSERT_DEBUG(Handle(), User::Panic(KSpecAssert_ESockCSockcscnct, 3));
       
    99 
       
   100     result = SendReceive(ECMAttachToTierManager, TIpcArgs(aTierId));
       
   101 	
       
   102 	if(result != KErrNone)
       
   103 		{
       
   104 		this->Close();
       
   105 		return result;
       
   106 		}
       
   107 
       
   108 	if( iConnectionServImpl == 0 )
       
   109 		{
       
   110 		TRAP(result, iConnectionServImpl = CConnectionServImpl::NewL(*this));
       
   111 		if (result != KErrNone)
       
   112     		{
       
   113     		this->Close();
       
   114     		}
       
   115 		}
       
   116 
       
   117 	return result;
       
   118 	}
       
   119 
       
   120 
       
   121 EXPORT_C void RConnectionServ::Close()
       
   122 /**
       
   123  Closes the comms manager sub-session
       
   124 
       
   125  Delete owned object and drop to base class
       
   126  */
       
   127 	{
       
   128 	LOG( ESockLog::Printf(_L8("RConnectionServ%08x:\tClose() tid %d"), this, (TUint)RThread().Id()); );
       
   129 	delete iConnectionServImpl; // this causes any requests to be cancelled
       
   130 	iConnectionServImpl = 0;
       
   131 	RSessionBase::Close();
       
   132 	
       
   133 	// The API uses ECom types.. This is the last time we get to attempt a cleanup.
       
   134 	// This call does no harm if the types are still in use (e.g. stored by client code).
       
   135 	REComSession::FinalClose();
       
   136 	}
       
   137 
       
   138 
       
   139 // Asynchronous multiple-IPC functions. Proxy them through to the active objects which handle them, via the impl object.
       
   140 
       
   141 EXPORT_C void RConnectionServ::AccessPointStatusQuery(const CConnectionServParameterBundle& aQuery, CConnectionServParameterBundle& aResult, TRequestStatus& aStatus)
       
   142 	{
       
   143 	__ASSERT_ALWAYS(iConnectionServImpl != NULL, User::Panic(KConnectionServerName, KErrBadHandle));
       
   144 	iConnectionServImpl->AccessPointStatusQuery(aQuery,aResult,aStatus);
       
   145 	}
       
   146 
       
   147 EXPORT_C void RConnectionServ::CancelAccessPointStatusQuery()
       
   148 	{
       
   149 	__ASSERT_ALWAYS(iConnectionServImpl != NULL, User::Panic(KConnectionServerName, KErrBadHandle));
       
   150 	iConnectionServImpl->CancelAccessPointStatusQuery();
       
   151 	}
       
   152 
       
   153 EXPORT_C void RConnectionServ::AccessPointNotification(const CConnectionServParameterBundle& aQuery, MAccessPointNotificationObserver& aObserver)
       
   154 	{
       
   155 	__ASSERT_ALWAYS(iConnectionServImpl != NULL, User::Panic(KConnectionServerName, KErrBadHandle));
       
   156 	iConnectionServImpl->AccessPointNotification(aQuery,aObserver);
       
   157 	}
       
   158 
       
   159 EXPORT_C void RConnectionServ::CancelAccessPointNotification()
       
   160 	{
       
   161 	__ASSERT_ALWAYS(iConnectionServImpl != NULL, User::Panic(KConnectionServerName, KErrBadHandle));
       
   162 	iConnectionServImpl->CancelAccessPointNotification();
       
   163 	}
       
   164 
       
   165