|
|
@@ -7,7 +7,7 @@ namespace spgen
|
|
|
{
|
|
|
public class CPPGenerator : GeneratorBase
|
|
|
{
|
|
|
- static string[] CPP_TYPE_NAMES = new string[]
|
|
|
+ static string[] CPP_TYPE_NAMES = new string[]
|
|
|
{
|
|
|
"bool",
|
|
|
"short",
|
|
|
@@ -36,7 +36,7 @@ namespace spgen
|
|
|
"CAutoArray<float>",
|
|
|
"CAutoArray<CSimpleStringA>",
|
|
|
"CAutoArray<CSimpleStringW>",
|
|
|
- "CAutoArray<CBlob>",
|
|
|
+ "CAutoArray<CBlob>",
|
|
|
};
|
|
|
|
|
|
static string GetCodeType(ParamType type)
|
|
|
@@ -44,9 +44,10 @@ namespace spgen
|
|
|
return CPP_TYPE_NAMES[(int)type];
|
|
|
}
|
|
|
|
|
|
- public override void GenerateCode(string dir, Entity entity)
|
|
|
+ public override void GenerateCode(string dir, Entity entity, bool inSourceDir)
|
|
|
{
|
|
|
- dir = Path.Combine(dir, "generate");
|
|
|
+ if (!inSourceDir)
|
|
|
+ dir = Path.Combine(dir, "generate");
|
|
|
if (!Directory.Exists(dir))
|
|
|
Directory.CreateDirectory(dir);
|
|
|
string deffilename = string.Format("{0}_def_g.h", entity.Name);
|
|
|
@@ -94,13 +95,13 @@ namespace spgen
|
|
|
sw.WriteLine();
|
|
|
}
|
|
|
|
|
|
- void WriteLineDefine(StreamWriter sw, Entity entity, string name, string num)
|
|
|
+ void WriteLineDefine(StreamWriter sw, Entity entity, string name, string num, bool tryReplace = true)
|
|
|
{
|
|
|
string value = "";
|
|
|
- if(entity.defineDic.TryGetValue(name, out value))
|
|
|
+ if (tryReplace && entity.defineDic.TryGetValue(name, out value))
|
|
|
{
|
|
|
//success ,judge if len > 3, len > 3, replace the new value; len <=3, must the same
|
|
|
- if(value.Length > 3)
|
|
|
+ if (value.Length > 3)
|
|
|
num = value;
|
|
|
else
|
|
|
{
|
|
|
@@ -133,6 +134,28 @@ namespace spgen
|
|
|
sw.WriteLine();
|
|
|
}
|
|
|
|
|
|
+ bool WriteLogCode(StreamWriter sw, Entity entity, EntityClass cls)
|
|
|
+ {
|
|
|
+ if (!Entity.entityDic.ContainsKey(entity.Name))
|
|
|
+ return false;
|
|
|
+ foreach (Method m in cls.MethodList)
|
|
|
+ {
|
|
|
+ if (typeof(Subscribe).IsInstanceOfType(m))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (m.Id > 256) m.Id = 99;
|
|
|
+ string nameStr = string.Format("{0}_LogCode_{1}", cls.Name, m.Name);
|
|
|
+ string defineStr = string.Format("\"QLR0402{0}{1}\"", Entity.entityDic[entity.Name], m.Id.ToString("D2"));
|
|
|
+ WriteLineDefine(sw, entity, nameStr, defineStr, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sw.WriteLine();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
void WriteMethodSignatureEnum(StreamWriter sw, Entity entity, EntityClass cls)
|
|
|
{
|
|
|
foreach (Method m in cls.MethodList)
|
|
|
@@ -259,6 +282,7 @@ namespace spgen
|
|
|
{
|
|
|
WriteMethodEnum(sw, entity, cls);
|
|
|
WriteMethodSignatureEnum(sw, entity, cls);
|
|
|
+ WriteLogCode(sw, entity, cls);
|
|
|
WriteMethodParam(sw, entity, cls);
|
|
|
sw.WriteLine();
|
|
|
sw.WriteLine("///////////////////////////");
|
|
|
@@ -422,6 +446,7 @@ namespace spgen
|
|
|
sw.WriteLine("\t\t\t\treturn;");
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
sw.WriteLine("#endif");
|
|
|
+ //sw.WriteLine("\t\tEntityResource::clearLink();");
|
|
|
sw.WriteLine("\t\t\tswitch (dwMessageID) {");
|
|
|
foreach (Method m in cls.MethodList)
|
|
|
{
|
|
|
@@ -433,6 +458,8 @@ namespace spgen
|
|
|
sw.WriteLine("\t\t\t\t\t\tSpOnewayCallContext<{0}>::Pointer ctx;", GetInfoStructName(entity, cls, m));
|
|
|
sw.WriteLine("\t\t\t\t\t\tctx.Attach(new SpOnewayCallContext<{0}>());", GetInfoStructName(entity, cls, m));
|
|
|
sw.WriteLine("\t\t\t\t\t\tSpBuffer2Object(Buf, ctx->Info);");
|
|
|
+ sw.WriteLine("\t\t\t\t\t\tpTransactionContext->GetLinkContext(ctx->link);");
|
|
|
+ sw.WriteLine("\t\t\t\t\t\tEntityResource::setLink(ctx->link);");
|
|
|
sw.WriteLine("\t\t\t\t\t\tHandle_{0}(ctx);", m.Name);
|
|
|
sw.WriteLine("\t\t\t\t\t}");
|
|
|
sw.WriteLine("\t\t\t\t\tbreak;");
|
|
|
@@ -445,6 +472,8 @@ namespace spgen
|
|
|
sw.WriteLine("\t\t\t\t\t\tSpReqAnsContext<{0},{1}>::Pointer ctx;", GetReqStructName(entity, cls, m), GetAnsStructName(entity, cls, m));
|
|
|
sw.WriteLine("\t\t\t\t\t\tctx.Attach(new SpReqAnsContext<{0},{1}>(pTransactionContext));", GetReqStructName(entity, cls, m), GetAnsStructName(entity, cls, m));
|
|
|
sw.WriteLine("\t\t\t\t\t\tSpBuffer2Object(Buf, ctx->Req);");
|
|
|
+ sw.WriteLine("\t\t\t\t\t\tpTransactionContext->GetLinkContext(ctx->link);");
|
|
|
+ sw.WriteLine("\t\t\t\t\t\tEntityResource::setLink(ctx->link);");
|
|
|
sw.WriteLine("\t\t\t\t\t\tHandle_{0}(ctx);", m.Name);
|
|
|
sw.WriteLine("\t\t\t\t\t}");
|
|
|
sw.WriteLine("\t\t\t\t\tbreak;");
|
|
|
@@ -563,8 +592,17 @@ namespace spgen
|
|
|
sw.WriteLine("\tErrorCodeEnum {0}({1} &Info)", oneway.Name, iname);
|
|
|
sw.WriteLine("\t{");
|
|
|
sw.WriteLine("\t\tCSmartPointer<IClientSessionFunction> pFunc = GetFunction();");
|
|
|
+ sw.WriteLine("\t\tif (m_context.checkEmpty())");
|
|
|
+ sw.WriteLine("\t\t{");
|
|
|
+ sw.WriteLine("\t\t\tm_context.AutoGenerate();");
|
|
|
+ sw.WriteLine("\t\t\tDbgToBeidou(m_context, m_pEntityBase != NULL ? m_pEntityBase->GetEntityName() : \"\")();");
|
|
|
+ sw.WriteLine("\t\t\tm_context = m_context.upgradeLink();");
|
|
|
+ sw.WriteLine("\t\t}");
|
|
|
+
|
|
|
sw.WriteLine("\t\tCAutoBuffer Buf = SpObject2Buffer(Info);");
|
|
|
- sw.WriteLine("\t\treturn pFunc->OnewayCall({0}, {1}, Buf);", GetMethodEnumName(entity, cls, oneway), GetMethodSignatureEnumName(entity, cls, oneway));
|
|
|
+ sw.WriteLine("\t\tauto ret = pFunc->OnewayCall({0}, {1}, Buf, m_context);", GetMethodEnumName(entity, cls, oneway), GetMethodSignatureEnumName(entity, cls, oneway));
|
|
|
+ sw.WriteLine("\t\tm_context.clear();");
|
|
|
+ sw.WriteLine("\t\treturn ret;");
|
|
|
sw.WriteLine("\t}");
|
|
|
}
|
|
|
else
|
|
|
@@ -572,7 +610,17 @@ namespace spgen
|
|
|
sw.WriteLine("\tErrorCodeEnum {0}()", oneway.Name);
|
|
|
sw.WriteLine("\t{");
|
|
|
sw.WriteLine("\t\tCSmartPointer<IClientSessionFunction> pFunc = GetFunction();");
|
|
|
- sw.WriteLine("\t\treturn pFunc->OnewayCall({0}, {1});", GetMethodEnumName(entity, cls, oneway), GetMethodSignatureEnumName(entity, cls, oneway));
|
|
|
+ sw.WriteLine("\t\tif (m_context.checkEmpty())");
|
|
|
+ sw.WriteLine("\t\t{");
|
|
|
+ sw.WriteLine("\t\t\tm_context.AutoGenerate();");
|
|
|
+ sw.WriteLine("\t\t\tDbgToBeidou(m_context, m_pEntityBase != NULL ? m_pEntityBase->GetEntityName() : \"\")();");
|
|
|
+ sw.WriteLine("\t\t\tm_context = m_context.upgradeLink();");
|
|
|
+ sw.WriteLine("\t\t}");
|
|
|
+
|
|
|
+
|
|
|
+ sw.WriteLine("\t\tauto ret = pFunc->OnewayCall({0}, {1}, m_context);", GetMethodEnumName(entity, cls, oneway), GetMethodSignatureEnumName(entity, cls, oneway));
|
|
|
+ sw.WriteLine("\t\tm_context.clear();");
|
|
|
+ sw.WriteLine("\t\treturn ret;");
|
|
|
sw.WriteLine("\t}");
|
|
|
}
|
|
|
sw.WriteLine();
|
|
|
@@ -585,7 +633,17 @@ namespace spgen
|
|
|
sw.WriteLine("\t{");
|
|
|
sw.WriteLine("\t\tCSmartPointer<IClientSessionFunction> pFunc = GetFunction();");
|
|
|
sw.WriteLine("\t\tCAutoBuffer Buf = SpObject2Buffer(Req);");
|
|
|
- sw.WriteLine("\t\treturn pFunc->AsyncRequest({0}, {1}, Buf, spAsyncWait, dwTimeout);", GetMethodEnumName(entity, cls, twoway), GetMethodSignatureEnumName(entity, cls, twoway));
|
|
|
+ sw.WriteLine("\t\tif (m_context.checkEmpty())");
|
|
|
+ sw.WriteLine("\t\t{");
|
|
|
+ sw.WriteLine("\t\t\tm_context.AutoGenerate();");
|
|
|
+ sw.WriteLine("\t\t\tDbgToBeidou(m_context, m_pEntityBase != NULL ? m_pEntityBase->GetEntityName() : \"\")();");
|
|
|
+ sw.WriteLine("\t\t\tm_context = m_context.upgradeLink();");
|
|
|
+ sw.WriteLine("\t\t}");
|
|
|
+
|
|
|
+
|
|
|
+ sw.WriteLine("\t\tauto ret = pFunc->AsyncRequest({0}, {1}, Buf, spAsyncWait, m_context, dwTimeout);", GetMethodEnumName(entity, cls, twoway), GetMethodSignatureEnumName(entity, cls, twoway));
|
|
|
+ sw.WriteLine("\t\tm_context.clear();");
|
|
|
+ sw.WriteLine("\t\treturn ret;");
|
|
|
sw.WriteLine("\t}");
|
|
|
|
|
|
// sync
|
|
|
@@ -601,6 +659,19 @@ namespace spgen
|
|
|
sw.WriteLine("\t\treturn Error;");
|
|
|
sw.WriteLine("\t}");
|
|
|
|
|
|
+ // sync with user error + buf
|
|
|
+ sw.WriteLine("\tErrorCodeEnum {0}({1} &Req, {2} &Ans, DWORD dwTimeout, DWORD &dwUserError, CSimpleString &str)", twoway.Name, GetReqStructName(entity, cls, twoway), GetAnsStructName(entity, cls, twoway));
|
|
|
+ sw.WriteLine("\t{");
|
|
|
+ sw.WriteLine("\t\tCSmartPointer<IAsynWaitSp> spAsyncWait;");
|
|
|
+ sw.WriteLine("\t\tErrorCodeEnum Error = {0}(Req, spAsyncWait, dwTimeout);", twoway.Name);
|
|
|
+ sw.WriteLine("\t\tif (Error == Error_Succeed) {");
|
|
|
+ sw.WriteLine("\t\t\tbool bEnd = false;");
|
|
|
+ sw.WriteLine("\t\t\tError = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);");
|
|
|
+ sw.WriteLine("\t\t\tLOG_ASSERT(Error || bEnd);");
|
|
|
+ sw.WriteLine("\t\t}");
|
|
|
+ sw.WriteLine("\t\treturn Error;");
|
|
|
+ sw.WriteLine("\t}");
|
|
|
+
|
|
|
// sync with user error
|
|
|
sw.WriteLine("\tErrorCodeEnum {0}({1} &Req, {2} &Ans, DWORD dwTimeout, DWORD &dwUserError)", twoway.Name, GetReqStructName(entity, cls, twoway), GetAnsStructName(entity, cls, twoway));
|
|
|
sw.WriteLine("\t{");
|
|
|
@@ -608,7 +679,8 @@ namespace spgen
|
|
|
sw.WriteLine("\t\tErrorCodeEnum Error = {0}(Req, spAsyncWait, dwTimeout);", twoway.Name);
|
|
|
sw.WriteLine("\t\tif (Error == Error_Succeed) {");
|
|
|
sw.WriteLine("\t\t\tbool bEnd = false;");
|
|
|
- sw.WriteLine("\t\t\tError = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, dwTimeout);");
|
|
|
+ sw.WriteLine("\t\t\tCSimpleString str;");
|
|
|
+ sw.WriteLine("\t\t\tError = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);");
|
|
|
sw.WriteLine("\t\t\tLOG_ASSERT(Error || bEnd);");
|
|
|
sw.WriteLine("\t\t}");
|
|
|
sw.WriteLine("\t\treturn Error;");
|
|
|
@@ -722,6 +794,16 @@ namespace spgen
|
|
|
sw.WriteLine();
|
|
|
}
|
|
|
|
|
|
+ void WriteOperatorContext(StreamWriter sw, Entity entity, EntityClass cls)
|
|
|
+ {
|
|
|
+ sw.WriteLine("\t{0}* operator () (const linkContext &curLink) ", GetClientClassName(entity, cls));
|
|
|
+ sw.WriteLine("\t{");
|
|
|
+ sw.WriteLine("\t\tm_context = curLink;");
|
|
|
+ sw.WriteLine("\t\treturn this;");
|
|
|
+ sw.WriteLine("\t}");
|
|
|
+ sw.WriteLine();
|
|
|
+ }
|
|
|
+
|
|
|
void WriteClientDestructor(StreamWriter sw, Entity entity, EntityClass cls)
|
|
|
{
|
|
|
sw.WriteLine("protected:");
|
|
|
@@ -735,12 +817,29 @@ namespace spgen
|
|
|
|
|
|
void WriteClientConnect(StreamWriter sw, Entity entity, EntityClass cls)
|
|
|
{
|
|
|
+ sw.WriteLine("\tvoid OnConnectSucceed()");
|
|
|
+ sw.WriteLine("\t{");
|
|
|
+ sw.WriteLine("\t\tbSessionClosed = false;");
|
|
|
+ sw.WriteLine("\t}");
|
|
|
+
|
|
|
+ sw.WriteLine("\tvoid OnClose(ErrorCodeEnum)");
|
|
|
+ sw.WriteLine("\t{");
|
|
|
+ sw.WriteLine("\t\tDbg(\"session closed.\");");
|
|
|
+ sw.WriteLine("\t\tbSessionClosed = true;");
|
|
|
+ sw.WriteLine("\t}");
|
|
|
+
|
|
|
+ sw.WriteLine("\tbool QuerySessionClosed()");
|
|
|
+ sw.WriteLine("\t{");
|
|
|
+ sw.WriteLine("\t\treturn bSessionClosed;");
|
|
|
+ sw.WriteLine("\t}");
|
|
|
+
|
|
|
sw.WriteLine("\tErrorCodeEnum Connect(CSmartPointer<IAsynWaitSp> &spAsyncWait)");
|
|
|
sw.WriteLine("\t{");
|
|
|
sw.WriteLine("\t\tCSmartPointer<IEntityFunction> pFunc = m_pEntityBase->GetFunction();");
|
|
|
sw.WriteLine("\t\tErrorCodeEnum Error = pFunc->ConnectRemoteEntity(this, \"{0}\", \"{1}\", spAsyncWait);", entity.Name, cls.Name);
|
|
|
sw.WriteLine("\t\tif (Error == Error_Succeed) {");
|
|
|
sw.WriteLine("\t\t\tm_bSysManaged = true;");
|
|
|
+ sw.WriteLine("\t\t\tbSessionClosed = false;");
|
|
|
sw.WriteLine("\t\t}");
|
|
|
sw.WriteLine("\t\treturn Error;");
|
|
|
sw.WriteLine("\t}");
|
|
|
@@ -784,6 +883,7 @@ namespace spgen
|
|
|
sw.WriteLine("class {0} : public CClientSessionBase {{", clsname);
|
|
|
sw.WriteLine("public:");
|
|
|
WriteClientConstructor(sw, entity, cls);
|
|
|
+ WriteOperatorContext(sw, entity, cls);
|
|
|
WriteClientDestructor(sw, entity, cls);
|
|
|
WriteClientConnect(sw, entity, cls);
|
|
|
foreach (Method m in cls.MethodList)
|
|
|
@@ -810,9 +910,11 @@ namespace spgen
|
|
|
{
|
|
|
WriteOnAnswer(sw, entity, cls);
|
|
|
}
|
|
|
- sw.WriteLine("private:");
|
|
|
+ sw.WriteLine("protected:");
|
|
|
sw.WriteLine("\tbool m_bSysManaged;");
|
|
|
sw.WriteLine("\tCEntityBase *m_pEntityBase;");
|
|
|
+ sw.WriteLine("\tlinkContext m_context;");
|
|
|
+ sw.WriteLine("\tbool bSessionClosed;");
|
|
|
sw.WriteLine("};");
|
|
|
}
|
|
|
|