Arcane  v3.16.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ApplicationInfo.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* ApplicationInfo.cc (C) 2000-2024 */
9/* */
10/* Informations sur une application. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ApplicationInfo.h"
15#include "arcane/utils/String.h"
16#include "arcane/utils/CommandLineArguments.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/List.h"
19#include "arcane/utils/Property.h"
20#include "arcane/utils/internal/ApplicationInfoProperties.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31class ApplicationInfoPrivate
32{
33 public:
34 ApplicationInfoPrivate(const CommandLineArguments& args,const String& name,
35 const VersionInfo& version)
36 : m_command_line_args(args), m_version(version), m_is_debug(false), m_application_name(name)
37 {
38 }
39 public:
40 CommandLineArguments m_command_line_args;
41 VersionInfo m_version; //!< Numéro de version
42 bool m_is_debug; //!< \a true s'il s'agit d'une version debug.
43 String m_version_date; //!< Date de la version.
44 String m_application_name; //!< Nom de l'application
45 String m_code_name; //!< Nom du code
46 String m_target_full_name; //!< Nom complet de la cible
47 String m_osname; //!< Nom de l'OS
48 String m_data_os_dir; //!< Répertoire des fichiers config dépendant OS
49 String m_data_dir; //!< Répertoire des fichiers de config communs
50 StringList m_args;
51 StringList m_dynamic_libraries_name;
52 UniqueArray<std::byte> m_runtime_config_file_content;
53};
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58ApplicationInfo::
59ApplicationInfo()
60: m_argc(nullptr)
61, m_argv(nullptr)
63{
64 _init("Arcane");
65}
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
70ApplicationInfo::
71ApplicationInfo(int* argc,char*** argv,const String& name,const VersionInfo& aversion)
72: m_argc(nullptr)
73, m_argv(nullptr)
74, m_p(new ApplicationInfoPrivate(CommandLineArguments(argc,argv),name,aversion))
75{
76 _init(name);
77}
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82ApplicationInfo::
83ApplicationInfo(const StringList& aargs,const String& name,
84 const VersionInfo& aversion)
85: m_argc(nullptr)
86, m_argv(nullptr)
87, m_p(new ApplicationInfoPrivate(CommandLineArguments(aargs),name,aversion))
88{
89 _init(name);
90}
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95ApplicationInfo::
96ApplicationInfo(const CommandLineArguments& aargs,const String& name,
97 const VersionInfo& aversion)
98: m_argc(nullptr)
99, m_argv(nullptr)
100, m_p(new ApplicationInfoPrivate(aargs,name,aversion))
101{
102 _init(name);
103}
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108ApplicationInfo::
109ApplicationInfo(const ApplicationInfo& rhs)
110: m_argc(nullptr)
111, m_argv(nullptr)
112, m_p(new ApplicationInfoPrivate(*rhs.m_p))
113{
114 _setArgs();
115}
116
117/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119
120ApplicationInfo& ApplicationInfo::
121operator=(const ApplicationInfo& rhs)
122{
123 if (&rhs!=this){
124 auto old_p = m_p;
125 m_p = new ApplicationInfoPrivate(*rhs.m_p);
126 delete old_p;
127 _setArgs();
128 }
129 return *this;
130}
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135ApplicationInfo::
136~ApplicationInfo()
137{
138 delete m_p;
139}
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144void ApplicationInfo::
145_setArgs()
146{
147 m_argc = m_p->m_command_line_args.commandLineArgc();
148 m_argv = m_p->m_command_line_args.commandLineArgv();
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154void ApplicationInfo::
155_init(const String& name)
156{
157 _setArgs();
158
159 m_p->m_version_date = "0";
160 m_p->m_data_os_dir = String();
161 m_p->m_data_dir = String();
162
163 {
164 String s = platform::getEnvironmentVariable("ARCANE_USER_CONFIG_FILE_NAME");
165 if (!s.null())
166 m_p->m_code_name = s;
167 else
168 m_p->m_code_name = name;
169 }
170
171 {
172 String s = platform::getEnvironmentVariable("ARCANE_SHARE_PATH");
173 if (!s.null())
174 m_p->m_data_dir = s;
175 else{
176 s = platform::getEnvironmentVariable("STDENV_PATH_SHR");
177 if (!s.null())
178 m_p->m_data_dir = s;
179 }
180 }
181 {
182 String s = platform::getEnvironmentVariable("ARCANE_LIB_PATH");
183 if (!s.null())
184 m_p->m_data_os_dir = s;
185 else{
186 String s = platform::getEnvironmentVariable("STDENV_PATH_LIB");
187 if (!s.null())
188 m_p->m_data_os_dir = s;
189 }
190 }
191
192 if (dataDir().null() || dataOsDir().null()){
193 // Considère que les infos partagées et les libs sont
194 // au même endroit qui est celui de l'exécutable.
195 String exe_full_path = platform::getExeFullPath();
196 String exe_path = platform::getFileDirName(exe_full_path);
197 if (dataDir().null())
198 setDataDir(exe_path);
199 if (dataOsDir().null())
200 setDataOsDir(exe_path);
201 }
202
203 m_p->m_target_full_name = "TargetUnknown";
204
205#ifdef ARCANE_DEBUG
206 m_p->m_is_debug = true;
207#else
208 m_p->m_is_debug = false;
209#endif
210}
211
212/*---------------------------------------------------------------------------*/
213/*---------------------------------------------------------------------------*/
214
216applicationName() const
217{
218 return m_p->m_application_name;
219}
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
225codeVersion() const
226{
227 return m_p->m_version;
228}
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
234dataOsDir() const
235{
236 return m_p->m_data_os_dir;
237}
238
240setDataOsDir(const String& v)
241{
242 m_p->m_data_os_dir = v;
243}
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247
249dataDir() const
250{
251 return m_p->m_data_dir;
252}
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
256
258setDataDir(const String& v)
259{
260 m_p->m_data_dir = v;
261}
262
263/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265
267versionMajor() const
268{
269 return m_p->m_version.versionMajor();
270}
271
272/*---------------------------------------------------------------------------*/
273/*---------------------------------------------------------------------------*/
274
276versionMinor() const
277{
278 return m_p->m_version.versionMinor();
279}
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
283
285versionPatch() const
286{
287 return m_p->m_version.versionPatch();
288}
289
290/*---------------------------------------------------------------------------*/
291/*---------------------------------------------------------------------------*/
292
294isDebug() const
295{
296 return m_p->m_is_debug;
297}
298
299/*---------------------------------------------------------------------------*/
300/*---------------------------------------------------------------------------*/
301
303codeName() const
304{
305 return m_p->m_code_name;
306}
307
308/*---------------------------------------------------------------------------*/
309/*---------------------------------------------------------------------------*/
310
312targetFullName() const
313{
314 return m_p->m_target_full_name;
315}
316
317/*---------------------------------------------------------------------------*/
318/*---------------------------------------------------------------------------*/
319
320int* ApplicationInfo::
321commandLineArgc() const
322{
323 return m_argc;
324}
325
326/*---------------------------------------------------------------------------*/
327/*---------------------------------------------------------------------------*/
328
329char*** ApplicationInfo::
330commandLineArgv() const
331{
332 return m_argv;
333}
334
335/*---------------------------------------------------------------------------*/
336/*---------------------------------------------------------------------------*/
337
339args(StringList& aargs) const
340{
341 m_p->m_command_line_args.fillArgs(aargs);
342}
343
344/*---------------------------------------------------------------------------*/
345/*---------------------------------------------------------------------------*/
346
348addDynamicLibrary(const String& lib_name)
349{
350 m_p->m_dynamic_libraries_name.add(lib_name);
351}
352
353/*---------------------------------------------------------------------------*/
354/*---------------------------------------------------------------------------*/
355
358{
359 return m_p->m_dynamic_libraries_name;
360}
361
362/*---------------------------------------------------------------------------*/
363/*---------------------------------------------------------------------------*/
364
367{
368 return m_p->m_command_line_args;
369}
370
371/*---------------------------------------------------------------------------*/
372/*---------------------------------------------------------------------------*/
373
376{
377 m_p->m_application_name = v;
378}
379
380/*---------------------------------------------------------------------------*/
381/*---------------------------------------------------------------------------*/
382
385{
386 m_p->m_version = version;
387}
388
389/*---------------------------------------------------------------------------*/
390/*---------------------------------------------------------------------------*/
391
393setCodeName(const String& code_name)
394{
395 m_p->m_code_name = code_name;
396}
397
398/*---------------------------------------------------------------------------*/
399/*---------------------------------------------------------------------------*/
400
403{
404 m_p->m_command_line_args = aargs;
405 _setArgs();
406}
407
408/*---------------------------------------------------------------------------*/
409/*---------------------------------------------------------------------------*/
410
412setIsDebug(bool v)
413{
414 m_p->m_is_debug = v;
415}
416
417/*---------------------------------------------------------------------------*/
418/*---------------------------------------------------------------------------*/
419
422{
423 m_p->m_runtime_config_file_content = content;
424}
425
426/*---------------------------------------------------------------------------*/
427/*---------------------------------------------------------------------------*/
428
431{
432 return m_p->m_runtime_config_file_content;
433}
434
435/*---------------------------------------------------------------------------*/
436/*---------------------------------------------------------------------------*/
437
439addParameterLine(const String& line)
440{
441 m_p->m_command_line_args.addParameterLine(line);
442}
443
444/*---------------------------------------------------------------------------*/
445/*---------------------------------------------------------------------------*/
446
447/*---------------------------------------------------------------------------*/
448/*---------------------------------------------------------------------------*/
449
450template<typename V> void ApplicationInfoProperties::
451_applyPropertyVisitor(V& p)
452{
453 auto b = p.builder();
454
455 p << b.addString("CodeName")
456 .addDescription("Name of the code")
457 .addGetter([](auto a) { return a.x.codeName(); })
458 .addSetter([](auto a) { a.x.setCodeName(a.v); });
459
460 p << b.addString("DataDir")
461 .addDescription("Directory containing os independant files")
462 .addGetter([](auto a) { return a.x.dataDir(); })
463 .addSetter([](auto a) { a.x.setDataDir(a.v); });
464
465 p << b.addString("DataOsDir")
466 .addDescription("Directory containing os dependant files")
467 .addGetter([](auto a) { return a.x.dataOsDir(); })
468 .addSetter([](auto a) { a.x.setDataOsDir(a.v); });
469
470 p << b.addBool("Debug")
471 .addDescription("Indicate if debug mode is active")
472 .addGetter([](auto a) { return a.x.isDebug(); })
473 .addSetter([](auto a) { a.x.setIsDebug(a.v); });
474
475 p << b.addString("CodeVersion")
476 .addDescription("Version (x.y.z) of the code")
477 .addSetter([](auto a) { a.x.setCodeVersion(VersionInfo(a.v)); })
478 .addGetter([](auto a) { return a.x.codeVersion().versionAsString(); });
479
480 p << b.addStringList("DynamicLibraries")
481 .addDescription("Dynamic libraries to load at startup")
482 .addSetter([](auto a)
483 {
484 for(String s : a.v)
485 a.x.addDynamicLibrary(s);
486 })
487 .addGetter([](auto a) { return a.x.dynamicLibrariesName(); });
488}
489
490/*---------------------------------------------------------------------------*/
491/*---------------------------------------------------------------------------*/
492
493ARCANE_REGISTER_PROPERTY_CLASS(ApplicationInfoProperties,());
494
495/*---------------------------------------------------------------------------*/
496/*---------------------------------------------------------------------------*/
497
498} // End namespace Arcane
499
500/*---------------------------------------------------------------------------*/
501/*---------------------------------------------------------------------------*/
502
String m_target_full_name
Nom complet de la cible.
bool m_is_debug
true s'il s'agit d'une version debug.
String m_data_os_dir
Répertoire des fichiers config dépendant OS.
String m_data_dir
Répertoire des fichiers de config communs.
VersionInfo m_version
Numéro de version.
String m_version_date
Date de la version.
String m_application_name
Nom de l'application.
Informations sur une application.
const String & dataDir() const
Retourne le chemin où se trouve les fichiers de données.
const String & codeName() const
Retourne le nom du code de calcul lié l'application.
void setCommandLineArguments(const CommandLineArguments &args)
Positionne les arguments de la ligne de commande.
int * m_argc
Nombre d'arguments de la ligne de commande.
void addParameterLine(const String &line)
Ajoute un paramètre Arcane à la ligne de commande.
void setCodeVersion(const VersionInfo &version_info)
Positionne le numéro de version.
ByteConstSpan runtimeConfigFileContent() const
Contenu du fichier de configuration de l'application.
void setDataDir(const String &v)
Positionne le chemin où se trouve les fichiers de données.
void setIsDebug(bool v)
Positionne l'état de débug.
const String & applicationName() const
Nom de l'application.
void addDynamicLibrary(const String &lib_name)
Ajoute la bibliothèque lib_name à la liste des bibliothèques chargées dynamiquements.
int versionMajor() const
Retourne le numéro de version majeure de l'application.
int versionMinor() const
Retourne le numéro de version mineure de l'application.
const String & targetFullName() const
Retourne le nom complet de la cible.
const CommandLineArguments & commandLineArguments() const
Arguments de la ligne de commande.
void args(StringList &args) const
Remplit args avec les arguments de la ligne de commande.
const VersionInfo & codeVersion() const
Numéro de version.
const VersionInfo & version() const
Numéro de version.
char *** m_argv
Tableau des arguments de la ligne de commande.
int versionPatch() const
Retourne le numéro de version patch de l'application.
void setApplicationName(const String &v)
Positionne le nom de l'application.
bool isDebug() const
Retourne true si on s'exécute en mode debug.
void setRuntimeConfigFileContent(ByteConstSpan content)
Positionne le contenu du fichier de configuration de l'application.
const String & dataOsDir() const
Retourne le chemin où se trouve les fichiers de données dépendant de l'OS.
void setDataOsDir(const String &v)
Positionne le chemin où se trouve les fichiers de données dépendant de l'OS.
StringCollection dynamicLibrariesName() const
Liste des bibliothèques dynamiques.
void setCodeName(const String &code_name)
Positionne le nom du code.
Arguments de la ligne de commande.
Chaîne de caractères unicode.
Vecteur 1D de données avec sémantique par valeur (style STL).
Informations sur une version.
Definition VersionInfo.h:46
ARCCORE_BASE_EXPORT String getFileDirName(const String &file_name)
Retourne le nom du répertoire d'un fichier.
ARCCORE_BASE_EXPORT String getEnvironmentVariable(const String &name)
Variable d'environnement du nom name.
String getExeFullPath()
Retourne le nom complet avec le chemin de l'exécutable.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Collection< String > StringCollection
Collection de chaînes de caractères.
Definition UtilsTypes.h:593
List< String > StringList
Tableau de chaînes de caractères unicode.
Definition UtilsTypes.h:596
Span< const std::byte > ByteConstSpan
Vue en lecture seule d'un tableau à une dimension de caractères.
Definition UtilsTypes.h:635