Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Backlight code, part 2

Part 2 demonstrates how the IBacklight interface was implemented. It demonstrates object creation, adding a reference, releasing an object, and querying the interface.

This part of the backlight code sample demonstrates object creation, adding a reference, releasing an object, and querying the interface.

This part contains functions that are common across all interfaces, such as object creation, adding an object reference, releasing an object, and querying an interface.

/********************************************************************************

  This part contains functions that are common across all interfaces such as:
  - Object creation
  - Add reference
  - Release
  - Query interface

*********************************************************************************

Function: AEEBacklight_New

Description:
   IBacklight constructor
 
********************************************************************************/

int AEEBacklight_New(IShell *pIShell, AEECLSID uCls, void **ppif)
{   
   int nErr = SUCCESS;
   IBacklight * pme = NULL;

   FARF(BACKLIGHT, ("==>  IBacklight_New"));
   
   if (!ISHELL_CheckPrivLevel(pIShell, uCls, TRUE)) {
      return EPRIVLEVEL;
   }

   pme = (IBacklight *)MALLOC(sizeof(IBacklight));

   *ppif = pme;

   if (pme) 
   {
      pme->pvt = gvtBacklight

      pme->uRef = 1;
      pme->pIShell = pIShell;
      ISHELL_AddRef(pIShell);
      pme->uCls = uCls;
   }
   else 
   {
      nErr = ENOMEMORY;
   }

   return nErr;
}

/*==============================================================

Function: AEEBacklight_AddRef

Description:
   Increases reference count
 
===============================================================*/
static uint32 AEEBacklight_AddRef(IBacklight *pme)
{
   FARF(BACKLIGHT, ("==>  AEEBacklight_AddRef"));
   return ++pme->uRef;
}

/*==============================================================

Function: AEEBacklight_Release

Description: 
   Decrements reference count. Frees object when the reference 
                                                count reaches 0. 
 
===============================================================*/
static uint32 AEEBacklight_Release(IBacklight *pme)
{
   FARF(BACKLIGHT, ("==>  AEEBacklight_Release"));

   if (--pme->uRef) {
      return pme->uRef;
   }

   RELEASEIF(pme->pIShell);
   FREEIF(pme);

   return 0;
}

/*==============================================================

Function: AEEBacklight_QueryInterface

Description:
   Query Interface
 
===============================================================*/
static int AEEBacklight_QueryInterface(IBacklight *pme, 
                                       AEECLSID id, void **ppo)
{
   FARF(BACKLIGHT, ("==>  AEEBacklight_QueryInterface"));
   
   if (!ppo)
   {
      return EBADPARM;
   }

   if ((id == AEECLSID_QUERYINTERFACE) || 
       (id == pme->uCls)) 
   {
      *ppo = pme;
      IQI_AddRef(*ppo);
      return SUCCESS;
   } 
   else 
   {
      return ECLASSNOTSUPPORT;
   }
}