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.

  1. Rename the folder to something different, eg. loginlogout

  2. Adding the new directory to the examples/CMakeLists.txt file

    add_subdirectory(loginlogout)
    
  3. Renaming the C++ source file to loginlogout.cpp

  4. Modifying the examples/loginlogout/CMakeLists.txt file to incorporate our changes

    1
    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"