Home | History | Annotate | Download | only in src
      1 /*
      2  INTEL CONFIDENTIAL
      3  Copyright 2009 Intel Corporation All Rights Reserved.
      4  The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intels prior express written permission.
      5 
      6  No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
      7 */
      8 
      9 /**
     10  * SECTION:mixdrmparams
     11  * @short_description: Drm parameters
     12  *
     13  * A data object which stores drm specific parameters.
     14  */
     15 
     16 #include "mixdrmparams.h"
     17 
     18 static GType _mix_drmparams_type = 0;
     19 static MixParamsClass *parent_class = NULL;
     20 
     21 #define _do_init { _mix_drmparams_type = g_define_type_id; }
     22 
     23 gboolean mix_drmparams_copy(MixParams* target, const MixParams *src);
     24 MixParams* mix_drmparams_dup(const MixParams *obj);
     25 gboolean mix_drmparams_equal(MixParams* first, MixParams *second);
     26 static void mix_drmparams_finalize(MixParams *obj);
     27 
     28 G_DEFINE_TYPE_WITH_CODE(MixDrmParams, mix_drmparams, MIX_TYPE_PARAMS, _do_init);
     29 
     30 void
     31 _mix_drmparams_initialize (void)
     32 {
     33   /* the MixParams types need to be class_ref'd once before it can be
     34    * done from multiple threads;
     35    * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
     36   g_type_class_ref (mix_drmparams_get_type ());
     37 }
     38 
     39 static void mix_drmparams_init (MixDrmParams *self)
     40 {
     41 }
     42 
     43 static void mix_drmparams_class_init(MixDrmParamsClass *klass)
     44 {
     45   MixParamsClass *mixparams_class = MIX_PARAMS_CLASS(klass);
     46 
     47   /* setup static parent class */
     48   parent_class = (MixParamsClass *) g_type_class_peek_parent (klass);
     49 
     50   mixparams_class->finalize = mix_drmparams_finalize;
     51   mixparams_class->copy = (MixParamsCopyFunction)mix_drmparams_copy;
     52   mixparams_class->dup = (MixParamsDupFunction)mix_drmparams_dup;
     53   mixparams_class->equal = (MixParamsEqualFunction)mix_drmparams_equal;
     54 }
     55 
     56 MixDrmParams *mix_drmparams_new(void)
     57 {
     58   MixDrmParams *ret = (MixDrmParams *)g_type_create_instance (MIX_TYPE_DRMPARAMS);
     59 
     60   return ret;
     61 }
     62 
     63 void mix_drmparams_finalize(MixParams *obj)
     64 {
     65   /* clean up here. */
     66 
     67   /* Chain up parent */
     68   if (parent_class->finalize)
     69     parent_class->finalize(obj);
     70 }
     71 
     72 MixDrmParams *mix_drmparams_ref(MixDrmParams *mix)
     73 {
     74   return (MixDrmParams*)mix_params_ref(MIX_PARAMS(mix));
     75 }
     76 
     77 /**
     78  * mix_drmparams_dup:
     79  * @obj: a #MixDrmParams object
     80  * @returns: a newly allocated duplicate of the object.
     81  *
     82  * Copy duplicate of the object.
     83  */
     84 MixParams* mix_drmparams_dup(const MixParams *obj)
     85 {
     86   MixParams *ret = NULL;
     87 
     88   if (MIX_IS_DRMPARAMS(obj))
     89   {
     90     MixDrmParams *duplicate = mix_drmparams_new();
     91     if (mix_drmparams_copy(MIX_PARAMS(duplicate), MIX_PARAMS(obj)))
     92     {
     93       ret = MIX_PARAMS(duplicate);
     94     }
     95     else
     96     {
     97       mix_drmparams_unref(duplicate);
     98     }
     99   }
    100 
    101   return ret;;
    102 }
    103 
    104 /**
    105  * mix_drmparams_copy:
    106  * @target: copy to target
    107  * @src: copy from src
    108  * @returns: boolean indicates if copy is successful.
    109  *
    110  * Copy instance data from @src to @target.
    111  */
    112 gboolean mix_drmparams_copy(MixParams* target, const MixParams *src)
    113 {
    114   if (MIX_IS_DRMPARAMS(target) && MIX_IS_DRMPARAMS(src))
    115   {
    116     // TODO perform copy.
    117     //
    118     // Now chainup base class
    119     // Get the root class from the cached parent_class object. This cached parent_class object has not be overwritten by this current class.
    120     // Using the cached parent_class object because this_class would have ->copy pointing to this method!
    121     // Cached parent_class contains the class object before it is overwritten by this derive class.
    122     // MixParamsClass *klass = MIX_PARAMS_CLASS(parent_class);
    123     if (parent_class->copy)
    124     {
    125       return parent_class->copy(MIX_PARAMS_CAST(target), MIX_PARAMS_CAST(src));
    126     }
    127     else
    128       return TRUE;
    129   }
    130   return FALSE;
    131 }
    132 
    133 /**
    134  * mix_drmparams_equal:
    135  * @first: first object to compare
    136  * @second: seond object to compare
    137  * @returns: boolean indicates if instance are equal.
    138  *
    139  * Copy instance data from @src to @target.
    140  */
    141 gboolean mix_drmparams_equal(MixParams* first, MixParams *second)
    142 {
    143   gboolean ret = TRUE;
    144 
    145   if (MIX_IS_DRMPARAMS(first) && MIX_IS_DRMPARAMS(second))
    146   {
    147     // TODO: do deep compare
    148 
    149     if (ret)
    150     {
    151       // members within this scope equal. chaining up.
    152       MixParamsClass *klass = MIX_PARAMS_CLASS(parent_class);
    153       if (klass->equal)
    154         ret = parent_class->equal(first, second);
    155       else
    156         ret = TRUE;
    157     }
    158   }
    159 
    160   return ret;
    161 }
    162 
    163 
    164