9 #include <lager/store.hpp> 
   28     template<
class EventLoop, 
class Xform, 
class ...Enhancers>
 
   34         using CursorT = lager::reader<ModelT>;
 
   35         using CursorTSP = std::shared_ptr<CursorT>;
 
   37         using StoreT = decltype(
 
   39                 std::declval<ModelT>(),
 
   41                 std::declval<EventLoop>(),
 
   43                     std::ref(detail::declref<JobInterface>()),
 
   44                     std::ref(detail::declref<EventInterface>()),
 
   45                     lager::dep::as<SdkModelCursorKey>(std::declval<std::function<CursorTSP()>>()),
 
   46                     std::ref(detail::declref<RandomInterface>())
 
   47 #ifdef KAZV_USE_THREAD_SAFETY_HELPER
 
   48                     , std::ref(detail::declref<EventLoopThreadIdKeeper>())
 
   51                 std::declval<Enhancers>()...)
 
   55 #ifdef KAZV_USE_THREAD_SAFETY_HELPER 
   56                                   , EventLoopThreadIdKeeper &
 
   65             EventLoop &&eventLoop,
 
   67             Enhancers &&...enhancers)
 
   69                       std::move(model), jobHandler, eventEmitter,
 
   70                       std::forward<EventLoop>(eventLoop), 
std::forward<Xform>(xform),
 
   71                       std::forward<Enhancers>(enhancers)...)) {}
 
  104             auto secondaryStore = lager::make_store<ModelT>(
 
  105                 std::move(initialModel),
 
  106                 std::forward<EL>(eventLoop),
 
  107                 lager::with_reducer([](
auto &&, 
auto next) { 
return next; }));
 
  109             lager::context<ModelT> secondaryCtx = secondaryStore;
 
  112                 .then([secondaryCtx, d=m_d.get()](
auto &&) {
 
  113                           lager::watch(*(d->sdk),
 
  114                                        [secondaryCtx](auto next) { secondaryCtx.dispatch(std::move(next)); });
 
  117             return secondaryStore;
 
  142                     EventLoop &&eventLoop,
 
  144                     Enhancers &&...enhancers)
 
  149                             std::forward<EventLoop>(eventLoop),
 
  151                                 std::ref(jobHandler),
 
  152                                 std::ref(eventEmitter),
 
  154                                     std::function<CursorTSP()>([this] { 
return sdk; })),
 
  156 #ifdef KAZV_USE_THREAD_SAFETY_HELPER 
  160                             std::forward<Enhancers>(enhancers)...))
 
  161                 , sdk(std::make_shared<lager::reader<ModelT>>(store.reader().xform(std::forward<Xform>(xform))))
 
  163 #ifdef KAZV_USE_THREAD_SAFETY_HELPER 
  164                     store.context().createResolvedPromise(EffectStatus{})
 
  165                         .then([
this](
auto &&) {
 
  166                                   keeper.set(std::this_thread::get_id());
 
  170 #ifdef KAZV_USE_THREAD_SAFETY_HELPER 
  171             EventLoopThreadIdKeeper keeper;
 
  173             std::optional<RandomInterface> rg;
 
  178         std::unique_ptr<Private> m_d;
 
  199     template<
class EventLoop, 
class Xform, 
class ...Enhancers>
 
  203                         EventLoop &&eventLoop,
 
  205                         Enhancers &&...enhancers)
 
  206         -> 
Sdk<EventLoop, Xform, Enhancers...>
 
  208         return { std::move(sdk),
 
  211                  std::forward<EventLoop>(eventLoop),
 
  212                  std::forward<Xform>(xform),
 
  213                  std::forward<Enhancers>(enhancers)... };
 
  221         return Crypto::constructRandomSize();
 
  224     template<
class EventLoop, 
class Xform, 
class ...Enhancers>
 
  225     [[deprecated(
"Use deterministic makeDefaultSdkWithCryptoRandom instead. In the future, this will be removed.")]]
 
  229         EventLoop &&eventLoop,
 
  231         Enhancers &&...enhancers)
 
  232         -> 
