xref: /haiku/src/tests/kits/app/bmessenger/SMInvoker.cpp (revision 0c66734e4da3cdd60a0552014b0f46275a358796)
1 // SMInvoker.cpp
2 
3 #include "SMInvoker.h"
4 #include "SMMessages.h"
5 
6 // SMInvoker
7 
8 // constructor
9 SMInvoker::SMInvoker()
10 		 : fReplyMessage(NULL)
11 {
12 }
13 
14 // destructor
15 SMInvoker::~SMInvoker()
16 {
17 	delete fReplyMessage;
18 }
19 
20 // ReplySuccess
21 bool
22 SMInvoker::ReplySuccess()
23 {
24 	return (fReplyMessage && fReplyMessage->what == MSG_REPLY);
25 }
26 
27 // DirectReply
28 bool
29 SMInvoker::DirectReply()
30 {
31 	return fReplyMessage;
32 }
33 
34 
35 // SMInvoker1
36 
37 // constructor
38 SMInvoker1::SMInvoker1(bool useReplyTo)
39 		  : SMInvoker(),
40 			fUseReplyTo(useReplyTo)
41 {
42 }
43 
44 // Invoke
45 status_t
46 SMInvoker1::Invoke(BMessenger &target, BHandler *replyHandler,
47 				   BMessenger &replyMessenger)
48 {
49 	BHandler *replyTo = (fUseReplyTo ? replyHandler : NULL);
50 	status_t result = target.SendMessage(MSG_TEST, replyTo);
51 	return result;
52 }
53 
54 
55 // SMInvoker2
56 
57 // constructor
58 SMInvoker2::SMInvoker2(bool useMessage, bool useReplyTo, bigtime_t timeout)
59 		  : SMInvoker(),
60 			fUseMessage(useMessage),
61 			fUseReplyTo(useReplyTo),
62 			fTimeout(timeout)
63 {
64 }
65 
66 // Invoke
67 status_t
68 SMInvoker2::Invoke(BMessenger &target, BHandler *replyHandler,
69 				   BMessenger &replyMessenger)
70 {
71 	BHandler *replyTo = (fUseReplyTo ? replyHandler : NULL);
72 	BMessage _message(MSG_TEST);
73 	BMessage *message = (fUseMessage ? &_message : NULL);
74 	status_t result = target.SendMessage(message, replyTo, fTimeout);
75 	return result;
76 }
77 
78 
79 // SMInvoker3
80 
81 // constructor
82 SMInvoker3::SMInvoker3(bool useMessage, bool useReplyTo, bigtime_t timeout)
83 		  : SMInvoker(),
84 			fUseMessage(useMessage),
85 			fUseReplyTo(useReplyTo),
86 			fTimeout(timeout)
87 {
88 }
89 
90 // Invoke
91 status_t
92 SMInvoker3::Invoke(BMessenger &target, BHandler *replyHandler,
93 				   BMessenger &replyMessenger)
94 {
95 	BMessenger badMessenger;
96 	BMessenger &replyTo = (fUseReplyTo ? replyMessenger : badMessenger);
97 	BMessage _message(MSG_TEST);
98 	BMessage *message = (fUseMessage ? &_message : NULL);
99 	status_t result = target.SendMessage(message, replyTo, fTimeout);
100 	return result;
101 }
102 
103 
104 // SMInvoker4
105 
106 // constructor
107 SMInvoker4::SMInvoker4(bool useReply)
108 		  : SMInvoker(),
109 			fUseReply(useReply)
110 {
111 }
112 
113 // Invoke
114 status_t
115 SMInvoker4::Invoke(BMessenger &target, BHandler *replyHandler,
116 				   BMessenger &replyMessenger)
117 {
118 	if (fUseReply)
119 		fReplyMessage = new BMessage(uint32(0));
120 	status_t result = target.SendMessage(MSG_TEST, fReplyMessage);
121 	return result;
122 }
123 
124 
125 // SMInvoker5
126 
127 // constructor
128 SMInvoker5::SMInvoker5(bool useMessage, bool useReply,
129 					   bigtime_t deliveryTimeout, bigtime_t replyTimeout)
130 		  : SMInvoker(),
131 			fUseMessage(useMessage),
132 			fUseReply(useReply),
133 			fDeliveryTimeout(deliveryTimeout),
134 			fReplyTimeout(replyTimeout)
135 {
136 }
137 
138 // Invoke
139 status_t
140 SMInvoker5::Invoke(BMessenger &target, BHandler *replyHandler,
141 				   BMessenger &replyMessenger)
142 {
143 	if (fUseReply)
144 		fReplyMessage = new BMessage(uint32(0));
145 	BMessage _message(MSG_TEST);
146 	BMessage *message = (fUseMessage ? &_message : NULL);
147 	status_t result = target.SendMessage(message, fReplyMessage,
148 										 fDeliveryTimeout, fReplyTimeout);
149 	return result;
150 }
151 
152 
153