Skip to content

Commit

Permalink
HPCC-31548 Improve qualifyMethodName in HIDL genreated code for ESP s…
Browse files Browse the repository at this point in the history
…ervices

Added a map for method name lookup to speed up qualification

Signed-Off-By: Kenneth Rowland [email protected]
  • Loading branch information
kenrowland committed Jun 5, 2024
1 parent 57b4dc8 commit 0016472
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions tools/hidl/hidlcomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <set>
#include <string>
#include <vector>
#include <algorithm>

//-------------------------------------------------------------------------------------------------------------
inline bool strieq(const char* s,const char* t) { return stricmp(s,t)==0; }
Expand Down Expand Up @@ -3940,6 +3941,7 @@ void EspServInfo::write_esp_binding_ipp()

outs("\tvirtual void init_strings();\n");
outs("\tvoid init_metrics();\n");
outs("\tvoid init_maps();\n");

outs("\tvirtual unsigned getCacheMethodCount(){return m_cacheMethodCount;}\n");

Expand Down Expand Up @@ -4060,6 +4062,8 @@ void EspServInfo::write_esp_binding_ipp()
outf("#endif\n");
}

outs("\tstd::map<std::string, std::string> m_qualifiedMethodNames;\n");

outs("};\n\n");
}

Expand Down Expand Up @@ -4090,6 +4094,7 @@ void EspServInfo::write_esp_binding(const char *packagename)
outf("{\n");
outf("\tinit_strings();\n");
outf("\tinit_metrics();\n");
outf("\tinit_maps();\n");
outf("\tsetWsdlVersion(%s);\n", wsdlVer.str());
outf("}\n");

Expand Down Expand Up @@ -4160,6 +4165,17 @@ void EspServInfo::write_esp_binding(const char *packagename)
}
outs("}\n");

// init_maps implementation
outf("\nvoid C%sSoapBinding::init_maps()\n", name_);
outs("{\n");
for (mthi=methods; mthi!= nullptr; mthi=mthi->next)
{
std::string methodNameKey(mthi->getName());
std::transform(methodNameKey.cbegin(), methodNameKey.cend(), methodNameKey.begin(), tolower);
outf("\tm_qualifiedMethodNames.emplace(\"%s\", \"%s\");\n", methodNameKey.c_str(), mthi->getName());
}
outs("}\n");

outf("\nint C%sSoapBinding::processRequest(IRpcMessage* rpc_call, IRpcMessage* rpc_response)\n", name_);
outs("{\n");
outs("\tif(rpc_call == NULL || rpc_response == NULL)\n\t\treturn -1;\n\n");
Expand Down Expand Up @@ -4370,15 +4386,16 @@ void EspServInfo::write_esp_binding(const char *packagename)
outs("\t\treturn true;\n");
outs("\t}\n");

for (mthi=methods;mthi!=NULL;mthi=mthi->next)
{
outf("\tif (Utils::strcasecmp(methname, \"%s\")==0)\n", mthi->getName());
outs("\t{\n");
outs("\t\tif (methQName!=NULL)\n");
outf("\t\t\tmethQName->set(\"%s\");\n", mthi->getName());
outs("\t\treturn true;\n");
outs("\t}\n");
}
outs("\tstd::string methodName(methname);\n");
outs("\tstd::transform(methodName.cbegin(), methodName.cend(), methodName.begin(), tolower);\n");
outs("\tauto it = m_qualifiedMethodNames.find(methodName);\n");
outs("\tif (it != m_qualifiedMethodNames.end())\n");
outs("\t{\n");
outs("\t\tif (methQName != nullptr)\n");
outs("\t\t\tmethQName->set(it->second.c_str());\n");
outs("\t\treturn true;\n");
outs("\t}\n");

outs("\treturn false;\n");
outs("}\n");

Expand Down

0 comments on commit 0016472

Please sign in to comment.