Exemple #1
0
def WriteClientFile(headerFiles, pf, ph, genericFunctions):
    codeGenCommon.WriteWarning(ClientFileText)

    print >> ClientFileText, '\n' + '\n'.join('#include "%s"' % h
                                              for h in headerFiles) + '\n'
    print >> ClientFileText, codeGenCommon.DefaultPackerUnpacker
    print >> ClientFileText, common.FormatCode(ClientGenericCode)

    # Note that this does not need to be an ordered dictionary, unlike genericFunctions
    protoDict = {
        n: codeGenCommon.GetFuncPrototypeStr(f)
        for n, f in genericFunctions.items()
    }
    print >> ClientFileText, common.FormatCode(ClientStartFuncCode,
                                               proto=protoDict)

    print >> ClientFileText, ClientStartClientCode

    for f in pf.values():
        #print f
        if f.handlerName:
            # Write out the handler first; there should only be one
            # todo: How can this be enforced
            for h in ph.values():
                if h.name == f.handlerName:
                    WriteClientHandler(f, h, ClientHandlerTemplate)
                    break

        # Write out the functions next
        WriteFuncCode(f, FuncImplTemplate)

    funcsWithHandlers = [f for f in pf.values() if f.handlerName]
    WriteAsyncHandler(funcsWithHandlers, AsyncHandlerTemplate)

    return ClientFileText
Exemple #2
0
def WriteLocalHeaderFile(pf, ph, hashValue, fileName, serviceName):

    # TODO: This is a temporary workaround. Some API files require a larger message size, so
    #       hand-code the required size.  The size is not increased for all API files, because
    #       this could significantly increase memory usage, although it is bumped up a little
    #       bit from 1000 to 1100.
    #
    #       In the future, this size will be automatically calculated.
    #
    if fileName.endswith( ("le_secStore_messages.h", "secStoreAdmin_messages.h") ):
        maxMsgSize = 8500
    elif fileName.endswith("le_cfg_messages.h"):
        maxMsgSize = 1600
    else:
        maxMsgSize = 1100

    codeGenCommon.WriteWarning(LocalHeaderFileText)
    WriteIncludeGuardBegin(LocalHeaderFileText, fileName)

    print >>LocalHeaderFileText, common.FormatCode(LocalHeaderStartTemplate,
                                                   idString=hashValue,
                                                   serviceName=serviceName,
                                                   maxMsgSize=maxMsgSize)

    # Write out the message IDs for the functions
    for i, name in enumerate(pf):
        print >>LocalHeaderFileText, "#define _MSGID_%s %i" % (name, i)
    print >>LocalHeaderFileText

    WriteIncludeGuardEnd(LocalHeaderFileText, fileName)

    return LocalHeaderFileText
Exemple #3
0
def WriteHandlerCode(func, template):
    # The prototype parameter is only needed for the AsyncFuncHandlerTemplate, but it does no
    # harm to always include it.  It will be ignored for the other template(s).
    funcStr = common.FormatCode(
        template,
        func=func,
        respondProto=codeGenCommon.GetRespondFuncPrototypeStr(func))
    print >> ServerFileText, funcStr
Exemple #4
0
def WriteServerFile(headerFiles, pf, ph, genericFunctions, genAsync):
    codeGenCommon.WriteWarning(ServerFileText)

    print >> ServerFileText, '\n' + '\n'.join('#include "%s"' % h
                                              for h in headerFiles) + '\n'
    print >> ServerFileText, codeGenCommon.DefaultPackerUnpacker
    print >> ServerFileText, ServerGenericCode

    # Note that this does not need to be an ordered dictionary, unlike genericFunctions
    protoDict = {
        n: codeGenCommon.GetFuncPrototypeStr(f)
        for n, f in genericFunctions.items()
    }
    print >> ServerFileText, common.FormatCode(ServerStartFuncCode,
                                               proto=protoDict)

    print >> ServerFileText, ServerStartClientCode

    for f in pf.values():
        #print f
        if f.handlerName:
            # Write out the handler first; there should only be one per function
            for h in ph.values():
                if h.name == f.handlerName:
                    WriteAsyncFuncCode(f, h, FuncAsyncTemplate)
                    break

        # Write out the functions next.
        # Functions that have handler parameters, or are Add and Remove handler functions are
        # never asynchronous.
        if genAsync and not f.handlerName and not f.isRemoveHandler:
            WriteHandlerCode(f, AsyncFuncHandlerTemplate)
        else:
            WriteHandlerCode(f, FuncHandlerTemplate)

    WriteMsgHandler(pf.values(), MsgHandlerTemplate)

    return ServerFileText
