Twitch SDK (Internal)
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ttv::experiment::ExperimentAPI Class Reference

#include <experimentapi.h>

Inheritance diagram for ttv::experiment::ExperimentAPI:
ttv::ModuleBase ttv::IModule

Classes

class  CoreApiClient
 

Public Types

using FetchExperimentsCallback = std::function< void(TTV_ErrorCode ec, const std::shared_ptr< ExperimentSet > &result)>
 
enum  State { State::Uninitialized, State::Initializing, State::Initialized, State::ShuttingDown }
 
using InitializeCallback = std::function< void(TTV_ErrorCode ec)>
 
using ShutdownCallback = std::function< void(TTV_ErrorCode ec)>
 

Public Member Functions

 ExperimentAPI ()
 
virtual ~ExperimentAPI ()
 
virtual std::string GetModuleName () const override
 
virtual TTV_ErrorCode Initialize (const InitializeCallback &callback) override
 
virtual TTV_ErrorCode Shutdown (const ShutdownCallback &callback) override
 
virtual TTV_ErrorCode Update () override
 
TTV_ErrorCode SetCoreApi (const std::shared_ptr< CoreAPI > &coreApi)
 
TTV_ErrorCode SetAnalyticsId (const std::string &id)
 
TTV_ErrorCode FetchExperiments (const FetchExperimentsCallback &callback)
 
TTV_ErrorCode SetExperiments (const ExperimentSet &experiments)
 
TTV_ErrorCode DeserializeExperiments (const std::string &json, ExperimentSet &result)
 
TTV_ErrorCode DetermineBucket (const std::string &experiment, std::string &result)
 
TTV_ErrorCode SetOverride (const std::string &experimentGuid, const std::string &groupValue)
 
TTV_ErrorCode GetOverride (const std::string &experimentGuid, std::string &result)
 
TTV_ErrorCode GetOverrides (std::map< std::string, std::string > &result)
 
TTV_ErrorCode RemoveOverride (const std::string &experimentGuid)
 
TTV_ErrorCode ClearOverrides ()
 
virtual State GetState () const override
 

Protected Member Functions

virtual bool CheckShutdown () override
 
virtual void CompleteShutdown () override
 
void NotifyStateChange ()
 
void RegisterInitializeCallback (const InitializeCallback &callback)
 
void RegisterShutdownCallback (const ShutdownCallback &callback)
 
template<typename T >
void Invoke (std::function< void(std::shared_ptr< T >)> callback)
 
std::shared_ptr< ComponentContainerGetComponentContainer ()
 

Protected Attributes

EventSource< IModuleListenermListeners
 
State mState
 
State mLastReportedState
 

Private Attributes

std::shared_ptr< CoreAPImCoreApi
 
std::shared_ptr< TaskRunnermTaskRunner
 
std::shared_ptr< CoreApiClientmCoreApiClient
 
ExperimentSet mExperimentSet
 
std::string mAnalyticsId
 
std::map< std::string, std::string > mOverrides
 

Detailed Description

Provides the client-side mini-experiment functionality.

The following properties must be set before calling Initialize().

The active experiments can be set in this API instance by

Once experiments have been loaded you can ask which bucket a user is in via DetermineBucket().

If debugging your app and want to force certain experiments use SetOverride() and RemoveOverride().

Member Typedef Documentation

◆ FetchExperimentsCallback

using ttv::experiment::ExperimentAPI::FetchExperimentsCallback = std::function<void(TTV_ErrorCode ec, const std::shared_ptr<ExperimentSet>& result)>

◆ InitializeCallback

using ttv::IModule::InitializeCallback = std::function<void(TTV_ErrorCode ec)>
inherited

◆ ShutdownCallback

using ttv::IModule::ShutdownCallback = std::function<void(TTV_ErrorCode ec)>
inherited

Member Enumeration Documentation

◆ State

enum ttv::IModule::State
stronginherited
Enumerator
Uninitialized 
Initializing 
Initialized 
ShuttingDown 

Constructor & Destructor Documentation

◆ ExperimentAPI()

ttv::experiment::ExperimentAPI::ExperimentAPI ( )

◆ ~ExperimentAPI()

virtual ttv::experiment::ExperimentAPI::~ExperimentAPI ( )
virtual

Member Function Documentation

◆ CheckShutdown()

virtual bool ttv::experiment::ExperimentAPI::CheckShutdown ( )
overrideprotectedvirtual

Reimplemented from ttv::ModuleBase.

◆ ClearOverrides()

TTV_ErrorCode ttv::experiment::ExperimentAPI::ClearOverrides ( )

Clears all overrides.

◆ CompleteShutdown()

virtual void ttv::experiment::ExperimentAPI::CompleteShutdown ( )
overrideprotectedvirtual

Reimplemented from ttv::ModuleBase.

◆ DeserializeExperiments()

TTV_ErrorCode ttv::experiment::ExperimentAPI::DeserializeExperiments ( const std::string &  json,
ExperimentSet result 
)

Parses the given experiments JSON. This is used to parse previously fetched ExperimentSet::serialized.

◆ DetermineBucket()

TTV_ErrorCode ttv::experiment::ExperimentAPI::DetermineBucket ( const std::string &  experiment,
std::string &  result 
)

