acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
implement_console.h
1
2#include "acme/exception/exception.h"
3namespace APPLICATION_NAMESPACE
4{
5CLASS_DECL_IMPORT void application_factory(::factory::factory * pfactory);
6
7}
8
9#include "acme/_operating_system.h"
10#include "acme/operating_system/process.h"
11#include APPLICATION_INCLUDE
12#include <type_traits>
13
14#if defined(__BSD__)
15#include <stdio.h>
16#endif
17
18
19
20
21//void stage();
22::platform::system * acme_system_init();
23void acme_system_term();
24
25#include "acme/platform/system.h"
26#include "acme/platform/acme.h"
27
28//::acme::layer g_layer;
29
30
31#ifdef UNIVERSAL_WINDOWS
32#include "acme/operating_system/console.inl"
33
34#endif
35
36
37#include "acme/platform/platform.h"
38#include "acme/platform/message_box.h"
39#include "acme/operating_system/acme_initialize.h"
40
41
42//#ifdef WINDOWS
43//CLASS_DECL_ACME void set_argc_argv_envp(::i32 argc, wchar_t ** argv, wchar_t ** envp);
44//#else
45//CLASS_DECL_ACME void set_argc_argv_envp(::i32 argc, char_pointer * argv, char_pointer * envp);
46//#endif
47
48
49//#include "acme/platform/acme.h"
50
51
52
53
54
55namespace acme
56{
57
58 void initialize();
59
60 void finalize();
61
62}
63
64
65extern char_pointer *environ;
66
67
68#ifdef WINDOWS
69::i32 wmain(::i32 argc, wchar_t* argv[], wchar_t* envp[])
70#else
71::i32 main(::i32 argc, char_pointer * argv)
72//::i32 main(::i32 argc, char_pointer * argv, char_pointer * envp)
73#endif
74{
75
76#if !defined(WINDOWS)
77
78 auto envp = environ;
79
80#endif
81
82 auto psystem = ::hold(new ::PLATFORM_LAYER_NAME::system);
83
84
85
86 //::acme::acme_impl < ::SYSTEM_NAMESPACE::system > acme;
87
88//#define DEEP_DEBUG
89#ifdef DEEP_DEBUG
90 printf("argc=%d\n", argc);
91 for(::i32 i = 0; i < argc; i++)
92 {
93 auto pszParameter = argv[i];
94 if constexpr(std::is_same_v<decltype(*argv[0]), wchar_t>)
95 {
96 printf("argv[%d]=%S\n", i, (wchar_t*) pszParameter);
97 }
98 else
99 {
100 printf("argv[%d]=%s\n", i, (char_pointer ) pszParameter);
101 }
102 }
103#endif
104
105 psystem->initialize_system(argc, argv, envp);
106
107 psystem->m_bConsole = true;
108
109 //::acme::acme::g_pacme->m_papplication->m_bConsole = true;
110
111 //string_array_base stra{ "StringNumber1", "StringNumber2", "StringNumber5" };
112
113 //string str4("StringNumber4");
114
115 //stra.insert_at(2, str4);
116
117
121 //::acme::acme::g_pacme->m_papplication->implement_application();
122
123 try
124 {
125
126 APPLICATION_NAMESPACE::application_factory(psystem->factory());
127
128 psystem->application_main();
129
130 }
131 catch (const ::exception& exception)
132 {
133
134 if (psystem->m_bConsole)
135 {
136
137
138 ::string strMessage(exception.get_message());
139
140 strMessage.find_replace("\n", "\n ");
141
142 ::string strStack(exception.m_strCallStackTrace.c_str());
143
144 strStack.find_replace("\n", "\n ");
145
146 fprintf(stderr,
147 "\n"
148 "\n"
149 "\n"
150 "\n"
151 " Error --------------------------- --- -- - - \n"
152 " --- -- - -\n"
153 " -- -\n"
154 " \n"
155 " %s\n"
156 " \n"
157 " \n"
158 " \n"
159 " Callstack --------- --- -- - - \n"
160 " \n"
161 " %s\n"
162 " \n"
163 " ------------------------------------------------------------------------\n"
164 "\n"
165 "\n"
166 "\n"
167 "\n"
168 , strMessage.c_str(), strStack.c_str());
169
170 }
171 else
172 {
173
174 auto pmessagebox = ::system()->createø < ::user_interface::message_box >();
175 pmessagebox->initialize_message_box(exception, "Exception", "Exception", ::user::e_message_box_icon_error, exception.get_message() +"\n\nCallstack:\n"+ exception.m_strCallStackTrace);
176
177 pmessagebox->display(e_display_normal, {});
178
179 pmessagebox->wait_dialog_response();
180
181 }
182
183 psystem->m_iExitCode = exception.m_estatus.exit_code();
184
185 }
186 catch (...)
187 {
188
189 if (psystem->m_bConsole)
190 {
191
192 fprintf(stderr, "%s", "Unhandled Exception");
193
194 }
195 else
196 {
197
198 auto pmessagebox = ::system()->createø < ::user_interface::message_box >();
199 pmessagebox->initialize_message_box("Unhandled Exception");
200
201 pmessagebox->display(e_display_normal, {});
202
203 pmessagebox->wait_dialog_response();
204
205 }
206
207 }
208
209 //system.on_system_before_destroy();
210
211 //return ::acme::acme::g_pacme->m_papplication->m_iExitCode;
212
213 psystem->destroy();
214
215 return psystem->m_iExitCode;
216
217
218// //sub_system subsystem(&acme);
219//
220// //acme.m_pplatform = &subsystem;
221//
222// //subsystem.m_pacme = &acme;
223// subsystem.m_argc = argc;
224//#if defined(WINDOWS) && defined(UNICODE)
225// subsystem.m_wargv = argv;
226// subsystem.m_wenvp = envp;
227//#else
228// subsystem.m_argv = argv;
229// subsystem.m_envp = envp;
230//#endif
231//
232// main_hold mainhold;
233//
234// //set_argc_argv_envp(argc, argv, envp);
235//
236// ::pointer<APPLICATION_CLASS>papp(allocateø APPLICATION_CLASS());
237//
238//#ifdef NO_NETWORKING
239//
240// papp->m_bNetworking = false;
241//
242//#endif
243
244//#ifdef WINDOWS
245//
246// papp->get_arguments_from_command_line();
247//
248//#else
249//
250// papp->set_args(argc, argv, envp);
251//
252//#endif
253
254
255// {
256// //__FACTORY(FACTORY)(factory());
257//
258// class ::main main;
259//
260// //Sleep(30'000);
261//
262// main.m_argc = argc;
263//
264//#ifdef WINDOWS
265//
266// main.m_wargv = argv;
267// main.m_wenvp = envp;
268//
269//#else
270//
271// main.m_argv = argv;
272// main.m_envp = envp;
273//
274//#endif
275
276//#ifdef APP_ID
277//
278// papp->m_strAppId = APP_ID;
279//
280//#endif
281//
282// papp->m_bConsole = true;
283//
284// papp->m_pfnImplement = &::implement;
285//
286// try
287// {
288//
289// __main(papp);
290//
291// }
292// catch (const ::exception & exception)
293// {
294//
295// string strReport;
296//
297// strReport += "Exception has occurred:\n";
298// strReport += exception.m_strMessage + ";\n";
299// //strReport += "Command Line:\n";
300// //strReport += node()->get_command_line() + ";\n";
301// strReport += exception.m_strDetails;
302// strReport += "Callstack:\n";
303// strReport += exception.m_strCallstack;
304//
305// fprintf(stderr, "%s", strReport.c_str());
306//
307// }
308// catch (...)
309// {
310//
311// fprintf(stderr, "Unknown exception has occurred\n");
312//
313// }
314//
339//
340//
354//
406//
408//
409// // ::acme::finalize();
410
411}
412
413
414#include "acme/memory/_new.inl"
415
416
417#if !defined(CUBE)
418
419
420#include "_new_impl.h"
421
422
423#if defined(WINDOWS)
424
425
426#include "acme/_library.h"
427
428
429#endif
430
431
432#endif
433
434
435//#include "acme/_defer.h"
436
437
438
439
440#ifdef CUBE
441#define STATIC_FACTORY_INCLUDE "_static_factory_.inl"
442#include "acme/_static_factory.h"
443#endif
444
445
Definition aaa_acme.h:15
Definition system.h:53
Definition message_box.h:145
include "aura/graphics/image/context.h"
Definition aaaa__defer.h:32