Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-31548 Improve qualifyMethodName in HIDL generated code for ESP services #18727

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esp/bindings/SOAP/Platform/soapbind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "espbinding.hpp"
#include "http/platform/httpbinding.hpp"

#include <initializer_list>

class esp_http_decl CSoapComplexType : implements IRpcSerializable, public CInterface
{
Expand Down
52 changes: 52 additions & 0 deletions esp/bindings/SOAP/Platform/soaphidlbind.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*##############################################################################
HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
############################################################################## */

#pragma warning( disable : 4786 )

#include "soaphidlbind.hpp"

void CHttpSoapHidlBinding::registerMethodNames(std::initializer_list<const char *> names)
{
for (const char *name : names)
{
std::string methodNameKey(name);
std::transform(methodNameKey.cbegin(), methodNameKey.cend(), methodNameKey.begin(),
[](unsigned char c){ return std::tolower(c); });
m_qualifiedMethodNames.emplace(methodNameKey.c_str(), name);
}
}

bool CHttpSoapHidlBinding::qualifyMethodName(IEspContext &context, const char *methname, StringBuffer *methQName)
{
if (!methname || !*methname)
{
if (methQName != nullptr)
methQName->clear();
return true;
}
std::string methodName(methname);
std::transform(methodName.cbegin(), methodName.cend(), methodName.begin(),
[](unsigned char c){ return std::tolower(c); });
auto it = m_qualifiedMethodNames.find(methodName);
if (it != m_qualifiedMethodNames.end())
{
if (methQName != nullptr)
methQName->set(it->second.c_str());
return true;
}
return false;
}
38 changes: 38 additions & 0 deletions esp/bindings/SOAP/Platform/soaphidlbind.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*##############################################################################
HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
############################################################################## */

#ifndef _SOAPHIDLBIND_HPP__
#define _SOAPHIDLBIND_HPP__

#include "soapbind.hpp"
#include <algorithm>

class esp_http_decl CHttpSoapHidlBinding : public CHttpSoapBinding
{
public:
CHttpSoapHidlBinding(IPropertyTree* cfg, const char *bindname=NULL, const char *procname=NULL, http_soap_log_level level=hsl_none) :
CHttpSoapBinding(cfg, bindname, procname, level) {}
virtual bool qualifyMethodName(IEspContext &context, const char *methname, StringBuffer *methQName);

protected:
virtual void registerMethodNames(std::initializer_list<const char *> names);

private:
std::map<std::string, std::string> m_qualifiedMethodNames;
};

#endif
1 change: 1 addition & 0 deletions esp/protocols/http/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(SRCS
../../bindings/http/platform/msgbuilder.cpp
../../bindings/SOAP/client/soapclient.cpp
../../bindings/SOAP/Platform/soapbind.cpp
../../bindings/SOAP/Platform/soaphidlbind.cpp
../../bindings/SOAP/Platform/soapmessage.cpp
../../bindings/SOAP/Platform/soapservice.cpp
../../bindings/SOAP/Platform/soapparam.cpp
Expand Down
58 changes: 28 additions & 30 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 @@ -3931,7 +3932,7 @@ void EspServInfo::write_esp_binding_ipp()
{
EspMethodInfo *mthi=NULL;

outf("\n\nclass C%sSoapBinding : public CHttpSoapBinding\n", name_);
outf("\n\nclass C%sSoapBinding : public CHttpSoapHidlBinding\n", name_);
outs("{\npublic:\n");

//dom
Expand All @@ -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 All @@ -3958,9 +3960,6 @@ void EspServInfo::write_esp_binding_ipp()
//method ==> isValidServiceName
outs("\tbool isValidServiceName(IEspContext &context, const char *name);\n");

//method ==> qualifyMethodName
outs("\tbool qualifyMethodName(IEspContext &context, const char *methname, StringBuffer *methQName);\n");

//method ==> qualifyServiceName
outs("\tbool qualifyServiceName(IEspContext &context, const char *servname, const char *methname, StringBuffer &servQName, StringBuffer *methQName);\n");

Expand Down Expand Up @@ -4080,16 +4079,17 @@ void EspServInfo::write_esp_binding(const char *packagename)
StrBuffer servicefeatureurl;
getMetaStringValue(servicefeatureurl,FEATEACCESSATTRIBUTE);

outf("\nC%sSoapBinding::C%sSoapBinding(http_soap_log_level level):CHttpSoapBinding(NULL, NULL, NULL, level)\n", name_, name_);
outf("\nC%sSoapBinding::C%sSoapBinding(http_soap_log_level level):CHttpSoapHidlBinding(NULL, NULL, NULL, level)\n", name_, name_);
outf("{\n");
outf("\tinit_strings();\n");
outf("\tsetWsdlVersion(%s);\n", wsdlVer.str());
outf("}\n");

outf("\nC%sSoapBinding::C%sSoapBinding(IPropertyTree* cfg, const char *bindname, const char *procname, http_soap_log_level level):CHttpSoapBinding(cfg, bindname, procname, level)\n", name_, name_);
outf("\nC%sSoapBinding::C%sSoapBinding(IPropertyTree* cfg, const char *bindname, const char *procname, http_soap_log_level level):CHttpSoapHidlBinding(cfg, bindname, procname, level)\n", name_, name_);
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 +4160,27 @@ void EspServInfo::write_esp_binding(const char *packagename)
}
outs("}\n");

// init_maps implementation
outf("\nvoid C%sSoapBinding::init_maps()\n", name_);
outs("{\n");
outs("\tstd::initializer_list<const char *> names = {\n");
for (mthi=methods; mthi!= nullptr; mthi=mthi->next)
{
outf("\t\t\"%s\"", mthi->getName());
if (mthi->next != nullptr)
{
outs(",\n");
}
else
{
outs("\n");
}
}
outs("\t};\n");

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

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 @@ -4363,30 +4384,6 @@ void EspServInfo::write_esp_binding(const char *packagename)
outs(2, "return (hasSubService(context, name));\n");
outs("}\n");

//method ==> qualifyMethodName
outf("\nbool C%sSoapBinding::qualifyMethodName(IEspContext &context, const char *methname, StringBuffer *methQName)\n", name_);
outs("{\n");

outs("\tif (!methname || !*methname)\n");
outs("\t{\n");
outs("\t\tif (methQName!=NULL)\n");
outs("\t\t\tmethQName->clear();\n");
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("\treturn false;\n");
outs("}\n");


//method ==> qualifyServiceName
outf("\nbool C%sSoapBinding::qualifyServiceName(IEspContext &context, const char *servname, const char *methname, StringBuffer &servQName, StringBuffer *methQName)\n", name_);
outs("{\n");
Expand Down Expand Up @@ -5548,6 +5545,7 @@ void HIDLcompiler::write_esp_ex_ipp()
outs("#include \"SOAP/Platform/soapmacro.hpp\"\n");
outs("#include \"SOAP/Platform/soapservice.hpp\"\n");
outs("#include \"SOAP/Platform/soapparam.hpp\"\n");
outs("#include \"SOAP/Platform/soaphidlbind.hpp\"\n");
outs("#include \"SOAP/client/soapclient.hpp\"\n");
outs("\n\n");

Expand Down
Loading