servicediscoveryandcontrol/pnp/test/upnp/IntegTest/testupnp/inc/testupnpmanager.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     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 // Contains declaration of CTestUPnPManager, CUPnPObserver, CUPnPTimer, 
       
    15 // and CAction classes
       
    16 // 
       
    17 //
       
    18 
       
    19 #ifndef __TEST_UPNP_MANAGER_H__
       
    20 #define __TEST_UPNP_MANAGER_H__
       
    21 
       
    22 // System Includes
       
    23 #include <testexecutestepbase.h>
       
    24 #include <e32base.h>
       
    25 #include <e32cmn.h>
       
    26 #include <e32std.h>
       
    27 #include <upnpparamset.h>
       
    28 #include <upnp/rpnpservicediscovery.h>
       
    29 #include <upnp/rpnpservicepublisher.h>
       
    30 #include <upnpparamset.h>
       
    31 #include <upnp/mpnpobserver.h>
       
    32 #include <upnp/pnpparameterbundle.h>
       
    33 #include <uri8.h>
       
    34 #include <inetprottextutils.h>
       
    35 #include <f32file.h>
       
    36 #include <es_sock.h>
       
    37 #include <in_sock.h>
       
    38 #include <commdbconnpref.h>
       
    39 #include <e32des8.h>
       
    40 #include <cinidata.h>
       
    41 #include <upnpdescriptionschema.h>
       
    42 #include <cstringpoolmanager.h>
       
    43 #include <cupnpdescriptionparser.h>
       
    44 
       
    45 
       
    46 
       
    47 // User Includes
       
    48 #include "constants.h"
       
    49 
       
    50 
       
    51 // Forward declarations
       
    52 class CUPnPObserver;
       
    53 class CAction;
       
    54 
       
    55 
       
    56 /*
       
    57 CTestUPnPManager class which is derived from the CTestStep and provides the
       
    58 functionalities to perform Create (and open) an individual TestStep (testcase or part testcase), Run a TestStep
       
    59 with defined pre and post processing, Abort a TestStep, Close a TestStep session.
       
    60 Also performs the creation control point or service point, performs a sequence of upnp operations
       
    61 and get back the results to compare them against expected results.
       
    62 */
       
    63 class CTestUPnPManager : public CTestStep
       
    64 	{
       
    65 public:
       
    66 	CTestUPnPManager();
       
    67 	~CTestUPnPManager();
       
    68 
       
    69 	virtual TVerdict doTestStepPreambleL();
       
    70 	virtual TVerdict doTestStepPostambleL();
       
    71 	virtual TVerdict doTestStepL();
       
    72 
       
    73 	void SetCurrentSection(const TDesC& aCurrentSection);
       
    74 	TDesC& GetCurrentSection();
       
    75 	
       
    76 	// Operation  related functions
       
    77 	void InitializeL();
       
    78 	void SequenceOperationsL();
       
    79 	void PerformDesiredOperationsL(const TDesC& aSequence);
       
    80 
       
    81 	// UPnP API related functions
       
    82 	TInt OpenPublisherL();
       
    83 	void OpenMultiplePublisherL();	
       
    84 	void OpenDiscovererL();
       
    85 	void ClosePublisher();
       
    86 	void DiscoverL(const TDesC& aOperationType);
       
    87 	void PublishDeviceL(const TDesC& aOperationType);
       
    88 	void PublishServiceL(const TDesC& aOperationType);
       
    89 	void DescribeL();
       
    90 	void DescribeServiceL();
       
    91 	void DescribeIconL();
       
    92 	void RegisterForAnnouncementsL(const TDesC& aOperationType);
       
    93 	void InitiateActionL(const TDesC& aOperationType);
       
    94 	void SubscribeForStateChangeNotificationsL();
       
    95 	void ReSubscribeForStateChangeNotificationsL();
       
    96 	TBool SendNotificationsL (CUPnPObserver* aObserver);
       
    97 
       
    98 	// Cancellation related functions
       
    99 	void CancelPublish();
       
   100 	void CancelDiscoverL(const TDesC& aOperationType);
       
   101 	void CancelNotifyAnnouncementL (const TDesC& aOperationType);
       
   102 	void UnsubscribeForStateChangeNotificationsL(const TDesC& aOperationType);
       
   103 	void CancelDescribeL(const TDesC& aOperationType);
       
   104 	void CancelAllDeviceDescribeL();
       
   105 	void CancelAllServiceDescribeL();
       
   106 
       
   107 	// Cleanup related functions
       
   108 	void CleanUpObserverArray();
       
   109 	void CloseDiscoverer();
       
   110 	void ScpdUriArrayCleanUp();
       
   111 	void ControlUriArrayCleanUp();
       
   112 	void EventUriArrayCleanUp();
       
   113 	void DeleteSeriveUrlsList(TInt aIndex);
       
   114 	void CleanUpResultsArray();
       
   115 
       
   116 	// Utility functions
       
   117 	void ResolveAllUrisL();
       
   118 	void ResolveScpdUrisL(TInt aIndex);
       
   119 	void ResolveEventUrisL(TInt aIndex);
       
   120 	void ResolveControlUrisL(TInt aIndex);
       
   121 	void AppendScpdUriL(RBuf8& aScpdUri);
       
   122 	void AppendEventUriL(RBuf8& aEventUri);
       
   123 	void AppendControlUriL(RBuf8& aControlUri);
       
   124 	void DescriptionSuiteCleanUp();
       
   125 	void GetServiceUrlsListL(TInt aIndex);
       
   126 	void GetEmbeddedDeviceServicesL(TInt aIndex, CUPnPDevice* aDevice);
       
   127 	void GetServiceValuesL(TInt aIndex, CUPnPDevice* aDevice);
       
   128 	void ExtractServiceDescriptionL (const TDesC& aConfigSection, CUPnPServiceRegisterParamSet& aServiceRegisterParamSet);
       
   129 	void TokenizeStringL(const TDesC& aString, RArray<TPtrC>& aList, TChar aSeparator = ',');
       
   130 	void StartTimerL(const TDesC& aOperationType);
       
   131 	void AppendBundlesL(RPnPParameterBundleBase& aPnPBundle);
       
   132 	//void AppendBundlesL(CPnPParameterBundleBase* aPnPBundle);
       
   133 	void AppendDeviceLocationL(TDesC8& aDevLocPointer);
       
   134 	void AppendDescriptionL(RBuf8& aBaseUri,RBuf8& aDescription);
       
   135 	TInt GetPublisherIndex (TInt aObserverIndex);
       
   136 	TPublisherControl GetPublisherControl (TInt aObserverIndex);
       
   137 	TInt NotifyCount();
       
   138 	void SavePreviousLogFileL();
       
   139 	const TDesC& ScriptFileName();
       
   140 	
       
   141 	void GetIconUrlsL (  TInt aBaseDescIdx, CUPnPDevice* aRootDevice );
       
   142 	void ResolveIconUrlL ( TInt aBaseDescIdx, const TDesC8& aUrl );
       
   143 	
       
   144 	// Functions related to Server
       
   145 	void  OpenServerL();
       
   146 	void  ListenL();
       
   147 	void  RecvDataL();
       
   148 	void  SendDataL();
       
   149 
       
   150 	// Functions related to Client
       
   151 	void OpenSocketL();
       
   152 	void DoConnectL();
       
   153 	void SendClientDataL(RSocket& aSocket);
       
   154 	void RecvClientDataL(RSocket& aSocket);
       
   155 
       
   156 	// Print related functions
       
   157 	//void PrintDiscoveryResultsL(CUPnPParameterFamily* aParamFamily);
       
   158 	void PrintDiscoveryResultsL(RParameterFamily& aParamFamily);
       
   159 	void PrintAndValidateResultsL(const TDesC& aOperationType);
       
   160 	void SetDiscoveryStatus(TBool aSuccess);
       
   161 	TBool IsDiscoverySuccess();
       
   162 	// Validation related functions
       
   163 	void ValidateDiscoveryResultsL(const TDesC& aOperationType);
       
   164 	TPublisherControl PublisherType (TInt aPublisherIndex);
       
   165 	
       
   166 private:
       
   167 	struct TPublisherObserverMap
       
   168 		{
       
   169 		TInt 				iPublisherIndex;
       
   170 		TInt 				iObserverIndex;
       
   171 		TPublisherControl	iPublisherControl;
       
   172 		};
       
   173 
       
   174 	struct TServiceUrl
       
   175 		{
       
   176 		RBuf8 serviceType;
       
   177 		RBuf8 scpdUrl;
       
   178 		RBuf8 controlUrl;
       
   179 		RBuf8 eventSubUrl;
       
   180 		};
       
   181 
       
   182 	struct TDescriptionSuite
       
   183 		{
       
   184 		//Base Url for which Description is retrieved
       
   185 		RBuf8 							iBaseUrl;
       
   186 		//Description of the url
       
   187 		RBuf8							iDescription;
       
   188 		//Retrieved urls from description
       
   189 		RArray<TServiceUrl> 			iServiceUrls;
       
   190 		};
       
   191 	
       
   192 	RArray<TPublisherObserverMap>			iPublisherObserverMap;
       
   193 	RArray<TDescriptionSuite>				iDescriptionSuiteArray;
       
   194 	RStringPool								iStringPool;
       
   195     CStringPoolManager* 					iStringPoolMgr;
       
   196 	RPnPServiceDiscovery					iControlPoint;
       
   197 	RArray<RPnPServicePublisher>			iPublisherArray;
       
   198 	RControlChannel							iControlChannel;
       
   199 	RPointerArray<CUPnPObserver>	 		iObserverArray;
       
   200 	RArray<RPnPParameterBundleBase>		iResultsArray;
       
   201 	CIniData*								iCIniDataHandle;
       
   202 	CAction*								iAction;
       
   203 	TInt									iNotifyCount;
       
   204 	TBool									iDiscoverySuccess;
       
   205 public:
       
   206 	CActiveScheduler*					iScheduler;
       
   207 	TBuf<KMaxBufLength>					iCurrentSection;
       
   208 	TBuf<KMaxBufLength> 				iScriptName;
       
   209 	TBool								iExpectedData;
       
   210 	RArray<TPtrC8>						iDeviceLocationArray;
       
   211 	RArray<RBuf8>						iScpdUriArray;
       
   212 	RArray<RBuf8>						iControlUriArray;
       
   213 	RArray<RBuf8>						iEventUriArray;
       
   214 	RArray<RBuf8>						iIconUriArray;
       
   215 	TBool								iCancelDiscovery;
       
   216 	TInt								iPublishCount;
       
   217 	TInt								iDescribeResponseCount;
       
   218 	TInt 								iRenewCount;
       
   219 	TInt 								iFailedNumUris;
       
   220 	
       
   221 	RConnection							iConnection;
       
   222 	RSocketServ							iSocketServ;
       
   223 	};
       
   224 
       
   225 /*
       
   226 CPnPObserver class which is derived from CBase and MPnPObserver to provide the
       
   227 following functionalities. It supports the methods capture the results when an
       
   228 upnp event is hit after performing any upnp operation.
       
   229 */
       
   230 class CUPnPObserver: public CBase, MPnPObserver
       
   231 	{
       
   232 public:
       
   233 	static CUPnPObserver* NewL(CTestUPnPManager* aManager);
       
   234 	~CUPnPObserver();
       
   235 	void OnPnPEventL (RPnPParameterBundleBase& aServiceEventInfo);
       
   236 	void OnPnPError (TInt aError);
       
   237 	CTestUPnPManager& Manager();
       
   238 	void CopyResultBundlesL(const RPnPParameterBundleBase& aPnpBundle);
       
   239 	void SequenceOperationsL();
       
   240 	void ExecuteL(const TDesC& aSequence);
       
   241 
       
   242 private:
       
   243 	CUPnPObserver();
       
   244 	void ConstructL(CTestUPnPManager* aManager);
       
   245 
       
   246 private:
       
   247 	CTestUPnPManager* 					iManager;
       
   248 	TUint								iSequence;
       
   249 	TInt 								iResultsCount;
       
   250 	RFs 								iFileServ;
       
   251 	};
       
   252 
       
   253 class TestUtils
       
   254 	{
       
   255 public:
       
   256 	void static LoadESockL ( RSocketServ& aSocketServ, RConnection& aConnection );
       
   257 	};
       
   258 
       
   259 /*
       
   260 CUPnPTimer class is derived from CActive. It to provides a Timer AO
       
   261 */
       
   262 class CUPnPTimer:public CActive
       
   263 	{
       
   264 public:
       
   265 	static CUPnPTimer* NewL (CTestUPnPManager* aManager);
       
   266 	~CUPnPTimer();
       
   267 	void IssueRequestL(TTimeIntervalMicroSeconds32 anInterval);
       
   268 
       
   269 	void RunL();
       
   270 	void DoCancel();
       
   271 
       
   272 private:
       
   273 	CUPnPTimer(CTestUPnPManager* aManager);
       
   274 	void ConstructL();
       
   275 
       
   276 private:
       
   277 	RTimer iTimer;
       
   278 	CTestUPnPManager* 	iManager;
       
   279 	};
       
   280 
       
   281 
       
   282 
       
   283 class CAction : public CActive
       
   284 	{
       
   285 public:
       
   286 	enum TActionState
       
   287 		{
       
   288 		ESendData,
       
   289 		EReceiveData
       
   290 		};
       
   291 	static CAction* NewL(CTestUPnPManager* aManager);
       
   292 	~CAction();
       
   293 	void RunL()	;
       
   294 	void InitiateActionControlL(TDesC8& aUri,RPnPServiceDiscovery& aControlPoint);
       
   295 
       
   296 private:
       
   297 	CAction(CTestUPnPManager* aManager);
       
   298 	void ConstructL();
       
   299 	void DoCancel();
       
   300 
       
   301 private:
       
   302 	CTestUPnPManager* 	iManager;
       
   303 	RControlChannel 	iControlChannel;
       
   304 	TActionState 		iActionState;
       
   305 	TControlMessage 	iCtrlMsg;
       
   306 	RBuf8 				iIncomingActionBuffer;
       
   307     RBuf8 				iOutgoingActionBuffer;
       
   308     RBuf8 				iCompleteBuffer;
       
   309 	RFs 				iFs;
       
   310     RFile				iFile;
       
   311 	};
       
   312 
       
   313 #endif //__TEST_UPNP_MANAGER_H__
       
   314