00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <badesca.h>
00017
00018 #include <interface.h>
00019
00020 #include "CommonFramework.h"
00021 #include "InterfaceClient.h"
00022
00023
00024 void CleanupEComArray(TAny* aArray);
00025
00026
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
00046 CExampleInterface* ex1 = CExampleInterface::NewL();
00047 CleanupStack::PushL(ex1);
00048 TBuf<100> buf;
00049 ex1 -> DoMethodL(buf);
00050 CleanupStack::PopAndDestroy();
00051
00052
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
00062 CExampleInterface::TExampleInterfaceInitParams p;
00063 p.integer = 0;
00064 _LIT(KMsg1,"Data in value: %d\n");
00065 console -> Printf(KMsg1,p.integer);
00066
00067
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();
00074
00075
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
00088 RImplInfoPtrArray infoArray;
00089
00090
00091 TCleanupItem cleanup(CleanupEComArray, &infoArray);
00092 CleanupStack::PushL(cleanup);
00093 CExampleInterface::ListAllImplementationsL(infoArray);
00094
00095
00096
00097 CExampleInterface* ex;
00098 TBuf<255> buf;
00099 for (TInt i=0; i< infoArray.Count(); i++)
00100 {
00101
00102 TPtrC8 type = infoArray[i]->DataType();
00103 type.Set(type.Left(type.Locate('|')));
00104
00105 buf.Copy(type);
00106 console -> Printf(buf);
00107 console -> Printf(_L(": "));
00108
00109
00110 ex = CExampleInterface::NewL(type);
00111 CleanupStack::PushL(ex);
00112 ex -> DoMethodL(buf);
00113 CleanupStack::PopAndDestroy();
00114
00115
00116 console -> Printf(buf);
00117
00118 ex = NULL;
00119 buf.Zero();
00120 }
00121
00122
00123 CleanupStack::PopAndDestroy();
00124 }
00125
00126
00127 void CleanupEComArray(TAny* aArray)
00128 {
00129 (static_cast<RImplInfoPtrArray*> (aArray))->ResetAndDestroy();
00130 (static_cast<RImplInfoPtrArray*> (aArray))->Close();
00131 }
00132