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. Gözlemci üyeler sanaldır ve zaman uyumsuz işlemler için geri çağırmaları işlemek üzere geçersiz kılınabilir.
-
Koruma Profili:
mip::ProtectionProfile::Observer -
Koruma Altyapısı:
mip::ProtectionEngine::Observer -
Koruma İşleyicisi:
mip::ProtectionHandler::Observer
Zaman uyumsuz bir işlem tamamlandığında, OnXxx() sonuca karşılık gelen üye işlevi çağrılır. Örnek olarak OnLoadSuccess(), OnLoadFailure()ve OnAddEngineSuccess() verilebilir mip::ProtectionProfile::Observer.
Aşağıdaki örneklerde, SDK örnekleri tarafından da kullanılan ve istenen geri çağırma davranışını uygulamak için genişletilebilen promise/future deseni gösterilmektedir.
ProtectionProfile Gözlemci Uygulaması
Aşağıdaki örnekte, öğesinden ProtectionProfileObserverImpltüretilen bir sınıf mip::ProtectionProfile::Observer oluşturduk. Örneklerde kullanılan promise/future desenini kullanmak için üye işlevleri geçersiz kılındı.
ProtectionProfileObserverImpl Sınıf Bildirimi
Üst bilgide, mip::ProtectionProfile::Observer öğesinde türetilmiş ProtectionProfileObserverImpl öğesini tanımlarız ve ardından üye işlevlerin her birini geçersiz kılarız.
//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 OnAddEngineError(const exception_ptr& error, const shared_ptr<void>& context) override;
};
ProtectionProfileObserverImpl Uygulaması
Uygulamanın kendisinde, her gözlemci üye işlevi için gerçekleştirecek bir eylem tanımlamamız yeterlidir.
Her üye iki parametre kabul eder. birincisi, işlevde ele aldığımız sınıfın paylaşılan bir işaretçisidir.
ProtectionObserver::OnLoadSuccessbir almayı mip::ProtectionProtectionbeklerdiProtectionObserver::OnAddEngineSuccess. mip::ProtectionEngine
İkincisi, bağlama ilişkin paylaşılan bir işaretçidir. Uygulamamızda std::promise olarak geçirilen bir shared_ptr<void> öğesine bağlam referansı yapılmaktadır. İşlevin ilk satırı bunu öğesine std::promiseatar ve adlı promisebir nesnede depolanır.
Son olarak, promise->set_value() ayarlanarak ve mip::ProtectionProtection nesnesi geçirilerek gelecek hazır hale getiriliyor.
//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::OnAddEngineError(
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ı örneği oluşturduğumuzda veya zaman uyumsuz işlemler gerçekleştiren bir işlev kullandığımızda, gözlemci implementasyonunu ayarlar oluşturucusuna veya zaman uyumsuz işlevin kendisine geçiririz.
mip::ProtectionProfile::Settings nesnesini başlatırken, oluşturucu mip::ProtectionProfile::Observer'i parametrelerden biri olarak alır. Aşağıdaki örnekte, bir ProtectionProfileObserverImpl oluşturucuda kullanılan özel mip::ProtectionProfile::Settingsörneğimiz gösterilmektedir.
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, yukarıda ayrıntılarıyla belirtilene benzer.
ProtectionHandlerObserverImpl aşağıda kısmen tanımlanmıştır. Uygulamanın tamamı GitHub örnek depomuzda bulunabilir.
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 OnCreateProtectionHandlerError(const exception_ptr& error, const shared_ptr<void>& context) override;
};
ProtectionHandlerObserverImpl - Kısmi Uygulama
Bu örnek yalnızca ilk iki işlevdir, ancak kalan işlevler ve ProtectionObserverişlevlerine benzer bir desen 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::OnCreateProtectionHandlerError(
const exception_ptr& error,
const shared_ptr<void>& context) {
auto createProtectionHandlerPromise = static_cast<promise<shared_ptr<mip::ProtectionHandler>>*>(context.get());
createProtectionHandlerPromise->set_exception(error);
};