Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ArcaneMono.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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#include <mono/jit/jit.h>
8#include <mono/metadata/environment.h>
9#include <mono/metadata/mono-config.h>
10#include <mono/metadata/threads.h>
11#include <stdlib.h>
12#include <string.h>
13
14#include <iostream>
15
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/String.h"
18#include "arcane/utils/CommandLineArguments.h"
19#include "arcane/Concurrency.h"
20#include "arcane/ObserverPool.h"
21
22namespace
23{
24bool dotnet_verbose = false;
25bool global_is_running = false;
26}
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
31
32extern "C" int mono_main(int argc,char* argv[]);
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
38{
39 public:
40 void init()
41 {
42 m_observers.addObserver(this,&ArcaneMonoThreadAttachCallback::_callback,
44 }
45 private:
46 void _callback()
47 {
48#ifndef ARCANE_MONO_NO_THREAD_ATTACH
49 if (dotnet_verbose)
50 std::cout << "MONO_THREAD_ATTACH CALLBACK !\n";
51 mono_thread_attach (mono_get_root_domain ());
52#endif
53 }
54 private:
55 Arcane::ObserverPool m_observers;
56};
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
61int
62_arcane_mono_main_internal(int argc, char* argv[],const char* assembly_name)
63{
64 if (global_is_running)
65 ARCANE_FATAL("mono wrapper has already been launched");
66 global_is_running = true;
67 int new_argc = argc+1;
68 char** new_argv = new char*[new_argc+1];
69 new_argv[0] = strdup(argv[0]);
70 for( int i=1; i<argc; ++i )
71 new_argv[i+1] = argv[i];
72 new_argv[1] = strdup(assembly_name);
73 Arcane::String verbose_str = Arcane::platform::getEnvironmentVariable("ARCANE_DEBUG_DOTNET");
74 dotnet_verbose = !verbose_str.null();
75
76 if (dotnet_verbose){
77 std::cout << "ArcaneMono: ASSEMBLY NAME is '" << assembly_name << "' argc=" << argc << "\n";
78 for( int i=0; i<new_argc; ++i )
79 std::cout<< "ArcaneMono: Arg i=" << i << " V=" << new_argv[i] << '\n';
80 std::cout.flush();
81 }
82
84 mtac.init();
85
86 int retval = mono_main(new_argc,new_argv);
87 global_is_running = false;
88 return retval;
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94// Obsolète: utiliser 'arcane_mono_main2' à la place.
95extern "C" ARCANE_EXPORT int
96arcane_mono_main(int argc, char* argv[],const char* assembly_name)
97{
98 if (!assembly_name || assembly_name[0]=='\0')
99 assembly_name = "Arcane.Main.dll";
100 return _arcane_mono_main_internal(argc,argv,assembly_name);
101}
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106extern "C" ARCANE_EXPORT int
107arcane_mono_main2(const Arcane::CommandLineArguments& cmd_args,
108 const Arcane::String& orig_assembly_name)
109{
110 Arcane::String assembly_name = orig_assembly_name;
111 if (assembly_name.empty())
112 assembly_name = "Arcane.Main.dll";
113
114 int argc = *(cmd_args.commandLineArgc());
115 char** argv = *(cmd_args.commandLineArgv());
116 const char* assembly_name_str = assembly_name.localstr();
117 return _arcane_mono_main_internal(argc,argv,assembly_name_str);
118}
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123void
124arcane_mono_launch()
125{
126}
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Arguments de la ligne de commande.
Liste d'observateurs.
void addObserver(T *obj, void(T::*func)(const IObservable &), IObservable *oba)
Ajoute un observateur.
static IObservable * createThreadObservable()
Observable appelé lors de la création d'un thread pour une tâche.
Chaîne de caractères unicode.
bool empty() const
Vrai si la chaîne est vide (nulle ou "")
Definition String.cc:315
const char * localstr() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
Definition String.cc:227
bool null() const
Retourne true si la chaîne est nulle.
Definition String.cc:304