Determines which bucket should be used based on the device id for the given experiment GUID. The data must have previously been fetched via FetchExperiments() which caches it internally.

◆ FetchExperiments()

TTV_ErrorCode ttv::experiment::ExperimentAPI::FetchExperiments ( const FetchExperimentsCallback callback)

Requests the current set of experiments from the backend.

◆ GetComponentContainer()

std::shared_ptr<ComponentContainer> ttv::ModuleBase::GetComponentContainer ( )
inlineprotectedinherited

Returns the common ComponentContainer which hosts all components which live at the module level.

◆ GetModuleName()

virtual std::string ttv::experiment::ExperimentAPI::GetModuleName ( ) const
overridevirtual

Returns the name of the module.

Implements ttv::IModule.

◆ GetOverride()

TTV_ErrorCode ttv::experiment::ExperimentAPI::GetOverride ( const std::string &  experimentGuid,
std::string &  result 
)

Determines the value of the group if it is overidden. This will be "" if not overidden.

◆ GetOverrides()

TTV_ErrorCode ttv::experiment::ExperimentAPI::GetOverrides ( std::map< std::string, std::string > &  result)

Retrieves all groups that have been overridden and their assigned value.

◆ GetState()

virtual State ttv::ModuleBase::GetState ( ) const
overridevirtualinherited

Returns the current state of the module.

Implements ttv::IModule.

◆ Initialize()

virtual TTV_ErrorCode ttv::experiment::ExperimentAPI::Initialize ( const InitializeCallback callback)
overridevirtual

Initializes the module asynchronously. The module state will be reported in IModuleListener::ModuleStateChanged(). No other calls should be made into the module until the module state is either State::Initialized or State::Uninitialized. You should only expect changes to the module state if this method succeeds.

Reimplemented from ttv::ModuleBase.

◆ Invoke()

template<typename T >
void ttv::ModuleBase::Invoke ( std::function< void(std::shared_ptr< T >)>  callback)
inlineprotectedinherited

Invokes the callback for the module listeners.

◆ NotifyStateChange()

void ttv::ModuleBase::NotifyStateChange ( )
protectedinherited

◆ RegisterInitializeCallback()

void ttv::ModuleBase::RegisterInitializeCallback ( const InitializeCallback callback)
inlineprotectedinherited

◆ RegisterShutdownCallback()

void ttv::ModuleBase::RegisterShutdownCallback ( const ShutdownCallback callback)
inlineprotectedinherited

◆ RemoveOverride()

TTV_ErrorCode ttv::experiment::ExperimentAPI::RemoveOverride ( const std::string &  experimentGuid)

Removes an explicit override set using SetOverride().

◆ SetAnalyticsId()

TTV_ErrorCode ttv::experiment::ExperimentAPI::SetAnalyticsId ( const std::string &  id)

◆ SetCoreApi()

TTV_ErrorCode ttv::experiment::ExperimentAPI::SetCoreApi ( const std::shared_ptr< CoreAPI > &  coreApi)

◆ SetExperiments()

TTV_ErrorCode ttv::experiment::ExperimentAPI::SetExperiments ( const ExperimentSet experiments)

Sets the active experiments.

◆ SetOverride()

TTV_ErrorCode ttv::experiment::ExperimentAPI::SetOverride ( const std::string &  experimentGuid,
const std::string &  groupValue 
)

Sets an explicit group to use for an experiment, typically used for debugging.

◆ Shutdown()

virtual TTV_ErrorCode ttv::experiment::ExperimentAPI::Shutdown ( const ShutdownCallback callback)
overridevirtual

Initiates an asynchronous shutdown of the module. The module state will be reported in IModuleListener::ModuleStateChanged(). No other calls should be made into the module until the module state is either State::Initialized or State::Uninitialized. All modules that depend on this module need to be shutdown first. You should only expect changes to the module state if this method succeeds.

Reimplemented from ttv::ModuleBase.

◆ Update()

virtual TTV_ErrorCode ttv::experiment::ExperimentAPI::Update ( )
overridevirtual

Updates the internal state of the module and fires any pending callbacks.

Reimplemented from ttv::ModuleBase.

Member Data Documentation

◆ mAnalyticsId

std::string ttv::experiment::ExperimentAPI::mAnalyticsId
private

◆ mCoreApi

std::shared_ptr<CoreAPI> ttv::experiment::ExperimentAPI::mCoreApi
private

◆ mCoreApiClient

std::shared_ptr<CoreApiClient> ttv::experiment::ExperimentAPI::mCoreApiClient
private

◆ mExperimentSet

ExperimentSet ttv::experiment::ExperimentAPI::mExperimentSet
private

◆ mLastReportedState

State ttv::ModuleBase::mLastReportedState
protectedinherited

◆ mListeners

EventSource<IModuleListener> ttv::ModuleBase::mListeners
protectedinherited

The registered listeners. These listeners extend IModuleListener and will be of the type required for the module.

◆ mOverrides

std::map<std::string, std::string> ttv::experiment::ExperimentAPI::mOverrides
private

◆ mState

State ttv::ModuleBase::mState
protectedinherited

◆ mTaskRunner

std::shared_ptr<TaskRunner> ttv::experiment::ExperimentAPI::mTaskRunner
private

The documentation for this class was generated from the following file: