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)
def WriteFuncCode(func, template): funcStr = common.FormatCode( template, func=func, prototype=codeGenCommon.GetFuncPrototypeStr(func)) print >> ClientFileText, funcStr