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.
Muatlah mip::Profile sebelum Anda melakukan operasi apa pun pada Policy SDK.
Dua contoh berikut menunjukkan cara membuat objek profileSettings dengan menggunakan penyimpanan lokal hanya untuk penyimpanan status atau dalam memori.
Memuat profil
Setelah Anda menentukan MipContext dan ProfileObserver, gunakan untuk membuat instans mip::PolicyProfile. Membuat objek mip::PolicyProfile memerlukan mip::PolicyProfile::Settings dan mip::MipContext.
Profil::Parameter pengaturan
PolicyProfile::Settings Konstruktor menerima empat parameter berikut:
-
const std::shared_ptr<MipContext>: Objekmip::MipContextyang diinisialisasi untuk menyimpan info aplikasi, jalur status, dll. -
mip::CacheStorageType: Menentukan cara menyimpan status: Dalam memori, pada disk, atau pada disk dan dienkripsi. Untuk detail selengkapnya, lihat konsep penyimpanan Cache. -
std::shared_ptr<mip::PolicyProfile::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 dalam 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>(mAppInfo,
"mip_data",
mip::LogLevel::Trace,
false);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
PolicyProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::InMemory, // use in memory storage
std::make_shared<PolicyProfileObserverImpl>()); // 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>(mAppInfo,
"mip_data",
mip::LogLevel::Trace,
false);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
PolicyProfile::Settings profileSettings(
mipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<PolicyProfileObserverImpl>()); // new protection profile observer
Selanjutnya, gunakan pola janji/masa depan untuk memuat Profile.
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<Profile>>>();
auto profileFuture = profilePromise->get_future();
Profile::LoadAsync(profileSettings, profilePromise);
Jika aplikasi berhasil memuat profil, ProfileObserver::OnLoadSuccess, yaitu implementasi mip::Profile::Observer::OnLoadSuccess, akan diberi tahu. SDK meneruskan objek yang dihasilkan, dalam hal ini , mip::Profiledan konteks sebagai parameter ke fungsi pengamat.
Konteks merupakan pointer ke std::promise yang dibuat untuk menangani operasi asinkron. Fungsi ini menetapkan nilai promise menjadi objek Profile yang diberikan sebagai parameter pertama. Ketika fungsi utama menggunakan Future.get(), fungsi utama dapat menyimpan hasilnya dalam objek baru di utas pemanggil.
//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 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>(mAppInfo,
"mip_data",
mip::LogLevel::Trace,
false);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
PolicyProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<PolicyProfileObserverImpl>()); // new protection profile observer
auto profilePromise = std::make_shared<promise<shared_ptr<PolicyProfile>>>();
auto profileFuture = profilePromise->get_future();
Profile::LoadAsync(profileSettings, profilePromise);
auto profile = profileFuture.get();
}
Kode memuat profil dan menyimpannya di objek yang disebut profile.
Langkah berikutnya
Sekarang setelah profil ditambahkan, langkah selanjutnya adalah menambahkan mesin ke profil.