Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb37a7ad

Browse files
committed
ability to send a message on behalf of the specific object
1 parent1cb5687 commitb37a7ad

File tree

6 files changed

+59
-12
lines changed

6 files changed

+59
-12
lines changed

‎CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
cmake_minimum_required (VERSION3.1)
22

3+
option (ACTO_BUILD_SAMPLES"Set to ON to build samples"OFF)
4+
35
project (actoLANGUAGESCXX)
46
find_package (ThreadsREQUIRED)
57

6-
option (ACTO_BUILD_SAMPLES"Set to ON to build samples"OFF)
7-
88
# Determine whether this is a standalone project or
99
# included by other projects.
1010
if (CMAKE_CURRENT_SOURCE_DIRSTREQUALCMAKE_SOURCE_DIR)

‎lib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ target_sources (acto-lib PRIVATE
1212
)
1313

1414
if (UNIX)
15-
target_link_libraries (acto-lib
15+
target_link_libraries (acto-libPUBLIC
1616
pthread
1717
)
1818
endif ()

‎lib/acto.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ bool actor_ref::send_message(std::unique_ptr<core::msg_t> msg) const {
4545
returncore::runtime_t::instance()->send(m_object,std::move(msg));
4646
}
4747

48+
boolactor_ref::send_message_on_behalf(
49+
core::object_t* sender, std::unique_ptr<core::msg_t> msg)const {
50+
returncore::runtime_t::instance()->send_on_behalf(
51+
m_object, sender,std::move(msg));
52+
}
53+
4854
actor_ref& actor_ref::operator=(const actor_ref& rhs) {
4955
if (this != &rhs) {
5056
if (rhs.m_object) {

‎lib/acto.h

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ class actor_ref {
196196
*
197197
* @return true if the message has been placed into the actor's mailbox.
198198
*/
199-
template<typenameMsgT>
200-
inlineboolsend(MsgT&& msg)const {
199+
template<typenameMsg>
200+
inlineboolsend(Msg&& msg)const {
201201
if (m_object) {
202202
returnsend_message(std::make_unique<
203-
core::msg_wrap_t<typename std::remove_reference<MsgT>::type>>(
203+
core::msg_wrap_t<typename std::remove_reference<Msg>::type>>(
204204
std::move(msg)));
205205
}
206206
returnfalse;
@@ -211,11 +211,36 @@ class actor_ref {
211211
*
212212
* @return true if the message has been placed into the actor's mailbox.
213213
*/
214-
template<typenameMsgT,typename... P>
214+
template<typenameMsg,typename... P>
215215
inlineboolsend(P&&... p)const {
216216
if (m_object) {
217217
returnsend_message(
218-
std::make_unique<core::msg_wrap_t<MsgT>>(std::forward<P>(p)...));
218+
std::make_unique<core::msg_wrap_t<Msg>>(std::forward<P>(p)...));
219+
}
220+
returnfalse;
221+
}
222+
223+
/**
224+
* Sends a message to the actor.
225+
*
226+
* @return true if the message has been placed into the actor's mailbox.
227+
*/
228+
template<typename Msg>
229+
inlineboolsend_on_behalf(const actor_ref& sender, Msg&& msg)const {
230+
if (m_object) {
231+
returnsend_message_on_behalf(sender.m_object,
232+
std::make_unique<
233+
core::msg_wrap_t<typename std::remove_reference<Msg>::type>>(
234+
std::move(msg)));
235+
}
236+
returnfalse;
237+
}
238+
239+
template<typename Msg,typename... P>
240+
inlineboolsend_on_behalf(const actor_ref& sender, P&&... p)const {
241+
if (m_object) {
242+
returnsend_message_on_behalf(sender.m_object,
243+
std::make_unique<core::msg_wrap_t<Msg>>(std::forward<P>(p)...));
219244
}
220245
returnfalse;
221246
}
@@ -235,6 +260,10 @@ class actor_ref {
235260
/// Dispatches a message.
236261
boolsend_message(std::unique_ptr<core::msg_t> msg)const;
237262

263+
/// Dispatches a message.
264+
boolsend_message_on_behalf(
265+
core::object_t* sender, std::unique_ptr<core::msg_t> msg)const;
266+
238267
private:
239268
core::object_t* m_object{nullptr};
240269
};

‎lib/runtime.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ unsigned long runtime_t::release(object_t* const obj) {
235235
}
236236

237237
boolruntime_t::send(object_t*const target, std::unique_ptr<msg_t> msg) {
238+
returnsend_on_behalf(target, active_actor,std::move(msg));
239+
}
240+
241+
boolruntime_t::send_on_behalf(
242+
object_t*const target,object_t*const sender, std::unique_ptr<msg_t> msg) {
238243
assert(msg);
239244
assert(target);
240245

@@ -245,9 +250,9 @@ bool runtime_t::send(object_t* const target, std::unique_ptr<msg_t> msg) {
245250
returnfalse;
246251
}else {
247252
// Acquire reference to a sender.
248-
if (active_actor) {
249-
msg->sender =active_actor;
250-
acquire(active_actor);
253+
if (sender) {
254+
msg->sender =sender;
255+
acquire(sender);
251256
}
252257
// Acquire reference to the target actor.
253258
msg->target = target;

‎lib/runtime.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ class runtime_t : public worker_t::callbacks {
4646
unsignedlongrelease(object_t*const obj);
4747
/// Зарегистрировать новый модуль
4848
voidregister_module();
49-
/// Послать сообщение указанному объекту
49+
50+
/// Sends the message to the specific actor.
51+
/// Uses the active actor as a sender.
5052
boolsend(object_t*const target, std::unique_ptr<msg_t> msg);
53+
54+
/// Sends the message to the specific actor.
55+
boolsend_on_behalf(
56+
object_t*const target,object_t* sender, std::unique_ptr<msg_t> msg);
57+
5158
/// Завершить выполнение
5259
voidshutdown();
5360
/// Начать выполнение

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp