Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Följande två exempel visar hur du skapar profileSettings-objektet med hjälp av lokal lagring endast för tillståndslagring eller minne.
Ladda en profil
Nu när har ProtectionProfileObserverImpl definierats använder du den för att instansiera mip::ProtectionProfile. För att skapa mip::ProtectionProfile objektet krävs mip::ProtectionProfile::Settings.
ProtectionProfile::Inställningsparametrar
-
std::shared_ptr<MipContext>: Objektetmip::MipContextinitierades för att lagra programinformation, tillståndssökväg och andra inställningar. -
mip::CacheStorageType: Definierar hur du lagrar tillstånd: i minne, på disk eller på disk och krypterad. -
std::shared_ptr<mip::ConsentDelegate>: En delad pekare för klassenmip::ConsentDelegate. -
std::shared_ptr<mip::ProtectionProfile::Observer> observer: En delad pekare till profilimplementeringenObserver(iPolicyProfile,ProtectionProfileochFileProfile).
Följande två exempel visar hur du skapar profileSettings-objektet med hjälp av lokal lagring endast för tillståndslagring eller minne.
Lagra endast tillstånd i minnet
mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(appInfo,
"mip_data",
mip::LogLevel::Trace,
false, mip::CacheStorageType::OnDisk);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::InMemory, // use in memory storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile observer
Läs-/skrivprofilinställningar från lagringssökväg på disk
mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(appInfo,
"mip_data",
mip::LogLevel::Trace,
false, mip::CacheStorageType::OnDisk);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile
Använd sedan mönstret promise/future för att läsa in ProtectionProfile.
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
Om profilen läses in korrekt anropar SDK:t ProtectionProfileObserverImpl::OnLoadSuccess, som är implementeringen av mip::ProtectionProfile::Observer::OnLoadSuccess. SDK skickar det resulterande objektet eller undantagspekaren och kontexten som parametrar till funktionen. Kontexten är en pekare till std::promise, som skapades för att hantera den asynkrona åtgärden. Funktionen anger värdet för löftet till Objektet ProtectionProfile (kontext). När huvudfunktionen använder Future.get()kan du lagra resultatet i ett nytt objekt.
//get the future value and store in profile.
auto profile = profileFuture.get();
Sammanfoga
När du har implementerat observatörerna och autentiseringsdelegaten kan du läsa in en profil fullständigt. Följande kodfragment förutsätter att alla nödvändiga rubriker redan ingår.
int main()
{
const string userName = "MyTestUser@contoso.com";
const string password = "P@ssw0rd!";
const string clientId = "MyClientId";
mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(appInfo,
"mip_data",
mip::LogLevel::Trace,
false, mip::CacheStorageType::OnDisk);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProfileObserver>()); // new protection profile observer
auto profilePromise = std::make_shared<promise<shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
auto profile = profileFuture.get();
}
Koden läser in profilen och lagrar den i objektet med namnet profile.
Nästa steg
Nu när du har laddat in profilen är nästa steg att lägga till en motor till profilen.
- Utforska MIP Protection SDK C++-exemplet på GitHub.