1*db7ef129SJohn Scipione/* 2*db7ef129SJohn Scipione * Copyright 2001-2015 Haiku, Inc. All rights reserved. 3*db7ef129SJohn Scipione * Distributed under the terms of the MIT License. 4*db7ef129SJohn Scipione * 5*db7ef129SJohn Scipione * Authors: 6*db7ef129SJohn Scipione * John Scipione, jscipione@gmail.com 7*db7ef129SJohn Scipione * Ingo Weinhold, bonefish@users.sf.net 8*db7ef129SJohn Scipione * 9*db7ef129SJohn Scipione * Corresponds to: 10*db7ef129SJohn Scipione * headers/os/app/MessageRunner.h hrev48689 11*db7ef129SJohn Scipione * src/kits/app/MessageRunner.cpp hrev48689 12*db7ef129SJohn Scipione */ 13*db7ef129SJohn Scipione 14*db7ef129SJohn Scipione 15*db7ef129SJohn Scipione/*! 16*db7ef129SJohn Scipione \file MessageRunner.h 17*db7ef129SJohn Scipione \ingroup app 18*db7ef129SJohn Scipione \ingroup libbe 19*db7ef129SJohn Scipione \brief Provides the BMessageRunner class. 20*db7ef129SJohn Scipione*/ 21*db7ef129SJohn Scipione 22*db7ef129SJohn Scipione 23*db7ef129SJohn Scipione/*! 24*db7ef129SJohn Scipione \class BMessageRunner 25*db7ef129SJohn Scipione \ingroup app 26*db7ef129SJohn Scipione \ingroup libbe 27*db7ef129SJohn Scipione \brief Provides a mechanism for sending one or more messages 28*db7ef129SJohn Scipione to a messenger at a specified interval and receive 29*db7ef129SJohn Scipione reply messages. 30*db7ef129SJohn Scipione 31*db7ef129SJohn Scipione The application that creates the BMessageRunner can specify the message, 32*db7ef129SJohn Scipione the BMessenger to send the message to, how often to send the message, 33*db7ef129SJohn Scipione how many times to send the message, and the BMessenger to send reply 34*db7ef129SJohn Scipione messages from. 35*db7ef129SJohn Scipione 36*db7ef129SJohn Scipione The system roster handles dispatching the messages to the appropriate 37*db7ef129SJohn Scipione messengers at the specified time intervals. The target for any reply 38*db7ef129SJohn Scipione messages is \c be_app_messenger by default, or it can be specified in the 39*db7ef129SJohn Scipione constructor. 40*db7ef129SJohn Scipione 41*db7ef129SJohn Scipione After initializing a BMessageRunner, the initialization can and should be 42*db7ef129SJohn Scipione checked by calling InitCheck(). BMessageRunner will not take ownership of 43*db7ef129SJohn Scipione the message, you may freely change or delete the message after 44*db7ef129SJohn Scipione initialization. 45*db7ef129SJohn Scipione 46*db7ef129SJohn Scipione The BMessageRunner can be reconfigured (to change the interval or count) 47*db7ef129SJohn Scipione by calling SetInterval() and SetCount(). This is useful if you want to stop 48*db7ef129SJohn Scipione a BMessageRunner from sending messages early or if messages are set to 49*db7ef129SJohn Scipione be sent forever. 50*db7ef129SJohn Scipione 51*db7ef129SJohn Scipione \since BeOS R5 52*db7ef129SJohn Scipione*/ 53*db7ef129SJohn Scipione 54*db7ef129SJohn Scipione 55*db7ef129SJohn Scipione/*! 56*db7ef129SJohn Scipione \fn BMessageRunner::BMessageRunner(BMessenger target, 57*db7ef129SJohn Scipione const BMessage* message, bigtime_t interval, int32 count) 58*db7ef129SJohn Scipione \brief Creates and initializes a new BMessageRunner and instructs the 59*db7ef129SJohn Scipione system roster to send the specified \a message to the \a target 60*db7ef129SJohn Scipione \a count times every \a interval microseconds, reply messages are 61*db7ef129SJohn Scipione sent to \c be_app_messenger. 62*db7ef129SJohn Scipione 63*db7ef129SJohn Scipione \param target The target of the message(s). 64*db7ef129SJohn Scipione \param message The message to be sent to the target. 65*db7ef129SJohn Scipione \param interval Period of time before the first message is sent and 66*db7ef129SJohn Scipione between messages (if more than one shall be sent) in microseconds. 67*db7ef129SJohn Scipione \param count Specifies how many times the message shall be sent. 68*db7ef129SJohn Scipione A negative value indicates that the message will be sent 69*db7ef129SJohn Scipione forever, or until the BMessageRunner is reconfigured or deleted. 70*db7ef129SJohn Scipione 71*db7ef129SJohn Scipione \since BeOS R5 72*db7ef129SJohn Scipione*/ 73*db7ef129SJohn Scipione 74*db7ef129SJohn Scipione 75*db7ef129SJohn Scipione/*! 76*db7ef129SJohn Scipione \fn BMessageRunner::BMessageRunner(BMessenger target, 77*db7ef129SJohn Scipione const BMessage& message, bigtime_t interval, int32 count) 78*db7ef129SJohn Scipione \brief Creates and initializes a new BMessageRunner and instructs the 79*db7ef129SJohn Scipione system roster to send the specified \a message to the \a target 80*db7ef129SJohn Scipione \a count times every \a interval microseconds, reply messages are 81*db7ef129SJohn Scipione sent to \c be_app_messenger. 82*db7ef129SJohn Scipione 83*db7ef129SJohn Scipione \param target Target of the message(s). 84*db7ef129SJohn Scipione \param message The message to be sent to the target. 85*db7ef129SJohn Scipione \param interval Period of time before the first message is sent and 86*db7ef129SJohn Scipione between messages (if more than one shall be sent) in microseconds. 87*db7ef129SJohn Scipione \param count Specifies how many times the message shall be sent. 88*db7ef129SJohn Scipione A negative value indicates that the message will be sent 89*db7ef129SJohn Scipione forever, or until the BMessageRunner is reconfigured or deleted. 90*db7ef129SJohn Scipione 91*db7ef129SJohn Scipione \since Haiku R1 92*db7ef129SJohn Scipione*/ 93*db7ef129SJohn Scipione 94*db7ef129SJohn Scipione 95*db7ef129SJohn Scipione/*! 96*db7ef129SJohn Scipione \fn BMessageRunner::BMessageRunner(BMessenger target, 97*db7ef129SJohn Scipione const BMessage* message, bigtime_t interval, int32 count, 98*db7ef129SJohn Scipione BMessenger replyTo) 99*db7ef129SJohn Scipione \brief Creates and initializes a new BMessageRunner and instructs the 100*db7ef129SJohn Scipione system roster to send the specified \a message to the \a target 101*db7ef129SJohn Scipione \a count times every \a interval microseconds. 102*db7ef129SJohn Scipione 103*db7ef129SJohn Scipione This constructor also allows you to specify the target for replies to 104*db7ef129SJohn Scipione the delivered messages. 105*db7ef129SJohn Scipione 106*db7ef129SJohn Scipione \param target Target of the message(s). 107*db7ef129SJohn Scipione \param message The message to be sent to the target. 108*db7ef129SJohn Scipione \param interval Period of time before the first message is sent and 109*db7ef129SJohn Scipione between messages (if more than one shall be sent) in microseconds. 110*db7ef129SJohn Scipione \param count Specifies how many times the message shall be sent. 111*db7ef129SJohn Scipione A negative value indicates that the message will be sent 112*db7ef129SJohn Scipione forever, or until the BMessageRunner is reconfigured or deleted. 113*db7ef129SJohn Scipione \param replyTo Target replies to the delivered message(s) shall be sent to. 114*db7ef129SJohn Scipione 115*db7ef129SJohn Scipione \since BeOS R5 116*db7ef129SJohn Scipione*/ 117*db7ef129SJohn Scipione 118*db7ef129SJohn Scipione 119*db7ef129SJohn Scipione/*! 120*db7ef129SJohn Scipione \fn BMessageRunner::BMessageRunner(BMessenger target, 121*db7ef129SJohn Scipione const BMessage& message, bigtime_t interval, int32 count, 122*db7ef129SJohn Scipione BMessenger replyTo) 123*db7ef129SJohn Scipione \brief Creates and initializes a new BMessageRunner and instructs the 124*db7ef129SJohn Scipione system roster to send the specified \a message to the \a target 125*db7ef129SJohn Scipione \a count times every \a interval microseconds. 126*db7ef129SJohn Scipione 127*db7ef129SJohn Scipione This constructor also allows you to specify the target for replies to 128*db7ef129SJohn Scipione the delivered messages. 129*db7ef129SJohn Scipione 130*db7ef129SJohn Scipione \param target Target of the message(s). 131*db7ef129SJohn Scipione \param message The message to be sent to the target. 132*db7ef129SJohn Scipione \param interval Period of time before the first message is sent and 133*db7ef129SJohn Scipione between messages (if more than one shall be sent) in microseconds. 134*db7ef129SJohn Scipione \param count Specifies how many times the message shall be sent. 135*db7ef129SJohn Scipione A negative value indicates that the message will be sent 136*db7ef129SJohn Scipione forever, or until the BMessageRunner is reconfigured or deleted. 137*db7ef129SJohn Scipione \param replyTo Target replies to the delivered message(s) shall be sent to. 138*db7ef129SJohn Scipione 139*db7ef129SJohn Scipione \since Haiku R1 140*db7ef129SJohn Scipione*/ 141*db7ef129SJohn Scipione 142*db7ef129SJohn Scipione 143*db7ef129SJohn Scipione/*! 144*db7ef129SJohn Scipione \fn BMessageRunner::~BMessageRunner() 145*db7ef129SJohn Scipione \brief Frees all resources associated with the object. 146*db7ef129SJohn Scipione 147*db7ef129SJohn Scipione \since BeOS R5 148*db7ef129SJohn Scipione*/ 149*db7ef129SJohn Scipione 150*db7ef129SJohn Scipione 151*db7ef129SJohn Scipione/*! 152*db7ef129SJohn Scipione \fn status_t BMessageRunner::InitCheck() const 153*db7ef129SJohn Scipione \brief Returns the initialization status. 154*db7ef129SJohn Scipione 155*db7ef129SJohn Scipione \note As soon as the last message is sent, the message runner 156*db7ef129SJohn Scipione becomes unusable. InitCheck() will still return \c B_OK, but 157*db7ef129SJohn Scipione SetInterval(), SetCount() and GetInfo() will all fail. 158*db7ef129SJohn Scipione 159*db7ef129SJohn Scipione \return \c B_OK if the object was properly initialized or an error code 160*db7ef129SJohn Scipione otherwise. 161*db7ef129SJohn Scipione 162*db7ef129SJohn Scipione \since BeOS R5 163*db7ef129SJohn Scipione*/ 164*db7ef129SJohn Scipione 165*db7ef129SJohn Scipione 166*db7ef129SJohn Scipione/*! 167*db7ef129SJohn Scipione \fn status_t BMessageRunner::SetInterval(bigtime_t interval) 168*db7ef129SJohn Scipione \brief Sets the interval of time between messages. 169*db7ef129SJohn Scipione 170*db7ef129SJohn Scipione \param interval The new interval in microseconds. 171*db7ef129SJohn Scipione 172*db7ef129SJohn Scipione \return A status code, \c B_OK on success or an error code otherwise. 173*db7ef129SJohn Scipione \retval B_OK Everything went fine. 174*db7ef129SJohn Scipione \retval B_NO_INIT The message runner was not properly initialized. 175*db7ef129SJohn Scipione \retval B_BAD_VALUE \a interval was \c 0 or negative, or the message runner 176*db7ef129SJohn Scipione had already sent all messages and became unusable. 177*db7ef129SJohn Scipione 178*db7ef129SJohn Scipione \since BeOS R5 179*db7ef129SJohn Scipione*/ 180*db7ef129SJohn Scipione 181*db7ef129SJohn Scipione 182*db7ef129SJohn Scipione/*! 183*db7ef129SJohn Scipione \fn status_t BMessageRunner::SetCount(int32 count) 184*db7ef129SJohn Scipione \brief Sets the number of times message should be sent. 185*db7ef129SJohn Scipione 186*db7ef129SJohn Scipione \param count Specifies how many times the message shall be sent. 187*db7ef129SJohn Scipione A negative value indicates that the message will be sent 188*db7ef129SJohn Scipione forever, or until the BMessageRunner is reconfigured or deleted. 189*db7ef129SJohn Scipione 190*db7ef129SJohn Scipione \return A status code, \c B_OK on success or an error code otherwise. 191*db7ef129SJohn Scipione \retval B_OK Everything went fine. 192*db7ef129SJohn Scipione \retval B_NO_INIT The message runner was not properly initialized. 193*db7ef129SJohn Scipione \retval B_BAD_VALUE \a interval was \c 0 or negative, or the message runner 194*db7ef129SJohn Scipione had already sent all messages and became unusable. 195*db7ef129SJohn Scipione 196*db7ef129SJohn Scipione \since BeOS R5 197*db7ef129SJohn Scipione*/ 198*db7ef129SJohn Scipione 199*db7ef129SJohn Scipione 200*db7ef129SJohn Scipione/*! 201*db7ef129SJohn Scipione \fn status_t BMessageRunner::GetInfo(bigtime_t* interval, 202*db7ef129SJohn Scipione int32* count) const 203*db7ef129SJohn Scipione \brief Returns the time interval between two messages and the number of 204*db7ef129SJohn Scipione times the message has still to be sent. 205*db7ef129SJohn Scipione 206*db7ef129SJohn Scipione Both parameters (\a interval and \a count) may be \c NULL. 207*db7ef129SJohn Scipione 208*db7ef129SJohn Scipione \param interval Pointer to a pre-allocated bigtime_t variable to be set 209*db7ef129SJohn Scipione to the time interval. May be \c NULL. 210*db7ef129SJohn Scipione \param count Pointer to a pre-allocated int32 variable to be set 211*db7ef129SJohn Scipione to the number of times the message has still to be sent. 212*db7ef129SJohn Scipione May be \c NULL. 213*db7ef129SJohn Scipione 214*db7ef129SJohn Scipione \return A status code, \c B_OK on success or an error code otherwise. 215*db7ef129SJohn Scipione \retval B_OK Everything went fine. 216*db7ef129SJohn Scipione \retval B_BAD_VALUE \a interval was 0 or negative, or the message runner 217*db7ef129SJohn Scipione had already sent all messages and became unusable. 218*db7ef129SJohn Scipione 219*db7ef129SJohn Scipione \since BeOS R5 220*db7ef129SJohn Scipione*/ 221*db7ef129SJohn Scipione 222*db7ef129SJohn Scipione 223*db7ef129SJohn Scipione/*! 224*db7ef129SJohn Scipione \fn status_t BMessageRunner::StartSending(BMessenger target, 225*db7ef129SJohn Scipione const BMessage* message, bigtime_t interval, int32 count) 226*db7ef129SJohn Scipione \brief Creates and initializes a detached BMessageRunner and instructs the 227*db7ef129SJohn Scipione system roster to send the specified \a message to the \a target 228*db7ef129SJohn Scipione \a count times every \a interval microseconds, reply messages are 229*db7ef129SJohn Scipione sent to \c be_app_messenger. 230*db7ef129SJohn Scipione 231*db7ef129SJohn Scipione You cannot alter the runner after the creation, and it will be deleted 232*db7ef129SJohn Scipione automatically the last message is sent. 233*db7ef129SJohn Scipione 234*db7ef129SJohn Scipione \param target Target of the message(s). 235*db7ef129SJohn Scipione \param message The message to be sent to the target. 236*db7ef129SJohn Scipione \param interval Period of time before the first message is sent and 237*db7ef129SJohn Scipione between messages (if more than one shall be sent) in microseconds. 238*db7ef129SJohn Scipione \param count Specifies how many times the message shall be sent. 239*db7ef129SJohn Scipione A negative value indicates that the message will be sent 240*db7ef129SJohn Scipione forever, or until the BMessageRunner is reconfigured or deleted. 241*db7ef129SJohn Scipione 242*db7ef129SJohn Scipione \since Haiku R1 243*db7ef129SJohn Scipione*/ 244*db7ef129SJohn Scipione 245*db7ef129SJohn Scipione 246*db7ef129SJohn Scipione/*! 247*db7ef129SJohn Scipione \fn status_t BMessageRunner::StartSending(BMessenger target, 248*db7ef129SJohn Scipione const BMessage* message, bigtime_t interval, int32 count, 249*db7ef129SJohn Scipione BMessenger replyTo) 250*db7ef129SJohn Scipione \brief Creates and initializes a detached BMessageRunner and instructs the 251*db7ef129SJohn Scipione system roster to send the specified \a message to the \a target 252*db7ef129SJohn Scipione \a count times every \a interval microseconds. 253*db7ef129SJohn Scipione 254*db7ef129SJohn Scipione You cannot alter the runner after the creation, and it will be deleted 255*db7ef129SJohn Scipione automatically once the last message is sent. 256*db7ef129SJohn Scipione 257*db7ef129SJohn Scipione \param target Target of the message(s). 258*db7ef129SJohn Scipione \param message The message to be sent to the target. 259*db7ef129SJohn Scipione \param interval Period of time before the first message is sent and 260*db7ef129SJohn Scipione between messages (if more than one shall be sent) in microseconds. 261*db7ef129SJohn Scipione \param count Specifies how many times the message shall be sent. 262*db7ef129SJohn Scipione A negative value indicates that the message will be sent 263*db7ef129SJohn Scipione forever, or until the BMessageRunner is reconfigured or deleted. 264*db7ef129SJohn Scipione \param replyTo Target replies to the delivered message(s) shall be sent to. 265*db7ef129SJohn Scipione 266*db7ef129SJohn Scipione \since Haiku R1 267*db7ef129SJohn Scipione*/ 268