mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Complete GxsChannels JSON API with blocking methods
RsGxsIfaceHelper::requestStatus expose it to JSON API Implemented RsGxsIfaceHelper::waitToken to wait for GXS operations RsItem::serial_process fix doxygen warning as it's a comment not documentation RsTypeSerializer add JSON conversion methods for double [de]serialization not implemented yet RsTypeSerializer_PRIVATE_{FROM,TO}_JSON_ARRAY fix doxygen warning as it's a comment not documentation make GxsChannels::ExtraFileHash a bit more reasonable jsonapi-generator fix unused variable warning if there is no input or output paramethers jsonapi-generator fix generation for inerithed jsonapi methods Convert to RsSerializable some Gxs structs for the JSON API
This commit is contained in:
parent
d731b665db
commit
15f39129f1
13 changed files with 316 additions and 82 deletions
|
@ -1,6 +1,5 @@
|
|||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = "libretroshare"
|
||||
#OUTPUT_DIRECTORY =
|
||||
|
||||
ALIASES += jsonapi{1}="\xmlonly<jsonapi minversion=\"\1\"/>\endxmlonly"
|
||||
|
||||
|
|
|
@ -115,9 +115,12 @@ int main(int argc, char *argv[])
|
|||
QString refid(member.attributes().namedItem("refid").nodeValue());
|
||||
QString methodName(member.firstChildElement("name").toElement().text());
|
||||
QString wrapperName(instanceName+methodName+"Wrapper");
|
||||
QString defFilePath(doxPrefix + refid.split('_')[0] + ".xml");
|
||||
|
||||
qDebug() << "Looking for" << typeName << methodName << "into"
|
||||
<< typeFilePath;
|
||||
|
||||
QDomDocument defDoc;
|
||||
QString defFilePath(doxPrefix + refid.split('_')[0] + ".xml");
|
||||
QFile defFile(defFilePath);
|
||||
if ( !defFile.open(QIODevice::ReadOnly) ||
|
||||
!defDoc.setContent(&defFile, &parseError, &line, &column) )
|
||||
|
@ -128,7 +131,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
QDomElement memberdef;
|
||||
QDomNodeList memberdefs = typeDoc.elementsByTagName("memberdef");
|
||||
QDomNodeList memberdefs = defDoc.elementsByTagName("memberdef");
|
||||
for (int k = 0; k < memberdefs.size(); ++k)
|
||||
{
|
||||
QDomElement tmpMBD = memberdefs.item(k).toElement();
|
||||
|
@ -148,6 +151,8 @@ int main(int argc, char *argv[])
|
|||
QString retvalType = memberdef.firstChildElement("type").text();
|
||||
QMap<QString,MethodParam> paramsMap;
|
||||
QStringList orderedParamNames;
|
||||
uint hasInput = false;
|
||||
uint hasOutput = false;
|
||||
|
||||
QDomNodeList params = memberdef.elementsByTagName("param");
|
||||
for (int k = 0; k < params.size(); ++k)
|
||||
|
@ -171,10 +176,20 @@ int main(int argc, char *argv[])
|
|||
QDomElement tmpPN = parameternames.item(k).toElement();
|
||||
MethodParam& tmpParam = paramsMap[tmpPN.text()];
|
||||
QString tmpD = tmpPN.attributes().namedItem("direction").nodeValue();
|
||||
tmpParam.in = tmpD.contains("in");
|
||||
tmpParam.out = tmpD.contains("out");
|
||||
if(tmpD.contains("in"))
|
||||
{
|
||||
tmpParam.in = true;
|
||||
hasInput = true;
|
||||
}
|
||||
if(tmpD.contains("out"))
|
||||
{
|
||||
tmpParam.out = true;
|
||||
hasOutput = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(retvalType != "void") hasOutput = true;
|
||||
|
||||
qDebug() << instanceName << apiPath << retvalType << typeName
|
||||
<< methodName;
|
||||
for (const QString& pn : orderedParamNames)
|
||||
|
@ -183,13 +198,25 @@ int main(int argc, char *argv[])
|
|||
qDebug() << "\t" << mp.type << mp.name << mp.in << mp.out;
|
||||
}
|
||||
|
||||
QString retvalSerialization;
|
||||
if(retvalType != "void")
|
||||
retvalSerialization = "\t\t\tRS_SERIAL_PROCESS(retval);";
|
||||
QString inputParamsDeserialization;
|
||||
if(hasInput)
|
||||
{
|
||||
inputParamsDeserialization +=
|
||||
"\t\t{\n"
|
||||
"\t\t\tRsGenericSerializer::SerializeContext& ctx(cReq);\n"
|
||||
"\t\t\tRsGenericSerializer::SerializeJob j(RsGenericSerializer::FROM_JSON);\n";
|
||||
}
|
||||
|
||||
QString outputParamsSerialization;
|
||||
if(hasOutput)
|
||||
{
|
||||
outputParamsSerialization +=
|
||||
"\t\t{\n"
|
||||
"\t\t\tRsGenericSerializer::SerializeContext& ctx(cAns);\n"
|
||||
"\t\t\tRsGenericSerializer::SerializeJob j(RsGenericSerializer::TO_JSON);\n";
|
||||
}
|
||||
|
||||
QString paramsDeclaration;
|
||||
QString inputParamsDeserialization;
|
||||
QString outputParamsSerialization;
|
||||
for (const QString& pn : orderedParamNames)
|
||||
{
|
||||
const MethodParam& mp(paramsMap[pn]);
|
||||
|
@ -202,13 +229,18 @@ int main(int argc, char *argv[])
|
|||
+ mp.name + ");\n";
|
||||
}
|
||||
|
||||
if(hasInput) inputParamsDeserialization += "\t\t}\n";
|
||||
if(retvalType != "void")
|
||||
outputParamsSerialization +=
|
||||
"\t\t\tRS_SERIAL_PROCESS(retval);\n";
|
||||
if(hasOutput) outputParamsSerialization += "\t\t}\n";
|
||||
|
||||
QMap<QString,QString> substitutionsMap;
|
||||
substitutionsMap.insert("instanceName", instanceName);
|
||||
substitutionsMap.insert("methodName", methodName);
|
||||
substitutionsMap.insert("paramsDeclaration", paramsDeclaration);
|
||||
substitutionsMap.insert("inputParamsDeserialization", inputParamsDeserialization);
|
||||
substitutionsMap.insert("outputParamsSerialization", outputParamsSerialization);
|
||||
substitutionsMap.insert("retvalSerialization", retvalSerialization);
|
||||
substitutionsMap.insert("retvalType", retvalType);
|
||||
substitutionsMap.insert("callParamsList", orderedParamNames.join(", "));
|
||||
substitutionsMap.insert("wrapperName", wrapperName);
|
||||
|
|
|
@ -47,22 +47,13 @@ void $%wrapperName%$(const std::shared_ptr<rb::Session> session)
|
|||
$%paramsDeclaration%$
|
||||
|
||||
// deserialize input parameters from JSON
|
||||
{
|
||||
RsGenericSerializer::SerializeContext& ctx(cReq);
|
||||
RsGenericSerializer::SerializeJob j(RsGenericSerializer::FROM_JSON);
|
||||
$%inputParamsDeserialization%$
|
||||
}
|
||||
|
||||
// call retroshare C++ API
|
||||
$%retvalType%$ retval = $%instanceName%$->$%methodName%$($%callParamsList%$);
|
||||
|
||||
// serialize out parameters and return value to JSON
|
||||
{
|
||||
RsGenericSerializer::SerializeContext& ctx(cAns);
|
||||
RsGenericSerializer::SerializeJob j(RsGenericSerializer::TO_JSON);
|
||||
$%retvalSerialization%$
|
||||
$%outputParamsSerialization%$
|
||||
}
|
||||
|
||||
// return them to the API caller
|
||||
std::stringstream ss;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue