次の 2 つの例は、状態ストレージまたはメモリのみにローカル ストレージを使用して profileSettings オブジェクトを作成する方法を示しています。
プロファイルを読み込む
ProtectionProfileObserverImplが定義されたので、それを使用してmip::ProtectionProfileをインスタンス化します。
mip::ProtectionProfile オブジェクトの作成には、mip::ProtectionProfile::Settings が必要です。
ProtectionProfile::Settings パラメータ
-
std::shared_ptr<MipContext>:アプリケーション情報、状態パス、およびその他の設定を格納するために初期化されたmip::MipContextオブジェクト。 -
mip::CacheStorageType: 状態を格納する方法を定義します。メモリ内、ディスク上、またはディスク上で暗号化されます。 -
std::shared_ptr<mip::ConsentDelegate>: クラスmip::ConsentDelegateの共有ポインター。 -
std::shared_ptr<mip::ProtectionProfile::Observer> observer: プロファイルObserver実装への共有ポインター (PolicyProfile、ProtectionProfileおよびFileProfile内)。
次の 2 つの例は、状態ストレージまたはメモリのみにローカル ストレージを使用して profileSettings オブジェクトを作成する方法を示しています。
メモリにのみの状態を格納する
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
ディスク上のストレージ パスからのプロファイル設定の読み取り/書き込み
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
次に、promise/future パターンを使用して、ProtectionProfile をロードします。
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
プロファイルが正常に読み込まれた場合、SDK は ProtectionProfileObserverImpl::OnLoadSuccess ( mip::ProtectionProfile::Observer::OnLoadSuccessの実装) を呼び出します。 SDK は、結果のオブジェクトまたは例外ポインターとコンテキストをパラメーターとして関数に渡します。 コンテキストは、非同期操作を処理するために作成された std::promise へのポインターです。 この関数は、Promise の値を ProtectionProfile オブジェクト (コンテキスト) に設定します。 main 関数で Future.get() を使用する場合は、結果を新しいオブジェクトに格納できます。
//get the future value and store in profile.
auto profile = profileFuture.get();
全体をまとめる
オブザーバーと認証デリゲートを実装したら、プロファイルを完全に読み込むことができます。 次のコード スニペットでは、必要なすべてのヘッダーが既に含まれていることを前提としています。
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();
}
このコードはプロファイルを読み込み、 profileというオブジェクトに格納します。
次のステップ
プロファイルを読み込んだので、次の手順は、プロファイルにエンジンを追加することです。
- GitHubの MIP Protection SDK C++ サンプルについて説明します。