Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
action.hxx
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21#ifndef __ANTARES_COMMON_ACTION_ACTION_HXX__
22#define __ANTARES_COMMON_ACTION_ACTION_HXX__
23
24#include "action.h"
25
26namespace Antares
27{
28namespace Private
29{
30namespace Dispatcher
31{
32class JobSimpleDispatcher final : public Yuni::Job::IJob
33{
34public:
36 {
37 }
38
39 explicit JobSimpleDispatcher(const Yuni::Bind<void()>& bind) : callback(bind)
40 {
41 }
42
43 template<class C>
44 JobSimpleDispatcher(const C* object, void (C::*method)(void))
45 {
46 using MemberType = void (C::*)();
47 callback.bind(const_cast<C*>(object), reinterpret_cast<MemberType>(method));
48 }
49
50 virtual ~JobSimpleDispatcher()
51 {
52 }
53
54protected:
55 virtual void onExecute()
56 {
57 callback();
58 }
59
60public:
62 Yuni::Bind<void()> callback;
63};
64
65} // namespace Dispatcher
66} // namespace Private
67} // namespace Antares
68
69namespace Antares
70{
71namespace Dispatcher
72{
73namespace GUI
74{
75template<class C>
76inline void Post(const C* object, void (C::*method)(void))
77{
78 ::Antares::Dispatcher::GUI::Post(
79 (const Yuni::Job::IJob::Ptr&)new
80 typename ::Antares::Private::Dispatcher::JobSimpleDispatcher(object, method));
81}
82
83template<class C>
84inline void Post(const C* object, void (C::*method)(void), uint delay)
85{
86 auto j = new ::Antares::Private::Dispatcher::JobSimpleDispatcher(object, method);
87 ::Antares::Dispatcher::GUI::Post((const Yuni::Job::IJob::Ptr&)j, delay);
88}
89
90inline void Post(const Yuni::Bind<void()>& job, uint delay)
91{
92 ::Antares::Dispatcher::GUI::Post(
93 (const Yuni::Job::IJob::Ptr&)new ::Antares::Private::Dispatcher::JobSimpleDispatcher(job),
94 delay);
95}
96
97} // namespace GUI
98
99inline void Post(const Yuni::Bind<void()>& job)
100{
102 (const Yuni::Job::IJob::Ptr&)new ::Antares::Private::Dispatcher::JobSimpleDispatcher(job));
103}
104
105template<class C>
106inline void Post(const C* object, void (C::*method)())
107{
109 (const Yuni::Job::IJob::Ptr&)new
110 typename ::Antares::Private::Dispatcher::JobSimpleDispatcher(object, method));
111}
112
113template<class C, class UserDataT>
114inline void Post(const C* object, void (C::*method)(), const UserDataT& userdata)
115{
117 (const Yuni::Job::IJob::Ptr&)new
118 typename ::Antares::Private::Dispatcher::JobSimpleDispatcher(object, method, userdata));
119}
120
121} // namespace Dispatcher
122} // namespace Antares
123
124namespace Antares
125{
126namespace Dispatcher
127{
128namespace Internal
129{
133void ExecuteQueueDispatcher();
134
135} // namespace Internal
136} // namespace Dispatcher
137} // namespace Antares
138
139#endif // __ANTARES_COMMON_ACTION_ACTION_HXX__
Yuni::Bind< void()> callback
Delayed callback.
Definition action.hxx:62
void Post(const Yuni::Job::IJob::Ptr &job)
Post a new job in the thread pool.
Definition action.cpp:105