Dear ROOT community!
I’d like to ask if it’s possible to register a class member function into THttpServer’s RegisterCommand
method with a cmake compiled project. In general things work fine when I use simpler structures with free functions that get registered.
I’m trying to get a structure like below to work, where other classes holding such a HttpServerBase
object can register some of their member functions to be executed.
Simplified:
class HttpServerBase {
public:
HttpServerBase(int port, std::function<void()> f) : m_mthdNoArgs(f) {
m_http_server =
std::make_unique<THttpServer>(("http:" + std::to_string(port)).c_str());
m_http_server->SetDefaultPage(
"/path/to/my/webpage.html");
m_http_server->RegisterCommand(
"/CmdFolder/noArgFunc", "callMethodWithougArgs()");
//m_http_server->RegisterCommand(
// "/CmdFolder/noArgFunc", "HttpServerBase::callMethodWithougArgs()"); doesn't work either
}
void callMethodWithougArgs() { m_mthdNoArgs(); }
private:
std::unique_ptr<THttpServer> m_http_server = nullptr;
std::function<void()> m_mthdNoArgs;
ClassDef(HttpServerBase, 1)
};
And currently try to generate the dict with the following linkdef
#ifdef __CINT__
#pragma link C++ class HttpServerBase;
#pragma link C++ function HttpServerBase::callMethodWithougArgs();
#endif
What I get when executing the command in the webbrowser, is either
input_line_11:2:3: error: use of undeclared identifier 'callMethodWithougArgs'
(callMethodWithougArgs())
^
Error in <HandleInterpreterException>: Error evaluating expression (callMethodWithougArgs()).
Execution of your code was aborted.
or
input_line_10:2:24: error: call to non-static member function without an object argument
HttpServerBase::callMethodWithougArgs()
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
^C
In the html I have
<button id="btn_connect" type="button">Connect</button>
<script type="text/javascript">
document.getElementById("btn_connect").onclick = function () {
JSROOT.NewHttpRequest("CmdFolder/noArgFunc/cmd.json", "object").send();
};
</script>
Is there maybe something wrong with the way I define the LinkDef? Or do I have no choice but make the member functions static?
Thanks a lot!