Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Koruma SDK'sı üç gözlemci sınıfı içerir. Zaman uyumsuz işlemler için geri çağrıları yönetmek üzere sanal gözlemci üyelerini geçersiz kılabilirsiniz.
-
Koruma Profili:
mip::ProtectionProfile::Observer -
Koruma Altyapısı:
mip::ProtectionEngine::Observer -
Koruma İşleyicisi:
mip::ProtectionHandler::Observer
Zaman uyumsuz bir işlem tamamlandığında SDK, sonuca karşılık gelen üye işlevini çağırır OnXxx() . Örnek olarak OnLoadSuccess(), OnLoadFailure()ve OnAddEngineSuccess() verilebilir mip::ProtectionProfile::Observer.
Aşağıdaki örneklerde promise/future deseni gösterilmektedir. SDK örnekleri de bu deseni kullanır ve istediğiniz geri çağırma davranışını uygulamak için genişletebilirsiniz.
ProtectionProfile gözlemci uygulaması
Aşağıdaki örnek, mip::ProtectionProfile::Observer'den türeyen ProtectionProfileObserverImpl sınıfını oluşturur. Üye işlevleri, örneklerde kullanılan promise/future desenini kullanmak için temel sınıfı geçersiz kılar.
ProtectionProfileObserverImpl sınıf bildirimi
Başlık, ProtectionProfileObserverImpl öğesini tanımlar, bunu mip::ProtectionProfile::Observer öğesinden türetir ve ardından üye işlevlerin her birini geçersiz kılar.
//ProtectionProfileObserverImpl.h
class ProtectionProfileObserverImpl final : public mip::ProtectionProfile::Observer {
public:
ProtectionProfileObserverImpl() { }
void OnLoadSuccess(const shared_ptr<mip::ProtectionProfile>& profile, const shared_ptr<void>& context) override;
void OnLoadFailure(const exception_ptr& error, const shared_ptr<void>& context) override;
void OnAddEngineSuccess(const shared_ptr<mip::ProtectionEngine>& engine, const shared_ptr<void>& context) override;
void OnAddEngineFailure(const exception_ptr& error, const shared_ptr<void>& context) override;
};
ProtectionProfileObserverImpl uygulaması
Uygulama, her gözlemci üye işlevi için gerçekleştirecek bir eylemi tanımlar.
Her üye iki parametre kabul eder. birincisi, işlevin işlediği sınıfın paylaşılan bir işaretçisidir.
ProtectionObserver::OnLoadSuccess bir mip::ProtectionProfile almayı bekler.
ProtectionObserver::OnAddEngineSuccess, mip::ProtectionEngine bekliyor.
İkincisi, bağlama ilişkin paylaşılan bir işaretçidir. Bu uygulamada bağlam, std::promise olarak geçirilen bir shared_ptr<void> referansıdır. İşlevin ilk satırı bu değeri öğesine std::promiseatar ve adlı bir nesnede promisedepolar.
Son olarak, kod promise->set_value() ayarlayıp mip::ProtectionProfile nesnesini aktararak geleceğe hazır hâle gelir.
//protection_observers.cpp
void ProtectionProfileObserverImpl::OnLoadSuccess(
const shared_ptr<mip::ProtectionProfile>& profile,
const shared_ptr<void>& context) {
auto loadPromise = static_cast<promise<shared_ptr<mip::ProtectionProfile>>*>(context.get());
loadPromise->set_value(profile);
};
void ProtectionProfileObserverImpl::OnLoadFailure(const exception_ptr& error, const shared_ptr<void>& context) {
auto loadPromise = static_cast<promise<shared_ptr<mip::ProtectionProfile>>*>(context.get());
loadPromise->set_exception(error);
};
void ProtectionProfileObserverImpl::OnAddEngineSuccess(
const shared_ptr<mip::ProtectionEngine>& engine,
const shared_ptr<void>& context) {
auto addEnginePromise = static_cast<promise<shared_ptr<mip::ProtectionEngine>>*>(context.get());
addEnginePromise->set_value(engine);
};
void ProtectionProfileObserverImpl::OnAddEngineFailure(
const exception_ptr& error,
const shared_ptr<void>& context) {
auto addEnginePromise = static_cast<promise<shared_ptr<mip::ProtectionEngine>>*>(context.get());
addEnginePromise->set_exception(error);
};
Herhangi bir SDK sınıfının örneğini oluştururken veya eşzamansız işlemler gerçekleştiren bir işlev kullanırken, gözlemci uygulamanızı ayarlar oluşturucusuna ya da doğrudan eşzamansız işlevin kendisine iletin.
mip::ProtectionProfile::Settings nesnesinin örneğini oluşturduğunuzda, oluşturucu parametrelerden biri olarak mip::ProtectionProfile::Observer değerini kabul eder. Aşağıdaki örnek, bir mip::ProtectionProfile::Settings oluşturucuda kullanılan özel ProtectionProfileObserverImplöğesini gösterir.
ProtectionHandler gözlemci uygulaması
Koruma gözlemcisine benzer şekilde, mip::ProtectionHandler koruma işlemleri sırasında zaman uyumsuz olay bildirimlerini işlemek için bir mip::ProtectionHandler::Observer sınıf uygular. Uygulama, önceki uygulamaya benzer. Aşağıdaki örnek kısmen tanımlar ProtectionHandlerObserverImpl. Tam uygulama GitHub örnek deposundadır.
ProtectionHandlerObserverImpl sınıf bildirimi
//protection_observers.h
class ProtectionHandlerObserverImpl final : public mip::ProtectionHandler::Observer {
public:
ProtectionHandlerObserverImpl() { }
void OnCreateProtectionHandlerSuccess(const shared_ptr<mip::ProtectionHandler>& protectionHandler, const shared_ptr<void>& context) override;
void OnCreateProtectionHandlerFailure(const exception_ptr& error, const shared_ptr<void>& context) override;
};
ProtectionHandlerObserverImpl kısmi uygulama
Bu örnek yalnızca ilk iki işlevi içerir, ancak geri kalan işlevler de bu işlevlere ve ProtectionObserver öğesine benzer bir yapı kullanır.
//protection_observers.cpp
void ProtectionHandlerObserverImpl::OnCreateProtectionHandlerSuccess(
const shared_ptr<mip::ProtectionHandler>& protectionHandler,
const shared_ptr<void>& context) {
auto createProtectionHandlerPromise = static_cast<promise<shared_ptr<mip::ProtectionHandler>>*>(context.get());
createProtectionHandlerPromise->set_value(protectionHandler);
};
void ProtectionHandlerObserverImpl::OnCreateProtectionHandlerFailure(
const exception_ptr& error,
const shared_ptr<void>& context) {
auto createProtectionHandlerPromise = static_cast<promise<shared_ptr<mip::ProtectionHandler>>*>(context.get());
createProtectionHandlerPromise->set_exception(error);
};
Sonraki Adımlar
- GitHub'da MIP Koruma SDK'sı C++ örneğini keşfedin.