InterfaceImplementation
: interface implementation
example code
Found in: Examples\SysLibs\ECom\InterfaceImplementation\
The files reproduced here are the main files contained in the examples directory. Some extra files may be needed to run the examples, and these will be found in the appropriate examples directory.
//
// CImplementationClassOne.h
// Copyright © 2001 Symbian Ltd. All rights reserved.
//
#ifndef _CIMPLEMENTATIONCLASSONE__
#define _CIMPLEMENTATIONCLASSONE__
#include <Interface.h>
// An implementation of the CExampleInterface definition
class CImplementationClassOne : public CExampleInterface
{
public:
// Standardised safe construction which leaves nothing the cleanup stack.
static CImplementationClassOne* NewL(TAny* aInitParams);
// Destructor
~CImplementationClassOne();
// Implementation of CExampleInterface
void DoMethodL(TDes& aString);
private:
// Construction
CImplementationClassOne(TAny* aParams);
void ConstructL();
private:
// Data to pass back from implementation to client
HBufC* iDescriptor;
// Parameters taken from client
CExampleInterface::TExampleInterfaceInitParams* iInitParams;
};
#endif
//
// CImplementationClassTwo.h
// Copyright © 2001 Symbian Ltd. All rights reserved.
//
#ifndef _CIMPLEMENTATIONCLASSTWO__
#define _CIMPLEMENTATIONCLASSTWO__
#include <Interface.h>
// An implementation of the CExampleInterface definition
class CImplementationClassTwo : public CExampleInterface
{
public:
// Standardised safe construction which leaves nothing the cleanup stack.
static CImplementationClassTwo* NewL(TAny* aInitParams);
// Destructor
~CImplementationClassTwo();
// Implementation of CExampleInterface
void DoMethodL(TDes& aString);
private:
// Construction
CImplementationClassTwo(TAny* aInitParams);
void ConstructL();
private:
// Data to pass back from implementation to client
HBufC* iDescriptor;
// Parameters taken from client
CExampleInterface::TExampleInterfaceInitParams* iInitParams;
};
#endif
//
// CImplementationClassOne.cpp
// Copyright © 1997-2001 Symbian Ltd. All rights reserved.
//
#include "CImplementationClassOne.h"
// Construction and destruction functions
CImplementationClassOne* CImplementationClassOne::NewL(TAny* aInitParams)
{
CImplementationClassOne* self=new(ELeave) CImplementationClassOne(aInitParams);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
CImplementationClassOne::~CImplementationClassOne()
{
delete iDescriptor;
}
CImplementationClassOne::CImplementationClassOne(TAny* aInitParams)
// Store input/output parameters
: iInitParams((CExampleInterface::TExampleInterfaceInitParams*)aInitParams)
{
// See ConstructL() for initialisation completion.
}
void CImplementationClassOne::ConstructL()
// Safely complete the initialization of the constructed object
{
// Set up the data on the heap to pass back
_LIT(KDescriptor, "Using Implementation One\n");
iDescriptor = KDescriptor().AllocL();
}
// Implementation of CExampleInterface
void CImplementationClassOne::DoMethodL(TDes& aString)
{
aString = *iDescriptor;
// Set the parameter to something significant
if (iInitParams)
iInitParams->integer=1;
}
// CImplementationClassTwo.cpp
// Copyright © 1997-2001 Symbian Ltd. All rights reserved.
//
#include "CImplementationClassTwo.h"
// Construction and destruction functions
CImplementationClassTwo* CImplementationClassTwo::NewL(TAny* aParams)
{
CImplementationClassTwo* self=new(ELeave) CImplementationClassTwo(aParams);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
CImplementationClassTwo::~CImplementationClassTwo()
{
delete iDescriptor;
}
CImplementationClassTwo::CImplementationClassTwo(TAny* aInitParams)
: iInitParams((CExampleInterface::TExampleInterfaceInitParams*)aInitParams)
{
// See ConstructL() for initialisation completion.
}
void CImplementationClassTwo::ConstructL()
// Safely complete the initialization of the constructed object
{
// Set up the data to pass back
_LIT(KDescriptor, "Using Implementation Two\n");
iDescriptor = KDescriptor().AllocL();
}
// Implementation of CExampleInterface
void CImplementationClassTwo::DoMethodL(TDes& aString)
{
aString = *iDescriptor;
if (iInitParams)
iInitParams->integer=2;
}
//
// Proxy.cpp
// Copyright © 1997-2001 Symbian Ltd. All rights reserved.
//
#include <e32std.h>
#include <ImplementationProxy.h>
#include "CImplementationClassOne.h"
#include "CImplementationClassTwo.h"
// Map the interface UIDs to implementation factory functions
const TImplementationProxy ImplementationTable[] =
{
IMPLEMENTATION_PROXY_ENTRY(0x10009DC3, CImplementationClassOne::NewL),
IMPLEMENTATION_PROXY_ENTRY(0x10009DC4, CImplementationClassTwo::NewL)
};
// Exported proxy for instantiation method resolution
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
{
aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
return ImplementationTable;
}
// 10009DB1.RSS
//
// Copyright (c) 1997-2001 Symbian Ltd. All rights reserved.
//
// Registry file for the Example Interface Implementation Collection
#include "RegistryInfo.rh"
// Declares info for two implementations
RESOURCE REGISTRY_INFO theInfo
{
// UID for the DLL
dll_uid = 0x10009DB1;
// Declare array of interface info
interfaces =
{
INTERFACE_INFO
{
// UID of interface that is implemented
interface_uid = 0x10009DC0;
implementations =
{
// Info for CImplementation1
IMPLEMENTATION_INFO
{
implementation_uid = 0x10009DC3;
version_no = 1;
display_name = "Implementation 1";
default_data = "text/wml||This is the type of data that this implementation understands. (Can be anything which will allow the resolver to identify this implementation as the correct one at run time. In this case it is a mime type).";
opaque_data = "test_params";
},
// Info for CImplementation2
IMPLEMENTATION_INFO
{
implementation_uid = 0x10009DC4;
version_no = 1;
display_name = "Implementation 1||Copyright © 1997-2001 Symbian Ltd. All Rights Reserved.||";
default_data = "text/xml||Type of data handled";
opaque_data = "";
}
};
}
};
}
// EComExample.mmp
//
// Copyright (c) 2001 Symbian Ltd. All rights reserved.
//
TARGET EComExample.dll
TARGETTYPE PLUGIN
// ECom Dll recognition UID followed by the unique UID for this dll
UID 0x10009D8D 0x10009DB1
VENDORID 0x70000001
CAPABILITY All -TCB
SOURCEPATH .
SOURCE main.cpp
SOURCE Proxy.cpp
SOURCE CImplementationClassOne.cpp
SOURCE CImplementationClassTwo.cpp
USERINCLUDE .
SYSTEMINCLUDE \epoc32\include
SYSTEMINCLUDE \epoc32\include\ecom
start resource 10009DB1.rss
TARGET EComExample.rsc
end
LIBRARY euser.lib ECom.lib
InterfaceImplementation
provides two implementations of
the CExampleInterface
interface that is defined in the
InterfaceDefinition
example.
The implementations, CImplementationClassOne
and
CImplementationClassTwo
, each define
CExampleInterface
's virtual DoMethodL()
function to
return a string, and to set an integer parameter passed by the client.
The 10009DB1.rss
file contains a
REGISTRY_INFO
resource that declares ECom registration information
for the two implementations.
Building InterfaceImplementation
produces a DLL,
EComExample.dll
, and compiled resource file,
EComExample.rsc
, in the \resource\plugins\
directory.
A client program that accesses these implementations is provided in the
InterfaceClient
example.