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

#include <trackingapi.h>

Inheritance diagram for ttv::tracking::TrackingAPI:
ttv::ModuleBase ttv::IModule

Classes

class  CoreApiClient
 

Public Types

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

 TrackingAPI ()
 
virtual ~TrackingAPI ()
 
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 SetMaxBytesInBatch (uint32_t batchSize)
 
TTV_ErrorCode SetFlushIntervalInMs (uint32_t flushInterval)
 
TTV_ErrorCode SetListener (const std::shared_ptr< ITrackingAPIListener > &listener)
 
TTV_ErrorCode TrackEvent (const std::string &eventName, const std::map< std::string, TrackingValue > &params)
 
TTV_ErrorCode TrackEvent (const std::string &eventName, const std::map< std::string, TrackingValue > &params, uint32_t &eventId)
 
TTV_ErrorCode FlushEvents ()
 
virtual State GetState () const override
 

Static Public Attributes

static const char * kSpadeUrl
 

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 Member Functions

TTV_ErrorCode TrackEventInternal (const std::string &eventName, const std::map< std::string, TrackingValue > &params, uint32_t &eventId)
 
TTV_ErrorCode FlushEventsInternal ()
 

Private Attributes

std::shared_ptr< CoreAPImCoreApi
 
std::shared_ptr< TaskRunnermTaskRunner
 
std::shared_ptr< CoreApiClientmCoreApiClient
 
std::stringstream mEventStream
 
uint32_t mQueuedBytes
 
uint32_t mBatchStartId
 
uint32_t mBatchEndId
 
uint32_t mMaxBytesInBatch
 
uint32_t mFlushIntervalInMs
 
ttv::WaitForExpiry mFlushTimer
 
std::shared_ptr< ITrackingAPIListenermListener
 
std::shared_ptr< IMutexmMutex
 

Detailed Description

Provides the main tracking service functionality.

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

Member Typedef Documentation

◆ 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

◆ TrackingAPI()

ttv::tracking::TrackingAPI::TrackingAPI ( )

◆ ~TrackingAPI()

virtual ttv::tracking::TrackingAPI::~TrackingAPI ( )
virtual

Member Function Documentation

◆ CheckShutdown()

virtual bool ttv::tracking::TrackingAPI::CheckShutdown ( )
overrideprotectedvirtual

Reimplemented from ttv::ModuleBase.

◆ CompleteShutdown()

virtual void ttv::tracking::TrackingAPI::CompleteShutdown ( )
overrideprotectedvirtual

Reimplemented from ttv::ModuleBase.

◆ FlushEvents()

TTV_ErrorCode ttv::tracking::TrackingAPI::FlushEvents ( )

Explicitly requests that any batched events are flushed and sent.

◆ FlushEventsInternal()

TTV_ErrorCode ttv::tracking::TrackingAPI::FlushEventsInternal ( )
private

◆ 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::tracking::TrackingAPI::GetModuleName ( ) const
overridevirtual

Returns the name of the module.

Implements ttv::IModule.

◆ GetState()

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

Returns the current state of the module.

Implements ttv::IModule.

◆ Initialize()

virtual TTV_ErrorCode ttv::tracking::TrackingAPI::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

◆ SetCoreApi()

TTV_ErrorCode ttv::tracking::TrackingAPI::SetCoreApi ( const std::shared_ptr< CoreAPI > &  coreApi)

◆ SetFlushIntervalInMs()

TTV_ErrorCode ttv::tracking::TrackingAPI::SetFlushIntervalInMs ( uint32_t  flushInterval)

◆ SetListener()

TTV_ErrorCode ttv::tracking::TrackingAPI::SetListener ( const std::shared_ptr< ITrackingAPIListener > &  listener)

◆ SetMaxBytesInBatch()

TTV_ErrorCode ttv::tracking::TrackingAPI::SetMaxBytesInBatch ( uint32_t  batchSize)

◆ Shutdown()

virtual TTV_ErrorCode ttv::tracking::TrackingAPI::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.

◆ TrackEvent() [1/2]

TTV_ErrorCode ttv::tracking::TrackingAPI::TrackEvent ( const std::string &  eventName,
const std::map< std::string, TrackingValue > &  params 
)

Enqueues an event for reporting.

◆ TrackEvent() [2/2]

TTV_ErrorCode ttv::tracking::TrackingAPI::TrackEvent ( const std::string &  eventName,
const std::map< std::string, TrackingValue > &  params,
uint32_t &  eventId 
)

Enqueues an event for reporting. The returned eventId value can be used to match up with the callbacks if the application would like status of events as they are batched and sent.

◆ TrackEventInternal()

TTV_ErrorCode ttv::tracking::TrackingAPI::TrackEventInternal ( const std::string &  eventName,
const std::map< std::string, TrackingValue > &  params,
uint32_t &  eventId 
)
private

◆ Update()

virtual TTV_ErrorCode ttv::tracking::TrackingAPI::Update ( )
overridevirtual

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

Reimplemented from ttv::ModuleBase.

Member Data Documentation

◆ kSpadeUrl

const char* ttv::tracking::TrackingAPI::kSpadeUrl
static

◆ mBatchEndId

uint32_t ttv::tracking::TrackingAPI::mBatchEndId
private

◆ mBatchStartId

uint32_t ttv::tracking::TrackingAPI::mBatchStartId
private

◆ mCoreApi

std::shared_ptr<CoreAPI> ttv::tracking::TrackingAPI::mCoreApi
private

◆ mCoreApiClient

std::shared_ptr<CoreApiClient> ttv::tracking::TrackingAPI::mCoreApiClient
private

◆ mEventStream

std::stringstream ttv::tracking::TrackingAPI::mEventStream
private

◆ mFlushIntervalInMs

uint32_t ttv::tracking::TrackingAPI::mFlushIntervalInMs
private

◆ mFlushTimer

ttv::WaitForExpiry ttv::tracking::TrackingAPI::mFlushTimer
private

◆ mLastReportedState

State ttv::ModuleBase::mLastReportedState
protectedinherited

◆ mListener

std::shared_ptr<ITrackingAPIListener> ttv::tracking::TrackingAPI::mListener
private

◆ mListeners

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

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

◆ mMaxBytesInBatch

uint32_t ttv::tracking::TrackingAPI::mMaxBytesInBatch
private

◆ mMutex

std::shared_ptr<IMutex> ttv::tracking::TrackingAPI::mMutex
private

◆ mQueuedBytes

uint32_t ttv::tracking::TrackingAPI::mQueuedBytes
private

◆ mState

State ttv::ModuleBase::mState
protectedinherited

◆ mTaskRunner

std::shared_ptr<TaskRunner> ttv::tracking::TrackingAPI::mTaskRunner
private

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