TCPMP之node

 typedef struct datadef
{
    int    No;       
    int    Type;
    int    Flags;
    int    Format1; // DF_MINMAX:min, DF_ENUMSRING:string class, DF_ENUMCLASS:node class, nodeclass
    int    Format2; // DF_MINMAX:max
    const tchar_t* Name;
    int Class;           
    int Size;
} datadef;
其中:
int NO  數據唯一標識。通過定義一個有意義的宏來表明用途。比如player.h中:
// buffer size in KB (int)
#define PLAYER_BUFFER_SIZE    0x20
// microdrive buffer size in KB (int)
#define PLAYER_MD_BUFFER_SIZE 0x80

int Type    數據類型標識。
#define TYPE_BOOL            1
#define TYPE_INT
#deinfe TYPE_RECT

int Flags    數據特性的標誌。可以“並”在一起使用。根據不同的Type,可以使用不同的Flags.
#define DF_RDONLY            0x00000001
#define DF_SETUP            0x00000002
#define DF_HIDDEN            0x00000004
#define DF_MINMAX            0x00000008

datatable都是用來定義數組的元素。在數組的最後都要添加宏DATATABLE_END(Class)。這樣,數組中的datatable類型的元素中,如果Type==-1,那麼就表示數組結束了。而-1前面的值則是這個數組中每項數據所屬的class(node)。
typedef struct datatable
{
    int    No;
    int    Type;
    int Flags;
    int Format1;
    int    Format2;
} datatable;
#define DATATABLE_END(Class) { Class, -1 }
在player.c中定義了PlayerParams[],這個數組可以看作是所有與Player相關的各種參數。
static const datatable PlayerParams[] =
{
    { PLAYER_AUTOPREROTATE,    TYPE_BOOL, DF_SETUP },
    { PLAYER_REPEAT,        TYPE_BOOL, DF_SETUP|DF_HIDDEN },
    { PLAYER_SHUFFLE,        TYPE_BOOL, DF_SETUP|DF_HIDDEN },
    { PLAYER_KEEPPLAY_AUDIO,TYPE_BOOL, DF_SETUP },
    ...
}
在player.c中定義的BufferParams[]則是與緩衝區相關的各種參數。
static const datatable BufferParams[] =
{
    { PLAYER_BUFFER_SIZE,    TYPE_INT, DF_SETUP|DF_KBYTE|DF_GAP, 512, 128*1024 },
    { PLAYER_UNDERRUN,        TYPE_INT, DF_SETUP|DF_PERCENT,0,PERCENT_ONE },

在node.h中定義的關於node的部分。其中VMT_NODE是用於擴展node的宏。node則定義了node的標識Class、獲取node所有屬性的函數指針Enum、設置和讀取node屬性的函數指針Get, Set。相對於nodedef,node可以理解爲一個數據實體。而nodedef則定義了node的類型Flags、創建、銷燬、優先級,以及node之間的關係(通過ParentClass)。node與nodedef的關聯是通過node Class。node class是一個int, 其中4個字節存放的是四個ascii字母。比如,DMO_CLASS='ADMO'。
#define VMT_NODE   /
 int   Class;  /
 nodeenum Enum;  /
 nodeget  Get;  /
 nodeset  Set;

typedef struct node
{
 int   Class;
 nodeenum Enum;
 nodeget  Get;
 nodeset  Set;
} node;

typedef struct nodedef
{
 int    Flags;
 int    Class;
 int    ParentClass;
 int    Priority;
 nodecreate  Create;
 nodedelete  Delete;
} nodedef;

Player Node. 通過擴展VMT_NODE,添加Player特有的函數定義了,Player節點。
typedef struct player_t
{
 VMT_NODE
 playerpaint  Paint;
 playercomment CommentByName;
 playerswap  ListSwap;
 playerprocess Process;

} player;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章