datacommsserver/esockserver/ssock/ss_linkcprnodemessages.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2005-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  @internalComponent
       
    19 */
       
    20 
       
    21 #include <comms-infras/api_ext_list.h>
       
    22 #include <cdblen.h>
       
    23 #include <ss_glob.h>
       
    24 #include <comms-infras/ss_connprov.h>
       
    25 #include "ss_linkcprnodemessages.h"
       
    26 #include "ss_legacynodemessages.h"
       
    27 #include <comms-infras/ss_thread.h>
       
    28 #include <comms-infras/metatype.h>
       
    29 #include <comms-infras/ss_log.h>
       
    30 
       
    31 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    32 #include <es_enum_partner.h>
       
    33 #endif
       
    34 
       
    35 
       
    36 #ifdef _DEBUG
       
    37 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    38 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    39 _LIT(KSpecAssert_ESockSSockslnkcp, "ESockSSockslnkcp");
       
    40 #endif
       
    41 
       
    42 using namespace ESock;
       
    43 using namespace Elements;
       
    44 using namespace Messages;
       
    45 
       
    46 #ifdef __CFLOG_ACTIVE
       
    47 	#define KShimCprTag KESockConnectionTag
       
    48 	_LIT8(KShimCprSubTag, "shimcpr");	// logging tag
       
    49 #endif
       
    50 
       
    51 
       
    52 // ===== MLinkCprExtensionApi =====
       
    53 
       
    54 // ----- TCprRetrieveProgress -----
       
    55 void TCprRetrieveProgress::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient)
       
    56     {
       
    57     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
    58     MLinkCprApiExt::TProgressBuf prog;
       
    59     TAny* interface = NULL;
       
    60     TRAPD(err,
       
    61 	     interface = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), MLinkCprApiExt::KInterfaceId);
       
    62 	     );
       
    63 
       
    64 	if (err == KErrNotFound)
       
    65 	    {
       
    66         // If an interface can't be found complete the client with the last
       
    67         // progress cached on the CConnection
       
    68         MLinkCprApiExt::TProgressBuf prog(iLastProgress);
       
    69         iMessage.WriteL(0, prog);
       
    70 		__CFLOG_VAR((KShimCprTag, KShimCprSubTag, _L8("TCprRetrieveProgress %08x:\tDispatchL() completing message (%08X) with KErrNone"),
       
    71 							 this, iMessage.Handle()));
       
    72         iMessage.Complete(KErrNone);
       
    73         return;
       
    74 	    }
       
    75 
       
    76     if (interface)
       
    77     	{
       
    78     	MLinkCprApiExt& linkCprItf = *static_cast<MLinkCprApiExt*>(interface);
       
    79     	linkCprItf.ProgressL(prog);
       
    80         iMessage.WriteL(0, prog);
       
    81 		__CFLOG_VAR((KShimCprTag, KShimCprSubTag, _L8("TCprRetrieveProgress %08x:\tDispatchL() completing message (%08X) with KErrNone"),
       
    82 							 this, iMessage.Handle()));
       
    83         iMessage.Complete(KErrNone);
       
    84     	}
       
    85     }
       
    86 
       
    87 
       
    88 // ----- TCprRetrieveLastProgressError -----
       
    89 void TCprRetrieveLastProgressError::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient)
       
    90     {
       
    91     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
    92     MLinkCprApiExt::TProgressBuf prog;
       
    93 	TAny* interface = NULL;
       
    94 	TRAPD(err,
       
    95 	    interface = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), MLinkCprApiExt::KInterfaceId);
       
    96 	    );
       
    97 
       
    98     if (err == KErrNotFound)
       
    99         {
       
   100         // If an interface can't be found complete the client with the last
       
   101         // progress error cached on the CConnection
       
   102         MLinkCprApiExt::TProgressBuf prog(iLastProgressError);
       
   103         iMessage.WriteL(0, prog);
       
   104 		__CFLOG_VAR((KShimCprTag, KShimCprSubTag, _L8("TCprRetrieveLastProgressError %08x:\tDispatchL() completing message (%08X) with KErrNone"),
       
   105 							 this, iMessage.Handle()));
       
   106 		iMessage.Complete(KErrNone);
       
   107         return;
       
   108         }
       
   109 
       
   110     if (interface)
       
   111     	{
       
   112     	MLinkCprApiExt& linkCprItf = *static_cast<MLinkCprApiExt*>(interface);
       
   113     	linkCprItf.LastProgressError(prog);
       
   114     	iMessage.WriteL(0, prog);
       
   115 		__CFLOG_VAR((KShimCprTag, KShimCprSubTag, _L8("TCprRetrieveLastProgressError %08x:\tDispatchL() completing message (%08X) with KErrNone"),
       
   116 							 this, iMessage.Handle()));
       
   117         iMessage.Complete(KErrNone);
       
   118     	}
       
   119     }
       
   120 
       
   121 
       
   122 // ----- TCprRequestServiceNotification -----
       
   123 void TCprRequestServiceNotification::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient)
       
   124     {
       
   125     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
   126 	TAny* interface = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), MLinkCprServiceChangeNotificationApiExt::KInterfaceId);
       
   127 
       
   128     if (interface)
       
   129     	{
       
   130     	MLinkCprServiceChangeNotificationApiExt& linkCprItf = *static_cast<MLinkCprServiceChangeNotificationApiExt*>(interface);
       
   131 		Elements::RResponseMsg response(iMessage, iMessage.Int0());
       
   132     	linkCprItf.RequestServiceChangeNotificationL(iSender, response);
       
   133     	}
       
   134     }
       
   135 
       
   136 
       
   137 // ----- TCprCancelServiceNotification -----
       
   138 void TCprCancelServiceNotification::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient)
       
   139     {
       
   140     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
   141 	TAny* interface = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), MLinkCprServiceChangeNotificationApiExt::KInterfaceId);
       
   142 
       
   143     if (interface)
       
   144     	{
       
   145     	MLinkCprServiceChangeNotificationApiExt& linkCprItf = *static_cast<MLinkCprServiceChangeNotificationApiExt*>(interface);
       
   146     	linkCprItf.CancelServiceChangeNotification(iSender);
       
   147     	}
       
   148     }
       
   149 
       
   150 
       
   151 void TCprCancelServiceNotification::Error(const TRuntimeCtxId& /*aSender*/, const TRuntimeCtxId& /*aRecipient*/, TInt /*aError*/)
       
   152     {
       
   153     // This happens when someone (IPProto Layer?) try to 
       
   154     // send CancelServiceChangeNotification BUT the node supposed to receive
       
   155     // it (AgentCpr) is ALREADY marked as Leaving from IPProto.
       
   156     
       
   157     // In general, it should not happen.
       
   158     __ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSockslnkcp, 1));
       
   159     }
       
   160 
       
   161 
       
   162 
       
   163 // ----- TCprEnumerateSubConnections -----
       
   164 void TCprEnumerateSubConnections::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient)
       
   165     {
       
   166     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
   167 	TAny* interface = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), MLinkCprApiExt::KInterfaceId);
       
   168 
       
   169     if (interface)
       
   170     	{
       
   171 //		MLinkCprApiExt& linkCprItf = *static_cast<MLinkCprApiExt*>(interface);
       
   172     	TUint connectionCount;
       
   173 //    	User::LeaveIfError(linkCprItf.EnumerateSubConnectionsL(connectionCount));
       
   174    		TPckg<TUint> connectionCountPckg(connectionCount);
       
   175    		iMessage.WriteL(0, connectionCountPckg);
       
   176 		__CFLOG_VAR((KShimCprTag, KShimCprSubTag, _L8("TCprEnumerateSubConnections %08x:\tDispatchL() completing message (%08X) with KErrNone"),
       
   177 							 this, iMessage.Handle()));
       
   178 		iMessage.Complete(KErrNone);
       
   179         }
       
   180     }
       
   181 
       
   182 
       
   183 
       
   184 // ----- TCprSendIoctl -----
       
   185 void TCprSendIoctl::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient)
       
   186     {
       
   187     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
   188 	TAny* interface = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), MLinkCprApiExt::KInterfaceId);
       
   189 
       
   190     if (interface)
       
   191     	{
       
   192     	MLinkCprApiExt& linkCprItf = *static_cast<MLinkCprApiExt*>(interface);
       
   193     	linkCprItf.SendIoctlMessageL(iMessage);
       
   194         }
       
   195     }
       
   196 
       
   197 
       
   198 
       
   199 // ----- TCprCancelIoctl -----
       
   200 void TCprCancelIoctl::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient)
       
   201     {
       
   202     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
   203 	TAny* interface = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), MLinkCprApiExt::KInterfaceId);
       
   204 
       
   205     if (interface)
       
   206     	{
       
   207     	MLinkCprApiExt& linkCprItf = *static_cast<MLinkCprApiExt*>(interface);
       
   208     	linkCprItf.SendCancelIoctl();
       
   209 		__CFLOG_VAR((KShimCprTag, KShimCprSubTag, _L8("TCprCancelIoctl %08x:\tDispatchL() completing message (%08X) with KErrNone"),
       
   210 							 this, iMessage.Handle()));
       
   211         iMessage.Complete(KErrNone);
       
   212     	}
       
   213     }
       
   214 
       
   215 
       
   216 
       
   217 // ----- TCprAllSubConnectionNotificationEnable -----
       
   218 void TCprAllSubConnectionNotificationEnable::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient)
       
   219     {
       
   220     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
   221 	TAny* interface = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), MLinkCprApiExt::KInterfaceId);
       
   222 
       
   223     if (interface)
       
   224     	{
       
   225     	MLinkCprApiExt& linkCprItf = *static_cast<MLinkCprApiExt*>(interface);
       
   226     	linkCprItf.AllSubConnectionNotificationEnable();
       
   227     	}
       
   228     }
       
   229 
       
   230 void TCprAllSubConnectionNotificationEnable::Error(const TRuntimeCtxId& /*aSender*/, const TRuntimeCtxId& /*aRecipient*/, TInt /*aError*/)
       
   231     {
       
   232     __ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSockslnkcp, 2));//should never get there. if so than we need to derive from TCFSigRMessage2Ext
       
   233     //to add RMessage and complete with error
       
   234     }
       
   235 
       
   236 
       
   237 // ===== MLinkCprFactExtensionApi =====
       
   238 
       
   239 // ----- TCprFactEnumerateConnections -----
       
   240 void TCprFactEnumerateConnections::DispatchL(const TRuntimeCtxId& /*aSender*/, const TRuntimeCtxId& aRecipient)
       
   241     {
       
   242     const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient);  //This message type operates on nodes
       
   243     __ASSERT_DEBUG(nodeId == SockManGlobals::Get()->GetPlaneFC(TCFPlayerRole(TCFPlayerRole::EConnPlane)), User::Panic(KSpecAssert_ESockSSockslnkcp, 3));
       
   244     TAny* interface = NULL;
       
   245     TInt count = 0;
       
   246     TRAP_IGNORE(interface = FetchInterfaceL(nodeId.Node(), MLinkCprFactApiExt::KInterfaceId));
       
   247     if (interface)
       
   248         {
       
   249     	MLinkCprFactApiExt* cenumapi = reinterpret_cast<MLinkCprFactApiExt*>(interface);
       
   250     	cenumapi->EnumerateConnectionsL(*iConnectionInfoPtrArray);
       
   251     	count = iConnectionInfoPtrArray->Count();
       
   252         }
       
   253 	iMessage.WriteL(0, TPckg<TUint>(count));
       
   254 	__CFLOG_VAR((KShimCprTag, KShimCprSubTag, _L8("TCprFactEnumerateConnections %08x:\tDispatchL() completing message (%08X) with KErrNone"),
       
   255 						 this, iMessage.Handle()));
       
   256 	iMessage.Complete(KErrNone);
       
   257     }
       
   258 
       
   259 
       
   260 START_ATTRIBUTE_TABLE(TCprRetrieveProgress, KESockCprLinkExtMessagesImplementationUid, ECprRetrieveProgress)
       
   261 	REGISTER_ATTRIBUTE(TCprRetrieveProgress, iLastProgress, TMeta<TStateChange>)
       
   262 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, 0)
       
   263 
       
   264 START_ATTRIBUTE_TABLE(TCprRetrieveLastProgressError, KESockCprLinkExtMessagesImplementationUid, ECprRetrieveLastProgressError)
       
   265 	REGISTER_ATTRIBUTE(TCprRetrieveLastProgressError, iLastProgressError, TMeta<TStateChange>)
       
   266 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, 0)
       
   267 
       
   268 START_ATTRIBUTE_TABLE(TCprRequestServiceNotification, KESockCprLinkExtMessagesImplementationUid, ECprRequestServiceNotification)
       
   269 	REGISTER_ATTRIBUTE(TCprRequestServiceNotification, iSender, TMeta<Messages::TNodeId>)
       
   270 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, 0)
       
   271 
       
   272 START_ATTRIBUTE_TABLE(TCprCancelServiceNotification, KESockCprLinkExtMessagesImplementationUid,  ECprCancelServiceNotification)
       
   273 	REGISTER_ATTRIBUTE(TCprCancelServiceNotification, iSender, TMeta<Messages::TNodeId>)
       
   274 END_ATTRIBUTE_TABLE_BASE(TSignalBase, 0)
       
   275 
       
   276 START_ATTRIBUTE_TABLE(TCprEnumerateSubConnections, KESockCprLinkExtMessagesImplementationUid, ECprEnumerateSubConnections)
       
   277 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, 0)
       
   278 
       
   279 START_ATTRIBUTE_TABLE(TCprSendIoctl, KESockCprLinkExtMessagesImplementationUid, ECprSendIoctl)
       
   280 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, 0)
       
   281 
       
   282 START_ATTRIBUTE_TABLE(TCprCancelIoctl, KESockCprLinkExtMessagesImplementationUid, ECprCancelIoctl)
       
   283 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, 0)
       
   284 
       
   285 START_ATTRIBUTE_TABLE(TCprAllSubConnectionNotificationEnable, KESockCprLinkExtMessagesImplementationUid, ECprAllSubConnectionNotificationEnable)
       
   286 END_ATTRIBUTE_TABLE_BASE(TSignalBase, 0)
       
   287 
       
   288 START_ATTRIBUTE_TABLE(TCprFactEnumerateConnections, KESockCprLinkExtMessagesImplementationUid, ECprEnumerateConnections)
       
   289 	REGISTER_ATTRIBUTE(TCprFactEnumerateConnections, iConnectionInfoPtrArray, TMeta<RPointerArray<TConnectionInfo>*>)
       
   290 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, 0)
       
   291 
       
   292 const TImplementationProxy SignatureImplementationTable[] =
       
   293 	{
       
   294 	//NOTE: Entries must be sorted for the binary search to work efficiently!
       
   295 	MVIP_CTR_ENTRY(ECprRetrieveProgress,TCprRetrieveProgress),						//1
       
   296 	MVIP_CTR_ENTRY(ECprRetrieveLastProgressError,TCprRetrieveLastProgressError),	//2
       
   297 	MVIP_CTR_ENTRY(ECprRequestServiceNotification,TCprRequestServiceNotification),	//3
       
   298 	MVIP_CTR_ENTRY(ECprCancelServiceNotification,TCprCancelServiceNotification),	//4
       
   299 	MVIP_CTR_ENTRY(ECprEnumerateSubConnections,TCprEnumerateSubConnections),		//5
       
   300 	MVIP_CTR_ENTRY(ECprSendIoctl,TCprSendIoctl),									//6
       
   301 	MVIP_CTR_ENTRY(ECprCancelIoctl,TCprCancelIoctl),								//7
       
   302 	MVIP_CTR_ENTRY(ECprAllSubConnectionNotificationEnable,TCprAllSubConnectionNotificationEnable),	//8
       
   303 	MVIP_CTR_ENTRY(ECprEnumerateConnections,TCprFactEnumerateConnections),			//9
       
   304 	
       
   305 	MVIP_CTR_ENTRY(EMCprGetConnectionSetting,TMCprGetConnectionSetting),				//10 - legacy ext api
       
   306 
       
   307 	// Move these to somewhere more appropriate?
       
   308 	MVIP_CTR_ENTRY(ELegacyDataMonitoringTransferredRequest, TLegacyDataMonitoringTransferredRequest),	//11
       
   309 	MVIP_CTR_ENTRY(ELegacyDataMonitoringNotificationRequest, TLegacyDataMonitoringNotificationRequest),	//12
       
   310 	MVIP_CTR_ENTRY(ELegacyDataMonitoringNotificationCancel, TLegacyDataMonitoringNotificationCancel),	//13
       
   311 
       
   312 	MVIP_CTR_ENTRY(ELegacySubConnectionActiveRequest, TLegacySubConnectionActiveRequest),	// 14
       
   313 	MVIP_CTR_ENTRY(ELegacyCancelSubConnectionActive, TLegacyCancelSubConnectionActive),	// 15
       
   314 	MVIP_CTR_ENTRY(ELegacyEnumerateSubConnections, TLegacyEnumerateSubConnections),	// 16
       
   315 	};
       
   316 
       
   317 DEFINE_MVIP_CTR(TCprRetrieveProgress);
       
   318 DEFINE_MVIP_CTR(TCprRetrieveLastProgressError);
       
   319 DEFINE_MVIP_CTR(TCprRequestServiceNotification);
       
   320 DEFINE_MVIP_CTR(TCprCancelServiceNotification);
       
   321 DEFINE_MVIP_CTR(TCprEnumerateSubConnections);
       
   322 DEFINE_MVIP_CTR(TCprSendIoctl);
       
   323 DEFINE_MVIP_CTR(TCprCancelIoctl);
       
   324 DEFINE_MVIP_CTR(TCprAllSubConnectionNotificationEnable);
       
   325 DEFINE_MVIP_CTR(TCprFactEnumerateConnections);
       
   326 
       
   327 void TCprLinkExtMessageTables::RegisterL()
       
   328 	{
       
   329 	TlsGlobals::Get().RegisterInterfaceL(TUid::Uid(KESockCprLinkExtMessagesImplementationUid), sizeof(SignatureImplementationTable) / sizeof(SignatureImplementationTable[0]), SignatureImplementationTable);
       
   330 	}
       
   331 
       
   332 void TCprLinkExtMessageTables::DeRegister()
       
   333 	{
       
   334 	TlsGlobals::Get().DeregisterInterface(TUid::Uid(KESockCprLinkExtMessagesImplementationUid));
       
   335 	}
       
   336