Skip to content

Commit

Permalink
dbus: Make it possible to build as shared_library.
Browse files Browse the repository at this point in the history
BUG=158887
R=satorux@chromium.org
NOTRY=true

Review URL: https://chromiumcodereview.appspot.com/11364033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165893 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tfarina@chromium.org committed Nov 5, 2012
1 parent aaf2a32 commit e302446
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 22 deletions.
5 changes: 3 additions & 2 deletions dbus/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
#include "base/tracked_objects.h"
#include "dbus/dbus_export.h"
#include "dbus/object_path.h"

class MessageLoop;
Expand Down Expand Up @@ -130,7 +131,7 @@ class ObjectProxy;
// alive when callbacks referencing |this| are called. However, after the
// bus is shut down, |connection_| can be NULL. Hence, callbacks should
// not rely on that |connection_| is alive.
class Bus : public base::RefCountedThreadSafe<Bus> {
class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
public:
// Specifies the bus type. SESSION is used to communicate with per-user
// services like GNOME applications. SYSTEM is used to communicate with
Expand All @@ -157,7 +158,7 @@ class Bus : public base::RefCountedThreadSafe<Bus> {
};

// Options used to create a Bus object.
struct Options {
struct CHROME_DBUS_EXPORT Options {
Options();
~Options();

Expand Down
6 changes: 5 additions & 1 deletion dbus/dbus.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'targets': [
{
'target_name': 'dbus',
'type': 'static_library',
'type': '<(component)',
'dependencies': [
'../base/base.gyp:base',
'../build/linux/system.gyp:dbus',
Expand All @@ -18,9 +18,13 @@
'export_dependent_settings': [
'../base/base.gyp:base',
],
'defines': [
'DBUS_IMPLEMENTATION',
],
'sources': [
'bus.cc',
'bus.h',
'dbus_export.h',
'exported_object.cc',
'exported_object.h',
'file_descriptor.cc',
Expand Down
38 changes: 38 additions & 0 deletions dbus/dbus_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef DBUS_DBUS_EXPORT_H_
#define DBUS_DBUS_EXPORT_H_

// Defines CHROME_DBUS_EXPORT so that functionality implemented by the dbus
// library can be exported to consumers.
// NOTE: We haven't used DBUS_EXPORT because it would conflict with the version
// from /usr/include/dbus-1.0/dbus/dbus-macros.h.

#if defined(COMPONENT_BUILD)
#if defined(WIN32)

#if defined(DBUS_IMPLEMENTATION)
#define CHROME_DBUS_EXPORT __declspec(dllexport)
#else
#define CHROME_DBUS_EXPORT __declspec(dllimport)
#endif // defined(DBUS_IMPLEMENTATION)

#else // !defined(WIN32)

#if defined(DBUS_IMPLEMENTATION)
#define CHROME_DBUS_EXPORT __attribute__((visibility("default")))
#else
#define CHROME_DBUS_EXPORT
#endif

#endif // defined(WIN32)

#else // !defined(COMPONENT_BUILD)

#define CHROME_DBUS_EXPORT

#endif // defined(COMPONENT_BUILD)

#endif // DBUS_DBUS_EXPORT_H_
4 changes: 3 additions & 1 deletion dbus/exported_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
#include "base/time.h"
#include "dbus/dbus_export.h"
#include "dbus/object_path.h"

namespace dbus {
Expand All @@ -30,7 +31,8 @@ class Signal;
//
// ExportedObject is a ref counted object, to ensure that |this| of the
// object is alive when callbacks referencing |this| are called.
class ExportedObject : public base::RefCountedThreadSafe<ExportedObject> {
class CHROME_DBUS_EXPORT ExportedObject
: public base::RefCountedThreadSafe<ExportedObject> {
public:
// Client code should use Bus::GetExportedObject() instead of this
// constructor.
Expand Down
5 changes: 4 additions & 1 deletion dbus/file_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#ifndef DBUS_FILE_DESCRIPTOR_H_
#define DBUS_FILE_DESCRIPTOR_H_

#include "base/basictypes.h"
#include "dbus/dbus_export.h"

namespace dbus {

// FileDescriptor is a type used to encapsulate D-Bus file descriptors
Expand All @@ -28,7 +31,7 @@ namespace dbus {
// directory to reduce the security risks. Splitting out validation
// also allows the caller to do this work on the File thread to conform
// with i/o restrictions.
class FileDescriptor {
class CHROME_DBUS_EXPORT FileDescriptor {
public:
// Permits initialization without a value for passing to
// dbus::MessageReader::PopFileDescriptor to fill in and from int values.
Expand Down
17 changes: 9 additions & 8 deletions dbus/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <dbus/dbus.h>

#include "base/basictypes.h"
#include "dbus/dbus_export.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"

Expand All @@ -35,7 +36,7 @@ class MessageReader;
// Returns true if Unix FD passing is supported in libdbus.
// The check is done runtime rather than compile time as the libdbus
// version used at runtime may be different from the one used at compile time.
bool IsDBusTypeUnixFdSupported();
CHROME_DBUS_EXPORT bool IsDBusTypeUnixFdSupported();

// Message is the base class of D-Bus message types. Client code must use
// sub classes such as MethodCall and Response instead.
Expand All @@ -44,7 +45,7 @@ bool IsDBusTypeUnixFdSupported();
// as the class is inside 'dbus' namespace. We chose to name this way, as
// libdbus defines lots of types starting with DBus, such as
// DBusMessage. We should avoid confusion and conflict with these types.
class Message {
class CHROME_DBUS_EXPORT Message {
public:
// The message type used in D-Bus. Redefined here so client code
// doesn't need to use raw D-Bus macros. DBUS_MESSAGE_TYPE_INVALID
Expand Down Expand Up @@ -137,7 +138,7 @@ class Message {
};

// MessageCall is a type of message used for calling a method via D-Bus.
class MethodCall : public Message {
class CHROME_DBUS_EXPORT MethodCall : public Message {
public:
// Creates a method call message for the specified interface name and
// the method name.
Expand Down Expand Up @@ -166,7 +167,7 @@ class MethodCall : public Message {
};

// Signal is a type of message used to send a signal.
class Signal : public Message {
class CHROME_DBUS_EXPORT Signal : public Message {
public:
// Creates a signal message for the specified interface name and the
// method name.
Expand Down Expand Up @@ -196,7 +197,7 @@ class Signal : public Message {

// Response is a type of message used for receiving a response from a
// method via D-Bus.
class Response : public Message {
class CHROME_DBUS_EXPORT Response : public Message {
public:
// Returns a newly created Response from the given raw message of the
// type DBUS_MESSAGE_TYPE_METHOD_RETURN. The caller must delete the
Expand All @@ -222,7 +223,7 @@ class Response : public Message {

// ErrorResponse is a type of message used to return an error to the
// caller of a method.
class ErrorResponse: public Response {
class CHROME_DBUS_EXPORT ErrorResponse: public Response {
public:
// Returns a newly created Response from the given raw message of the
// type DBUS_MESSAGE_TYPE_METHOD_RETURN. The caller must delete the
Expand Down Expand Up @@ -261,7 +262,7 @@ class ErrorResponse: public Response {
//
// writer.AppendString(str);
//
class MessageWriter {
class CHROME_DBUS_EXPORT MessageWriter {
public:
// Data added with Append* will be written to |message|, which may be NULL
// to create a sub-writer for passing to OpenArray, etc.
Expand Down Expand Up @@ -362,7 +363,7 @@ class MessageWriter {
//
// MessageReader manages an internal iterator to read data. All functions
// starting with Pop advance the iterator on success.
class MessageReader {
class CHROME_DBUS_EXPORT MessageReader {
public:
// The data will be read from the given |message|, which may be NULL to
// create a sub-reader for passing to PopArray, etc.
Expand Down
5 changes: 4 additions & 1 deletion dbus/object_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

#include <string>

#include "dbus/dbus_export.h"

namespace dbus {

// ObjectPath is a type used to distinguish D-Bus object paths from simple
// strings, especially since normal practice is that these should be only
// initialized from static constants or obtained from remote objects and no
// assumptions about their value made.
class ObjectPath {
class CHROME_DBUS_EXPORT ObjectPath {
public:
// Permit initialization without a value for passing to
// dbus::MessageReader::PopObjectPath to fill in and from std::string
Expand All @@ -39,6 +41,7 @@ class ObjectPath {
// observers.
bool operator==(const ObjectPath&) const;
bool operator!=(const ObjectPath&) const;

private:
std::string value_;
};
Expand Down
4 changes: 3 additions & 1 deletion dbus/object_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "base/memory/ref_counted.h"
#include "base/string_piece.h"
#include "base/time.h"
#include "dbus/dbus_export.h"
#include "dbus/object_path.h"

namespace dbus {
Expand All @@ -32,7 +33,8 @@ class Signal;
// object is is alive when callbacks referencing |this| are called; the
// bus always holds at least one of those references so object proxies
// always last as long as the bus that created them.
class ObjectProxy : public base::RefCountedThreadSafe<ObjectProxy> {
class CHROME_DBUS_EXPORT ObjectProxy
: public base::RefCountedThreadSafe<ObjectProxy> {
public:
// Client code should use Bus::GetObjectProxy() or
// Bus::GetObjectProxyWithOptions() instead of this constructor.
Expand Down
5 changes: 3 additions & 2 deletions dbus/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback.h"
#include "dbus/dbus_export.h"
#include "dbus/message.h"
#include "dbus/object_proxy.h"

Expand Down Expand Up @@ -194,7 +195,7 @@ class PropertyBase {
//
// After creation, client code should call ConnectSignals() and most likely
// GetAll() to seed initial values and update as changes occur.
class PropertySet {
class CHROME_DBUS_EXPORT PropertySet {
public:
// Callback for changes to cached values of properties, either notified
// via signal, or as a result of calls to Get() and GetAll(). The |name|
Expand Down Expand Up @@ -349,7 +350,7 @@ class PropertySet {
// default value. Specializations for basic D-Bus types, strings, object
// paths and arrays are provided for you.
template <class T>
class Property : public PropertyBase {
class CHROME_DBUS_EXPORT Property : public PropertyBase {
public:
Property() {}

Expand Down
4 changes: 3 additions & 1 deletion dbus/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

#include <string>

#include "dbus/dbus_export.h"

namespace dbus {

// Returns true if the specified string is a valid object path.
bool IsValidObjectPath(const std::string& value);
CHROME_DBUS_EXPORT bool IsValidObjectPath(const std::string& value);

} // namespace dbus

Expand Down
12 changes: 8 additions & 4 deletions dbus/values_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef DBUS_VALUES_UTIL_H_
#define DBUS_VALUES_UTIL_H_

#include "dbus/dbus_export.h"

namespace base {
class Value;
}
Expand All @@ -18,14 +20,16 @@ class MessageWriter;
// Returns NULL if an error occurs.
// Note: Integer values larger than int32 (including uint32) are converted to
// double. Non-string diciontary keys are converted to strings.
base::Value* PopDataAsValue(MessageReader* reader);
CHROME_DBUS_EXPORT base::Value* PopDataAsValue(MessageReader* reader);

// Appends a basic type value to |writer|.
void AppendBasicTypeValueData(MessageWriter* writer, const base::Value& value);
CHROME_DBUS_EXPORT void AppendBasicTypeValueData(MessageWriter* writer,
const base::Value& value);

// Appends a basic type value to |writer| as a variant.
void AppendBasicTypeValueDataAsVariant(MessageWriter* writer,
const base::Value& value);
CHROME_DBUS_EXPORT void AppendBasicTypeValueDataAsVariant(
MessageWriter* writer,
const base::Value& value);

} // namespace dbus

Expand Down

0 comments on commit e302446

Please sign in to comment.