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
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
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
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)