The scope of this tutorial is to learn, how to create a source module which uses the RCC Api.
We will make use of the json_api framework, which allows us to encapsulate our code in a seperate
source file, with well defined interfaces to the rest of the App.
The tutorial is based on a newly created innovaphone App with the Visual Studio plugin.
The messages related to the RCC Api are identified by a property "api" having the value "RCC". The json_api within the AppWebsocket library is used to route all messages with this property to the code, which registered to handle this Api.
There may be multiple PBXs, from which a AppWebsocket connection is established, which provides this Api, so one object is used to keep a list of all these connections an other global information.
For each AppWebsocket connection another object is used to keep the status information
The used file and class names in this example are based on a newly created App with the name NewApp1 and the company name innovaphone.
Your filenames might be different according to your settings.
/*-----------------------------------------------------------------------------------------------*/
/* rccapi.h */
/* copyright (c) innovaphone 2019 */
/* */
/*-----------------------------------------------------------------------------------------------*/
class RccApiSession;
class RccApi {
class istd::list<RccApiSession> sessions;
public:
RccApi();
class JsonApi * CreateJsonApi(class IJsonApiConnection * connection, class json_io & msg, word base);
};
class RccApiSession : public JsonApi, public istd::listElement<RccApiSession> {
const char * Name() { return "RCC"; };
void Message(class json_io & msg, word base, const char * mt, const char * src);
void JsonApiConnectionClosed();
class RccApi * rccapi;
class IJsonApiConnection * connection;
public:
RccApiSession(class RccApi * rccapi, class IJsonApiConnection * connection);
~RccApiSession();
};
/*-----------------------------------------------------------------------------------------------*/
/* rccapi.cpp */
/* copyright (c) innovaphone 2019 */
/* */
/*-----------------------------------------------------------------------------------------------*/
#include "platform/platform.h"
#include "common/ilib/json.h"
#include "common/interface/json_api.h"
#include "rccapi.h"
#define DBG(x) debug->printf x
/*-----------------------------------------------------------------------------------------------*/
/* RccApi */
/*-----------------------------------------------------------------------------------------------*/
RccApi::RccApi()
{
}
class JsonApi * RccApi::CreateJsonApi(class IJsonApiConnection * connection, class json_io & msg, word base)
{
DBG(("RccApi::CreateJsonApi()"));
class RccApiSession * session = new RccApiSession(this, connection);
sessions.push_back(session);
return session;
}
/*-----------------------------------------------------------------------------------------------*/
/* RccApiSession */
/*-----------------------------------------------------------------------------------------------*/
RccApiSession::RccApiSession(class RccApi * rccapi, class IJsonApiConnection * connection)
{
DBG(("RccApiSession::RccApiSession()"));
this->rccapi = rccapi;
this->connection = connection;
char sb[1000];
class json_io send(sb);
word base = send.add_object(0xffff, 0);
send.add_string(base, "mt", "Initialize");
send.add_string(base, "api", "RCC");
connection->JsonApiMessage(send, sb);
connection->RegisterJsonApi(this);
}
RccApiSession::~RccApiSession()
{
DBG(("RccApiSession::~RccApiSession()"));
connection->UnRegisterJsonApi(this);
}
void RccApiSession::Message(class json_io & msg, word base, const char * mt, const char * src)
{
connection->JsonApiMessageComplete();
DBG(("RccApiSession::Message(%s)", mt));
if (!strcmp(mt, "UserInfo")) {
}
}
void RccApiSession::JsonApiConnectionClosed()
{
delete this;
}
In NewApp1.mak add the following rule
APP_OBJS += $(OUTDIR)/obj/rccapi.o
$(OUTDIR)/obj/rccapi.o: NewApp1/rccapi.cpp
At this point the project should run a build without an error. You should check this.
class RccApi * rccapi;
#include "rccapi.h"
rccapi = new RccApi();
delete rccapi;
else if (!strcmp(mt, "PbxInfo")) {
badgecount = new BadgeCountSignaling(instance, this);
instance->rccapi->CreateJsonApi(this, msg, base); // new line
AppWebsocketMessageComplete();
}
Run the App and check in the log file what is happening.