Skip to content

Working with Xasu

Victorma Perez Colado edited this page Jun 14, 2022 · 3 revisions

Xasu works like a state machine. Its status can be checked in the Status property of the Xasu tracker.

When Xasu awakes, it starts in the Uninitialized state. In this state traces could be enqueued but they won't be submitted.

To initialize Xasu there are three different posibilities: using AutoStart, using the Init method and using the Init method with custom configuration. Later in this page you can see more details on these topics. During initialization, Xasu will create the different Trace Processors (https://github.com/e-ucm/xasu/wiki/Working-Modes) and initialize the Authorization protocols (https://github.com/e-ucm/xasu/wiki/Authorization-protocols).

If everything initializes correctly, Xasu will enter in Working state, where it is able to receive and process traces. To send the traces, Xasu uses a asynchronous queue and a processing loop that is called every Processing Time seconds.

Finally, when the session finalizes, Xasu has to be finalized before closing the application. This finalization is required in order to flush the remaining traces or upload the pending backups. After finalization ends, Xasu will be in Finalized state.

If any error happens in any of the steps, Xasu will enter in Errored state, and details about the error can be found in the Status property.

The diagram below ilustrates the state machine diagram:

Xasu State Machone

Initialization

By default, Xasu starts up in a Idle (Created) state. In this state, Xasu is still in a blank state and is not ready to handle any traces.

To initialize it, there are threepossibilities:

  • AutoStart using the configuration file
  • Manual start using the configuration file (recommended)
  • Manual start using the scripting API

Initialization Architecture

The following diagram illustrates the parts involved in the Tracker initialization. Xasu Init Architecture (1)

Please note that Authorization initialization may require the game to open browser windows or perform redirections (in WebGL).

Using the AutoStart

To use AutoStart just check the AutoStart property in XasuTracker from the GameObject Inspector.

image

Using the configuration file

To initialize Xasu using the configuration file located in the StreamingAssets folder you just have to call to.

    await Xasu.Instance.Init();

Note that "Init" is an asynchronous task and thus await is the preferred method to continue after initialization.

Using the scripting API

To initialize Xasu using the scripting API you have to mannually create the TrackerConfig object and pass it to the Init function.

    await Xasu.Instance.Init(new TrackerConfig
    {
        Online = true,
        LRSEndpoint = "https://my.lrs.endpoint/",
        AuthProtocol = "basic",
        AuthParameters = new Dictionary<string, string>
        {
            { "username", "your-username" },
            { "password", "your-password" }
        }
    });

Finalizing Xasu

Before the game is closed, Xasu has to be finalized manually so its processors (online, offline or backup) perform their final tasks.

These tasks include:

  • Flushing all the queues in all processors.
  • Sending all the online/fallback pending traces to the LRS (forcely requires internet connection to continue).
  • Submitting the trace backup to the backup endpoint.
  • Closing all the opened logs and connections.

To finalize Xasu, the Finalize function is used. The finalization progress can be measured using the IProgress interface.

    var progress = new Progress<float>();
    progress.ProgressChanged += (_, p) =>
    {
        Debug.Log("Finalization progress: " + p);
    };
    await Xasu.Instance.Finalize(progress);
    Debug.Log("Tracker finalized");
    Application.Quit();