电竞比分网-中国电竞赛事及体育赛事平台

分享

struct class 和 struct class_device

 nt_bookworm 2012-03-19
設(shè)備類struct class是一個(gè)設(shè)備的高級(jí)視圖,它抽象出低級(jí)的實(shí)現(xiàn)細(xì)節(jié)。例如,驅(qū)動(dòng)可以見到一個(gè)SCSI磁盤或者一個(gè)ATA磁盤,在類的級(jí)別,他們都是磁盤,類允許用戶空間基于它們作什么來使用設(shè)備,而不是它們?nèi)绾伪贿B接或者它們?nèi)绾喂ぷ鳌?br>struct class{
    const char *name;   //類名稱
    struct module *owner;   //對(duì)應(yīng)模塊
    struct subsystem subsys;   //對(duì)應(yīng)的subsystem;
    struct list_head children;   //class_device鏈表
    struct list_head  interfaces;   //class_interface鏈表
    struct semaphore  sem;   //用于同步的信號(hào)鎖
    struct class_attribute *class_attrs;   //類屬性
    int (*uevent)(struct class_device *dev,char **envp,int num_envp,
                  char *buffer,int buffer_size);   //事件
    void (*release)(struct class_device *dev);   //釋放類設(shè)備
    void (*class_release)(struct class *class);    //釋放類
}

 

調(diào)用函數(shù):

int class_register(struct class *cls); 

用于注冊(cè)
void class_unregister(struct class *cls);

用于注銷


      class可以看成是一個(gè)容器,容器總包含了很多的class_device,每個(gè)都對(duì)應(yīng)著一個(gè)具體的邏輯設(shè)備,并通過成員變量dev關(guān)聯(lián)一個(gè)物理設(shè)備。定義為:
struct class_device
{
    struct list_head node;

    struct kobject  kobj;   //內(nèi)嵌的kobject,用于計(jì)數(shù)

    struct class   *class;   //所屬的類;

    dev_t   devt;   //dev_t設(shè)備號(hào)

    struct class_device_attribute  *devt_attr;

    struct class_device_attribute  uevent_attr;

    struct device  *dev;   //如果存在,創(chuàng)建到/sys/devices相應(yīng)入口的符號(hào)鏈接

    void *class_data;   //私有數(shù)據(jù)

    struct class_device  *parent;   //父設(shè)備

    void (*release)(struct class_device *dev);   //釋放對(duì)應(yīng)類實(shí)際設(shè)備的方法

    int(*uevent)(struct class_device *dev,char **envp,
                int num_envp,char *buffer,int buffer_size);

    char class_id[BUS_IO_SIZE];  //類標(biāo)志
}

調(diào)用函數(shù):

int class_device_register(struct class_device *class_dev); 

用于注冊(cè)
void class_device_unregister(struct class_device *class_dev);

用于注銷

 

相關(guān)結(jié)構(gòu)體

struct class_interface
{
    struct list_head node;  
    struct class *class;   //所屬的class
    int (*add)(struct class_device *,struct class_interface *);  //設(shè)備加入時(shí)觸發(fā)
    void (*remove)(struct class_device *,struct class_interface *);//設(shè)備移出時(shí)觸發(fā)
}

調(diào)用函數(shù):
int class_interface_register(struct class_interface *class_intf);

用于注冊(cè)
void class_interface_unregister(struct class_interface *class_intf);
用于注銷

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多