Remove unused dbus.cc/.h and related things.
BUG=none Review-Url: https://codereview.webrtc.org/2520533002 Cr-Commit-Position: refs/heads/master@{#15155}
This commit is contained in:
@ -97,12 +97,6 @@ config("common_inherited_config") {
|
||||
# }
|
||||
}
|
||||
|
||||
if (rtc_have_dbus_glib) {
|
||||
pkg_config("dbus-glib") {
|
||||
packages = [ "dbus-glib-1" ]
|
||||
}
|
||||
}
|
||||
|
||||
config("common_config") {
|
||||
cflags = []
|
||||
cflags_cc = []
|
||||
@ -116,16 +110,6 @@ config("common_config") {
|
||||
defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ]
|
||||
}
|
||||
|
||||
if (rtc_have_dbus_glib) {
|
||||
defines += [ "HAVE_DBUS_GLIB" ]
|
||||
|
||||
# TODO(kjellander): Investigate this, it seems like include <dbus/dbus.h>
|
||||
# is still not found even if the execution of
|
||||
# build/config/linux/pkg-config.py dbus-glib-1 returns correct include
|
||||
# dirs on Linux.
|
||||
all_dependent_configs = [ "dbus-glib" ]
|
||||
}
|
||||
|
||||
if (rtc_relative_path) {
|
||||
defines += [ "EXPAT_RELATIVE_PATH" ]
|
||||
}
|
||||
|
||||
@ -561,10 +561,6 @@ rtc_static_library("rtc_base") {
|
||||
|
||||
if (is_linux) {
|
||||
sources += [
|
||||
"dbus.cc",
|
||||
"dbus.h",
|
||||
"libdbusglibsymboltable.cc",
|
||||
"libdbusglibsymboltable.h",
|
||||
"linuxfdwalk.c",
|
||||
"linuxfdwalk.h",
|
||||
]
|
||||
|
||||
@ -1,401 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
|
||||
#include "webrtc/base/dbus.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "webrtc/base/logging.h"
|
||||
#include "webrtc/base/thread.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
// Avoid static object construction/destruction on startup/shutdown.
|
||||
static pthread_once_t g_dbus_init_once = PTHREAD_ONCE_INIT;
|
||||
static LibDBusGlibSymbolTable *g_dbus_symbol = NULL;
|
||||
|
||||
// Releases DBus-Glib symbols.
|
||||
static void ReleaseDBusGlibSymbol() {
|
||||
if (g_dbus_symbol != NULL) {
|
||||
delete g_dbus_symbol;
|
||||
g_dbus_symbol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Loads DBus-Glib symbols.
|
||||
static void InitializeDBusGlibSymbol() {
|
||||
// This is thread safe.
|
||||
if (NULL == g_dbus_symbol) {
|
||||
g_dbus_symbol = new LibDBusGlibSymbolTable();
|
||||
|
||||
// Loads dbus-glib
|
||||
if (NULL == g_dbus_symbol || !g_dbus_symbol->Load()) {
|
||||
LOG(LS_WARNING) << "Failed to load dbus-glib symbol table.";
|
||||
ReleaseDBusGlibSymbol();
|
||||
} else {
|
||||
// Nothing we can do if atexit() failed. Just ignore its returned value.
|
||||
atexit(ReleaseDBusGlibSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline static LibDBusGlibSymbolTable *GetSymbols() {
|
||||
return DBusMonitor::GetDBusGlibSymbolTable();
|
||||
}
|
||||
|
||||
// Implementation of class DBusSigMessageData
|
||||
DBusSigMessageData::DBusSigMessageData(DBusMessage *message)
|
||||
: TypedMessageData<DBusMessage *>(message) {
|
||||
GetSymbols()->dbus_message_ref()(data());
|
||||
}
|
||||
|
||||
DBusSigMessageData::~DBusSigMessageData() {
|
||||
GetSymbols()->dbus_message_unref()(data());
|
||||
}
|
||||
|
||||
// Implementation of class DBusSigFilter
|
||||
|
||||
// Builds a DBus filter string from given DBus path, interface and member.
|
||||
std::string DBusSigFilter::BuildFilterString(const std::string &path,
|
||||
const std::string &interface,
|
||||
const std::string &member) {
|
||||
std::string ret(DBUS_TYPE "='" DBUS_SIGNAL "'");
|
||||
if (!path.empty()) {
|
||||
ret += ("," DBUS_PATH "='");
|
||||
ret += path;
|
||||
ret += "'";
|
||||
}
|
||||
if (!interface.empty()) {
|
||||
ret += ("," DBUS_INTERFACE "='");
|
||||
ret += interface;
|
||||
ret += "'";
|
||||
}
|
||||
if (!member.empty()) {
|
||||
ret += ("," DBUS_MEMBER "='");
|
||||
ret += member;
|
||||
ret += "'";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Forwards the message to the given instance.
|
||||
DBusHandlerResult DBusSigFilter::DBusCallback(DBusConnection *dbus_conn,
|
||||
DBusMessage *message,
|
||||
void *instance) {
|
||||
ASSERT(instance);
|
||||
if (instance) {
|
||||
return static_cast<DBusSigFilter *>(instance)->Callback(message);
|
||||
}
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
}
|
||||
|
||||
// Posts a message to caller thread.
|
||||
DBusHandlerResult DBusSigFilter::Callback(DBusMessage *message) {
|
||||
if (caller_thread_) {
|
||||
caller_thread_->Post(RTC_FROM_HERE, this, DSM_SIGNAL,
|
||||
new DBusSigMessageData(message));
|
||||
}
|
||||
// Don't "eat" the message here. Let it pop up.
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
}
|
||||
|
||||
// From MessageHandler.
|
||||
void DBusSigFilter::OnMessage(Message *message) {
|
||||
if (message != NULL && DSM_SIGNAL == message->message_id) {
|
||||
DBusSigMessageData *msg =
|
||||
static_cast<DBusSigMessageData *>(message->pdata);
|
||||
if (msg) {
|
||||
ProcessSignal(msg->data());
|
||||
delete msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Definition of private class DBusMonitoringThread.
|
||||
// It creates a worker-thread to listen signals on DBus. The worker-thread will
|
||||
// be running in a priate GMainLoop forever until either Stop() has been invoked
|
||||
// or it hits an error.
|
||||
class DBusMonitor::DBusMonitoringThread : public rtc::Thread {
|
||||
public:
|
||||
explicit DBusMonitoringThread(DBusMonitor *monitor,
|
||||
GMainContext *context,
|
||||
GMainLoop *mainloop,
|
||||
std::vector<DBusSigFilter *> *filter_list)
|
||||
: monitor_(monitor),
|
||||
context_(context),
|
||||
mainloop_(mainloop),
|
||||
connection_(NULL),
|
||||
idle_source_(NULL),
|
||||
filter_list_(filter_list) {
|
||||
ASSERT(monitor_);
|
||||
ASSERT(context_);
|
||||
ASSERT(mainloop_);
|
||||
ASSERT(filter_list_);
|
||||
}
|
||||
|
||||
virtual ~DBusMonitoringThread() {
|
||||
Stop();
|
||||
}
|
||||
|
||||
// Override virtual method of Thread. Context: worker-thread.
|
||||
virtual void Run() {
|
||||
ASSERT(NULL == connection_);
|
||||
|
||||
// Setup DBus connection and start monitoring.
|
||||
monitor_->OnMonitoringStatusChanged(DMS_INITIALIZING);
|
||||
if (!Setup()) {
|
||||
LOG(LS_ERROR) << "DBus monitoring setup failed.";
|
||||
monitor_->OnMonitoringStatusChanged(DMS_FAILED);
|
||||
CleanUp();
|
||||
return;
|
||||
}
|
||||
monitor_->OnMonitoringStatusChanged(DMS_RUNNING);
|
||||
g_main_loop_run(mainloop_);
|
||||
monitor_->OnMonitoringStatusChanged(DMS_STOPPED);
|
||||
|
||||
// Done normally. Clean up DBus connection.
|
||||
CleanUp();
|
||||
return;
|
||||
}
|
||||
|
||||
// Override virtual method of Thread. Context: caller-thread.
|
||||
virtual void Stop() {
|
||||
ASSERT(NULL == idle_source_);
|
||||
// Add an idle source and let the gmainloop quit on idle.
|
||||
idle_source_ = g_idle_source_new();
|
||||
if (idle_source_) {
|
||||
g_source_set_callback(idle_source_, &Idle, this, NULL);
|
||||
g_source_attach(idle_source_, context_);
|
||||
} else {
|
||||
LOG(LS_ERROR) << "g_idle_source_new() failed.";
|
||||
QuitGMainloop(); // Try to quit anyway.
|
||||
}
|
||||
|
||||
Thread::Stop(); // Wait for the thread.
|
||||
}
|
||||
|
||||
private:
|
||||
// Registers all DBus filters.
|
||||
void RegisterAllFilters() {
|
||||
ASSERT(NULL != GetSymbols()->dbus_g_connection_get_connection()(
|
||||
connection_));
|
||||
|
||||
for (std::vector<DBusSigFilter *>::iterator it = filter_list_->begin();
|
||||
it != filter_list_->end(); ++it) {
|
||||
DBusSigFilter *filter = (*it);
|
||||
if (!filter) {
|
||||
LOG(LS_ERROR) << "DBusSigFilter list corrupted.";
|
||||
continue;
|
||||
}
|
||||
|
||||
GetSymbols()->dbus_bus_add_match()(
|
||||
GetSymbols()->dbus_g_connection_get_connection()(connection_),
|
||||
filter->filter().c_str(), NULL);
|
||||
|
||||
if (!GetSymbols()->dbus_connection_add_filter()(
|
||||
GetSymbols()->dbus_g_connection_get_connection()(connection_),
|
||||
&DBusSigFilter::DBusCallback, filter, NULL)) {
|
||||
LOG(LS_ERROR) << "dbus_connection_add_filter() failed."
|
||||
<< "Filter: " << filter->filter();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unregisters all DBus filters.
|
||||
void UnRegisterAllFilters() {
|
||||
ASSERT(NULL != GetSymbols()->dbus_g_connection_get_connection()(
|
||||
connection_));
|
||||
|
||||
for (std::vector<DBusSigFilter *>::iterator it = filter_list_->begin();
|
||||
it != filter_list_->end(); ++it) {
|
||||
DBusSigFilter *filter = (*it);
|
||||
if (!filter) {
|
||||
LOG(LS_ERROR) << "DBusSigFilter list corrupted.";
|
||||
continue;
|
||||
}
|
||||
GetSymbols()->dbus_connection_remove_filter()(
|
||||
GetSymbols()->dbus_g_connection_get_connection()(connection_),
|
||||
&DBusSigFilter::DBusCallback, filter);
|
||||
}
|
||||
}
|
||||
|
||||
// Sets up the monitoring thread.
|
||||
bool Setup() {
|
||||
g_main_context_push_thread_default(context_);
|
||||
|
||||
// Start connection to dbus.
|
||||
// If dbus daemon is not running, returns false immediately.
|
||||
connection_ = GetSymbols()->dbus_g_bus_get_private()(monitor_->type_,
|
||||
context_, NULL);
|
||||
if (NULL == connection_) {
|
||||
LOG(LS_ERROR) << "dbus_g_bus_get_private() unable to get connection.";
|
||||
return false;
|
||||
}
|
||||
if (NULL == GetSymbols()->dbus_g_connection_get_connection()(connection_)) {
|
||||
LOG(LS_ERROR) << "dbus_g_connection_get_connection() returns NULL. "
|
||||
<< "DBus daemon is probably not running.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Application don't exit if DBus daemon die.
|
||||
GetSymbols()->dbus_connection_set_exit_on_disconnect()(
|
||||
GetSymbols()->dbus_g_connection_get_connection()(connection_), FALSE);
|
||||
|
||||
// Connect all filters.
|
||||
RegisterAllFilters();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cleans up the monitoring thread.
|
||||
void CleanUp() {
|
||||
if (idle_source_) {
|
||||
// We did an attach() with the GSource, so we need to destroy() it.
|
||||
g_source_destroy(idle_source_);
|
||||
// We need to unref() the GSource to end the last reference we got.
|
||||
g_source_unref(idle_source_);
|
||||
idle_source_ = NULL;
|
||||
}
|
||||
if (connection_) {
|
||||
if (GetSymbols()->dbus_g_connection_get_connection()(connection_)) {
|
||||
UnRegisterAllFilters();
|
||||
GetSymbols()->dbus_connection_close()(
|
||||
GetSymbols()->dbus_g_connection_get_connection()(connection_));
|
||||
}
|
||||
GetSymbols()->dbus_g_connection_unref()(connection_);
|
||||
connection_ = NULL;
|
||||
}
|
||||
g_main_loop_unref(mainloop_);
|
||||
mainloop_ = NULL;
|
||||
g_main_context_unref(context_);
|
||||
context_ = NULL;
|
||||
}
|
||||
|
||||
// Handles callback on Idle. We only add this source when ready to stop.
|
||||
static gboolean Idle(gpointer data) {
|
||||
static_cast<DBusMonitoringThread *>(data)->QuitGMainloop();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// We only hit this when ready to quit.
|
||||
void QuitGMainloop() {
|
||||
g_main_loop_quit(mainloop_);
|
||||
}
|
||||
|
||||
DBusMonitor *monitor_;
|
||||
|
||||
GMainContext *context_;
|
||||
GMainLoop *mainloop_;
|
||||
DBusGConnection *connection_;
|
||||
GSource *idle_source_;
|
||||
|
||||
std::vector<DBusSigFilter *> *filter_list_;
|
||||
};
|
||||
|
||||
// Implementation of class DBusMonitor
|
||||
|
||||
// Returns DBus-Glib symbol handle. Initialize it first if hasn't.
|
||||
LibDBusGlibSymbolTable *DBusMonitor::GetDBusGlibSymbolTable() {
|
||||
// This is multi-thread safe.
|
||||
pthread_once(&g_dbus_init_once, InitializeDBusGlibSymbol);
|
||||
|
||||
return g_dbus_symbol;
|
||||
};
|
||||
|
||||
// Creates an instance of DBusMonitor
|
||||
DBusMonitor *DBusMonitor::Create(DBusBusType type) {
|
||||
if (NULL == DBusMonitor::GetDBusGlibSymbolTable()) {
|
||||
return NULL;
|
||||
}
|
||||
return new DBusMonitor(type);
|
||||
}
|
||||
|
||||
DBusMonitor::DBusMonitor(DBusBusType type)
|
||||
: type_(type),
|
||||
status_(DMS_NOT_INITIALIZED),
|
||||
monitoring_thread_(NULL) {
|
||||
ASSERT(type_ == DBUS_BUS_SYSTEM || type_ == DBUS_BUS_SESSION);
|
||||
}
|
||||
|
||||
DBusMonitor::~DBusMonitor() {
|
||||
StopMonitoring();
|
||||
}
|
||||
|
||||
bool DBusMonitor::AddFilter(DBusSigFilter *filter) {
|
||||
if (monitoring_thread_) {
|
||||
return false;
|
||||
}
|
||||
if (!filter) {
|
||||
return false;
|
||||
}
|
||||
filter_list_.push_back(filter);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBusMonitor::StartMonitoring() {
|
||||
if (!monitoring_thread_) {
|
||||
g_type_init();
|
||||
// g_thread_init API is deprecated since glib 2.31.0, see release note:
|
||||
// http://mail.gnome.org/archives/gnome-announce-list/2011-October/msg00041.html
|
||||
#if !GLIB_CHECK_VERSION(2, 31, 0)
|
||||
g_thread_init(NULL);
|
||||
#endif
|
||||
GetSymbols()->dbus_g_thread_init()();
|
||||
|
||||
GMainContext *context = g_main_context_new();
|
||||
if (NULL == context) {
|
||||
LOG(LS_ERROR) << "g_main_context_new() failed.";
|
||||
return false;
|
||||
}
|
||||
|
||||
GMainLoop *mainloop = g_main_loop_new(context, FALSE);
|
||||
if (NULL == mainloop) {
|
||||
LOG(LS_ERROR) << "g_main_loop_new() failed.";
|
||||
g_main_context_unref(context);
|
||||
return false;
|
||||
}
|
||||
|
||||
monitoring_thread_ = new DBusMonitoringThread(this, context, mainloop,
|
||||
&filter_list_);
|
||||
if (monitoring_thread_ == NULL) {
|
||||
LOG(LS_ERROR) << "Failed to create DBus monitoring thread.";
|
||||
g_main_context_unref(context);
|
||||
g_main_loop_unref(mainloop);
|
||||
return false;
|
||||
}
|
||||
monitoring_thread_->Start();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBusMonitor::StopMonitoring() {
|
||||
if (monitoring_thread_) {
|
||||
monitoring_thread_->Stop();
|
||||
monitoring_thread_ = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DBusMonitor::DBusMonitorStatus DBusMonitor::GetStatus() {
|
||||
return status_;
|
||||
}
|
||||
|
||||
void DBusMonitor::OnMonitoringStatusChanged(DBusMonitorStatus status) {
|
||||
status_ = status;
|
||||
}
|
||||
|
||||
#undef LATE
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // HAVE_DBUS_GLIB
|
||||
@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_BASE_DBUS_H_
|
||||
#define WEBRTC_BASE_DBUS_H_
|
||||
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/libdbusglibsymboltable.h"
|
||||
#include "webrtc/base/messagehandler.h"
|
||||
#include "webrtc/base/thread.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
#define DBUS_TYPE "type"
|
||||
#define DBUS_SIGNAL "signal"
|
||||
#define DBUS_PATH "path"
|
||||
#define DBUS_INTERFACE "interface"
|
||||
#define DBUS_MEMBER "member"
|
||||
|
||||
#ifdef CHROMEOS
|
||||
#define CROS_PM_PATH "/"
|
||||
#define CROS_PM_INTERFACE "org.chromium.PowerManager"
|
||||
#define CROS_SIG_POWERCHANGED "PowerStateChanged"
|
||||
#define CROS_VALUE_SLEEP "mem"
|
||||
#define CROS_VALUE_RESUME "on"
|
||||
#else
|
||||
#define UP_PATH "/org/freedesktop/UPower"
|
||||
#define UP_INTERFACE "org.freedesktop.UPower"
|
||||
#define UP_SIG_SLEEPING "Sleeping"
|
||||
#define UP_SIG_RESUMING "Resuming"
|
||||
#endif // CHROMEOS
|
||||
|
||||
// Wraps a DBus messages.
|
||||
class DBusSigMessageData : public TypedMessageData<DBusMessage *> {
|
||||
public:
|
||||
explicit DBusSigMessageData(DBusMessage *message);
|
||||
~DBusSigMessageData();
|
||||
};
|
||||
|
||||
// DBusSigFilter is an abstract class that defines the interface of DBus
|
||||
// signal handling.
|
||||
// The subclasses implement ProcessSignal() for various purposes.
|
||||
// When a DBus signal comes, a DSM_SIGNAL message is posted to the caller thread
|
||||
// which will then invokes ProcessSignal().
|
||||
class DBusSigFilter : protected MessageHandler {
|
||||
public:
|
||||
enum DBusSigMessage { DSM_SIGNAL };
|
||||
|
||||
// This filter string should ususally come from BuildFilterString()
|
||||
explicit DBusSigFilter(const std::string &filter)
|
||||
: caller_thread_(Thread::Current()), filter_(filter) {
|
||||
}
|
||||
|
||||
// Builds a DBus monitor filter string from given DBus path, interface, and
|
||||
// member.
|
||||
// See http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html
|
||||
static std::string BuildFilterString(const std::string &path,
|
||||
const std::string &interface,
|
||||
const std::string &member);
|
||||
|
||||
// Handles callback on DBus messages by DBus system.
|
||||
static DBusHandlerResult DBusCallback(DBusConnection *dbus_conn,
|
||||
DBusMessage *message,
|
||||
void *instance);
|
||||
|
||||
// Handles callback on DBus messages to each DBusSigFilter instance.
|
||||
DBusHandlerResult Callback(DBusMessage *message);
|
||||
|
||||
// From MessageHandler.
|
||||
virtual void OnMessage(Message *message);
|
||||
|
||||
// Returns the DBus monitor filter string.
|
||||
const std::string &filter() const { return filter_; }
|
||||
|
||||
private:
|
||||
// On caller thread.
|
||||
virtual void ProcessSignal(DBusMessage *message) = 0;
|
||||
|
||||
Thread *caller_thread_;
|
||||
const std::string filter_;
|
||||
};
|
||||
|
||||
// DBusMonitor is a class for DBus signal monitoring.
|
||||
//
|
||||
// The caller-thread calls AddFilter() first to add the signals that it wants to
|
||||
// monitor and then calls StartMonitoring() to start the monitoring.
|
||||
// This will create a worker-thread which listens on DBus connection and sends
|
||||
// DBus signals back through the callback.
|
||||
// The worker-thread will be running forever until either StopMonitoring() is
|
||||
// called from the caller-thread or the worker-thread hit some error.
|
||||
//
|
||||
// Programming model:
|
||||
// 1. Caller-thread: Creates an object of DBusMonitor.
|
||||
// 2. Caller-thread: Calls DBusMonitor::AddFilter() one or several times.
|
||||
// 3. Caller-thread: StartMonitoring().
|
||||
// ...
|
||||
// 4. Worker-thread: DBus signal recieved. Post a message to caller-thread.
|
||||
// 5. Caller-thread: DBusFilterBase::ProcessSignal() is invoked.
|
||||
// ...
|
||||
// 6. Caller-thread: StopMonitoring().
|
||||
//
|
||||
// Assumption:
|
||||
// AddFilter(), StartMonitoring(), and StopMonitoring() methods are called by
|
||||
// a single thread. Hence, there is no need to make them thread safe.
|
||||
class DBusMonitor {
|
||||
public:
|
||||
// Status of DBus monitoring.
|
||||
enum DBusMonitorStatus {
|
||||
DMS_NOT_INITIALIZED, // Not initialized.
|
||||
DMS_INITIALIZING, // Initializing the monitoring thread.
|
||||
DMS_RUNNING, // Monitoring.
|
||||
DMS_STOPPED, // Not monitoring. Stopped normally.
|
||||
DMS_FAILED, // Not monitoring. Failed.
|
||||
};
|
||||
|
||||
// Returns the DBus-Glib symbol table.
|
||||
// We should only use this function to access DBus-Glib symbols.
|
||||
static LibDBusGlibSymbolTable *GetDBusGlibSymbolTable();
|
||||
|
||||
// Creates an instance of DBusMonitor.
|
||||
static DBusMonitor *Create(DBusBusType type);
|
||||
~DBusMonitor();
|
||||
|
||||
// Adds a filter to DBusMonitor.
|
||||
bool AddFilter(DBusSigFilter *filter);
|
||||
|
||||
// Starts DBus message monitoring.
|
||||
bool StartMonitoring();
|
||||
|
||||
// Stops DBus message monitoring.
|
||||
bool StopMonitoring();
|
||||
|
||||
// Gets the status of DBus monitoring.
|
||||
DBusMonitorStatus GetStatus();
|
||||
|
||||
private:
|
||||
// Forward declaration. Defined in the .cc file.
|
||||
class DBusMonitoringThread;
|
||||
|
||||
explicit DBusMonitor(DBusBusType type);
|
||||
|
||||
// Updates status_ when monitoring status has changed.
|
||||
void OnMonitoringStatusChanged(DBusMonitorStatus status);
|
||||
|
||||
DBusBusType type_;
|
||||
DBusMonitorStatus status_;
|
||||
DBusMonitoringThread *monitoring_thread_;
|
||||
std::vector<DBusSigFilter *> filter_list_;
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // HAVE_DBUS_GLIB
|
||||
|
||||
#endif // WEBRTC_BASE_DBUS_H_
|
||||
@ -1,234 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "webrtc/base/dbus.h"
|
||||
#include "webrtc/base/gunit.h"
|
||||
#include "webrtc/base/thread.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
#define SIG_NAME "NameAcquired"
|
||||
|
||||
static const uint32_t kTimeoutMs = 5000U;
|
||||
|
||||
class DBusSigFilterTest : public DBusSigFilter {
|
||||
public:
|
||||
// DBusSigFilterTest listens on DBus service itself for "NameAcquired" signal.
|
||||
// This signal should be received when the application connects to DBus
|
||||
// service and gains ownership of a name.
|
||||
// http://dbus.freedesktop.org/doc/dbus-specification.html
|
||||
DBusSigFilterTest()
|
||||
: DBusSigFilter(GetFilter()),
|
||||
message_received_(false) {
|
||||
}
|
||||
|
||||
bool MessageReceived() {
|
||||
return message_received_;
|
||||
}
|
||||
|
||||
private:
|
||||
static std::string GetFilter() {
|
||||
return rtc::DBusSigFilter::BuildFilterString("", "", SIG_NAME);
|
||||
}
|
||||
|
||||
// Implement virtual method of DBusSigFilter. On caller thread.
|
||||
virtual void ProcessSignal(DBusMessage *message) {
|
||||
EXPECT_TRUE(message != NULL);
|
||||
message_received_ = true;
|
||||
}
|
||||
|
||||
bool message_received_;
|
||||
};
|
||||
|
||||
TEST(DBusMonitorTest, StartStopStartStop) {
|
||||
DBusSigFilterTest filter;
|
||||
std::unique_ptr<rtc::DBusMonitor> monitor;
|
||||
monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM));
|
||||
if (monitor) {
|
||||
EXPECT_TRUE(monitor->AddFilter(&filter));
|
||||
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_NOT_INITIALIZED);
|
||||
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs);
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs);
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_RUNNING);
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
} else {
|
||||
LOG(LS_WARNING) << "DBus Monitor not started. Skipping test.";
|
||||
}
|
||||
}
|
||||
|
||||
// DBusMonitorTest listens on DBus service itself for "NameAcquired" signal.
|
||||
// This signal should be received when the application connects to DBus
|
||||
// service and gains ownership of a name.
|
||||
// This test is to make sure that we capture the "NameAcquired" signal.
|
||||
TEST(DBusMonitorTest, ReceivedNameAcquiredSignal) {
|
||||
DBusSigFilterTest filter;
|
||||
std::unique_ptr<rtc::DBusMonitor> monitor;
|
||||
monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM));
|
||||
if (monitor) {
|
||||
EXPECT_TRUE(monitor->AddFilter(&filter));
|
||||
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs);
|
||||
EXPECT_TRUE_WAIT(filter.MessageReceived(), kTimeoutMs);
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
} else {
|
||||
LOG(LS_WARNING) << "DBus Monitor not started. Skipping test.";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DBusMonitorTest, ConcurrentMonitors) {
|
||||
DBusSigFilterTest filter1;
|
||||
std::unique_ptr<rtc::DBusMonitor> monitor1;
|
||||
monitor1.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM));
|
||||
if (monitor1) {
|
||||
EXPECT_TRUE(monitor1->AddFilter(&filter1));
|
||||
DBusSigFilterTest filter2;
|
||||
std::unique_ptr<rtc::DBusMonitor> monitor2;
|
||||
monitor2.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM));
|
||||
EXPECT_TRUE(monitor2->AddFilter(&filter2));
|
||||
|
||||
EXPECT_TRUE(monitor1->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor1->GetStatus(), kTimeoutMs);
|
||||
EXPECT_TRUE(monitor2->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor2->GetStatus(), kTimeoutMs);
|
||||
|
||||
EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs);
|
||||
EXPECT_TRUE(monitor2->StopMonitoring());
|
||||
EXPECT_EQ(monitor2->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
|
||||
EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs);
|
||||
EXPECT_TRUE(monitor1->StopMonitoring());
|
||||
EXPECT_EQ(monitor1->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
} else {
|
||||
LOG(LS_WARNING) << "DBus Monitor not started. Skipping test.";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DBusMonitorTest, ConcurrentFilters) {
|
||||
DBusSigFilterTest filter1;
|
||||
DBusSigFilterTest filter2;
|
||||
std::unique_ptr<rtc::DBusMonitor> monitor;
|
||||
monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM));
|
||||
if (monitor) {
|
||||
EXPECT_TRUE(monitor->AddFilter(&filter1));
|
||||
EXPECT_TRUE(monitor->AddFilter(&filter2));
|
||||
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs);
|
||||
|
||||
EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs);
|
||||
EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs);
|
||||
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
} else {
|
||||
LOG(LS_WARNING) << "DBus Monitor not started. Skipping test.";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DBusMonitorTest, NoAddFilterIfRunning) {
|
||||
DBusSigFilterTest filter1;
|
||||
DBusSigFilterTest filter2;
|
||||
std::unique_ptr<rtc::DBusMonitor> monitor;
|
||||
monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM));
|
||||
if (monitor) {
|
||||
EXPECT_TRUE(monitor->AddFilter(&filter1));
|
||||
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs);
|
||||
EXPECT_FALSE(monitor->AddFilter(&filter2));
|
||||
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
} else {
|
||||
LOG(LS_WARNING) << "DBus Monitor not started. Skipping test.";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DBusMonitorTest, AddFilterAfterStop) {
|
||||
DBusSigFilterTest filter1;
|
||||
DBusSigFilterTest filter2;
|
||||
std::unique_ptr<rtc::DBusMonitor> monitor;
|
||||
monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM));
|
||||
if (monitor) {
|
||||
EXPECT_TRUE(monitor->AddFilter(&filter1));
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs);
|
||||
EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs);
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
|
||||
EXPECT_TRUE(monitor->AddFilter(&filter2));
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs);
|
||||
EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs);
|
||||
EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs);
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED);
|
||||
} else {
|
||||
LOG(LS_WARNING) << "DBus Monitor not started. Skipping test.";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DBusMonitorTest, StopRightAfterStart) {
|
||||
DBusSigFilterTest filter;
|
||||
std::unique_ptr<rtc::DBusMonitor> monitor;
|
||||
monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM));
|
||||
if (monitor) {
|
||||
EXPECT_TRUE(monitor->AddFilter(&filter));
|
||||
|
||||
EXPECT_TRUE(monitor->StartMonitoring());
|
||||
EXPECT_TRUE(monitor->StopMonitoring());
|
||||
|
||||
// Stop the monitoring thread right after it had been started.
|
||||
// If the monitoring thread got a chance to receive a DBus signal, it would
|
||||
// post a message to the main thread and signal the main thread wakeup.
|
||||
// This message will be cleaned out automatically when the filter get
|
||||
// destructed. Here we also consume the wakeup signal (if there is one) so
|
||||
// that the testing (main) thread is reset to a clean state.
|
||||
rtc::Thread::Current()->ProcessMessages(1);
|
||||
} else {
|
||||
LOG(LS_WARNING) << "DBus Monitor not started.";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DBusSigFilter, BuildFilterString) {
|
||||
EXPECT_EQ(DBusSigFilter::BuildFilterString("", "", ""),
|
||||
(DBUS_TYPE "='" DBUS_SIGNAL "'"));
|
||||
EXPECT_EQ(DBusSigFilter::BuildFilterString("p", "", ""),
|
||||
(DBUS_TYPE "='" DBUS_SIGNAL "'," DBUS_PATH "='p'"));
|
||||
EXPECT_EQ(DBusSigFilter::BuildFilterString("p","i", ""),
|
||||
(DBUS_TYPE "='" DBUS_SIGNAL "'," DBUS_PATH "='p',"
|
||||
DBUS_INTERFACE "='i'"));
|
||||
EXPECT_EQ(DBusSigFilter::BuildFilterString("p","i","m"),
|
||||
(DBUS_TYPE "='" DBUS_SIGNAL "'," DBUS_PATH "='p',"
|
||||
DBUS_INTERFACE "='i'," DBUS_MEMBER "='m'"));
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // HAVE_DBUS_GLIB
|
||||
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
|
||||
#include "webrtc/base/libdbusglibsymboltable.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
#define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME LIBDBUS_GLIB_CLASS_NAME
|
||||
#define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST LIBDBUS_GLIB_SYMBOLS_LIST
|
||||
#define LATE_BINDING_SYMBOL_TABLE_DLL_NAME "libdbus-glib-1.so.2"
|
||||
#include "webrtc/base/latebindingsymboltable.cc.def"
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // HAVE_DBUS_GLIB
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_BASE_LIBDBUSGLIBSYMBOLTABLE_H_
|
||||
#define WEBRTC_BASE_LIBDBUSGLIBSYMBOLTABLE_H_
|
||||
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
|
||||
#include "webrtc/base/latebindingsymboltable.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
#define LIBDBUS_GLIB_CLASS_NAME LibDBusGlibSymbolTable
|
||||
// The libdbus-glib symbols we need, as an X-Macro list.
|
||||
// This list must contain precisely every libdbus-glib function that is used in
|
||||
// dbus.cc.
|
||||
#define LIBDBUS_GLIB_SYMBOLS_LIST \
|
||||
X(dbus_bus_add_match) \
|
||||
X(dbus_connection_add_filter) \
|
||||
X(dbus_connection_close) \
|
||||
X(dbus_connection_remove_filter) \
|
||||
X(dbus_connection_set_exit_on_disconnect) \
|
||||
X(dbus_g_bus_get) \
|
||||
X(dbus_g_bus_get_private) \
|
||||
X(dbus_g_connection_get_connection) \
|
||||
X(dbus_g_connection_unref) \
|
||||
X(dbus_g_thread_init) \
|
||||
X(dbus_message_get_interface) \
|
||||
X(dbus_message_get_member) \
|
||||
X(dbus_message_get_path) \
|
||||
X(dbus_message_get_type) \
|
||||
X(dbus_message_iter_get_arg_type) \
|
||||
X(dbus_message_iter_get_basic) \
|
||||
X(dbus_message_iter_init) \
|
||||
X(dbus_message_ref) \
|
||||
X(dbus_message_unref)
|
||||
|
||||
#define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME LIBDBUS_GLIB_CLASS_NAME
|
||||
#define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST LIBDBUS_GLIB_SYMBOLS_LIST
|
||||
#include "webrtc/base/latebindingsymboltable.h.def"
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // HAVE_DBUS_GLIB
|
||||
|
||||
#endif // WEBRTC_BASE_LIBDBUSGLIBSYMBOLTABLE_H_
|
||||
@ -57,9 +57,6 @@ declare_args() {
|
||||
rtc_build_ssl = true
|
||||
rtc_build_usrsctp = true
|
||||
|
||||
# Disable by default.
|
||||
rtc_have_dbus_glib = false
|
||||
|
||||
# Enable to use the Mozilla internal settings.
|
||||
build_with_mozilla = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user