Vidalia
0.3.1
src
torcontrol
SendCommandEvent.h
Go to the documentation of this file.
1
/*
2
** This file is part of Vidalia, and is subject to the license terms in the
3
** LICENSE file, found in the top level directory of this distribution. If
4
** you did not receive the LICENSE file with this file, you may obtain it
5
** from the Vidalia source package distributed by the Vidalia Project at
6
** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7
** including this file, may be copied, modified, propagated, or distributed
8
** except according to the terms described in the LICENSE file.
9
*/
10
11
/*
12
** \file SendCommandEvent.h
13
** \brief An event posted to a socket living in another thread, indicating
14
** that it should send the given control command.
15
*/
16
17
#ifndef _SENDCOMMANDEVENT_H
18
#define _SENDCOMMANDEVENT_H
19
20
#include "
ControlCommand.h
"
21
22
#include <QEvent>
23
#include <QMutex>
24
#include <QWaitCondition>
25
26
27
class
SendCommandEvent
:
public
QEvent {
28
public
:
29
/** Object used to wait for the result of a send operation. */
30
class
SendWaiter
{
31
public
:
32
/** Status of the send SendWaiter. */
33
enum
SenderStatus
{
Waiting
,
Failed
,
Success
}
_status
;
34
/** Default constructor. */
35
SendWaiter
() { _status =
Waiting
; }
36
/** Sets the result of the send operation. */
37
void
setResult
(
bool
success,
const
QString &errmsg = QString());
38
/** Waits for and returns the result of the send operation. */
39
bool
getResult
(QString *errmsg = 0);
40
/** Returns the SendWaiter's current SenderStatus value. */
41
SenderStatus
status
();
42
private
:
43
QMutex
_mutex
;
/**< Mutex around the wait condition. */
44
QWaitCondition
_waitCond
;
/**< Waits for the send to complete. */
45
QString
_errmsg
;
/**< Error message if the send fails. */
46
};
47
48
/** Constructor. */
49
SendCommandEvent
(
const
ControlCommand
&cmd,
SendWaiter
*w = 0);
50
/** Returns the control command to send to Tor. */
51
ControlCommand
command
() {
return
_cmd
; }
52
/** Returns a SendWaiter (if any) for the result of this send. */
53
SendWaiter
*
waiter
() {
return
_waiter
; }
54
55
private
:
56
ControlCommand
_cmd
;
/**< Command to send to Tor. */
57
SendWaiter
*
_waiter
;
/**< SendWaiter for the result of this event. */
58
};
59
60
#endif
SendCommandEvent
Definition:
SendCommandEvent.h:27
SendCommandEvent::SendWaiter::setResult
void setResult(bool success, const QString &errmsg=QString())
Definition:
SendCommandEvent.cpp:31
SendCommandEvent::SendWaiter::Waiting
Definition:
SendCommandEvent.h:33
SendCommandEvent::_cmd
ControlCommand _cmd
Definition:
SendCommandEvent.h:56
SendCommandEvent::command
ControlCommand command()
Definition:
SendCommandEvent.h:51
SendCommandEvent::_waiter
SendWaiter * _waiter
Definition:
SendCommandEvent.h:57
SendCommandEvent::SendCommandEvent
SendCommandEvent(const ControlCommand &cmd, SendWaiter *w=0)
Definition:
SendCommandEvent.cpp:22
SendCommandEvent::SendWaiter::_mutex
QMutex _mutex
Definition:
SendCommandEvent.h:43
SendCommandEvent::SendWaiter::status
SenderStatus status()
Definition:
SendCommandEvent.cpp:62
SendCommandEvent::SendWaiter::_waitCond
QWaitCondition _waitCond
Definition:
SendCommandEvent.h:44
SendCommandEvent::SendWaiter
Definition:
SendCommandEvent.h:30
SendCommandEvent::SendWaiter::_status
enum SendCommandEvent::SendWaiter::SenderStatus _status
SendCommandEvent::SendWaiter::Success
Definition:
SendCommandEvent.h:33
SendCommandEvent::SendWaiter::getResult
bool getResult(QString *errmsg=0)
Definition:
SendCommandEvent.cpp:42
SendCommandEvent::waiter
SendWaiter * waiter()
Definition:
SendCommandEvent.h:53
SendCommandEvent::SendWaiter::Failed
Definition:
SendCommandEvent.h:33
ControlCommand
Definition:
ControlCommand.h:22
ControlCommand.h
SendCommandEvent::SendWaiter::SendWaiter
SendWaiter()
Definition:
SendCommandEvent.h:35
SendCommandEvent::SendWaiter::_errmsg
QString _errmsg
Definition:
SendCommandEvent.h:45
SendCommandEvent::SendWaiter::SenderStatus
SenderStatus
Definition:
SendCommandEvent.h:33
Generated by
1.8.12