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 std::ref(detail::declref<VerificationTracker>())
48#ifdef KAZV_USE_THREAD_SAFETY_HELPER
49 , std::ref(detail::declref<EventLoopThreadIdKeeper>())
52 std::declval<Enhancers>()...)
56#ifdef KAZV_USE_THREAD_SAFETY_HELPER
57 , EventLoopThreadIdKeeper &
66 EventLoop &&eventLoop,
68 Enhancers &&...enhancers)
70 std::move(model), jobHandler, eventEmitter,
71 std::forward<EventLoop>(eventLoop),
std::forward<Xform>(xform),
72 std::forward<Enhancers>(enhancers)...)) {}
105 auto secondaryStore = lager::make_store<ModelT>(
106 std::move(initialModel),
107 std::forward<EL>(eventLoop),
108 lager::with_reducer([](
auto &&,
auto next) {
return next; }));
110 lager::context<ModelT> secondaryCtx = secondaryStore;
113 .then([secondaryCtx, d=m_d.get()](
auto &&) {
114 lager::watch(*(d->sdk),
115 [secondaryCtx](auto next) { secondaryCtx.dispatch(std::move(next)); });
118 return secondaryStore;
143 EventLoop &&eventLoop,
145 Enhancers &&...enhancers)
147 , vt(VerificationUtils::DeviceIdentity())
151 std::forward<EventLoop>(eventLoop),
153 std::ref(jobHandler),
154 std::ref(eventEmitter),
156 std::function<CursorTSP()>([this] {
return sdk; })),
157 std::ref(rg.value()),
159#ifdef KAZV_USE_THREAD_SAFETY_HELPER
163 std::forward<Enhancers>(enhancers)...))
164 , sdk(std::make_shared<lager::reader<ModelT>>(store.reader().xform(std::forward<Xform>(xform))))
166#ifdef KAZV_USE_THREAD_SAFETY_HELPER
167 store.context().createResolvedPromise(EffectStatus{})
168 .then([
this](
auto &&) {
169 keeper.set(std::this_thread::get_id());
173#ifdef KAZV_USE_THREAD_SAFETY_HELPER
174 EventLoopThreadIdKeeper keeper;
176 std::optional<RandomInterface> rg;
177 VerificationTracker vt;
182 std::unique_ptr<Private> m_d;
203 template<
class EventLoop,
class Xform,
class ...Enhancers>
207 EventLoop &&eventLoop,
209 Enhancers &&...enhancers)
210 ->
Sdk<EventLoop, Xform, Enhancers...>
212 return { std::move(sdk),
215 std::forward<EventLoop>(eventLoop),
216 std::forward<Xform>(xform),
217 std::forward<Enhancers>(enhancers)... };
225 return Crypto::constructRandomSize();
228 template<
class EventLoop,
class Xform,
class ...Enhancers>
229 [[deprecated(
"Use deterministic makeDefaultSdkWithCryptoRandom instead. In the future, this will be removed.")]]
233 EventLoop &&eventLoop,
235 Enhancers &&...enhancers)
236 ->
Sdk<EventLoop, Xform, Enhancers...>
244 std::forward<EventLoop>(eventLoop),
245 std::forward<Xform>(xform),
246 std::forward<Enhancers>(enhancers)...);
269 template<
class PH,
class Xform,
class ...Enhancers>
276 Enhancers &&...enhancers)
277 ->
Sdk<PH, Xform, Enhancers...>
285 std::forward<PH>(ph),
286 std::forward<Xform>(xform),
287 std::forward<Enhancers>(enhancers)...);
300 return lager::with_deps(std::ref(random));
Represent a Matrix client.
Definition client.hpp:87
Definition context.hpp:130
PromiseT createResolvedPromise(RetType v) const
Definition context.hpp:185
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:63
ContextT context() const
Get the context associated with this.
Definition sdk.hpp:80
Client client() const
Get a Client representing this.
Definition sdk.hpp:89
auto createSecondaryRoot(EL &&eventLoop, ModelT initialModel=ModelT{}) const
Create a secondary root for this Sdk.
Definition sdk.hpp:104
Client clientFromSecondaryRoot(lager::reader< ModelT > sr) const
Get a Client representing this.
Definition sdk.hpp:133
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:204
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:223
auto withRandomGenerator(RandomInterface &random)
An enhancer to use a custom random generator.
Definition sdk.hpp:298
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:270
auto makeDefaultEncryptedSdk(JobInterface &jobHandler, EventInterface &eventEmitter, EventLoop &&eventLoop, Xform &&xform, Enhancers &&...enhancers) -> Sdk< EventLoop, Xform, Enhancers... >
Definition sdk.hpp:230
auto makeStore(Model &&initialModel, Reducer &&reducer, PH &&ph, Enhancers &&...enhancers)
Definition store.hpp:141
Definition clientutil.hpp:140
Definition client-model.hpp:59
std::optional< immer::box< Crypto > > crypto
Definition client-model.hpp:85
Definition client.hpp:102
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
A stateful tracker for all verification processes.
Definition verification-tracker.hpp:98