XBMC研究之C-Pluff熟悉

来源:互联网 发布:深入浅出4g网络下载 编辑:程序博客网 时间:2024/06/17 14:28

转载自:http://blog.sina.com.cn/s/blog_6c14c17e0100ln87.html   

    在XBMC中,有不少libraries没用过,在研究XBMC框架前,先把它们过一遍。
    在XBMC中,扩展功能模块采用了c-pluff,c-pluff是一个用于访问扩展功能和管理插件依赖关系的框架。
XBMC研究之C-Pluff熟悉


    下面来介绍一下常用的函数:
    1) Call cp_init to initializing the plug-in framework
    #include <cpluff.h>
    ctx = cp_init();
    if (ctx == NULL)
    {
        ...
    }
    2) Call cp_create_context to creating a plug-in context
    #include <cpluff.h>
    ctx = cp_create_context(&status);
    if (ctx == NULL)
    {
        ...
    }
    3) Loading plug-ins
    the main program can load individual plug-ins from known locations using cp_load_plugin_descriptor and cp_install_plugin.
    #include <stdio.h>
    #include <cpluff.h>
    extern cp_context_t *ctx;
    static char *plugindir[] = { "/home/addons/skin.beagle", "/User/addons/confluence",};
    void load_plugins(void)
    {
        int i = 0;
        // Load each listed plug-in
        for(i = 0; i < 2; i )
        {
             cp_plugin_info_t *plugininfo;
             cp_status_t status;
             // Load plug-in descriptor
             plugininfo = cp_load_plugin_descriptor(ctx, plugindir[i], &status);
             if (plugininfo == NULL) {
                 // ... handle loading failure ...
             }
             // Install plug-in descriptor
             status = cp_install_plugin(ctx, plugininfo);
             if (status != CP_OK) {
                 // ... handle loading failure ...
             }
            // Release plug-in descriptor information
            cp_release_info(ctx, plugininfo);
        }
    }
    4) using cp_register_pcollection to register a plug-in context, and using cp_scan_plugins to scan/load plug-in
    #include <cpluff.h>
    extern cp_context_t *ctx;
    static const char pluginCollectionDir[] = "/home/addon";
    void load_plugins(void) {
        cp_status_t status;

        status = cp_register_pcollection(ctx, pluginCollectionDir);
        if (status != CP_OK) {
            // ... handle loading failure ...
        }
        status = cp_scan_plugins(ctx, 0);
        if (status != CP_OK) {
            // ... handle loading failure ...
            // (notice that some plug-ins might have been loaded)
        }
    }
    5) start the core plug-in using cp_start_plugin and then execute plug-in run functions using cp_run_plugins.
    #include <cpluff.h>
    extern cp_context_t *ctx;
    static const char corePluginId[] = "org.example.core";
    void run_plugins(char *argv[]) {
        cp_status_t status;
        // Set plug-in startup arguments
        cp_set_context_args(ctx, argv);
        // Start the core plug-in, possibly activating other plug-ins as well
        status = cp_start_plugin(ctx, corePluginId);
        if (status != CP_OK) {
            // ... handle startup failure ...
        }
        // Execute plug-ins until there is no more work to be done
        cp_run_plugins(ctx);
    }
    int main(int argc, char *argv[]) {
        // ... do initialization and load plug-ins ...
        run_plugins(argv);
        // ... do destruction ...
    }
    插件介绍
    每个插件都保存在单独的目录(目录命名与addon id一致),并命名为addon.xml。在插件目录也会有一些资源文件如icon.png,fanart.jpg等,用于直观的显示到UI上。
    <?xml version="1.0" encoding="UTF-8"?>
    <addon id="skin.beagle" version="1.0.0" name="Beagle" provider-name="topfs2, Team XBMC">
        <requires>
            <import addon="xbmc.gui" version="2.11"/>
        </requires>
        <extension point="xbmc.gui.skin" defaultresolution="720p" defaultresolutionwide="720p" defaultthemename="textures.xbt" effectslowdown="1.0" debugging="false"/>
        <extension point="xbmc.addon.metadata">
            <summary>Beagle skin by topfs2</summary>
            <description>Beagle is a skin created in Google Summer of Code 2010 meant to be an extremely lightweight skin for use on embedded systems</description>
            <platform>all</platform>
        </extension>
    </addon>
    以上面的plug-in为例,分析如下:
    1) requires子元素用于插件依赖项

    2) extension子元素用于描述扩展项功能
    3) addon id属性是此扩展功能的唯一性标识。只能使用小写字母和半角点号、下划线、连字符以及数字。这个标识符同时用于保存此扩展功能模块的目录名。为便于查找,建议使用类似<扩展功能类型>.<唯一性名称>的形式。
    4) addon version属性由XBMC用来判断是否有可用更新。
    5) addon name属性是扩展功能在用户界面中显示的名称。
    6) addon provider-name属性是开发者信息。
    7) addon requires元素的import子元素用于插入依赖的其它扩展功能及版本
    一些推荐的规则:
    icon.png有一些规则:
    1) 用于向用户表述这个扩展功能;
    2) 256x256的正方形PNG文件;
    3) 没有阴影、光泽或类似特效
    4) 它不应该有阴影、光泽或类似特效--XBMC皮肤系统会处理这些;
    5) 采用在平面背景(非透明)下的logo。
    fanart.png规则如下:
    1) 用作背景,应该简洁没有文字;
    2) 为1280x720的JPG文件,分辨率不要高于1920x1080;
    3) 文件字节尽量小。

参考:
http://www.c-pluff.org/reference/c-api/plugin.html
http://bbs.htpc1.com/archiver/tid-98828.html
原创粉丝点击