Twitch SDK (Internal)
channelrepository.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * Twitch Broadcasting SDK
3 *
4 * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5 * may not be copied or used except in accordance with the terms of that agreement
6 * Copyright (c) 2012-2016 Twitch Interactive, Inc.
7 *********************************************************************************************/
8 
9 #pragma once
10 
14 #include "twitchsdk/core/cache.h"
15 #include "twitchsdk/core/mutex.h"
16 
17 #include <memory>
18 #include <map>
19 
20 
21 namespace ttv
22 {
23  class TaskRunner;
24  class ChannelRepository;
25  class GetChannelTask;
26  struct ChannelInfo;
27 }
28 
29 
31 {
32 public:
33  typedef std::function<void(TTV_ErrorCode ec, const ChannelInfo& channelInfo)> LookupCallback;
34 
35 public:
37 
41  TTV_ErrorCode FetchChannelInfo(ChannelId channelId, LookupCallback callback);
46  TTV_ErrorCode CacheChannelInfo(const ChannelInfo& channelInfo);
47 
48  // Component overrides
49  virtual void Update() override;
50  virtual TTV_ErrorCode Shutdown() override;
51  virtual std::string GetLoggerName() const override;
52 
53 
54 private:
55  struct LookupEntry
56  {
58  LookupCallback callback;
59  std::shared_ptr<GetChannelTask> task;
60  };
61 
62  // Component overrides
63  virtual bool CheckShutdown() override;
64  virtual void CompleteShutdown() override;
65 
67  void CompleteLookup(ChannelId channelId, const ChannelInfo& channelInfo, TTV_ErrorCode ec);
68 
69  std::shared_ptr<ttv::IMutex> mMutex;
71  std::vector<LookupEntry> mPendingChannelInfoLookups;
72 
74 };
TTV_ErrorCode GetChannelInfo(ChannelId channelId, ChannelInfo &result)
void CompleteLookup(ChannelId channelId, const ChannelInfo &channelInfo, TTV_ErrorCode ec)
virtual std::string GetLoggerName() const override
Definition: cache.h:23
TTV_ErrorCode ScheduleLookup()
std::shared_ptr< GetChannelTask > task
Definition: channelrepository.h:59
std::shared_ptr< ttv::IMutex > mMutex
Definition: channelrepository.h:69
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
Cache< ChannelId, ChannelInfo > mChannelInfoCache
Definition: channelrepository.h:70
std::function< void(TTV_ErrorCode ec, const ChannelInfo &channelInfo)> LookupCallback
Definition: channelrepository.h:33
TTV_ErrorCode CacheChannelInfo(const ChannelInfo &channelInfo)
ChannelId channelId
Definition: channelrepository.h:57
virtual bool CheckShutdown() override
Definition: component.h:50
bool mLookupInProgress
Definition: channelrepository.h:73
uint32_t TTV_ErrorCode
Definition: errortypes.h:30
virtual void CompleteShutdown() override
virtual TTV_ErrorCode Shutdown() override
Definition: channelrepository.h:55
TTV_ErrorCode FetchChannelInfo(ChannelId channelId, LookupCallback callback)
uint32_t ChannelId
Definition: coretypes.h:23
Definition: coretypes.h:58
LookupCallback callback
Definition: channelrepository.h:58
std::vector< LookupEntry > mPendingChannelInfoLookups
Definition: channelrepository.h:71
virtual void Update() override
Definition: channelrepository.h:30