#include <dlfcn.h>
#include <stdlib.h>
#include "st_static_component_loader.h"
#include "omx_dtsxdec_component.h"

#define MAX_LINE_LENGTH    256

int omx_component_library_Setup(stLoaderComponentType **stComponents)
{
    OMX_U32 i;

    DEBUG(DEB_LEV_FUNCTION_NAME, "In %s \n",__func__);

    if (stComponents == NULL)
    {
        DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s \n",__func__);
        return 1; // Return Number of Component/s
    }

    stComponents[0]->componentVersion.s.nVersionMajor = 1;
    stComponents[0]->componentVersion.s.nVersionMinor = 1;
    stComponents[0]->componentVersion.s.nRevision = 1;
    stComponents[0]->componentVersion.s.nStep = 1;

    stComponents[0]->name = calloc(1,OMX_MAX_STRINGNAME_SIZE);
    if (stComponents[0]->name == NULL)
    {
        return OMX_ErrorInsufficientResources;
    }

    strcpy(stComponents[0]->name, DTSXDEC_COMP_NAME);
    stComponents[0]->name_specific_length = 1;
    stComponents[0]->constructor = omx_type1_decoder_component_Constructor;

    stComponents[0]->name_specific = calloc(stComponents[0]->name_specific_length,sizeof(char *));
    stComponents[0]->role_specific = calloc(stComponents[0]->name_specific_length,sizeof(char *));

    for (i=0;i<stComponents[0]->name_specific_length;i++)
    {
        stComponents[0]->name_specific[i] = calloc(1, OMX_MAX_STRINGNAME_SIZE);
        if (stComponents[0]->name_specific[i] == NULL)
        {
            return OMX_ErrorInsufficientResources;
        }
    }
    for (i=0;i<stComponents[0]->name_specific_length;i++)
    {
        stComponents[0]->role_specific[i] = calloc(1, OMX_MAX_STRINGNAME_SIZE);
        if (stComponents[0]->role_specific[i] == NULL)
        {
            return OMX_ErrorInsufficientResources;
        }
    }

    strcpy(stComponents[0]->name_specific[0], DTSXDEC_COMP_NAME);
    strcpy(stComponents[0]->role_specific[0], DTSXDEC_COMP_ROLE);

    DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s \n",__func__);
    return 1;
}
