Re: Create custom API in C++ backend
Hello Wim,
I have attached an implementation, based on the documentation here:
https://sdk.innovaphone.com/13r2/sdk/common/interface/json_api.htm
You have to integrate it in your project, e.g. boilerplate app you get on a freshly created C++ App project:
- #include "jsonapiexample_echo.h"
- don't forget to add it to make file
Extend header file of the app class by the member variable for the context:
class ITask * currentTask;
std::list<class jsonapiexampleSession *> sessionList;
class EchoJsonApiContext * echoJsonApiContext;
std::list<class jsonapiexampleSession *> sessionList;
class EchoJsonApiContext * echoJsonApiContext;
Instantiate the Context object right after RegisterJsonApi(this) for default AppWebsocket in the app class constructor implementation:
RegisterJsonApi(this);
this->echoJsonApiContext = new EchoJsonApiContext("EchoApi", this);
Log("App instance started");
this->echoJsonApiContext = new EchoJsonApiContext("EchoApi", this);
Log("App instance started");
Make sure to release it in the destructor:
jsonapiexample::~jsonapiexample()
{
delete this->echoJsonApiContext;
}
{
delete this->echoJsonApiContext;
}
The JavaScript client implementation can use the custom API directly the AppWebsocket connection:
function app_connected(domain, user, dn, appdomain) {
var src = new app.Src(update);
src.send({ mt: "MonitorCount" });
src.send({ api:"EchoApi", mt: "Ping", text: "foobar" });
var src = new app.Src(update);
src.send({ mt: "MonitorCount" });
src.send({ api:"EchoApi", mt: "Ping", text: "foobar" });
Best Regards
Andreas Fink
