1 / 16

Symbian 上的 ECOM 开发

Symbian 上的 ECOM 开发. 主要内容. ECOM 架构 ECOM 接口类的定义及实现 实现 ECOM 接口 使用 ECOM 插件. ECOM 接口类的定义及实现. ECom 接口类的定义 ( 1 )接口对外提供的方法应该是一组虚函数 ( 2 )需要提供工厂函数 ( 3 )需要提供释放方法 ( 4 ) ECOM 接口还必须要定义一个 TUid 成员. ECOM 接口类的定义及实现. ECom 接口类的定义例子 class CShape : public CBase { public: // 接口的工厂函数

kyrie
Download Presentation

Symbian 上的 ECOM 开发

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Symbian上的ECOM开发

  2. 主要内容 • ECOM架构 • ECOM接口类的定义及实现 • 实现ECOM接口 • 使用ECOM插件

  3. ECOM接口类的定义及实现 • ECom接口类的定义 • (1)接口对外提供的方法应该是一组虚函数 • (2)需要提供工厂函数 • (3)需要提供释放方法 • (4)ECOM接口还必须要定义一个TUid成员

  4. ECOM接口类的定义及实现 • ECom接口类的定义例子 class CShape : public CBase { public: //接口的工厂函数 static CShape* NewL(); static CShape* NewL(const TDesC8& aMatch); //接口的析构函数,用于释放已经创建的实现 virtual ~CShape(); public: //接口类提供的方法 virtual void Draw(CWindowGc& aGraphicsContext) const = 0; private: //实现的标识 TUid iDtor_ID_Key; };

  5. ECOM接口类的定义及实现 • ECom接口类的定义例子 • 声明 class CShape : public CBase { public: //接口的工厂函数 static CShape* NewL(); static CShape* NewL(const TDesC8& aMatch); //接口的析构函数,用于释放已经创建的实现 virtual ~CShape(); public: //接口类提供的方法 virtual void Draw(CWindowGc& aGraphicsContext) const = 0; private: //实现的标识 TUid iDtor_ID_Key; };

  6. ECOM接口类的定义及实现 • ECom接口类的定义例子 • 工厂方法1 // 创建接口缺省的接口实现 inline CShape* CShape::NewL() { const TUid KCCircleInterfaceUid = {0x101F6150}; TAny* interface = REComSession::CreateImplementationL ( KCCircleInterfaceUid, _FOFF (CShape, iDtor_ID_Key)); return reinterpret_cast <CShape*> (interface); }

  7. ECOM接口类的定义及实现 • ECom接口类的定义例子 • 工厂方法2 //使用指定的解析器根据名字创建一个接口实现 inline CShape* CShape::NewL(const TDesC8& aMatch) { const TUid KCShapeInterfaceUid = {0x101F6001}; const TUid KCShapeResolverUid = {0x101F614E}; TEComResolverParams resolverParams; resolverParams.SetDataType (aMatch); resolverParams.SetWildcardMatch (ETrue); TAny* interface = REComSession::CreateImplementationL ( KCShapeInterfaceUid,_FOFF (CShape, iDtor_ID_Key), resolverParams, KCShapeResolverUid); return reinterpret_cast <CShape*> (interface); }

  8. ECOM接口类的定义及实现 • ECom接口类的定义例子 • 析构函数 inline CShape::~CShape() { REComSession::DestroyedImplementation (iDtor_ID_Key); }

  9. ECOM接口类的定义及实现 • ECom接口类的定义例子 • 实现解析器 #include <ecom/resolver.h> class CShapeResolver : public CResolver { public: static CShapeResolver* NewL (MPublicRegistry& aRegistry); virtual ~CShapeResolver(); public: // CResolver virtual TUid IdentifyImplementationL(TUid aInterfaceUid, const TEComResolverParams& aAdditionalParameters) const; virtual RImplInfoArray* ListAllL(TUid aInterfaceUid, const TEComResolverParams& aAdditionalParameters) const; ... ... };

  10. ECOM接口类的定义及实现 • ECom接口类的定义例子 • 实现解析器 //定义接口实现的工厂函数 const TImplementationProxy ImplementationTable[] = { IMPLEMENTATION_PROXY_ENTRY(0x101F614E, CShapeResolver::NewL) }; //输出接口实现 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) { aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); return ImplementationTable; }

  11. ECOM接口类的定义及实现 • ECom接口类的定义例子 • 解析器的资源定义 RESOURCE REGISTRY_INFO theInfo { dll_uid = 0xE01F614D; interfaces = { INTERFACE_INFO { // 系统的解析器接口ID interface_uid = 0x10009D90; implementations = { IMPLEMENTATION_INFO { implementation_uid = 0x101F614E; version_no = 1; display_name = ""; default_data = ""; opaque_data = ""; } }; } }; }

  12. ECOM接口类的定义及实现 • 实现ECOM接口 定义接口实现 class CCircle : public CShape { public: static CCircle* NewL(); public: // 从接口CShape继承的方法 virtual void Draw(CWindowGc& aGraphicsContext) const; protected: CCircle(); void ConstructL(); };

  13. ECOM接口类的定义及实现 • 实现ECOM接口 • 实现接口方法 void CCircle::Draw(CWindowGc& aGraphicsContext) const { const TInt KStartCoOrd = 30; const TInt KEndCoOrd = 90; TRect rect(TPoint(KStartCoOrd ,KStartCoOrd ), TPoint(KEndCoOrd ,KEndCoOrd )); aGraphicsContext.DrawEllipse(rect); }

  14. ECOM接口类的定义及实现 • 实现ECOM接口 • 定义及输出接口实现信息表 const TImplementationProxy ImplementationTable[] = { IMPLEMENTATION_PROXY_ENTRY(0x101F6150, CCircle::NewL), IMPLEMENTATION_PROXY_ENTRY(0x101F6151, CSquare::NewL), IMPLEMENTATION_PROXY_ENTRY(0x101F6152, CTriangle::NewL) }; EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) { aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); return ImplementationTable; }

  15. ECOM接口类的定义及实现 • 实现ECOM接口 • 定义实现的资源文件 RESOURCE REGISTRY_INFO theInfo { dll_uid = 0xE01F614F; // 声明接口的实现信息数组 interfaces = { INTERFACE_INFO { // 被实现的接口UID interface_uid = 0x101F6001; implementations = { // 圆形实现的插件信息 IMPLEMENTATION_INFO { implementation_uid = 0x101F6150; version_no = 1; display_name = "Circle shape"; default_data = "CIRCLE"; opaque_data = ""; }, … …

  16. ECOM接口类的定义及实现 • 使用ECOM插件 CShape* iCircle; _LIT8 (KCircleText,"Circle"); iCircle = CShape::NewL(KCircleText); iCircle->Draw(gc); delete iCircle;

More Related