// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Types/String.h"
#include "Engine/Core/Collections/Array.h"
#include "Engine/Core/Singleton.h"
#include "MTypes.h"
///
/// Main handler for CLR Engine.
///
class FLAXENGINE_API MCore : public Singleton
{
friend MDomain;
private:
MDomain* _rootDomain;
MDomain* _activeDomain;
Array> _domains;
public:
///
/// Initializes a new instance of the class.
///
MCore();
public:
///
/// Creates an new empty domain.
///
/// The domain name to create.
/// The domain object.
MDomain* CreateDomain(const MString& domainName);
///
/// Unloads the domain.
///
/// The domain name to remove.
void UnloadDomain(const MString& domainName);
///
/// Gets the root domain.
///
/// The root domain.
FORCE_INLINE MDomain* GetRootDomain() const
{
return _rootDomain;
}
///
/// Gets the currently active domain.
///
/// The current domain.
FORCE_INLINE MDomain* GetActiveDomain() const
{
return _activeDomain;
}
public:
///
/// Initialize CLR Engine
///
/// True if failed, otherwise false.
bool LoadEngine();
///
/// Unload CLR Engine
///
void UnloadEngine();
///
/// Attaches CLR runtime to the current thread. Use it to allow invoking managed runtime from native threads.
///
static void AttachThread();
///
/// Exits the managed runtime thread. Clears the thread data and sets its exit code to 0. Use it before ending the native thread that uses AttachThread.
///
static void ExitThread();
public:
///
/// Helper utilities for C# garbage collector.
///
class GC
{
public:
///
/// Forces an immediate garbage collection of all generations.
///
static void Collect();
///
/// Forces an immediate garbage collection of the given generation.
///
/// The target generation
static void Collect(int32 generation);
///
/// Suspends the current thread until the thread that is processing the queue of finalizers has emptied that queue.
///
static void WaitForPendingFinalizers();
};
};