Vidalia 0.2.12

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 ** \brief An event posted to a socket living in another thread, indicating
00014 ** that it should send the given control command.
00015 */
00016 
00017 #ifndef _SENDCOMMANDEVENT_H
00018 #define _SENDCOMMANDEVENT_H
00019 
00020 #include "ControlCommand.h"
00021 
00022 #include <QEvent>
00023 #include <QMutex>
00024 #include <QWaitCondition>
00025 
00026 
00027 class SendCommandEvent : public QEvent {
00028 public:
00029   /** Object used to wait for the result of a send operation. */
00030   class SendWaiter {
00031   public:
00032     /** Status of the send SendWaiter. */
00033     enum SenderStatus { Waiting, Failed, Success } _status;
00034     /** Default constructor. */
00035     SendWaiter() { _status = Waiting; }
00036     /** Sets the result of the send operation. */
00037     void setResult(bool success, const QString &errmsg = QString());
00038     /** Waits for and returns the result of the send operation. */
00039     bool getResult(QString *errmsg = 0);
00040     /** Returns the SendWaiter's current SenderStatus value. */
00041     SenderStatus status();
00042   private:
00043     QMutex _mutex; /**< Mutex around the wait condition. */
00044     QWaitCondition _waitCond; /**< Waits for the send to complete. */
00045     QString _errmsg; /**< Error message if the send fails. */
00046   };
00047   
00048   /** Constructor. */
00049   SendCommandEvent(const ControlCommand &cmd, SendWaiter *w = 0);
00050   /** Returns the control command to send to Tor. */
00051   ControlCommand command() { return _cmd; }
00052   /** Returns a SendWaiter (if any) for the result of this send. */
00053   SendWaiter* waiter() { return _waiter; }
00054     
00055 private:
00056   ControlCommand _cmd;  /**< Command to send to Tor. */
00057   SendWaiter* _waiter; /**< SendWaiter for the result of this event. */  
00058 };
00059 
00060 #endif