13#include "arcane/impl/FlexLMTools.h"
20#define FLEXLMAPI_IS_STATIC_LIBRARY
24#include "arcane/IParallelSuperMng.h"
25#include "arcane/utils/FatalErrorException.h"
26#include "arcane/utils/TraceInfo.h"
27#include "arcane/utils/StringBuilder.h"
28#include "arcane/utils/Array.h"
38LicenseErrorException::
39LicenseErrorException(
const String& where)
40: Exception(
"LicenseError",where)
48LicenseErrorException::
49LicenseErrorException(
const String& where,
const String& message)
50: Exception(
"LicenseError",where,message)
58LicenseErrorException::
59LicenseErrorException(
const TraceInfo& where)
60: Exception(
"LicenseError",where)
68LicenseErrorException::
69LicenseErrorException(
const TraceInfo& where,
const String& message)
70: Exception(
"LicenseError",where,message)
78void LicenseErrorException::
79explain(std::ostream& m)
const
81 m <<
"Licensing error occured.\n"
82 <<
"Excution stopped.\n";
88void LicenseErrorException::
89write(std::ostream& o)
const
93 o <<
"Exception thrown in: '" << where() <<
"\n";
95 if (!message().null())
96 o <<
"Message: " << message() <<
'\n';
99 String st = stackTrace().toString();
101 o <<
"\nCall stack:\n";
113FlexLMMng* FlexLMMng::m_instance = NULL ;
120 : m_parallel_super_mng(NULL)
144 if (m_parallel_super_mng != NULL)
151 m_parallel_super_mng = parallel_super_mng;
172 if (m_parallel_super_mng == NULL)
177 test = license_test((
char*)name.
localstr(),(
char*)String::format(
"{0}",version).localstr());
180 if (test != 0 && do_fatal)
192 if (m_parallel_super_mng == NULL)
198 m_features[name] += nb_licenses ;
199 for(
Integer i=0;i<nb_licenses;++i)
200 error += license_begin_rc((
char*)name.
localstr(), (
char*)String::format(
"{0}",version).localstr()) ;
204 throw LicenseErrorException(A_FUNCINFO,String::format(
"Cannot checkout {0} license{1} for feature {2} (v{3})\nFeature info: {4}",nb_licenses,((nb_licenses>1)?
"s":
""),name,version,
featureInfo(name,version)));
214 if (m_parallel_super_mng == NULL)
217 if (nb_licenses == 0)
222 FeatureMapType::iterator finder = m_features.find(name);
225 if (finder == m_features.end())
return;
227 Integer & nb_allocated_licenses = finder->second;
228 if (nb_licenses == 0) nb_licenses = nb_allocated_licenses;
229 for(
Integer i=0;i<nb_licenses;++i)
230 license_end_no_quit((
char*)name.
localstr()) ;
232 nb_allocated_licenses -= nb_licenses;
233 if (nb_allocated_licenses < 0) nb_allocated_licenses = 0;
244 if (m_parallel_super_mng == NULL)
249 for(FeatureMapType::iterator iter = m_features.begin(); iter!=m_features.end(); ++iter)
251 const String name = (*iter).first ;
252 Integer nb_licenses = (*iter).second ;
253 for(
Integer i=0; i<nb_licenses; ++i)
254 license_end_no_quit((
char*) name.
localstr()) ;
271 if (license_test((
char*)name.
localstr(),(
char*)String::format(
"{0}",version).localstr()) == 0)
274 char ** users = get_user_list((
char*)name.
localstr());
275 while(users[count]) { info_builder += String::format(
"{0} ",users[count++]); }
277 info_builder = String::format(
"no declared user");
279 info_builder = String::format(
"Used by {0} user{1} : ",count,((count>1)?
"s":
""),info_builder.
toString());
290 info =
"Unknown feature";
299 m_parallel_super_mng->broadcast(utf8_array,0);
302 m_parallel_super_mng->broadcast(utf8_array,0);
303 info = String::fromUtf8(utf8_array);
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
static FlexLMMng * instance()
Accès au singleton.
void getLicense(const String name, const Real version, Integer nb_licenses=1)
Demande l'allocation de.
bool checkLicense(const String name, const Real version, bool do_fatal=true) const
Teste la présence d'une fonctionnalité statique.
void setCheckInterval(const Integer t=120)
Définit une nouvelle périodicité du contrôle des licences.
void init(IParallelSuperMng *parallel_super_mng)
Initialise le gestionnaire de licences.
void releaseAllLicenses()
Relache toutes les licences allouées.
bool m_is_master
Cet host est il le maître des contrôles ?
void releaseLicense(const String name, Integer nb_licenses=0)
Relache les licences de la fonctionnalité
String featureInfo(const String name, const Real version) const
Return info on feature.
Classe abstraite du superviseur de parallélisme.
virtual Int32 commRank() const =0
Retourne le numéro du process (compris entre 0 et nbProcess()-1).
Constructeur de chaîne de caractère unicode.
String toString() const
Retourne la chaîne de caractères construite.
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
const char * localstr() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
ByteConstArrayView utf8() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
Int32 Integer
Type représentant un entier.
ArrayView< Integer > IntegerArrayView
Equivalent C d'un tableau à une dimension d'entiers.
UniqueArray< Byte > ByteUniqueArray
Tableau dynamique à une dimension de caractères.
double Real
Type représentant un réel.