////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// THIS IS AUTO-GENERATED CODE.  PLEASE DO NOT EDIT (File bug reports against tools).
///
/// Auto-generated by: Parameter Parser V5.5.1 (2411131018)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  parametermodule.cpp
/// @brief Auto-generated Chromatix parameter file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "parametermodule.h"
#include "parametersetmanager.h"

ParameterModule::ParameterModule(
    const CHAR* const   name,
    const VersionUnion& version,
    ModuleData* const   moduleData)
{
    const INT32 nameSize = (INT32)PARAMETER_STRLEN(name) + 1;

    Version    = version;
    Data       = moduleData;
    Mode.Value = moduleData != nullptr ? moduleData->Mode->Mode.Value : 0;
    Loaded     = false;
    Modified   = 0;

    Name = PARAMETER_NEW CHAR[nameSize];
    PARAMETER_INITIALIZE_PTR(Name, nameSize);
    PARAMETER_STRCPY(Name, nameSize, name);

    CHAR type[TYPE_CHAR_ARRAY_LEN] = "";
    ModuleData::GetType(type, name);

    const SIZE_T len = PARAMETER_STRLEN(type);
    Type = PARAMETER_NEW CHAR[len + 1];
    PARAMETER_STRCPY(Type, len + 1, type);
}

ParameterModule::ParameterModule(
    const CHAR* const  name,
    UINT16 const       major,
    UINT16 const       minor,
    UINT32 const       patch,
    ModuleData* const  moduleData)
{
    const INT32 nameSize = (INT32)PARAMETER_STRLEN(name) + 1;

    Version.Version.Major = major;
    Version.Version.Minor = minor;
    Version.Version.Patch = patch;
    Data                  = moduleData;
    Mode.Value            = moduleData != nullptr ? moduleData->Mode->Mode.Value : 0;
    Loaded                = false;
    Modified              = 0;

    Name = PARAMETER_NEW CHAR[nameSize];
    PARAMETER_INITIALIZE_PTR(Name, nameSize);
    PARAMETER_STRCPY(Name, nameSize, name);

    CHAR type[TYPE_CHAR_ARRAY_LEN] = "";
    ModuleData::GetType(type, name);

    const SIZE_T len = PARAMETER_STRLEN(type);
    Type = PARAMETER_NEW CHAR[len + 1];
    PARAMETER_STRCPY(Type, len + 1, type);
}

ParameterModule::~ParameterModule()
{
    PARAMETER_DELETE[] Name;
    PARAMETER_DELETE[] Type;
    Name = nullptr;
    Type = nullptr;
}

void ParameterModule::Release()
{
    if (Data != nullptr && Data->SetManager != nullptr)
    {
        if (Data->SetManager->IsFileMode())
        {
            Data->SetManager->ReleaseModule(this);
        }
    }
    else
    {
        PARAMETER_LOG_ERROR(nullptr, "Attempt to release module reference when Data or SetManager is nullptr. Module %s\n", Name);
    }
}

UINT32 ParameterModule::GetReferenceCount()
{
    UINT32 refCnt = 0;
    if (Data != nullptr && Data->Mode != nullptr)
    {
        refCnt = Data->Mode->GetReferenceCount(this);
    }

    return refCnt;
}

