# Path: progSpec.py
# def cdlog(lvl, mesg):
#     global MaxLogLevelToShow
#     global lastLogMesgs
#     global highestLvl
#     highestLvl=lvl
#     resizeLogArray(lvl)
#     lastLogMesgs[lvl]=mesg
#     for i in range(highestLvl+1, len(lastLogMesgs)):
#         lastLogMesgs[i]=''
#     if(lvl<=MaxLogLevelToShow):
#         if(lvl==0): print('')
#         printAtLvl(lvl, mesg, '|    ')
# 
# def cdErr(mesg):
#     global lastLogMesgs
#     global highestLvl
#     highestLvl+=1
#     lastLogMesgs[highestLvl]="\n\nError: "+mesg
#     exit(1)


import progSpec
import codeDogParser
from progSpec import cdlog, cdErr
                newParamFields = newParamFields + argOwner+' '+ argFieldType+': '+ argName + '\n'
                count = count + 1

        CODE =  '''
struct GLOBAL {
    bool: '''+callbackName+'''(their '''+bundleName+''': bundle) <- {
        bundle._object.'''+funcName+'''('''+runParams+''')
        return(false)
    }
}
struct '''+bundleName+''' {
    their '''+className+''': _object
    '''+newParamFields+'''

}\n'''
        codeDogParser.AddToObjectFromText(classes[0], classes[1], CODE, callbackName)
    elif proxyStyle == "bundledArgs" and platformTag == "Android":
        #print "Android BundledArgs: ", callbackName, funcSpec
        if len(argList)>0:
            count=0
            for arg in argList:
                argName      = arg['fieldName']
                argTypeSpec  = arg['typeSpec']
                argOwner     = argTypeSpec['owner']
                argFieldType = progSpec.getFieldType(argTypeSpec)
                if not isinstance(argFieldType, str): argFieldType=argFieldType[0]
                if count > 0:
                    runParams      = runParams+', '
                    newParamFields = newParamFields+ '    '
                runParams=runParams+argName

# Path: progSpec.py
# def cdlog(lvl, mesg):
#     global MaxLogLevelToShow
#     global lastLogMesgs
#     global highestLvl
#     highestLvl=lvl
#     resizeLogArray(lvl)
#     lastLogMesgs[lvl]=mesg
#     for i in range(highestLvl+1, len(lastLogMesgs)):
#         lastLogMesgs[i]=''
#     if(lvl<=MaxLogLevelToShow):
#         if(lvl==0): print('')
#         printAtLvl(lvl, mesg, '|    ')
# 
# def cdErr(mesg):
#     global lastLogMesgs
#     global highestLvl
#     highestLvl+=1
#     lastLogMesgs[highestLvl]="\n\nError: "+mesg
#     exit(1)


# Path: pattern_WriteCallProxy.py
import progSpec
import codeDogParser
from progSpec import cdlog, cdErr

                newParamFields = newParamFields + argOwner+' '+ argFieldType+': '+ argName + '\n'
                count = count + 1

        CODE =  '''
struct GLOBAL {
    bool: '''+callbackName+'''(their '''+bundleName+''': bundle) <- {
        bundle._object.'''+funcName+'''('''+runParams+''')
        return(false)
    }
}
struct '''+bundleName+''' {
    their '''+className+''': _object
    '''+newParamFields+'''

}\n'''
        codeDogParser.AddToObjectFromText(classes[0], classes[1], CODE, callbackName)
    elif proxyStyle == "bundledArgs" and platformTag == "Android":
        #print "Android BundledArgs: ", callbackName, funcSpec
        if len(argList)>0:
            count=0
            for arg in argList:
                argName      = arg['fieldName']
                argTypeSpec  = arg['typeSpec']
                argOwner     = argTypeSpec['owner']
                argFieldType = progSpec.getFieldType(argTypeSpec)
                if not isinstance(argFieldType, str): argFieldType=argFieldType[0]
                if count > 0:
                    runParams      = runParams+', '
                    newParamFields = newParamFields+ '    '
                runParams=runParams+argName

                newParamFields = newParamFields + argOwner+' '+ argFieldType+': '+ argName + '\n'