YSTest: YApplication.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

YApplication.cpp
浏览该文件的文档.
1 /*
2 © 2009-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "YSLib/Core/YModules.h"
29 #include YFM_YSLib_Core_YApplication
30 #include YFM_YSLib_Core_YException // for ExtractAndTrace;
31
32 namespace YSLib
33 {
34
35 Application::Application()
36 : Shell()
37 {}
38 Application::~Application()
39 {
40 // NOTE: It is necessary to cleanup to make sure all shells are destroyed.
41 qMain.clear();
42 // hShell = {};
43 // NOTE: All shells must have been released.
44 YAssert(!hShell, "Active shell found.");
45 YTraceDe(Notice, "Uninitialization entered with %zu handler(s) to be"
46 " called.", on_exit.size());
47 // NOTE: This is needed because the standard containers (and adaptors)
48 // guarantee nothing about destruction order of contained elements.
49 while(!on_exit.empty())
50 on_exit.pop();
51 }
52
53 void
54 Application::OnGotMessage(const Message& msg)
55 {
56 TryExpr(Deref(GetShellHandle()).OnGotMessage(msg))
57 CatchIgnore(Messaging::MessageSignal&)
58 #ifndef NDEBUG
59 CatchExpr(std::exception& e, YTraceDe(Emergent, "Unexpected exception."),
60 ExtractAndTrace(e, Emergent), throw)
61 CatchExpr(..., YTraceDe(Emergent, "Unknown unexpected exception."), throw)
62 #endif
63 }
64
65 bool
66 Application::Switch(shared_ptr<Shell>& h) ynothrow
67 {
68 if(YB_LIKELY(hShell != h))
69 {
70 std::swap(hShell, h);
71 return true;
72 }
73 return {};
74 }
75
76
77 void
78 PostMessage(const Message& msg, Messaging::Priority prior)
79 {
80 FetchAppInstance().AccessQueue([=, &msg](MessageQueue& mq){
81 mq.Push(msg, prior);
82 });
83 }
84
85 void
86 PostQuitMessage(int n, Messaging::Priority prior)
87 {
88 YTraceDe(Informative, "Ready to post quit message with exit code = %d,"
89 " priority = %u.", n, unsigned(prior));
90 PostMessage<SM_Set>(prior, shared_ptr<Shell>());
91 PostMessage<SM_Quit>(prior, n);
92 }
93
94 } // namespace YSLib;
95
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:313
platform::msg
const string & msg
Definition: Debug.h:464
YSLib::Application::Switch
bool Switch(shared_ptr< Shell > &) ynothrow
切换：若参数非空，和线程空间中当前运行的 Shell 的句柄交换。
Definition: YApplication.cpp:66
YSLib::Messaging::Priority
std::uint8_t Priority
消息优先级。
Definition: YMessage.h:51
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
YSLib::Application::on_exit
stack< ystdex::any > on_exit
初始化守护。
Definition: YApplication.h:53
platform::Descriptions::Emergent
Definition: YCommon.h:163
YSLib::shared_ptr< Shell >
shared_ptr< Shell >
Definition: GUIApplication.h:307
CatchIgnore
#define CatchIgnore(_ex)
指定异常处理器忽略指定异常。
Definition: YBaseMacro.h:133
YSLib::YAssert
YAssert(!(v< Deref(a)),"Value less than lower bound found.")
YSLib::Application::qMain
MessageQueue qMain
Definition: YApplication.h:70
YSLib::PostQuitMessage
YF_API void PostQuitMessage(int=0, Messaging::Priority p=DefaultQuitPriority)
以指定错误码和优先级发起 Shell 终止请求。
Definition: YApplication.cpp:86
YSLib::Application::~Application
~Application() override
析构：释放 Shell 所有权和其它资源。
Definition: YApplication.cpp:38
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
platform::Descriptions::Notice
Definition: YCommon.h:168
YSLib::Application::Application
Application()
无参数构造：默认构造。
Definition: YApplication.cpp:35
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
YSLib::Messaging::MessageSignal
消息信号：表示单一处理中断的异常。
Definition: YMessage.h:283
YSLib::Application::OnGotMessage
void OnGotMessage(const Message &) override
处理消息：分发消息。
Definition: YApplication.cpp:54
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
YModules.h
platform::Descriptions::Informative
Definition: YCommon.h:169
YSLib::PostMessage
const shared_ptr< Shell > &hShl ImplRet(FetchAppInstance().Switch(shared_ptr< Shell >(hShl))) yconstexpr const Messaging YF_API void PostMessage(const Message &, Messaging::Priority)
默认退出消息优先级。
Definition: YApplication.cpp:78
YSLib::Application::hShell
shared_ptr< Shell > hShell
当前 Shell 句柄：指示当前线程空间中运行的 Shell 。
Definition: YApplication.h:75
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:463
YSLib::FetchAppInstance
YF_API Application & FetchAppInstance()
取应用程序实例。
Definition: GUIApplication.cpp:295
YSLib::ExtractAndTrace
YF_API void ExtractAndTrace(const std::exception &, RecordLevel=Err) ynothrow
使用 TraceException 展开和跟踪异常类型和信息。