SendCommandEvent.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If 
00004 **  you did not receive the LICENSE file with this file, you may obtain it
00005 **  from the Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to
00008 **  the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file SendCommandEvent.h
00013 ** \version $Id: SendCommandEvent.h 4054 2009-08-17 02:25:08Z edmanm $
00014 ** \brief An event posted to a socket living in another thread, indicating
00015 ** that it should send the given control command.
00016 */
00017 
00018 #ifndef _SENDCOMMANDEVENT_H
00019 #define _SENDCOMMANDEVENT_H
00020 
00021 #include "ControlCommand.h"
00022 
00023 #include <QEvent>
00024 #include <QMutex>
00025 #include <QWaitCondition>
00026 
00027 
00028 class SendCommandEvent : public QEvent {
00029 public:
00030   /** Object used to wait for the result of a send operation. */
00031   class SendWaiter {
00032   public:
00033     /** Status of the send SendWaiter. */
00034     enum SenderStatus { Waiting, Failed, Success } _status;
00035     /** Default constructor. */
00036     SendWaiter() { _status = Waiting; }
00037     /** Sets the result of the send operation. */
00038     void setResult(bool success, const QString &errmsg = QString());
00039     /** Waits for and returns the result of the send operation. */
00040     bool getResult(QString *errmsg = 0);
00041     /** Returns the SendWaiter's current SenderStatus value. */
00042     SenderStatus status();
00043   private:
00044     QMutex _mutex; /**< Mutex around the wait condition. */
00045     QWaitCondition _waitCond; /**< Waits for the send to complete. */
00046     QString _errmsg; /**< Error message if the send fails. */
00047   };
00048   
00049   /** Constructor. */
00050   SendCommandEvent(const ControlCommand &cmd, SendWaiter *w = 0);
00051   /** Returns the control command to send to Tor. */
00052   ControlCommand command() { return _cmd; }
00053   /** Returns a SendWaiter (if any) for the result of this send. */
00054   SendWaiter* waiter() { return _waiter; }
00055     
00056 private:
00057   ControlCommand _cmd;  /**< Command to send to Tor. */
00058   SendWaiter* _waiter; /**< SendWaiter for the result of this event. */  
00059 };
00060 
00061 #endif

Generated on Mon Aug 30 19:09:59 2010 for Vidalia by  doxygen 1.5.9