Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Dua contoh berikut menunjukkan cara membuat objek profileSettings dengan menggunakan penyimpanan lokal hanya untuk penyimpanan status atau memori.
Memuat profil
Sekarang setelah ProtectionProfileObserverImpl didefinisikan, gunakan ProtectionProfileObserverImpl untuk membuat instans mip::ProtectionProfile. Membuat objek mip::ProtectionProfile memerlukan mip::ProtectionProfile::Settings.
Parameter ProtectionProfile::Settings
-
std::shared_ptr<MipContext>: Objek yangmip::MipContextdiinisialisasi untuk menyimpan info aplikasi, jalur status, dan pengaturan lainnya. -
mip::CacheStorageType: Menentukan cara menyimpan status: dalam memori, pada disk, atau pada disk dan dienkripsi. -
std::shared_ptr<mip::ConsentDelegate>: Pointer bersama kelasmip::ConsentDelegate. -
std::shared_ptr<mip::ProtectionProfile::Observer> observer: Pointer bersama ke implementasi profilObserver(dalamPolicyProfile,ProtectionProfile, danFileProfile).
Dua contoh berikut menunjukkan cara membuat objek profileSettings dengan menggunakan penyimpanan lokal hanya untuk penyimpanan status atau memori.
Simpan status dalam memori saja
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
Membaca/menulis pengaturan profil dari jalur penyimpanan pada 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
Selanjutnya, gunakan pola promise/future untuk memuat ProtectionProfile.
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
Jika profil berhasil dimuat, SDK memanggil ProtectionProfileObserverImpl::OnLoadSuccess, implementasi dari mip::ProtectionProfile::Observer::OnLoadSuccess. SDK meneruskan objek atau penunjuk pengecualian yang dihasilkan dan konteks sebagai parameter ke fungsi. Konteks adalah pointer ke std::promise yang dibuat untuk menangani operasi asinkron. Fungsi ini menetapkan nilai janji ke objek ProtectionProfile (konteks). Saat fungsi utama menggunakan Future.get(), Anda dapat menyimpan hasilnya di objek baru.
//get the future value and store in profile.
auto profile = profileFuture.get();
Menyusunnya menjadi satu
Setelah Anda menerapkan observer dan delegat autentikasi, Anda dapat memuat profil secara penuh. Cuplikan kode berikut mengasumsikan bahwa semua header yang diperlukan sudah disertakan.
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();
}
Kode memuat profil dan menyimpannya di objek yang disebut profile.
Langkah berikutnya
Sekarang setelah Anda memuat profil, langkah selanjutnya adalah menambahkan mesin ke profil.
- Jelajahi sampel MIP Protection SDK C++ pada GitHub.