YSTest: yapp.h 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
yapp.h
浏览该文件的文档.
1 /*
2 © 2009-2014 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 #ifndef YSL_INC_Core_yapp_h_
29 #define YSL_INC_Core_yapp_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YShell
33 #if YF_Multithread == 1
34 # include <mutex>
35 #endif
36
37 namespace YSLib
38 {
39
40 using Messaging::MessageQueue;
41
46 class YF_API Application : public Shell
47 {
48 #if YF_Multithread == 1
49 private:
50 /*
51 \brief 主消息队列互斥锁。
52 \since build 481
53 */
54 std::recursive_mutex queue_mutex;
55 #endif
56
57 protected:
58 /*
59 \brief 主消息队列。
60 \since build 481
61 */
62 MessageQueue qMain;
67 shared_ptr<Shell> hShell;
68
69 public:
70 //标准程序实例事件。
71 std::function<void()> ApplicationExit;
72 // std::function<void()> Idle;
73
77 Application();
78
82 virtual
83 ~Application();
84
88 DefGetter(const ynothrow, shared_ptr<Shell>, ShellHandle, hShell)
89
90
95 template<typename _fCallable>
96 auto
97 AccessQueue(_fCallable f) -> decltype(f(qMain))
98 {
99 #if YF_Multithread == 1
100 std::lock_guard<std::recursive_mutex> lck(queue_mutex);
101
102 #endif
103 return f(qMain);
104 }
105
112 void
113 OnGotMessage(const Message&) override;
114
115 //启动线程消息循环。
116 // void
117 // Run(shared_ptr<Shell>);
118
124 bool
125 Switch(shared_ptr<Shell>&) ynothrow;
132 PDefH(bool, Switch, shared_ptr<Shell>&& h) ynothrow
133 ImplRet(Switch(h))
134 };
135
136
143 extern YF_API Application&
144 FetchAppInstance() ynothrow;
145
151 inline shared_ptr<Shell>
152 FetchShellHandle() ynothrow
153 {
154 return FetchAppInstance().GetShellHandle();
155 }
156
163 inline bool
164 Activate(const shared_ptr<Shell>& hShl)
165 {
166 YAssert(bool(hShl), "Null shell handle found.");
167
168 auto h(hShl);
169
170 return FetchAppInstance().Switch(h);
171 }
172
173
180 YF_API void
182 PostMessage(const Message&, Messaging::Priority) ynothrow;
184 inline void
185 PostMessage(Messaging::ID id, Messaging::Priority prior,
186 const ValueObject& vo = {}) ynothrow
187 {
188 PostMessage(Message(id, vo), prior);
189 }
191 inline void
192 PostMessage(Messaging::ID id, Messaging::Priority prior, ValueObject&& c)
193 ynothrow
194 {
195 PostMessage(Message(id, std::move(c)), prior);
196 }
198 template<Messaging::MessageID _vID>
199 inline void
200 PostMessage(Messaging::Priority prior,
201 const typename Messaging::SMessageMap<_vID>::TargetType& target) ynothrow
202 {
203 PostMessage(_vID, prior, ValueObject(target));
204 }
206
210 YF_API void
211 PostQuitMessage(int nExitCode, Messaging::Priority p = 0xF0);
212
213 } // namespace YSLib;
214
215 #endif
216
YSLib::FetchAppInstance
YF_API Application & FetchAppInstance() ynothrow
取应用程序实例。
Definition: GUIApplication.cpp:135
YSLib::PostMessage
YF_API void PostMessage(const Message &, Messaging::Priority) ynothrow
全局默认队列消息发送函数。
Definition: yapp.cpp:75
ImplRet
#define ImplRet(...)
Definition: YBaseMacro.h:97
YModules.h
YSLib::PostQuitMessage
YF_API void PostQuitMessage(int nExitCode, Messaging::Priority p=0xF0)
以优先级 p 发起 Shell 终止请求，返回 nExitCode。
Definition: yapp.cpp:83
YF_API
#define YF_API
Definition: Platform.h:64
YSLib::FetchShellHandle
shared_ptr< Shell > FetchShellHandle() ynothrow
取当前应用程序线程空间中活动的 Shell 句柄。
Definition: yapp.h:152
YSLib::Application::ApplicationExit
std::function< void()> ApplicationExit
资源释放函数。
Definition: yapp.h:71
YSLib::ValueObject
值类型对象类。
Definition: yobject.h:281
YSLib::Application::hShell
shared_ptr< Shell > hShell
当前 Shell 句柄：指示当前线程空间中运行的 Shell 。
Definition: yapp.h:67
YSLib::Application
程序实例。
Definition: yapp.h:46
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::Activate
bool Activate(const shared_ptr< Shell > &hShl)
激活 Shell 对象：控制权转移给此对象以维持单线程运行。
Definition: yapp.h:164
YSLib::Application::DefGetter
DefGetter(const ynothrow, shared_ptr< Shell >, ShellHandle, hShell) template< typename _fCallable > auto AccessQueue(_fCallable f) -> decltype(f(qMain))
取得线程空间中当前运行的 Shell 的句柄。
Definition: yapp.h:88
YSLib::UI::f
_tWidget _fCallable && f
Definition: ywgtevt.h:597
CHRLib::c
c
Definition: chrproc.h:76
YSLib::Messaging::SMessageMap
Definition: ymsgdef.h:72
YSLib::Application::qMain
MessageQueue qMain
Definition: yapp.h:62
YSLib::Messaging::Priority
u8 Priority
消息优先级。
Definition: ymsg.h:52
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:73
YSLib::Messaging::ID
yimpl(u32) ID
消息标识。
Definition: ymsg.h:46
YSLib::Application::Switch
bool Switch(shared_ptr< Shell > &) ynothrow
线程切换：若参数非空，和线程空间中当前运行的 Shell 的句柄交换。
Definition: yapp.cpp:63