Chinaunix首页 | 论坛 | 博客
  • 博客访问: 318748
  • 博文数量: 88
  • 博客积分: 2051
  • 博客等级: 大尉
  • 技术积分: 950
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-14 23:59
文章分类

全部博文(88)

文章存档

2012年(3)

2011年(2)

2010年(9)

2009年(14)

2008年(60)

我的朋友

分类: C/C++

2008-11-20 23:52:53

plug-in本质是一个dll
mmp文件是这样的
TARGET  ShoutcastEngine.dll
TARGETTYPE      PLUGIN
UID  0x10009D8D 0xE020240A
 
这个dll是对某种interface的实现,这个interface的定义如下:
#define KInternetRadioAdapterInterfaceUid 0x1020240E   //定义接口的id
class MInternetRadioAdapter //接口函数的声明
 
一般M类不能通过指针记录保存下来,所以定义一个C类继承至M类,但是基本什么都不做。
class CPluginAdapter : public CBase,
           public MInternetRadioAdapter
{
//这个接口的实现类可以通过Observer向调用者回调
MInternetRadioAdapterObserver *iObserver;
}
 
所以,plug-in现在要做的就是要实现M类接口,其实就是从CPluginAdapter 继承! 但是接口可以有多种实现,这样就需要一个实现ID,调用者可以根据需要调用不同的实现,但是代码不需要很多改动!
 
最后,plug-in需要向ECom组件注册,能够让外界找到自己!symbian是这样做的,为这个DLL同时生成RSS文件,向系统注册自己。
 

RESOURCE REGISTRY_INFO theInfo
    {
    dll_uid = KShoutcastDLLUid;
    interfaces =
        {
            INTERFACE_INFO // PluginAdapter

            {
            interface_uid = KAudioAdapterInterfaceUid;
            implementations =
                {
                IMPLEMENTATION_INFO
                    {
                    implementation_uid = KShoutcastImplementationUid;
                    version_no = 1;
                    display_name = "Shoutcast Engine Plugin";
                    default_data = "Shoutcast";
                    opaque_data = "";
                    }
                };
            }        
        };
    }

这里最主要的三个ID分别是:

DLL ID - OS范围内识别该DLL的

Interface ID - 调用者通过REComSession::ListImplementationsL(TUid::Uid(KInternetRadioAdapterInterfaceUid), infoArray);指明Interface ID可以将自己曝露

Implementation ID - 调用者可以通过impl = REComSession::CreateImplementationL(implementationUid, _FOFF(CPluginAdapter,iDestructorIDKey), this);这个ID创建接口实现对象,最后一个this参数将会作为实现类的观察者。

因此,设计plug-in最重要的就是要设计接口。接口是调用者和实现类之间交互的方式,只有接口设计好了,plug-in才能有多种实现。

阅读(2021) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~