g_object_new()的理解。

os posted @ 2013年9月11日 18:03 in GObject , 3452 阅读

gobjec相关学习文章的list.

 

前面大致弄明白了:

Parameter, paramSpec, closure, marsharl, gsignal, quark data

以及base_class_init()/class_init()/instance_init()的过程。

 

下面开始看gobject的具体使用,涉及到property/signal等等。

 

先看g_object_new(): 

 这个函数的过程要理解透:

1. 调用g_type_class_ref()

    (1). 先递归找到最top层的,然后开始层层处理

    (2). type_class_init_Wm()

         <1>. 从Top --> Bottom 调用base_class_init()

         <2>. 调用class_init()

               class_init()里面干了不少事情,参考后面的。

2. 调用class->constructor()

    这个API, 很少被子类override(重写),就直接用

    g_object_constructor():

    (1). g_type_create_instance()

          <1>. 先调用Top-->父类的instance_init()

          <2>. 调用自己的instance_init()

    (2). 给object设置Property

           因为前面g_object_new时,可能传入了一些参数,会被赋值给class->contruct_properties

           同时在class_init()里面,g_object_install_property()也安装了一些Property

           给object设置Property的过程:

          <1>. 取得notify queue (object的quark data)

          <2>. 调用object_set_property()

                   1*: class->set_property(), 这个子类一般会override GObjectClass的set_property

                   2*: g_object_notify_queue_add(), 把property插入到单链表中

         <3>. g_object_notify_queue_thaw()

                  notify_queue->context->dispatcher() = g_object_notify_dispatcher()

                  --> class->dispatch_properties_changed() = g_object_dispatch_properties_changed()

                  对所有的pspec发射NOTIFY信号

                         

 Class_init()

再重新整理一遍:

1. override GObjectClass(最上层类)的一些API,

   主要是:

    (1). gobject_class->set_property()

    (2). gobject_class->get_property()

    (3). gobject_class->dispose()

    (4). gobject_class->finalize()

 

2. 给GObjectClass install properites

    (1). 把属性插入到全局的Hash Table: pspec_pool中

    (2). 插入到链表中:gobject_class->construct_properites (以备后用)

 

3. 给自己New一些Signal

    (1). 放入GSignal的全局数组中:g_signal_nodes[]

    (2). 放入自己定义的一个“小”的全局数组,方便自己使用

 

4. 配合3,指定自己class的私有成员APIs

 

5. override “父类”的一些APIs

    比如,GstBin中override GstElement的一些APIs

                GstPipeline中 overrde GstElement的一些APIs

   

  

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter