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

#include <coreapi.h>

Inheritance diagram for ttv::CoreAPI:
ttv::ModuleBase ttv::IModule

Classes

class  PubSubListener
 
class  UserListener
 

Public Types

using FetchUserInfoCallback = std::function< void(TTV_ErrorCode ec, const UserInfo &userInfo)>
 
using FetchChannelInfoCallback = std::function< void(TTV_ErrorCode ec, const ChannelInfo &channelInfo)>
 
using FetchStreamInfoCallback = std::function< void(TTV_ErrorCode ec, const StreamInfo &streamInfo)>
 
using LogInCallback = std::function< void(TTV_ErrorCode ec, const UserInfo &userInfo)>
 
using LogOutCallback = std::function< void(TTV_ErrorCode ec)>
 
using UploadProfileImageCallback = std::function< void(TTV_ErrorCode ec, const std::vector< ProfileImage > &images)>
 
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

 CoreAPI ()
 
virtual ~CoreAPI ()
 
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 SetListener (std::shared_ptr< ICoreAPIListener > listener)
 
std::shared_ptr< UserRepositoryGetUserRepository () const
 
std::shared_ptr< ChannelRepositoryGetChannelRepository () const
 
std::shared_ptr< SettingRepositoryGetSettingRepository () const
 
std::shared_ptr< TrackingContextGetTrackingContext () const
 
TTV_ErrorCode GetClientId (std::string &clientId)
 
TTV_ErrorCode SetLocalLanguage (const std::string &language)
 
TTV_ErrorCode GetLocalLanguage (std::string &language)
 
TTV_ErrorCode FetchUserInfoById (UserId userId, FetchUserInfoCallback callback)
 
TTV_ErrorCode FetchUserInfoByName (const std::string &userName, FetchUserInfoCallback callback)
 
TTV_ErrorCode FetchChannelInfoById (ChannelId channelId, const FetchChannelInfoCallback &callback)
 
TTV_ErrorCode FetchChannelInfoByName (const std::string &channelName, const FetchChannelInfoCallback &callback)
 
TTV_ErrorCode FetchStreamInfoById (ChannelId channelId, const FetchStreamInfoCallback &callback)
 
TTV_ErrorCode FetchStreamInfoByName (const std::string &channelName, const FetchStreamInfoCallback &callback)
 
TTV_ErrorCode CreateChannelStatus (UserId userId, ChannelId channelId, const std::shared_ptr< IChannelListener > &listener, std::shared_ptr< IChannelStatus > &result)
 
TTV_ErrorCode GetRequiredOAuthScopes (std::vector< std::string > &modules, std::vector< std::string > &scopes)
 
TTV_ErrorCode LogIn (const std::string &oauthToken, LogInCallback callback)
 
TTV_ErrorCode LogOut (UserId userId, LogOutCallback callback)
 
TTV_ErrorCode ConnectPubSub (UserId userId)
 
TTV_ErrorCode DisconnectPubSub (UserId userId)
 
TTV_ErrorCode RegisterClient (std::shared_ptr< ICoreApiClient > client)
 
TTV_ErrorCode UnregisterClient (std::shared_ptr< ICoreApiClient > client)
 
TTV_ErrorCode SetGlobalSetting (const std::string &key, const std::string &value)
 
TTV_ErrorCode RemoveGlobalSetting (const std::string &key)
 
TTV_ErrorCode GetGlobalSetting (const std::string &key, std::string &value)
 
virtual State GetState () const override
 

Protected Member Functions

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

void OnPubSubStateChanged (PubSubClient *source, PubSubState state, TTV_ErrorCode ec)
 
void OnUserLogInComplete (User *source, TTV_ErrorCode ec)
 
void OnUserLogOutComplete (User *source, TTV_ErrorCode ec)
 
void OnUserInfoFetchComplete (User *source, TTV_ErrorCode ec)
 
void OnUserAuthenticationIssue (User *source, std::shared_ptr< const OAuthToken > oauthToken, TTV_ErrorCode ec)
 
virtual bool CheckShutdown () override
 
virtual void CompleteShutdown () override
 
TTV_ErrorCode DisposeChannelStatus (const std::shared_ptr< IChannelStatus > &channelStatus)
 
void InitializeAnonymousUser ()
 
TTV_ErrorCode ValidateOAuthToken (const std::string &oauth, const std::function< void(TTV_ErrorCode ec)> &callback)
 

Private Attributes

std::shared_ptr< ChannelRepositorymChannelRepository
 
std::shared_ptr< UserRepositorymUserRepository
 
std::shared_ptr< TrackingContextmTrackingContext
 
std::shared_ptr< UserListenermUserListener
 
std::shared_ptr< PubSubListenermPubSubListener
 
std::shared_ptr< TaskRunnermTaskRunner
 
std::shared_ptr< SettingRepositorymSettingRepository
 
std::shared_ptr< CoreAPIInternalData > mInternalData
 
std::vector< std::shared_ptr< ICoreApiClient > > mApiClients
 
std::string mLocalLanguage
 

Detailed Description

Provides the core services need by other subsystems.

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

Member Typedef Documentation

◆ FetchChannelInfoCallback

using ttv::CoreAPI::FetchChannelInfoCallback = std::function<void(TTV_ErrorCode ec, const ChannelInfo& channelInfo)>

◆ FetchStreamInfoCallback

using ttv::CoreAPI::FetchStreamInfoCallback = std::function<void(TTV_ErrorCode ec, const StreamInfo& streamInfo)>

◆ FetchUserInfoCallback

using ttv::CoreAPI::FetchUserInfoCallback = std::function<void(TTV_ErrorCode ec, const UserInfo& userInfo)>

◆ InitializeCallback

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

◆ LogInCallback

using ttv::CoreAPI::LogInCallback = std::function<void(TTV_ErrorCode ec, const UserInfo& userInfo)>

◆ LogOutCallback

using ttv::CoreAPI::LogOutCallback = std::function<void(TTV_ErrorCode ec)>

◆ ShutdownCallback

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

◆ UploadProfileImageCallback

using ttv::CoreAPI::UploadProfileImageCallback = std::function<void(TTV_ErrorCode ec, const std::vector<ProfileImage>& images)>

Member Enumeration Documentation

◆ State

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

Constructor & Destructor Documentation

◆ CoreAPI()

ttv::CoreAPI::CoreAPI ( )

◆ ~CoreAPI()

virtual ttv::CoreAPI::~CoreAPI ( )
virtual

Member Function Documentation

◆ CheckShutdown()

virtual bool ttv::CoreAPI::CheckShutdown ( )
overrideprivatevirtual

Reimplemented from ttv::ModuleBase.

◆ CompleteShutdown()

virtual void ttv::CoreAPI::CompleteShutdown ( )
overrideprivatevirtual

Reimplemented from ttv::ModuleBase.

◆ ConnectPubSub()

TTV_ErrorCode ttv::CoreAPI::ConnectPubSub ( UserId  userId)

◆ CreateChannelStatus()

TTV_ErrorCode ttv::CoreAPI::CreateChannelStatus ( UserId  userId,
ChannelId  channelId,
const std::shared_ptr< IChannelListener > &  listener,
std::shared_ptr< IChannelStatus > &  result 
)

An IChannelListener object can be passed in to receive updates for the channel.

Parameters
[in]userIdThe user id to create the channel listener for. Can be 0 if for not specific user.
[in]channelIdThe channel id to listen on. Cannot be 0.
[in]listenerThe listener to use for callbacks. Can be null if listener is not needed.
[out]resultThe resulting IChannelStatus implementation for the given user/channel to receive updates on.
Returns
:
  • TTV_EC_SUCCESS if we've initialized and created FollowersStatus successfully.
  • TTV_EC_NOT_INITIALIZED if we haven't initialized properly.
  • TTV_EC_NEED_TO_LOGIN if we aren't logged in properly.
  • TTV_EC_INVALID_ARG: If any input arguments are invalid.

◆ DisconnectPubSub()

TTV_ErrorCode ttv::CoreAPI::DisconnectPubSub ( UserId  userId)

◆ DisposeChannelStatus()

TTV_ErrorCode ttv::CoreAPI::DisposeChannelStatus ( const std::shared_ptr< IChannelStatus > &  channelStatus)
private

◆ FetchChannelInfoById()

TTV_ErrorCode ttv::CoreAPI::FetchChannelInfoById ( ChannelId  channelId,
const FetchChannelInfoCallback callback 
)

Asynchonously fetches the channel information for the given channel id.

◆ FetchChannelInfoByName()

TTV_ErrorCode ttv::CoreAPI::FetchChannelInfoByName ( const std::string &  channelName,
const FetchChannelInfoCallback callback 
)

Asynchonously fetches the channel information for the named channel.

◆ FetchStreamInfoById()

TTV_ErrorCode ttv::CoreAPI::FetchStreamInfoById ( ChannelId  channelId,
const FetchStreamInfoCallback callback 
)

Asynchonously fetches the stream information for the given channel id.

Parameters
[in]channelIdThe id of the channel to fetch stream information for.
Returns
:
  • TTV_EC_SUCCESS if we've successfully fetched the stream info.
  • TTV_EC_WEBAPI_RESULT_NO_STREAMINFO if we've successfully fetched, but there is no stream info available (i.e. the stream is down).
  • TTV_EC_WEBAPI_RESULT_INVALID_JSON if we were unable to process the fetch response.

◆ FetchStreamInfoByName()

TTV_ErrorCode ttv::CoreAPI::FetchStreamInfoByName ( const std::string &  channelName,
const FetchStreamInfoCallback callback 
)

Asynchonously fetches the stream information for the given channel name.

Parameters
[in]channelNameThe name of the channel to fetch stream information for.
Returns
:
  • TTV_EC_SUCCESS if we've successfully fetched the stream info.
  • TTV_EC_WEBAPI_RESULT_NO_STREAMINFO if we've successfully fetched, but there is no stream info available (i.e. the stream is down).
  • TTV_EC_WEBAPI_RESULT_INVALID_JSON if we were unable to process the fetch response.

◆ FetchUserInfoById()

TTV_ErrorCode ttv::CoreAPI::FetchUserInfoById ( UserId  userId,
FetchUserInfoCallback  callback 
)

Asynchonously fetches the user information for the user with a given id. The result of the fetch will be returned in the callback.

◆ FetchUserInfoByName()

TTV_ErrorCode ttv::CoreAPI::FetchUserInfoByName ( const std::string &  userName,
FetchUserInfoCallback  callback 
)

Asynchronously fetches the user information for the named user. The result of the fetch will be returned in the callback.

◆ GetChannelRepository()

std::shared_ptr<ChannelRepository> ttv::CoreAPI::GetChannelRepository ( ) const
inline

◆ GetClientId()

TTV_ErrorCode ttv::CoreAPI::GetClientId ( std::string &  clientId)

Retrieves the currently set client-id.

◆ GetComponentContainer()

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

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

◆ GetGlobalSetting()

TTV_ErrorCode ttv::CoreAPI::GetGlobalSetting ( const std::string &  key,
std::string &  value 
)

◆ GetLocalLanguage()

TTV_ErrorCode ttv::CoreAPI::GetLocalLanguage ( std::string &  language)

Retrieves the currently set local language. This is a 2 language character code.

◆ GetModuleName()

virtual std::string ttv::CoreAPI::GetModuleName ( ) const
overridevirtual

Returns the name of the module.

Implements ttv::IModule.

◆ GetRequiredOAuthScopes()

TTV_ErrorCode ttv::CoreAPI::GetRequiredOAuthScopes ( std::vector< std::string > &  modules,
std::vector< std::string > &  scopes 
)

Retrieves the required scopes from all registered modules.

◆ GetSettingRepository()

std::shared_ptr<SettingRepository> ttv::CoreAPI::GetSettingRepository ( ) const
inline

◆ GetState()

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

Returns the current state of the module.

Implements ttv::IModule.

◆ GetTrackingContext()

std::shared_ptr<TrackingContext> ttv::CoreAPI::GetTrackingContext ( ) const
inline

◆ GetUserRepository()

std::shared_ptr<UserRepository> ttv::CoreAPI::GetUserRepository ( ) const
inline

◆ Initialize()

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

◆ InitializeAnonymousUser()

void ttv::CoreAPI::InitializeAnonymousUser ( )
private

◆ Invoke()

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

Invokes the callback for the module listeners.

◆ LogIn()

TTV_ErrorCode ttv::CoreAPI::LogIn ( const std::string &  oauthToken,
LogInCallback  callback 
)

◆ LogOut()

TTV_ErrorCode ttv::CoreAPI::LogOut ( UserId  userId,
LogOutCallback  callback 
)

◆ NotifyStateChange()

void ttv::ModuleBase::NotifyStateChange ( )
protectedinherited

◆ OnPubSubStateChanged()

void ttv::CoreAPI::OnPubSubStateChanged ( PubSubClient source,
PubSubState  state,
TTV_ErrorCode  ec 
)
private

◆ OnUserAuthenticationIssue()

void ttv::CoreAPI::OnUserAuthenticationIssue ( User source,
std::shared_ptr< const OAuthToken oauthToken,
TTV_ErrorCode  ec 
)
private

◆ OnUserInfoFetchComplete()

void ttv::CoreAPI::OnUserInfoFetchComplete ( User source,
TTV_ErrorCode  ec 
)
private

◆ OnUserLogInComplete()

void ttv::CoreAPI::OnUserLogInComplete ( User source,
TTV_ErrorCode  ec 
)
private

◆ OnUserLogOutComplete()

void ttv::CoreAPI::OnUserLogOutComplete ( User source,
TTV_ErrorCode  ec 
)
private

◆ RegisterClient()

TTV_ErrorCode ttv::CoreAPI::RegisterClient ( std::shared_ptr< ICoreApiClient client)

◆ RegisterInitializeCallback()

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

◆ RegisterShutdownCallback()

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

◆ RemoveGlobalSetting()

TTV_ErrorCode ttv::CoreAPI::RemoveGlobalSetting ( const std::string &  key)

◆ SetGlobalSetting()

TTV_ErrorCode ttv::CoreAPI::SetGlobalSetting ( const std::string &  key,
const std::string &  value 
)

◆ SetListener()

TTV_ErrorCode ttv::CoreAPI::SetListener ( std::shared_ptr< ICoreAPIListener listener)

◆ SetLocalLanguage()

TTV_ErrorCode ttv::CoreAPI::SetLocalLanguage ( const std::string &  language)

Sets the language used by the local client. This is a 2 language character code.

◆ Shutdown()

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

◆ UnregisterClient()

TTV_ErrorCode ttv::CoreAPI::UnregisterClient ( std::shared_ptr< ICoreApiClient client)

◆ Update()

virtual TTV_ErrorCode ttv::CoreAPI::Update ( )
overridevirtual

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

Reimplemented from ttv::ModuleBase.

◆ ValidateOAuthToken()

TTV_ErrorCode ttv::CoreAPI::ValidateOAuthToken ( const std::string &  oauth,
const std::function< void(TTV_ErrorCode ec)> &  callback 
)
private

Member Data Documentation

◆ mApiClients

std::vector<std::shared_ptr<ICoreApiClient> > ttv::CoreAPI::mApiClients
private

◆ mChannelRepository

std::shared_ptr<ChannelRepository> ttv::CoreAPI::mChannelRepository
private

◆ mInternalData

std::shared_ptr<CoreAPIInternalData> ttv::CoreAPI::mInternalData
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.

◆ mLocalLanguage

std::string ttv::CoreAPI::mLocalLanguage
private

◆ mPubSubListener

std::shared_ptr<PubSubListener> ttv::CoreAPI::mPubSubListener
private

◆ mSettingRepository

std::shared_ptr<SettingRepository> ttv::CoreAPI::mSettingRepository
private

◆ mState

State ttv::ModuleBase::mState
protectedinherited

◆ mTaskRunner

std::shared_ptr<TaskRunner> ttv::CoreAPI::mTaskRunner
private

◆ mTrackingContext

std::shared_ptr<TrackingContext> ttv::CoreAPI::mTrackingContext
private

◆ mUserListener

std::shared_ptr<UserListener> ttv::CoreAPI::mUserListener
private

◆ mUserRepository

std::shared_ptr<UserRepository> ttv::CoreAPI::mUserRepository
private

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