This example can be found in examples\cpp\restserver\restserver.cpp. When the PST SDK has been installed through the PST Software Suite installer the examples can be found in the Development folder.
This example shows how to enable the REST server using the PST SDK. The REST server enables network-based access to the PST Tracker using the HTTP protocol. GET and POST requests can be made to the server to send and receive data and change parameters. The REST interface offers a programming language independent interface to the PST Tracker. Besides accessing the REST server directly using a browser, a networking library like Curl can be used to interface with the server programatically.
When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Redist directory into the build directory. When the PST SDK has been installed through the PST Software Suite installer the Redist folder can be found in the Development folder.). On Windows, the Visual Studio project files are configured to use a relative path to the Redist directory as the working directory. If the examples have been copied, please ensure the working directory is still valid.
#ifdef WIN32
#include <windows.h>
#else
#include <csignal>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <iostream>
#include <thread>
#include <chrono>
static void Exithandler(int sig)
{
exit(0);
}
int main(int argc, char *argv[])
{
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
try
{
#ifdef WIN32
#else
#endif
std::cout << "PST REST server enabled. See the PST SDK Manual for example commands.\n";
std::this_thread::sleep_for(std::chrono::milliseconds(60000));
}
{
}
return 0;
}
virtual const char * full_description() const
Definition TrackerExceptions.h:54
Main PST SDK class implementing tracker communication.
Definition pstsdk_cpp.h:101
void Start()
Start tracking.
static void Shutdown()
Shutdown the tracking system, stopping tracking.
static void EnableRestServer(const Utils::PstString &server_address, const Utils::PstString &server_port, int eventStream_retry_timeout_ms=3000)
Enable a REST Server using the HTTP protocol on a local area network.
static void DisableRestServer()
Disable the REST server communication layer.