Vidalia  0.2.21
SendCommandEvent.cpp
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 SendEommandEvent.cpp
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 #include "SendCommandEvent.h"
18 
19 #include <QMutexLocker>
20 
21 
23  : QEvent(QEvent::User)
24 {
25  _cmd = cmd;
26  _waiter = w;
27 }
28 
29 /** Sets the result of the send operation. */
30 void
31 SendCommandEvent::SendWaiter::setResult(bool success, const QString &errmsg)
32 {
33  _mutex.lock();
34  _status = (success ? Success : Failed);
35  _errmsg = errmsg;
36  _mutex.unlock();
37  _waitCond.wakeAll();
38 }
39 
40 /** Waits for and gets the result of the send operation. */
41 bool
43 {
44  forever {
45  _mutex.lock();
46  if (_status == Waiting) {
47  _waitCond.wait(&_mutex);
48  _mutex.unlock();
49  } else {
50  _mutex.unlock();
51  break;
52  }
53  }
54  if (errmsg) {
55  *errmsg = _errmsg;
56  }
57  return (_status == Success);
58 }
59 
60 /** Returns the SendWaiter's current SenderStatus value. */
63 {
64  QMutexLocker locker(&_mutex);
65  return _status;
66 }