Vidalia 0.2.10
|
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 SendEommandEvent.cpp 00013 ** \version $Id: SendCommandEvent.cpp 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 #include "SendCommandEvent.h" 00019 00020 #include <QMutexLocker> 00021 00022 00023 SendCommandEvent::SendCommandEvent(const ControlCommand &cmd, SendWaiter *w) 00024 : QEvent(QEvent::User) 00025 { 00026 _cmd = cmd; 00027 _waiter = w; 00028 } 00029 00030 /** Sets the result of the send operation. */ 00031 void 00032 SendCommandEvent::SendWaiter::setResult(bool success, const QString &errmsg) 00033 { 00034 _mutex.lock(); 00035 _status = (success ? Success : Failed); 00036 _errmsg = errmsg; 00037 _mutex.unlock(); 00038 _waitCond.wakeAll(); 00039 } 00040 00041 /** Waits for and gets the result of the send operation. */ 00042 bool 00043 SendCommandEvent::SendWaiter::getResult(QString *errmsg) 00044 { 00045 forever { 00046 _mutex.lock(); 00047 if (_status == Waiting) { 00048 _waitCond.wait(&_mutex); 00049 _mutex.unlock(); 00050 } else { 00051 _mutex.unlock(); 00052 break; 00053 } 00054 } 00055 if (errmsg) { 00056 *errmsg = _errmsg; 00057 } 00058 return (_status == Success); 00059 } 00060 00061 /** Returns the SendWaiter's current SenderStatus value. */ 00062 SendCommandEvent::SendWaiter::SenderStatus 00063 SendCommandEvent::SendWaiter::status() 00064 { 00065 QMutexLocker locker(&_mutex); 00066 return _status; 00067 }