Exemple #5
0
def WriteTypeDefinition(fp, typeDef):
    typeDefStr = common.FormatCode(TypeDefinitionTemplate, typeDef=typeDef)
    print >>fp, typeDefStr
Exemple #6
0
def WriteCommonInterface(fp,
                         startTemplate,
                         pf,
                         ph,
                         pt,
                         importList,
                         fileName,
                         genericFunctions,
                         headerComments,
                         genAsync):

    codeGenCommon.WriteWarning(fp)

    # Write the user-supplied doxygen-style header comments
    for comments in headerComments:
        print >>fp, comments

    WriteIncludeGuardBegin(fp, fileName)
    print >>fp, common.FormatCode(startTemplate)

    # Write the imported include files.
    if importList:
        print >>fp, '// Interface specific includes'
        for i in importList:
            print >>fp, '#include "%s"' % i
        print >>fp, '\n'

    # Write out the prototypes for the generic functions
    for s in genericFunctions.values():
        print >>fp, "%s;\n" % codeGenCommon.GetFuncPrototypeStr(s)

    # Write out the type definitions
    for t in pt.values():
        # Types that have a simple definition will have the appropriate attribute; otherwise call an
        # explicit function to write out the definition.
        if hasattr(t, "definition"):
            WriteTypeDefinition(fp, t)
        elif isinstance( t, codeTypes.EnumData ):
            WriteEnumDefinition(fp, t)
        elif isinstance( t, codeTypes.BitMaskData ):
            # TODO: Bitmask may get it's own function later
            WriteEnumDefinition(fp, t)
        else:
            # todo: Should I print an error or something here?
            pass

    # Write out the handler type definitions
    for h in ph.values():
        WriteHandlerTypeDef(fp, h)

    # Write out the function prototypes, and if required, the respond function prototypes
    for f in pf.values():
        #print f

        # Functions that have handler parameters, or are Add and Remove handler functions are
        # never asynchronous.
        if genAsync and not f.handlerName and not f.isRemoveHandler :
            print >>fp, "%s;\n" % codeGenCommon.GetRespondFuncPrototypeStr(f)
            print >>fp, "%s;\n" % codeGenCommon.GetServerAsyncFuncPrototypeStr(f)
        else:
            print >>fp, "%s;\n" % codeGenCommon.GetFuncPrototypeStr(f)

    WriteIncludeGuardEnd(fp, fileName)
Exemple #7
0
def WriteIncludeGuardEnd(fp, fileName):
    print >>fp, common.FormatCode(IncludeGuardEndTemplate, fileName=FormatFileName(fileName))
Exemple #8
0
def WriteHandlerTypeDef(fp, handler):
    headerComment = AddHandlerParamComments(handler.comment, handler.parmList)
    handlerStr = common.FormatCode(HandlerTypeTemplate, handler=handler, headerComment=headerComment)
    print >>fp, handlerStr
Exemple #9
0
def WriteEnumDefinition(fp, enumDef):
    enumDefStr = common.FormatCode(EnumDefinitionTemplate, enumDef=enumDef)
    print >>fp, enumDefStr
Exemple #10
0
def GetServerAsyncFuncPrototypeStr(func):
    funcStr = common.FormatCode(ServerAsyncFuncPrototypeTemplate, func=func)

    # Remove any leading or trailing whitespace on the return string, such as newlines, so that
    # it doesn't add extra, unintended, spaces in the generated code output.
    return funcStr.strip()
Exemple #11
0
def FormatHeaderComment(comment):
    comment = '\n * '.join(comment.splitlines())
    headerComment = common.FormatCode(HeaderCommentTemplate, comment=comment)

    # Strip any leading/trailing white space
    return headerComment.strip()
Exemple #12
0
def WriteAsyncFuncCode(func, handler, template):
    handlerStr = common.FormatCode(template, func=func, handler=handler)
    print >> ServerFileText, handlerStr
Exemple #13
0
def WriteMsgHandler(flist, template):
    print >> ServerFileText, common.FormatCode(template, funcList=flist)
Exemple #14
0
def WriteFuncCode(func, template):
    funcStr = common.FormatCode(
        template, func=func, prototype=codeGenCommon.GetFuncPrototypeStr(func))
    print >> ClientFileText, funcStr
Exemple #15
0
def WriteAsyncHandler(flist, template):
    print >> ClientFileText, common.FormatCode(template, funcList=flist)
Exemple #16
0
def WriteClientHandler(func, handler, template):
    funcStr = common.FormatCode(template, func=func, handler=handler)
    print >> ClientFileText, funcStr