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 2837 2008-07-06 22:41:50Z 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 <QEvent>
00022 #include <QMutex>
00023 #include <QWaitCondition>
00024 
00025 #include "eventtype.h"
00026 #include "controlcommand.h"
00027 
00028 
00029 class SendCommandEvent : public QEvent {
00030 public:
00031   /** Object used to wait for the result of a send operation. */
00032   class SendWaiter {
00033   public:
00034     /** Status of the send SendWaiter. */
00035     enum SenderStatus { Waiting, Failed, Success } _status;
00036     /** Default constructor. */
00037     SendWaiter() { _status = Waiting; }
00038     /** Sets the result of the send operation. */
00039     void setResult(bool success, const QString &errmsg = QString());
00040     /** Waits for and returns the result of the send operation. */
00041     bool getResult(QString *errmsg = 0);
00042     /** Returns the SendWaiter's current SenderStatus value. */
00043     SenderStatus status();
00044   private:
00045     QMutex _mutex; /**< Mutex around the wait condition. */
00046     QWaitCondition _waitCond; /**< Waits for the send to complete. */
00047     QString _errmsg; /**< Error message if the send fails. */
00048   };
00049   
00050   /** Constructor. */
00051   SendCommandEvent(const ControlCommand &cmd, SendWaiter *w = 0);
00052   /** Returns the control command to send to Tor. */
00053   ControlCommand command() { return _cmd; }
00054   /** Returns a SendWaiter (if any) for the result of this send. */
00055   SendWaiter* waiter() { return _waiter; }
00056     
00057 private:
00058   ControlCommand _cmd;  /**< Command to send to Tor. */
00059   SendWaiter* _waiter; /**< SendWaiter for the result of this event. */  
00060 };
00061 
00062 #endif

Generated on Tue Jul 7 16:58:11 2009 for Vidalia by  doxygen 1.4.7