/** Copyright 2001-2015 Haiku, Inc. All rights reserved.* Distributed under the terms of the MIT License.** Authors:* John Scipione, jscipione@gmail.com* Ingo Weinhold, bonefish@users.sf.net** Corresponds to:* headers/os/app/MessageRunner.h hrev48689* src/kits/app/MessageRunner.cpp hrev48689*//*!\file MessageRunner.h\ingroup app\ingroup libbe\brief Provides the BMessageRunner class.*//*!\class BMessageRunner\ingroup app\ingroup libbe\brief Provides a mechanism for sending one or more messagesto a messenger at a specified interval and receivereply messages.The application that creates the BMessageRunner can specify the message,the BMessenger to send the message to, how often to send the message,how many times to send the message, and the BMessenger to send replymessages from.The system roster handles dispatching the messages to the appropriatemessengers at the specified time intervals. The target for any replymessages is \c be_app_messenger by default, or it can be specified in theconstructor.After initializing a BMessageRunner, the initialization can and should bechecked by calling InitCheck(). BMessageRunner will not take ownership ofthe message, you may freely change or delete the message afterinitialization.The BMessageRunner can be reconfigured (to change the interval or count)by calling SetInterval() and SetCount(). This is useful if you want to stopa BMessageRunner from sending messages early or if messages are set tobe sent forever.\since BeOS R5*//*!\fn BMessageRunner::BMessageRunner(BMessenger target,const BMessage* message, bigtime_t interval, int32 count)\brief Creates and initializes a new BMessageRunner and instructs thesystem roster to send the specified \a message to the \a target\a count times every \a interval microseconds, reply messages aresent to \c be_app_messenger.\param target The target of the message(s).\param message The message to be sent to the target.\param interval Period of time before the first message is sent andbetween messages (if more than one shall be sent) in microseconds.\param count Specifies how many times the message shall be sent.A negative value indicates that the message will be sentforever, or until the BMessageRunner is reconfigured or deleted.\since BeOS R5*//*!\fn BMessageRunner::BMessageRunner(BMessenger target,const BMessage& message, bigtime_t interval, int32 count)\brief Creates and initializes a new BMessageRunner and instructs thesystem roster to send the specified \a message to the \a target\a count times every \a interval microseconds, reply messages aresent to \c be_app_messenger.\param target Target of the message(s).\param message The message to be sent to the target.\param interval Period of time before the first message is sent andbetween messages (if more than one shall be sent) in microseconds.\param count Specifies how many times the message shall be sent.A negative value indicates that the message will be sentforever, or until the BMessageRunner is reconfigured or deleted.\since Haiku R1*//*!\fn BMessageRunner::BMessageRunner(BMessenger target,const BMessage* message, bigtime_t interval, int32 count,BMessenger replyTo)\brief Creates and initializes a new BMessageRunner and instructs thesystem roster to send the specified \a message to the \a target\a count times every \a interval microseconds.This constructor also allows you to specify the target for replies tothe delivered messages.\param target Target of the message(s).\param message The message to be sent to the target.\param interval Period of time before the first message is sent andbetween messages (if more than one shall be sent) in microseconds.\param count Specifies how many times the message shall be sent.A negative value indicates that the message will be sentforever, or until the BMessageRunner is reconfigured or deleted.\param replyTo Target replies to the delivered message(s) shall be sent to.\since BeOS R5*//*!\fn BMessageRunner::BMessageRunner(BMessenger target,const BMessage& message, bigtime_t interval, int32 count,BMessenger replyTo)\brief Creates and initializes a new BMessageRunner and instructs thesystem roster to send the specified \a message to the \a target\a count times every \a interval microseconds.This constructor also allows you to specify the target for replies tothe delivered messages.\param target Target of the message(s).\param message The message to be sent to the target.\param interval Period of time before the first message is sent andbetween messages (if more than one shall be sent) in microseconds.\param count Specifies how many times the message shall be sent.A negative value indicates that the message will be sentforever, or until the BMessageRunner is reconfigured or deleted.\param replyTo Target replies to the delivered message(s) shall be sent to.\since Haiku R1*//*!\fn BMessageRunner::~BMessageRunner()\brief Frees all resources associated with the object.\since BeOS R5*//*!\fn status_t BMessageRunner::InitCheck() const\brief Returns the initialization status.\note As soon as the last message is sent, the message runnerbecomes unusable. InitCheck() will still return \c B_OK, butSetInterval(), SetCount() and GetInfo() will all fail.\return \c B_OK if the object was properly initialized or an error codeotherwise.\since BeOS R5*//*!\fn status_t BMessageRunner::SetInterval(bigtime_t interval)\brief Sets the interval of time between messages.\param interval The new interval in microseconds.\return A status code, \c B_OK on success or an error code otherwise.\retval B_OK Everything went fine.\retval B_NO_INIT The message runner was not properly initialized.\retval B_BAD_VALUE \a interval was \c 0 or negative, or the message runnerhad already sent all messages and became unusable.\since BeOS R5*//*!\fn status_t BMessageRunner::SetCount(int32 count)\brief Sets the number of times message should be sent.\param count Specifies how many times the message shall be sent.A negative value indicates that the message will be sentforever, or until the BMessageRunner is reconfigured or deleted.\return A status code, \c B_OK on success or an error code otherwise.\retval B_OK Everything went fine.\retval B_NO_INIT The message runner was not properly initialized.\retval B_BAD_VALUE \a interval was \c 0 or negative, or the message runnerhad already sent all messages and became unusable.\since BeOS R5*//*!\fn status_t BMessageRunner::GetInfo(bigtime_t* interval,int32* count) const\brief Returns the time interval between two messages and the number oftimes the message has still to be sent.Both parameters (\a interval and \a count) may be \c NULL.\param interval Pointer to a pre-allocated bigtime_t variable to be setto the time interval. May be \c NULL.\param count Pointer to a pre-allocated int32 variable to be setto the number of times the message has still to be sent.May be \c NULL.\return A status code, \c B_OK on success or an error code otherwise.\retval B_OK Everything went fine.\retval B_BAD_VALUE \a interval was 0 or negative, or the message runnerhad already sent all messages and became unusable.\since BeOS R5*//*!\fn status_t BMessageRunner::StartSending(BMessenger target,const BMessage* message, bigtime_t interval, int32 count)\brief Creates and initializes a detached BMessageRunner and instructs thesystem roster to send the specified \a message to the \a target\a count times every \a interval microseconds, reply messages aresent to \c be_app_messenger.You cannot alter the runner after the creation, and it will be deletedautomatically the last message is sent.\param target Target of the message(s).\param message The message to be sent to the target.\param interval Period of time before the first message is sent andbetween messages (if more than one shall be sent) in microseconds.\param count Specifies how many times the message shall be sent.A negative value indicates that the message will be sentforever, or until the BMessageRunner is reconfigured or deleted.\since Haiku R1*//*!\fn status_t BMessageRunner::StartSending(BMessenger target,const BMessage* message, bigtime_t interval, int32 count,BMessenger replyTo)\brief Creates and initializes a detached BMessageRunner and instructs thesystem roster to send the specified \a message to the \a target\a count times every \a interval microseconds.You cannot alter the runner after the creation, and it will be deletedautomatically once the last message is sent.\param target Target of the message(s).\param message The message to be sent to the target.\param interval Period of time before the first message is sent andbetween messages (if more than one shall be sent) in microseconds.\param count Specifies how many times the message shall be sent.A negative value indicates that the message will be sentforever, or until the BMessageRunner is reconfigured or deleted.\param replyTo Target replies to the delivered message(s) shall be sent to.\since Haiku R1*/