Sdk<EventLoop, Xform, Enhancers...>
 
  240                        std::forward<EventLoop>(eventLoop),
 
  241                        std::forward<Xform>(xform),
 
  242                        std::forward<Enhancers>(enhancers)...);
 
  265     template<
class PH, 
class Xform, 
class ...Enhancers>
 
  272         Enhancers &&...enhancers)
 
  273         -> 
Sdk<PH, Xform, Enhancers...>
 
  281                        std::forward<PH>(ph),
 
  282                        std::forward<Xform>(xform),
 
  283                        std::forward<Enhancers>(enhancers)...);
 
  296         return lager::with_deps(std::ref(random));
 
Represent a Matrix client.
Definition: client.hpp:60
Definition: context.hpp:130
PromiseT createResolvedPromise(RetType v) const
Definition: context.hpp:185
Definition: crypto.hpp:36
Definition: eventinterface.hpp:15
A movable wrapper around std::random_device.
Definition: random-generator.hpp:103
Definition: random-generator.hpp:16
Contain the single source of truth of a matrix sdk.
Definition: sdk.hpp:30
Sdk(ModelT model, JobInterface &jobHandler, EventInterface &eventEmitter, EventLoop &&eventLoop, Xform &&xform, Enhancers &&...enhancers)
Definition: sdk.hpp:62
ContextT context() const
Get the context associated with this.
Definition: sdk.hpp:79
Client client() const
Get a Client representing this.
Definition: sdk.hpp:88
auto createSecondaryRoot(EL &&eventLoop, ModelT initialModel=ModelT{}) const
Create a secondary root for this Sdk.
Definition: sdk.hpp:103
Client clientFromSecondaryRoot(lager::reader< ModelT > sr) const
Get a Client representing this.
Definition: sdk.hpp:132
Definition: location.hpp:10
@ Private
Definition: client-model.hpp:41
auto makeSdk(SdkModel sdk, JobInterface &jobHandler, EventInterface &eventEmitter, EventLoop &&eventLoop, Xform &&xform, Enhancers &&...enhancers) -> Sdk< EventLoop, Xform, Enhancers... >
Create an sdk with the provided model.
Definition: sdk.hpp:200
lager::dep::key< SdkModelCursorTag, lager::dep::fn< std::shared_ptr< lager::reader< SdkModel > >> > SdkModelCursorKey
Definition: sdk-model-cursor-tag.hpp:23
std::string RandomData
Definition: crypto-util.hpp:35
RandomData genRandomData(int len)
Definition: crypto-util.hpp:66
std::size_t makeDefaultSdkWithCryptoRandomSize()
Definition: sdk.hpp:219
auto withRandomGenerator(RandomInterface &random)
An enhancer to use a custom random generator.
Definition: sdk.hpp:294
auto makeDefaultSdkWithCryptoRandom(RandomData random, JobInterface &jobHandler, EventInterface &eventEmitter, PH &&ph, Xform &&xform, Enhancers &&...enhancers) -> Sdk< PH, Xform, Enhancers... >
Create an sdk with a default-constructed model, and a Crypto constructed with user-provided random da...
Definition: sdk.hpp:266
auto makeDefaultEncryptedSdk(JobInterface &jobHandler, EventInterface &eventEmitter, EventLoop &&eventLoop, Xform &&xform, Enhancers &&...enhancers) -> Sdk< EventLoop, Xform, Enhancers... >
Definition: sdk.hpp:226
auto makeStore(Model &&initialModel, Reducer &&reducer, PH &&ph, Enhancers &&...enhancers)
Definition: store.hpp:141
Definition: clientutil.hpp:213
Definition: client-model.hpp:59
std::optional< immer::box< Crypto > > crypto
Definition: client-model.hpp:85
Definition: client.hpp:75
Definition: jobinterface.hpp:21
The tag to indicate that a constructor should use user-provided random data.
Definition: crypto-util.hpp:33
Definition: sdk-model.hpp:26
SdkAction Action
Definition: sdk-model.hpp:32
static SdkResult update(SdkModel s, SdkAction a)
Definition: sdk-model.cpp:23
ClientModel client
Definition: sdk-model.hpp:27