%%================================================================================
%%
%%
%%
%%
%%Copyright1994-2014TheMathWorks,Inc.
%%
%%ThisistheModelPackagingLibraryofFunctions.
%%
%%=================================================================================
 
%%==================ListofFunctionavailableinthislibarry===================
%%
%%SLibMPRegSymbols()void
%%
%%=================================================================================
 
%%===================SLibMPRegSymbols============================================
%%
 
%function SLibMPRegSymbols() void
%assign modelName = LibGetModelName()
%assign enabled = FEVAL("ec_mpt_enabled",modelName)
%if (enabled == 1 && !IsModelReferenceTarget())
 
  %% Get list of all files and file types
  %assign fileNameList = []
  %assign typeList = []
  %assign codeTemplate = []
  %foreach fileIdx = LibGetNumModelFiles()
    %assign opFile = LibGetSourceFileFromIdx(fileIdx)
    %assign fName = LibGetFileRecordName(opFile)
     
    %assign fileNameList = fileNameList + fName
    %assign typeList = typeList + LibGetModelFileAttribute(fileIdx, "Type")
    %assign codeTemplate = codeTemplate + LibGetModelFileAttribute(fileIdx, "CodeTemplate")
  %endforeach
 
 
  %% Get all template symbol related information in a single call to m
  %% Symbol and associated parents are included
  %% Any special symbol contents are also provided
 
  %assign info = FEVAL("ec_get_mp_data",modelName,fileNameList,typeList,codeTemplate)
  %if info.state == 1
 
    %% For each file, register symbols.
    %%
    %% for each file
    %% get the file name and type
    %% get file reference record to permit registration of symbols
    %% for each symbol
    %% register it with the file. Include parent relationship
    %% end
    %% end
 
 
    %assign lSize = SIZE(info.fileBuf)
    %foreach fileIdx = lSize[1]
      %% Ensure we dont regenerate imported shared type files that are
      %% registered in file repository
      %if SLibFileContainsImportedSharedType(fileIdx)
        %continue
      %endif
 
      %assign fileName = info.fileBuf[fileIdx].fileName
      %assign fileType = info.fileBuf[fileIdx].fileType
      %assign cFile = SLibDoesModelFileExist(fileType, fileName)
      %if TYPE(cFile) != "Scope" %% file doesn't exist.
         %assign fileType = fileType == "SystemBody" ? "Source" : "Header"
         %assign cFile = LibCreateSourceFile(fileType, "Simulink", fileName)
      %endif
      %assign lSize2 = SIZE(info.fileBuf[fileIdx].symreg)
      %foreach index =lSize2[1]
        %<LibAddSourceFileCustomSection(cFile,info.fileBuf[fileIdx].symreg[index].parent, info.fileBuf[fileIdx].symreg[index].symbolName)>
      %endforeach
    %endforeach
 
    %% Register any addition symbol buffer contents
    %% for each file with contents
    %% Get file and type infomration
    %% get file indentification record. Create file is necessary
    %% set template association
    %% for each buffer associated with the file
    %% Register the contents into the associated symbol
    %% end
    %% end
    %assign lSize = SIZE(info.fileBuf)
    %foreach index =lSize[1]
      %% Ensure we dont register information about imported shared type files
      %% that are registered in file repository
      %if SLibFileContainsImportedSharedType(index)
        %continue
      %endif
      %assign fileName = info.fileBuf[index].fileName
      %assign fileType = info.fileBuf[index].fileType
      %assign cFile = SLibDoesModelFileExist(fileType, fileName)
      %<LibSetSourceFileCodeTemplate(cFile,info.fileBuf[index].templateFileName)>
      %if TYPE(cFile) != "Scope" %% file doesn't exist.
         %assign fileType = fileType == "SystemBody" ? "Source" : "Header"
         %assign cFile = LibCreateSourceFile(fileType, "Simulink", fileName)
      %endif
      %assign lSize2 = SIZE(info.fileBuf[index].buffer)
      %foreach index2 = lSize2[1]
        %assign bufferName = info.fileBuf[index].buffer[index2].bufferName
        %assign bufferContent = info.fileBuf[index].buffer[index2].bufferContent
        %if info.fileBuf[index].buffer[index2].customFlag == 1
          %<LibSetSourceFileCustomSection(cFile,bufferName,bufferContent)>
        %else
          %<LibSetSourceFileSection(cFile, bufferName,bufferContent)>
        %endif
      %endforeach
    %endforeach
  %endif
%endif
%return
%endfunction