khronosfws/openmax_al/src/vibra/xavibradevice.c
changeset 33 5e8b14bae8c3
parent 28 ebf79c79991a
child 36 73253677b50a
equal deleted inserted replaced
28:ebf79c79991a 33:5e8b14bae8c3
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <stdlib.h>
       
    20 #include <assert.h>
       
    21 #include "xavibradevice.h"
       
    22 #include "xavibraitf.h"
       
    23 #include "xaconfigextensionsitf.h"
       
    24 #include "xadynintmgmtitf.h"
       
    25 #include "xavibraadaptctx.h"
       
    26 
       
    27 /* Static mapping of enumeration XAVibraDeviceInterfaces to interface iids */
       
    28 static const XAInterfaceID* XAVibraDeviceItfIIDs[VIBRA_ITFCOUNT]=
       
    29 {
       
    30     &XA_IID_OBJECT,
       
    31     &XA_IID_CONFIGEXTENSION,
       
    32     &XA_IID_VIBRA,
       
    33     &XA_IID_DYNAMICINTERFACEMANAGEMENT
       
    34 };
       
    35 
       
    36 
       
    37 /*****************************************************************************
       
    38  * Global methods
       
    39  *****************************************************************************/
       
    40 /*
       
    41  * XAresult XAVibraDeviceImpl_CreateVibraDevice
       
    42  * Description: Create object
       
    43  */
       
    44 XAresult XAVibraDeviceImpl_CreateVibraDevice(FrameworkMap* mapper,
       
    45                                              XAObjectItf* pDevice,
       
    46                                              XAuint32 deviceID,
       
    47                                              XAuint32 numInterfaces,
       
    48                                              const XAInterfaceID * pInterfaceIds,
       
    49                                              const XAboolean * pInterfaceRequired)
       
    50 {
       
    51     XAVibraDeviceImpl* pImpl = NULL;
       
    52     XAObjectItfImpl* pBaseObj = NULL;
       
    53     XAuint8 itfIndex = 0;
       
    54 
       
    55     DEBUG_API("->XAVibraDeviceImpl_CreateVibraDevice");
       
    56 
       
    57     if( !pDevice )
       
    58     {
       
    59         /* invalid parameter */
       
    60         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    61         DEBUG_API("<-XAVibraDeviceImpl_CreateVibraDevice");
       
    62         return XA_RESULT_PARAMETER_INVALID;
       
    63     }
       
    64 
       
    65     /* instantiate object implementation */
       
    66     pImpl = (XAVibraDeviceImpl*)calloc(1,sizeof(XAVibraDeviceImpl));
       
    67     if( !pImpl )
       
    68     {
       
    69         /* memory allocation failed */
       
    70         DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
    71         DEBUG_API("<-XAVibraDeviceImpl_CreateVibraDevice");
       
    72         return XA_RESULT_MEMORY_FAILURE;
       
    73     }
       
    74     pBaseObj = &pImpl->baseObj;
       
    75 
       
    76     /* Initialize base object default implementation */
       
    77     XAObjectItfImpl_Init(pBaseObj,
       
    78                          VIBRA_ITFCOUNT,
       
    79                          XAVibraDeviceItfIIDs,
       
    80                          XAVibraDeviceImpl_DoRealize,
       
    81                          XAVibraDeviceImpl_DoResume,
       
    82                          XAVibraDeviceImpl_FreeResources);
       
    83 
       
    84     /* Mark interfaces that need to be exposed */
       
    85     /* Implicit and mandated interfaces */
       
    86     pBaseObj->interfaceMap[VIBRA_VIBRAITF].required = XA_BOOLEAN_TRUE;
       
    87     pBaseObj->interfaceMap[VIBRA_DIMITF].required = XA_BOOLEAN_TRUE;
       
    88 
       
    89     /* Explicit interfaces */
       
    90     if( (numInterfaces != 0) && pInterfaceIds && pInterfaceRequired )
       
    91     {
       
    92         /* Check required interfaces */
       
    93         for( itfIndex = 0; itfIndex < numInterfaces; itfIndex++ )
       
    94         {
       
    95             /* If mapEntry is null then required interface is not supported.*/
       
    96             XAObjItfMapEntry *entry =
       
    97                 XAObjectItfImpl_GetItfEntry((XAObjectItf)&(pBaseObj), pInterfaceIds[itfIndex]);
       
    98             if( !entry  )
       
    99             {
       
   100                 if( pInterfaceRequired[itfIndex] )
       
   101                 {
       
   102                     /* required interface cannot be accommodated - fail creation */
       
   103                     XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj));
       
   104                     DEBUG_ERR("Required interface not found - abort creation!");
       
   105                     DEBUG_API("<-XAVibraDeviceImpl_CreateVibraDevice");
       
   106                     return XA_RESULT_FEATURE_UNSUPPORTED;
       
   107                 }
       
   108                 else
       
   109                 {
       
   110                     DEBUG_INFO("Requested (not required) interface not found - continue creation");
       
   111                 }
       
   112             }
       
   113             else
       
   114             {
       
   115                 entry->required = XA_BOOLEAN_TRUE;
       
   116             }
       
   117         }
       
   118     }
       
   119 
       
   120     /* This code is put here to return Feature Not Supported since adaptation is not present*/
       
   121     /*************************************************/
       
   122     DEBUG_ERR("Required interface not found - abort creation!");
       
   123     XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj));
       
   124     DEBUG_API("<-XAVibraDeviceImpl_CreateVibraDevice");
       
   125     return XA_RESULT_FEATURE_UNSUPPORTED;
       
   126     /*************************************************/
       
   127     
       
   128 /*    // Initialize XAVibraDeviceImpl variables 
       
   129     pImpl->deviceID = deviceID;
       
   130 
       
   131 
       
   132     pImpl->adaptationCtx = XAVibraAdapt_Create(pImpl->deviceID);
       
   133 
       
   134      //Set ObjectItf to point to newly created object 
       
   135     *pDevice = (XAObjectItf)&(pBaseObj->self);
       
   136 
       
   137     DEBUG_API("<-XAVibraDeviceImpl_Create");
       
   138     return XA_RESULT_SUCCESS;*/
       
   139 }
       
   140 /* XAResult XAVibraDeviceImpl_QueryNumSupportedInterfaces
       
   141  * Description: Statically query number of supported interfaces
       
   142  */
       
   143 XAresult XAVibraDeviceImpl_QueryNumSupportedInterfaces(XAuint32 *pNumSupportedInterfaces)
       
   144 {
       
   145     DEBUG_API("->XAVibraDeviceImpl_QueryNumSupportedInterfaces");
       
   146     if( pNumSupportedInterfaces )
       
   147     {
       
   148         *pNumSupportedInterfaces = VIBRA_ITFCOUNT;
       
   149 
       
   150         DEBUG_API_A1("<-XAVibraDeviceImpl_QueryNumSupportedInterfaces - %ld", *pNumSupportedInterfaces );
       
   151         return XA_RESULT_SUCCESS;
       
   152     }
       
   153     else
       
   154     {
       
   155         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   156         DEBUG_API("<-XAVibraDeviceImpl_QueryNumSupportedInterfaces");
       
   157         return XA_RESULT_PARAMETER_INVALID;
       
   158     }
       
   159 }
       
   160 /* XAResult XACVibraDeviceImpl_QuerySupportedInterfaces
       
   161  * Description: Statically query supported interfaces
       
   162  */
       
   163 XAresult XAVibraDeviceImpl_QuerySupportedInterfaces(XAuint32 index,
       
   164                                                     XAInterfaceID *pInterfaceId)
       
   165 {
       
   166     DEBUG_API("->XAVibraDeviceImpl_QuerySupportedInterfaces");
       
   167 
       
   168     if( index >= VIBRA_ITFCOUNT || !pInterfaceId )
       
   169     {
       
   170         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   171         DEBUG_API("<-XAVibraDeviceImpl_QuerySupportedInterfaces");
       
   172         return XA_RESULT_PARAMETER_INVALID;
       
   173     }
       
   174     else
       
   175     {
       
   176         *pInterfaceId = *(XAVibraDeviceItfIIDs[index]);
       
   177 
       
   178         DEBUG_API("<-XAVibraDeviceImpl_QuerySupportedInterfaces");
       
   179         return XA_RESULT_SUCCESS;
       
   180     }
       
   181 }
       
   182 /*****************************************************************************
       
   183  * base object XAObjectItfImpl methods
       
   184  *****************************************************************************/
       
   185 /* XAResult XAVibraDeviceImpl_DoRealize
       
   186  * Description: Realize all implicit and explicitly wanted interfaces.
       
   187  * Create and initialize implementation-specific variables.
       
   188  * Called from base object XAObjectItfImpl
       
   189  */
       
   190 XAresult XAVibraDeviceImpl_DoRealize(XAObjectItf self)
       
   191 {
       
   192     XAuint8 itfIdx = 0;
       
   193     XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self);
       
   194     XAVibraDeviceImpl* pObjImpl = (XAVibraDeviceImpl*)(pObj);
       
   195     XAresult ret = XA_RESULT_SUCCESS;
       
   196 
       
   197     DEBUG_API("->XAVibraDeviceImpl_DoRealize");
       
   198 
       
   199     /* check casting from correct pointer type */
       
   200     if( !pObjImpl || pObj != pObjImpl->baseObj.self )
       
   201     {
       
   202         /* invalid parameter */
       
   203         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   204         DEBUG_API("<-XAVibraDeviceImpl_DoRealize");
       
   205         return XA_RESULT_PARAMETER_INVALID;
       
   206     }
       
   207 
       
   208 
       
   209     ret = XAVibraAdapt_PostInit( pObjImpl->adaptationCtx );
       
   210 
       
   211     if( ret != XA_RESULT_SUCCESS )
       
   212     {
       
   213         DEBUG_API("<-XAVibraDeviceImpl_DoRealize");
       
   214         return ret;
       
   215     }
       
   216 
       
   217     /* Realize all implicit and explicitly wanted interfaces */
       
   218     for( itfIdx = 0; itfIdx < VIBRA_ITFCOUNT; itfIdx++)
       
   219     {
       
   220         if( !(pObj->interfaceMap[itfIdx].pItf) &&
       
   221             pObj->interfaceMap[itfIdx].required )
       
   222         {
       
   223             void *pItf = NULL;
       
   224             switch( itfIdx )
       
   225             {
       
   226                 case VIBRA_VIBRAITF:
       
   227 
       
   228                     pItf = XAVibraItfImpl_Create(pObjImpl->adaptationCtx);
       
   229 
       
   230                     break;
       
   231                 case VIBRA_CONFIGEXTENSIONITF:
       
   232                     pItf = XAConfigExtensionsItfImpl_Create();
       
   233                     break;
       
   234                 case VIBRA_DIMITF:
       
   235                     pItf = XADIMItfImpl_Create();
       
   236                     break;
       
   237                 default:
       
   238                     break;
       
   239             }
       
   240             if( !pItf )
       
   241             {
       
   242                 /* memory allocation failed */
       
   243                 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
   244                 DEBUG_API("<-XAVibraDeviceImpl_DoRealize");
       
   245                 return XA_RESULT_MEMORY_FAILURE;
       
   246             }
       
   247             else
       
   248             {
       
   249                 pObj->interfaceMap[itfIdx].pItf = pItf;
       
   250             }
       
   251         }
       
   252     }
       
   253 
       
   254     pObj->state = XA_OBJECT_STATE_REALIZED;
       
   255     DEBUG_API("<-XAVibraDeviceImpl_DoRealize");
       
   256     return XA_RESULT_SUCCESS;
       
   257 }
       
   258 
       
   259 /* XAResult XAVibraDeviceImpl_DoResume
       
   260  * Description: Resume object from suspended state
       
   261  */
       
   262 XAresult XAVibraDeviceImpl_DoResume(XAObjectItf self)
       
   263 {
       
   264     DEBUG_API("->XAVibraDeviceImpl_DoResume");
       
   265     DEBUG_API("<-XAVibraDeviceImpl_DoResume");
       
   266     /* This implementation does not support suspended state */
       
   267     return XA_RESULT_PRECONDITIONS_VIOLATED;
       
   268 }
       
   269 /* void XAVibraDeviceImpl_FreeResources
       
   270  * Description: Free all resources reserved at XAVibraDeviceImpl_DoRealize()
       
   271  */
       
   272 void XAVibraDeviceImpl_FreeResources(XAObjectItf self)
       
   273 {
       
   274     XAObjectItfImpl* pObj = (XAObjectItfImpl*) (*self);
       
   275     XAVibraDeviceImpl* pImpl = (XAVibraDeviceImpl*) (*self);
       
   276     XAuint8 itfIdx = 0;
       
   277     DEBUG_API("->XAVibraDeviceImpl_FreeResources");
       
   278 
       
   279     
       
   280     assert( pObj && pImpl && pObj == pObj->self );
       
   281     if (pImpl->adaptationCtx != NULL)
       
   282     {
       
   283         XAVibraAdapt_Destroy(pImpl->adaptationCtx);
       
   284         pImpl->adaptationCtx = NULL;
       
   285     }
       
   286 
       
   287     /* free all allocated interfaces */
       
   288     for (itfIdx = 0; itfIdx < VIBRA_ITFCOUNT; itfIdx++)
       
   289     {
       
   290         void *pItf = pObj->interfaceMap[itfIdx].pItf;
       
   291         if (pItf)
       
   292         {
       
   293             switch (itfIdx)
       
   294             {
       
   295                  case VIBRA_VIBRAITF:
       
   296                      XAVibraItfImpl_Free( pItf );
       
   297                      break;
       
   298                  case VIBRA_CONFIGEXTENSIONITF:
       
   299                      XAConfigExtensionsItfImpl_Free( pItf );
       
   300                      break;
       
   301                  case VIBRA_DIMITF:
       
   302                      XADIMItfImpl_Free( pItf );
       
   303                      break;
       
   304                  default:
       
   305                      break;
       
   306             }
       
   307             pObj->interfaceMap[itfIdx].pItf = NULL;
       
   308         }
       
   309     }
       
   310 
       
   311     DEBUG_API("<-XAVibraDeviceImpl_FreeResources");
       
   312 
       
   313     return;
       
   314 }
       
   315 /* END OF FILE*/