TorService Class Reference

#include <TorService.h>

List of all members.

Signals

void started ()
void finished (int exitCode, QProcess::ExitStatus)
void startFailed (QString error)

Public Member Functions

 TorService (QObject *parent=0)
 ~TorService ()
bool isInstalled ()
bool isRunning ()
void start ()
bool stop ()
int exitCode ()
QProcess::ExitStatus exitStatus ()
bool install (const QString &torPath, const QString &torrc, quint16 controlPort)
bool remove ()

Static Public Member Functions

static bool isSupported ()
static bool loadServiceFunctions ()

Private Member Functions

SC_HANDLE openService ()
DWORD status ()

Static Private Member Functions

static SC_HANDLE openSCM ()
static void closeHandle (SC_HANDLE handle)

Private Attributes

SC_HANDLE _scm

Static Private Attributes

static ServiceFunctions _service_fns


Detailed Description

Definition at line 94 of file TorService.h.


Constructor & Destructor Documentation

TorService::TorService ( QObject *  parent = 0  ) 

Default ctor.

Definition at line 35 of file TorService.cpp.

References _scm, and openSCM().

TorService::~TorService (  ) 

Default dtor.

Definition at line 42 of file TorService.cpp.

References _scm, and closeHandle().


Member Function Documentation

void TorService::closeHandle ( SC_HANDLE  handle  )  [static, private]

Closes the service handle.

Definition at line 111 of file TorService.cpp.

References _service_fns, ServiceFunctions::CloseServiceHandle, and loadServiceFunctions().

Referenced by exitCode(), install(), isInstalled(), remove(), start(), status(), stop(), and ~TorService().

int TorService::exitCode (  ) 

Returns the exit code of the last Tor service that finished.

Definition at line 204 of file TorService.cpp.

References _service_fns, closeHandle(), openService(), ServiceFunctions::QueryServiceStatus, and UNKNOWN_EXIT_CODE.

Referenced by stop().

QProcess::ExitStatus TorService::exitStatus (  ) 

Returns the exit status of the last Tor service that finished.

Definition at line 226 of file TorService.cpp.

Referenced by stop().

void TorService::finished ( int  exitCode,
QProcess::ExitStatus   
) [signal]

Called when the service gets stopped.

Referenced by stop().

bool TorService::install ( const QString &  torPath,
const QString &  torrc,
quint16  controlPort 
)

Installs the Tor service.

Installs the Tor service. Returns true if the service was successfully installed or already exists.

Definition at line 240 of file TorService.cpp.

References _scm, _service_fns, ServiceFunctions::ChangeServiceConfig2A, closeHandle(), ServiceFunctions::CreateServiceA, tc::debug(), tc::error(), openService(), TOR_SERVICE_ACCESS, TOR_SERVICE_DESC, TOR_SERVICE_DISP, and TOR_SERVICE_NAME.

bool TorService::isInstalled (  ) 

Returns true if the Tor service is installed.

Definition at line 120 of file TorService.cpp.

References closeHandle(), and openService().

Referenced by AdvancedPage::load().

bool TorService::isRunning (  ) 

Returns true if the Tor service is running.

Definition at line 131 of file TorService.cpp.

References status().

bool TorService::isSupported (  )  [static]

Returns if services are supported.

Returns true if services are supported.

Definition at line 49 of file TorService.cpp.

Referenced by AdvancedPage::AdvancedPage(), loadServiceFunctions(), and TorControl::start().

bool TorService::loadServiceFunctions (  )  [static]

Dynamically loads NT service related functions from advapi32.dll.

Dyanmically loads NT service related functions from advapi32.dll. This function is adapted from Tor's nt_service_load_library() function. See LICENSE for details on Tor's license.

Definition at line 58 of file TorService.cpp.

References _service_fns, isSupported(), LOAD_SERVICE_FN, and ServiceFunctions::loaded.

Referenced by closeHandle(), openSCM(), and openService().

SC_HANDLE TorService::openSCM (  )  [static, private]

Opens a handle to the service control manager. Returns NULL on error.

Definition at line 102 of file TorService.cpp.

References _service_fns, loadServiceFunctions(), and ServiceFunctions::OpenSCManagerA.

Referenced by TorService().

SC_HANDLE TorService::openService (  )  [private]

Opens a handle to the Tor service. Returns NULL on error.

Definition at line 89 of file TorService.cpp.

References _scm, _service_fns, loadServiceFunctions(), ServiceFunctions::OpenServiceA, TOR_SERVICE_ACCESS, and TOR_SERVICE_NAME.

Referenced by exitCode(), install(), isInstalled(), remove(), start(), status(), and stop().

bool TorService::remove (  ) 

Removes the Tor service.

Removes the Tor service. Returns true if the service was removed successfully or does not exist.

Definition at line 281 of file TorService.cpp.

References _service_fns, closeHandle(), tc::debug(), ServiceFunctions::DeleteService, tc::error(), openService(), and stop().

void TorService::start (  ) 

Starts the Tor service. Emits started on success.

Starts Tor service.

Definition at line 138 of file TorService.cpp.

References _service_fns, closeHandle(), tc::debug(), tc::error(), openService(), started(), startFailed(), ServiceFunctions::StartServiceA, and status().

void TorService::started (  )  [signal]

Called when the service gets started.

Referenced by start().

void TorService::startFailed ( QString  error  )  [signal]

Called when there is an error in starting the service.

Referenced by start().

DWORD TorService::status (  )  [private]

Gets the status of the Tor service.

Definition at line 301 of file TorService.cpp.

References _service_fns, closeHandle(), openService(), ServiceFunctions::QueryServiceStatus, and SERVICE_ERROR.

Referenced by isRunning(), start(), and stop().

bool TorService::stop (  ) 

Stops the Tor service. Emits finished on success.

Stops Tor service.

Definition at line 169 of file TorService.cpp.

References _service_fns, closeHandle(), ServiceFunctions::ControlService, tc::debug(), tc::error(), exitCode(), exitStatus(), finished(), openService(), and status().

Referenced by remove().


Member Data Documentation

SC_HANDLE TorService::_scm [private]

Handle to the service control manager.

Definition at line 146 of file TorService.h.

Referenced by install(), openService(), TorService(), and ~TorService().

Initial value:

 
  { false,
    NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL
  }
List of dynamically loaded NT service functions.

Definition at line 148 of file TorService.h.

Referenced by closeHandle(), exitCode(), install(), loadServiceFunctions(), openSCM(), openService(), remove(), start(), status(), and stop().


The documentation for this class was generated from the following files:

Generated on Mon Aug 30 19:14:04 2010 for Vidalia by  doxygen 1.5.9