Antares Simulator
Power System Simulator
action.hxx
1 /*
2  * Copyright 2007-2025, 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 
26 namespace Antares::Private::Dispatcher
27 {
28 class JobSimpleDispatcher final: public Yuni::Job::IJob
29 {
30 public:
32  {
33  }
34 
35  explicit JobSimpleDispatcher(const Yuni::Bind<void()>& bind):
36  callback(bind)
37  {
38  }
39 
40  template<class C>
41  JobSimpleDispatcher(const C* object, void (C::*method)(void))
42  {
43  using MemberType = void (C::*)();
44  callback.bind(const_cast<C*>(object), reinterpret_cast<MemberType>(method));
45  }
46 
47  virtual ~JobSimpleDispatcher()
48  {
49  }
50 
51 protected:
52  virtual void onExecute()
53  {
54  callback();
55  }
56 
57 public:
59  Yuni::Bind<void()> callback;
60 };
61 
62 } // namespace Antares::Private::Dispatcher
63 
64 namespace Antares::Dispatcher
65 {
66 namespace GUI
67 {
68 template<class C>
69 inline void Post(const C* object, void (C::*method)(void))
70 {
71  ::Antares::Dispatcher::GUI::Post(
72  (const Yuni::Job::IJob::Ptr&)new
73  typename ::Antares::Private::Dispatcher::JobSimpleDispatcher(object, method));
74 }
75 
76 template<class C>
77 inline void Post(const C* object, void (C::*method)(void), uint delay)
78 {
79  auto j = new ::Antares::Private::Dispatcher::JobSimpleDispatcher(object, method);
80  ::Antares::Dispatcher::GUI::Post((const Yuni::Job::IJob::Ptr&)j, delay);
81 }
82 
83 inline void Post(const Yuni::Bind<void()>& job, uint delay)
84 {
85  ::Antares::Dispatcher::GUI::Post(
86  (const Yuni::Job::IJob::Ptr&)new ::Antares::Private::Dispatcher::JobSimpleDispatcher(job),
87  delay);
88 }
89 
90 } // namespace GUI
91 
92 inline void Post(const Yuni::Bind<void()>& job)
93 {
94  ::Antares::Dispatcher::Post(
95  (const Yuni::Job::IJob::Ptr&)new ::Antares::Private::Dispatcher::JobSimpleDispatcher(job));
96 }
97 
98 template<class C>
99 inline void Post(const C* object, void (C::*method)())
100 {
101  ::Antares::Dispatcher::Post(
102  (const Yuni::Job::IJob::Ptr&)new
103  typename ::Antares::Private::Dispatcher::JobSimpleDispatcher(object, method));
104 }
105 
106 template<class C, class UserDataT>
107 inline void Post(const C* object, void (C::*method)(), const UserDataT& userdata)
108 {
109  ::Antares::Dispatcher::Post(
110  (const Yuni::Job::IJob::Ptr&)new
111  typename ::Antares::Private::Dispatcher::JobSimpleDispatcher(object, method, userdata));
112 }
113 
114 } // namespace Antares::Dispatcher
115 
116 namespace Antares::Dispatcher::Internal
117 {
121 void ExecuteQueueDispatcher();
122 
123 } // namespace Antares::Dispatcher::Internal
124 
125 #endif // __ANTARES_COMMON_ACTION_ACTION_HXX__
Yuni::Bind< void()> callback
Delayed callback.
Definition: action.hxx:59
An ASynchroneous Job Dispatcher.
Definition: action.cpp:36
void Post(const Yuni::Job::IJob::Ptr &job)
Post a new job in the thread pool.
Definition: action.cpp:108