Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
FlexLMTools.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* FlexLMTools.h (C) 2000-2026 */
9/* */
10/* FlexLM Protection Management. */
11/*---------------------------------------------------------------------------*/
12
13#ifndef ARCANE_UTILS_FLEXLMTOOLS_H_
14#define ARCANE_UTILS_FLEXLMTOOLS_H_
15
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19#include "arcane/utils/String.h"
20#include "arcane/utils/Exception.h"
21
22#include "arcane/core/ArcaneVersion.h"
23
24#include <map>
25#include <iostream>
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
36class TraceInfo;
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
42class ARCANE_IMPL_EXPORT LicenseErrorException
43: public Exception
44{
45 public:
46
47 LicenseErrorException(const String& where);
48 LicenseErrorException(const TraceInfo& where);
49 LicenseErrorException(const String& where, const String& message);
50 LicenseErrorException(const TraceInfo& where, const String& message);
51 ~LicenseErrorException() ARCANE_NOEXCEPT {}
52
53 public:
54
55 virtual void explain(std::ostream& m) const;
56 virtual void write(std::ostream& o) const;
57
58 private:
59};
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
65
73class ARCANE_IMPL_EXPORT FlexLMMng
74{
75 private:
76
78 FlexLMMng();
79
81 virtual ~FlexLMMng() {}
82
83 public:
84
86 static FlexLMMng* instance();
87
88 public:
89
91 void init(IParallelSuperMng* parallel_super_mng);
92
94
99 void setCheckInterval(const Integer t = 120);
100
102
105 bool checkLicense(const String name, const Real version, bool do_fatal = true) const;
106
108
111 void getLicense(const String name, const Real version, Integer nb_licenses = 1);
112
114
116 void releaseLicense(const String name, Integer nb_licenses = 0);
117
119
120 void releaseAllLicenses();
121
123 String featureInfo(const String name, const Real version) const;
124
125 private:
126
127 typedef std::map<String, Integer> FeatureMapType;
128 FeatureMapType m_features;
129 static FlexLMMng* m_instance;
130 IParallelSuperMng* m_parallel_super_mng;
132};
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
138template <typename FeatureModel>
140{
141 public:
142
145
147 virtual ~FlexLMTools() {}
148
149 public:
150
152
153 bool checkLicense(typename FeatureModel::eFeature feature, const bool do_fatal) const
154 {
155 const String name = FeatureModel::getName(feature);
156 const Real version = FeatureModel::getVersion(feature);
157 return FlexLMMng::instance()->checkLicense(name, version, do_fatal);
158 }
159
161
163 bool checkLicense(typename FeatureModel::eFeature feature, const Real version, const bool do_fatal) const
164 {
165 const String name = FeatureModel::getName(feature);
166 return FlexLMMng::instance()->checkLicense(name, version, do_fatal);
167 }
168
170
171 void getLicense(typename FeatureModel::eFeature feature, Integer nb_licenses = 1)
172 {
173 const String name = FeatureModel::getName(feature);
174 const Real version = FeatureModel::getVersion(feature);
175 return FlexLMMng::instance()->getLicense(name, version, nb_licenses);
176 }
177
179
180 void releaseLicense(typename FeatureModel::eFeature feature, Integer nb_licenses = 0)
181 {
182 const String name = FeatureModel::getName(feature);
183 return FlexLMMng::instance()->releaseLicense(name, nb_licenses);
184 }
185
187 String featureInfo(typename FeatureModel::eFeature feature) const
188 {
189 const String name = FeatureModel::getName(feature);
190 const Real version = FeatureModel::getVersion(feature);
191 return FlexLMMng::instance()->featureInfo(name, version);
192 }
193};
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198} // namespace Arcane
199
200/*---------------------------------------------------------------------------*/
201/*---------------------------------------------------------------------------*/
202
203#endif
const String & where() const
Location of the exception.
const String & message() const
Exception message.
Exception(const String &name, const String &where)
FlexLM manager.
Definition FlexLMTools.h:74
virtual ~FlexLMMng()
Destructor.
Definition FlexLMTools.h:81
static FlexLMMng * instance()
Access to the singleton.
FlexLMMng()
Constructor.
void getLicense(const String name, const Real version, Integer nb_licenses=1)
Requests the allocation of.
bool checkLicense(const String name, const Real version, bool do_fatal=true) const
Tests the presence of a static feature.
bool m_is_master
Is this host the master for checks?
void releaseLicense(const String name, Integer nb_licenses=0)
Releases the licenses for the feature.
String featureInfo(const String name, const Real version) const
Return info on feature.
bool checkLicense(typename FeatureModel::eFeature feature, const bool do_fatal) const
Tests the availability of a feature.
void releaseLicense(typename FeatureModel::eFeature feature, Integer nb_licenses=0)
Releases.
bool checkLicense(typename FeatureModel::eFeature feature, const Real version, const bool do_fatal) const
Tests the availability of a feature on a maximum version.
String featureInfo(typename FeatureModel::eFeature feature) const
Return info on feature.
virtual ~FlexLMTools()
Destructor.
FlexLMTools()
Constructor.
void getLicense(typename FeatureModel::eFeature feature, Integer nb_licenses=1)
Requests the allocation of.
Abstract class of the parallelism supervisor.
virtual void explain(std::ostream &m) const
Explains the cause of the exception in the stream o.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.