3.1. Logging in/out¶
The goal of this example is to create a C++ console application which logs in to a profile if the turret is logged out or is in Recieve Calls Only or log out if it is logged in.
For this we can start from the connect example found in TurretApiSDK.
3.1.1. Creating a new project¶
We can copy the examples/connect folder and make some changes to create a new project.
Rename the folder to something different, eg.
loginlogoutAdding the new directory to the
examples/CMakeLists.txtfileadd_subdirectory(loginlogout)
Renaming the C++ source file to
loginlogout.cppModifying the
examples/loginlogout/CMakeLists.txtfile to incorporate our changes1 2 3 4 5 6
cmake_minimum_required(VERSION 3.13 FATAL_ERROR) add_executable(loginlogout loginlogout.cpp) target_link_libraries(loginlogout PRIVATE TurretApi )
3.1.2. Adding the logic¶
For our application to work we need to first query the login state of the connected turret. Thankfully after inspecting the API we can see that there is a function on the interface just for this purpose, namely TurretApi.TurretRequestService.getLoginState
Using that we can get the login state of the turret after the connection was made
auto connection = osxpert::thrift::connect(client);
osxpert::turret::api::TurretState loginState = connection->getLoginState();
The getLoginState function returns a TurretApi.TurretState so using the values generated into osxpert::turret::api::TurretState found in the TurretApi_types.h file we can check if the turret is logged in and act on it with the help of TurretApi.TurretRequestService.login and TurretApi.TurretRequestService.logout
if (loginState == osxpert::turret::api::TurretState::Login)
{
connection->logout();
}
else
{
connection->login("<profile name>", "<profile password>");
}
And with that it should be complete.
Note
This example can be found in ThriftApiSDK. It uses the profile name “API Profile” and no password, but it also accepts command line arguments to change that eg. loginlogout.exe "Your Profile" "password"