realtimenetprots/rtp/cfrtp/inc/rtpbaseflow.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2008-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 // RTP Base Flow definitions.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef CRTPBASEFLOW_H
       
    24 #define CRTPBASEFLOW_H
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <e32std.h>
       
    28 
       
    29 #include <comms-infras/ss_factorycontainermap.h>
       
    30 #include <comms-infras/cfperfmetrics.h>
       
    31 #include <comms-infras/ss_subconnflow.h>
       
    32 #include <cs_subconparams.h>
       
    33 #include <comms-infras/ss_flowbinders.h>
       
    34 #include <comms-infras/ss_protflow.h>
       
    35 #include <comms-infras/nifif.h>
       
    36 #include <comms-infras/ss_nodemessages.h>
       
    37 #include <in_sock.h>
       
    38 #include <comms-infras/commsdebugutility.h>
       
    39 #include <es_mbuf.h>
       
    40 
       
    41 #include "cfrtphandler.h"
       
    42 
       
    43 using namespace ESock;
       
    44 class ESock::CSubConnectionFlowBase;
       
    45 
       
    46 #if defined(_DEBUG) || defined(__RTP_LOG_ACTIVE)
       
    47  #define KRtpFlowTag KCFNodeTag
       
    48 _LIT8(KRtpBaseFlowTag, "RtpBaseFlow");
       
    49 #endif
       
    50 
       
    51 
       
    52 _LIT (KRtpFlowPanic,"RtpFlowPanic");
       
    53 
       
    54 namespace RtpFlowPanics
       
    55 {
       
    56 enum
       
    57 	{
       
    58 	KPanicNoServiceProvider = 1,
       
    59 	KPanicNoControlProvider = 2,
       
    60 	KPanicNoDataClient = 2,
       
    61 
       
    62 	KPanicIncorrectMessage = 3,
       
    63 	
       
    64 	KPanicUnexpectedExecutionPath =4,
       
    65 	KPanicIncorrectState = 5,
       
    66 	KPanicPeerMisbehaving = 6,
       
    67 	KPanicIncompleteBuffer = 7,
       
    68 	};
       
    69 }
       
    70 //Fetches out an integer option. Returns if error.
       
    71 #define GETOPTION_OR_RETURN(optDESC,optVal) do{TInt optRet; optRet = GetOptionFromDesc(optDESC,optVal); \
       
    72 	                                                               if(KErrNone != optRet)return optRet;}while(0)
       
    73 
       
    74 class CRtpBaseFlow :public ESock::CSubConnectionFlowBase, public ESock::MFlowBinderControl,
       
    75 				    public MSessionControlNotify, MSessionDataNotify,ESock::MSessionData,ESock::MSessionControl,public MRtpDataSender
       
    76     /** CRtpBaseFlow is the base calss for both RTP and RTCP Flows
       
    77 
       
    78 	@internalComponent 
       
    79 	
       
    80 	**/				    
       
    81 	{
       
    82 	
       
    83 	friend class CRtpFlowFactory;
       
    84 
       
    85 	public:
       
    86 	
       
    87 	// Handling SCPR messages
       
    88 	void StopFlow(TCFDataClient::TStop& aMessage);
       
    89 	void BindToL(TCFDataClient::TBindTo& aBindTo);
       
    90 	void Destroy();
       
    91 
       
    92 	void ProcessDCIdleState();
       
    93 	void CompleteStart(TInt aError);
       
    94 
       
    95 	TInt iIsStarting;
       
    96 	TUint iStartActivityId:16;
       
    97 	
       
    98 
       
    99 	//CSubConnectionFlowBase	
       
   100  	virtual MFlowBinderControl* DoGetBinderControlL();
       
   101 	
       
   102 	// MFlowBinderControl Methods
       
   103 	 virtual ESock::MSessionControl* GetControlL(TInt aSessionType, ESock::MSessionControlNotify& aSessionControlNotify);
       
   104 	 virtual ESock::MSessionData* BindL(ESock::MSessionDataNotify& aNotify);
       
   105 	 virtual void Unbind();
       
   106 	 virtual CSubConnectionFlowBase& CloneFlowL();
       
   107 	 virtual CSubConnectionFlowBase* Flow();
       
   108 	 
       
   109 	// APIs From MSessionControl
       
   110 	public:
       
   111 	virtual void ActiveOpen();
       
   112 	virtual void ActiveOpen(const TDesC8& aConnectionData);
       
   113 	virtual TInt PassiveOpen(TUint aQueueSize);
       
   114 	virtual TInt PassiveOpen(TUint aQueueSize,const TDesC8& aConnectionData);
       
   115 	virtual void AutoBind();
       
   116 	virtual void LocalName(TSockAddr& anAddr) const;
       
   117 #ifndef SYMBIAN_STRICT_EXPLICIT_SOCKET_BINDING
       
   118 	virtual TInt SetLocalName(TSockAddr& anAddr);
       
   119 #else
       
   120 	virtual void SetLocalName(TSockAddr& anAddr);
       
   121 #endif //SYMBIAN_STRICT_EXPLICIT_SOCKET_BINDING
       
   122 	virtual void RemName(TSockAddr& anAddr) const;
       
   123 	virtual TInt SetRemName(TSockAddr& anAddr);
       
   124 	virtual void Shutdown(MSessionControl::TCloseType option);
       
   125 	virtual void Shutdown(MSessionControl::TCloseType option, const TDesC8& aDisconnectionData);
       
   126 	virtual TInt SecurityCheck(MProvdSecurityChecker* aSecurityChecker);
       
   127 	virtual TInt GetOption(TUint level, TUint name, TDes8 &anOption) const;
       
   128 	virtual TInt SetOption(TUint level, TUint name, const TDesC8 &anOption);
       
   129 	virtual void Ioctl(TUint level, TUint name, TDes8 *anOption);
       
   130 	virtual void CancelIoctl(TUint aLevel, TUint aName);
       
   131 	virtual void Start();
       
   132 	// END MSessionControl
       
   133 	
       
   134 	public:
       
   135 	//APIs from MSessionData 
       
   136 	virtual TUint Write(const TDesC8& aDesc,TUint aOptions, TSockAddr* anAddr = NULL);
       
   137 	virtual TInt Write(RMBufChain& aData, TUint aOptions, TSockAddr* anAddr = NULL )=0;
       
   138 	virtual void GetData(TDes8& aDesc,TUint options,TSockAddr* anAddr=NULL);
       
   139 	virtual TInt GetData(RMBufChain& aData, TUint aLength,TUint aOptions,TSockAddr* anAddr=NULL)=0;
       
   140 	//End MSessionData
       
   141 	
       
   142 	public:
       
   143 	//APIs from MSessionDataNotify 
       
   144 	virtual void NewData(TUint aCount);
       
   145 	virtual void CanSend();
       
   146 	//End MSessionDataNotify
       
   147 	
       
   148 	public:
       
   149 	/* from MSessionControlNotify */
       
   150 	virtual void ConnectComplete();
       
   151 	virtual void ConnectComplete(const TDesC8& aConnectData);
       
   152     virtual void ConnectComplete(CSubConnectionFlowBase& aSSP);
       
   153     virtual void ConnectComplete(CSubConnectionFlowBase& aSSP,const TDesC8& aConnectData);
       
   154 
       
   155 	/* From MRtpDataSender */
       
   156 	virtual void SendData(TDes8& aBuffer,TSockAddr& aRemoteAddr, TInt aFlags, TRequestStatus& aStatus)=0;
       
   157     
       
   158 	virtual void CanClose(MSessionControlNotify::TDelete aDelete=MSessionControlNotify::EDelete);
       
   159 	virtual void CanClose(const TDesC8& aDisconnectData,MSessionControlNotify::TDelete aDelete=MSessionControlNotify::EDelete);
       
   160 	virtual TInt Error(TInt anError,TUint anOperationMask=MSessionControlNotify::EErrorAllOperations);
       
   161 	virtual void Disconnect();
       
   162 	virtual void Disconnect(TDesC8& aDisconnectData);
       
   163 	virtual void IoctlComplete(TDesC8* aBuf);
       
   164 	virtual void DisconnectFromListener(CSubConnectionFlowBase& )
       
   165 		{
       
   166 		return;
       
   167 		}
       
   168 #ifdef SYMBIAN_STRICT_EXPLICIT_SOCKET_BINDING
       
   169 	//New callback to notify the completion of the asynchrnous call SetLocalName
       
   170 	virtual void SetLocalNameComplete();
       
   171 #endif //SYMBIAN_STRICT_EXPLICIT_SOCKET_BINDING
       
   172 
       
   173     /* Custom cleaning up */
       
   174     virtual void DoCanClose(MSessionControlNotify::TDelete aDelete)=0;
       
   175     
       
   176     /* Update Local address*/
       
   177     virtual void DoUpdateLocalAddress(const TSockAddr& anAddr)=0;
       
   178 
       
   179 	virtual TInt DoSetOption(TUint level, TUint name, const TDesC8 &anOption)=0;
       
   180 	virtual TInt DoGetOption(TUint level, TUint name, TDes8 &anOption) const=0;
       
   181     
       
   182     virtual ~CRtpBaseFlow();
       
   183     
       
   184 	protected:
       
   185 	CRtpBaseFlow(ESock::CSubConnectionFlowFactoryBase& aFactory, const  Messages::TNodeId& aSubConnId, ESock::CProtocolIntfBase* aProtocolIntf);
       
   186 	
       
   187 	/* Helper funtion that will send a No Bearer and save the Activity ID */
       
   188 	TInt HandleProvisionMessage(Messages::TSignatureBase& aMessage);
       
   189 	/* Creates and Sends a provision Done message with the Error Code */
       
   190 	TInt HandleBindToMessage(Messages::TSignatureBase& aMessage, TInt aErrCode);
       
   191 	/* handles a TError Message from SubConnection */
       
   192 	TInt HandleError(TInt aErrorCode);
       
   193 	
       
   194 	/* Fetches an option of type T from a descriptor */
       
   195 	template <class T> 
       
   196 	inline TInt GetOptionFromDesc(const TDesC8& aOption, T &opt) const
       
   197 		{
       
   198 		if(aOption.Length() < sizeof(T) || aOption.Length() > sizeof(T))
       
   199 			{
       
   200 			return KErrArgument;
       
   201 			}
       
   202 		TPckgBuf<T> optParams;
       
   203 		optParams.Copy(aOption);
       
   204 		opt = optParams();
       
   205 		return KErrNone;
       
   206 		}
       
   207 	
       
   208 	/* Fetches an option of type T from a descriptor */
       
   209 	template <class T> 
       
   210 	inline TInt CopyOptionToDesc(TDes8& aOption,const T& opt) const
       
   211 		{
       
   212 		if(aOption.Length() < sizeof(T))
       
   213 			{
       
   214 			return KErrOverflow;
       
   215 			}
       
   216 		// Descriptor containing Option 
       
   217 		TPckgBuf<T> optParams(opt);
       
   218 		aOption.Copy(optParams);
       
   219 		return KErrNone;
       
   220 		}
       
   221 
       
   222 	protected:	
       
   223 	ESock::MSessionDataNotify* iSessionDataNotify;
       
   224 	ESock::MSessionControlNotify* iSessionControlNotify;
       
   225 	
       
   226 	// Rtp Buffer
       
   227 	RMBufChain iRtpUpperLayerBuffer, iRtpLowerLayerBuffer;
       
   228 	
       
   229 	MSessionControl* iSSP; 
       
   230 	MSessionData* iSSPData;
       
   231 	MFlowBinderControl* iFlowBinder;
       
   232 	Messages::RNodeInterface iServiceProvider;
       
   233 			
       
   234 	/* Incase flows wants to hold on to an Activity */
       
   235 	TUint iScprActivityId; 
       
   236 	
       
   237 	/* Store destination address if connected */
       
   238 	TSockAddr iDestAddr;
       
   239 	/* Connected already .. thats it */
       
   240 	TBool     iConnected;
       
   241 	
       
   242 	/* We have issued a NoBearer and Waiting for its result */
       
   243 	TBool     iWaitingForBindTo;
       
   244  	
       
   245 	/* We received an imediate ShutDown. When UnBind is called 
       
   246 	 * shoot ourselves */
       
   247 	TBool     iRecvdImmediateShutDown;
       
   248 	
       
   249 	Messages::RRequestOriginator iStartRequest;
       
   250 	
       
   251 #ifdef SYMBIAN_STRICT_EXPLICIT_SOCKET_BINDING
       
   252 	TSockAddr iLocalAddress;	
       
   253 #endif //SYMBIAN_STRICT_EXPLICIT_SOCKET_BINDING	
       
   254 };
       
   255 
       
   256 
       
   257 
       
   258 
       
   259 #endif // CRTPBASEFLOW_H
       
   260 
       
   261