00001 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // 00015 00016 #include <badesca.h> 00017 00018 #include <interface.h> 00019 00020 #include "CommonFramework.h" 00021 #include "InterfaceClient.h" 00022 00023 // Utility clean up function 00024 void CleanupEComArray(TAny* aArray); 00025 00026 // do the example 00027 LOCAL_C void doExampleL() 00028 { 00029 _LIT(KText,"ECom client example\n\n"); 00030 console->Printf(KText); 00031 00032 TInterfaceClient client; 00033 client.GetDefaultL(); 00034 client.GetBySpecificationL(); 00035 client.GetByDiscoveryL(); 00036 00037 REComSession::FinalClose(); 00038 } 00039 00040 void TInterfaceClient::GetDefaultL() 00041 { 00042 _LIT(KText,"Case 1: getting the default implementation\n"); 00043 console->Printf(KText); 00044 00045 // Get the default implementation and call its method 00046 CExampleInterface* ex1 = CExampleInterface::NewL(); 00047 CleanupStack::PushL(ex1); 00048 TBuf<100> buf; 00049 ex1 -> DoMethodL(buf); 00050 CleanupStack::PopAndDestroy(); //ex1 00051 00052 // Print results 00053 console -> Printf(buf); 00054 } 00055 00056 void TInterfaceClient::GetBySpecificationL() 00057 { 00058 _LIT(KText,"\nCase 2: getting an implementation by specification\n"); 00059 console->Printf(KText); 00060 00061 // Prepare data to pass to implementation 00062 CExampleInterface::TExampleInterfaceInitParams p; 00063 p.integer = 0; 00064 _LIT(KMsg1,"Data in value: %d\n"); 00065 console -> Printf(KMsg1,p.integer); 00066 00067 // Get the implementation that has a data identifier text/xml 00068 _LIT8(KSpec,"text/xml"); 00069 CExampleInterface* ex1 = CExampleInterface::NewL(KSpec,p); 00070 CleanupStack::PushL(ex1); 00071 TBuf<100> buf; 00072 ex1 -> DoMethodL(buf); 00073 CleanupStack::PopAndDestroy(); //ex1 00074 00075 // Print results 00076 console -> Printf(buf); 00077 _LIT(KMsg2,"Data out value: %d\n"); 00078 console -> Printf(KMsg2,p.integer); 00079 } 00080 00081 00082 void TInterfaceClient::GetByDiscoveryL() 00083 { 00084 _LIT(KText,"\nCase 3: getting all implementations\n"); 00085 console->Printf(KText); 00086 00087 // Read info about all implementations into infoArray 00088 RImplInfoPtrArray infoArray; 00089 // Note that a special cleanup function is required to reset and destroy 00090 // all items in the array, and then close it. 00091 TCleanupItem cleanup(CleanupEComArray, &infoArray); 00092 CleanupStack::PushL(cleanup); 00093 CExampleInterface::ListAllImplementationsL(infoArray); 00094 00095 // Loop through each info for each implementation 00096 // and create and use each in turn 00097 CExampleInterface* ex; 00098 TBuf<255> buf; 00099 for (TInt i=0; i< infoArray.Count(); i++) 00100 { 00101 // Slice off first sub-section in the data section 00102 TPtrC8 type = infoArray[i]->DataType(); 00103 type.Set(type.Left(type.Locate('|'))); 00104 // Need to convert narrow descriptor to be wide in order to print it 00105 buf.Copy(type); 00106 console -> Printf(buf); 00107 console -> Printf(_L(": ")); 00108 00109 // Create object of type and call its function 00110 ex = CExampleInterface::NewL(type); 00111 CleanupStack::PushL(ex); 00112 ex -> DoMethodL(buf); 00113 CleanupStack::PopAndDestroy(); //ex 00114 00115 // Print results 00116 console -> Printf(buf); 00117 00118 ex = NULL; 00119 buf.Zero(); 00120 } 00121 00122 // Clean up 00123 CleanupStack::PopAndDestroy(); //infoArray, results in a call to CleanupEComArray 00124 } 00125 00126 // CleanupEComArray function is used for cleanup support of locally declared arrays 00127 void CleanupEComArray(TAny* aArray) 00128 { 00129 (static_cast<RImplInfoPtrArray*> (aArray))->ResetAndDestroy(); 00130 (static_cast<RImplInfoPtrArray*> (aArray))->Close(); 00131 } 00132
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.