testdev/ite/test/com.nokia.testfw.cmdtool.test/test.resource/unittest/several.mmp.in.one.path/SysLibs/ECom/InterfaceClient/InterfaceClient.cpp
changeset 1 96906a986c3b
equal deleted inserted replaced
0:f1112f777ce9 1:96906a986c3b
       
     1 // InterfaceClient.cpp
       
     2 //
       
     3 // Copyright (c) 2001 Symbian Ltd.  All rights reserved.
       
     4 
       
     5 #include <badesca.h>
       
     6 
       
     7 #include <Interface.h>
       
     8 
       
     9 #include "CommonFramework.h"
       
    10 #include "InterfaceClient.h"
       
    11 
       
    12 // Utility clean up function
       
    13 void CleanupEComArray(TAny* aArray);
       
    14 
       
    15 // do the example
       
    16 LOCAL_C void doExampleL()
       
    17     {
       
    18 	_LIT(KText,"ECom client example\n\n");
       
    19 	console->Printf(KText);
       
    20 
       
    21 	TInterfaceClient client;
       
    22 	client.GetDefaultL();
       
    23 	client.GetBySpecificationL();
       
    24 	client.GetByDiscoveryL();
       
    25 	
       
    26 	REComSession::FinalClose();
       
    27 	}
       
    28 
       
    29 void TInterfaceClient::GetDefaultL()
       
    30 	{
       
    31 	_LIT(KText,"Case 1: getting the default implementation\n");
       
    32 	console->Printf(KText);
       
    33 
       
    34 	// Get the default implementation and call its method
       
    35 	CExampleInterface* ex1 = CExampleInterface::NewL();
       
    36 	CleanupStack::PushL(ex1);
       
    37 	TBuf<100> buf;
       
    38 	ex1 -> DoMethodL(buf);
       
    39 	CleanupStack::PopAndDestroy(); //ex1
       
    40 
       
    41 	// Print results
       
    42 	console -> Printf(buf);
       
    43 	}
       
    44 
       
    45 void TInterfaceClient::GetBySpecificationL()
       
    46 	{
       
    47 	_LIT(KText,"\nCase 2: getting an implementation by specification\n");
       
    48 	console->Printf(KText);
       
    49 
       
    50 	// Prepare data to pass to implementation
       
    51 	CExampleInterface::TExampleInterfaceInitParams p;
       
    52 	p.integer = 0;
       
    53 	_LIT(KMsg1,"Data in value: %d\n");
       
    54 	console -> Printf(KMsg1,p.integer);
       
    55 
       
    56 	// Get the implementation that has a data identifier text/xml
       
    57 	_LIT8(KSpec,"text/xml");
       
    58 	CExampleInterface* ex1 = CExampleInterface::NewL(KSpec,p);
       
    59 	CleanupStack::PushL(ex1);
       
    60 	TBuf<100> buf;
       
    61 	ex1 -> DoMethodL(buf);
       
    62 	CleanupStack::PopAndDestroy(); //ex1
       
    63 
       
    64 	// Print results
       
    65 	console -> Printf(buf);
       
    66 	_LIT(KMsg2,"Data out value: %d\n");
       
    67 	console -> Printf(KMsg2,p.integer);
       
    68 	}
       
    69 
       
    70 
       
    71 void TInterfaceClient::GetByDiscoveryL()
       
    72 	{
       
    73 	_LIT(KText,"\nCase 3: getting all implementations\n");
       
    74 	console->Printf(KText);
       
    75 
       
    76 	// Read info about all implementations into infoArray
       
    77 	RImplInfoPtrArray infoArray;
       
    78 	// Note that a special cleanup function is required to reset and destroy
       
    79 	// all items in the array, and then close it.
       
    80 	TCleanupItem cleanup(CleanupEComArray, &infoArray);
       
    81 	CleanupStack::PushL(cleanup);
       
    82 	CExampleInterface::ListAllImplementationsL(infoArray);
       
    83 
       
    84 	// Loop through each info for each implementation
       
    85 	// and create and use each in turn
       
    86 	CExampleInterface* ex;
       
    87 	TBuf<255> buf;
       
    88 	for (TInt i=0; i< infoArray.Count(); i++)
       
    89 		{
       
    90 		// Slice off first sub-section in the data section
       
    91 		TPtrC8 type = infoArray[i]->DataType();
       
    92 		type.Set(type.Left(type.Locate('|')));
       
    93 		// Need to convert narrow descriptor to be wide in order to print it
       
    94 		buf.Copy(type);
       
    95 		console -> Printf(buf);
       
    96 		console -> Printf(_L(": "));
       
    97 
       
    98 		// Create object of type and call its function
       
    99 		ex = CExampleInterface::NewL(type);
       
   100 		CleanupStack::PushL(ex);
       
   101 		ex -> DoMethodL(buf);
       
   102 		CleanupStack::PopAndDestroy(); //ex
       
   103 
       
   104 		// Print results
       
   105 		console -> Printf(buf); 
       
   106 		
       
   107 		ex = NULL;
       
   108 		buf.Zero();
       
   109 		}
       
   110 
       
   111 	// Clean up
       
   112 	CleanupStack::PopAndDestroy(); //infoArray, results in a call to CleanupEComArray
       
   113 	}
       
   114 
       
   115 // CleanupEComArray function is used for cleanup support of locally declared arrays
       
   116 void CleanupEComArray(TAny* aArray)
       
   117 	{
       
   118 	(static_cast<RImplInfoPtrArray*> (aArray))->ResetAndDestroy();
       
   119 	(static_cast<RImplInfoPtrArray*> (aArray))->Close();
       
   120 	}
       
   121