From e3024465ac38cafd6ef30c4e08c107acef249b94 Mon Sep 17 00:00:00 2001 From: "tfarina@chromium.org" Date: Mon, 5 Nov 2012 01:56:14 +0000 Subject: [PATCH] dbus: Make it possible to build as shared_library. 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 --- dbus/bus.h | 5 +++-- dbus/dbus.gyp | 6 +++++- dbus/dbus_export.h | 38 ++++++++++++++++++++++++++++++++++++++ dbus/exported_object.h | 4 +++- dbus/file_descriptor.h | 5 ++++- dbus/message.h | 17 +++++++++-------- dbus/object_path.h | 5 ++++- dbus/object_proxy.h | 4 +++- dbus/property.h | 5 +++-- dbus/string_util.h | 4 +++- dbus/values_util.h | 12 ++++++++---- 11 files changed, 83 insertions(+), 22 deletions(-) create mode 100644 dbus/dbus_export.h diff --git a/dbus/bus.h b/dbus/bus.h index 6f31b37ab76331..75de9a3d1e240d 100644 --- a/dbus/bus.h +++ b/dbus/bus.h @@ -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; @@ -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 { +class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe { public: // Specifies the bus type. SESSION is used to communicate with per-user // services like GNOME applications. SYSTEM is used to communicate with @@ -157,7 +158,7 @@ class Bus : public base::RefCountedThreadSafe { }; // Options used to create a Bus object. - struct Options { + struct CHROME_DBUS_EXPORT Options { Options(); ~Options(); diff --git a/dbus/dbus.gyp b/dbus/dbus.gyp index 25317de024380b..be5f68646e722e 100644 --- a/dbus/dbus.gyp +++ b/dbus/dbus.gyp @@ -9,7 +9,7 @@ 'targets': [ { 'target_name': 'dbus', - 'type': 'static_library', + 'type': '<(component)', 'dependencies': [ '../base/base.gyp:base', '../build/linux/system.gyp:dbus', @@ -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', diff --git a/dbus/dbus_export.h b/dbus/dbus_export.h new file mode 100644 index 00000000000000..0eda41a26fb61e --- /dev/null +++ b/dbus/dbus_export.h @@ -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_ diff --git a/dbus/exported_object.h b/dbus/exported_object.h index c897ea6a5e9b1d..9d3164fcca0e19 100644 --- a/dbus/exported_object.h +++ b/dbus/exported_object.h @@ -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 { @@ -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 { +class CHROME_DBUS_EXPORT ExportedObject + : public base::RefCountedThreadSafe { public: // Client code should use Bus::GetExportedObject() instead of this // constructor. diff --git a/dbus/file_descriptor.h b/dbus/file_descriptor.h index 5b89f2f44534e1..19e0b1ab44b32d 100644 --- a/dbus/file_descriptor.h +++ b/dbus/file_descriptor.h @@ -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 @@ -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. diff --git a/dbus/message.h b/dbus/message.h index 85d045c2812b41..42d686052363df 100644 --- a/dbus/message.h +++ b/dbus/message.h @@ -10,6 +10,7 @@ #include #include "base/basictypes.h" +#include "dbus/dbus_export.h" #include "dbus/file_descriptor.h" #include "dbus/object_path.h" @@ -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. @@ -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 @@ -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. @@ -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. @@ -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 @@ -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 @@ -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. @@ -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. diff --git a/dbus/object_path.h b/dbus/object_path.h index 9789b938d6060f..89c5287c54a670 100644 --- a/dbus/object_path.h +++ b/dbus/object_path.h @@ -7,13 +7,15 @@ #include +#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 @@ -39,6 +41,7 @@ class ObjectPath { // observers. bool operator==(const ObjectPath&) const; bool operator!=(const ObjectPath&) const; + private: std::string value_; }; diff --git a/dbus/object_proxy.h b/dbus/object_proxy.h index 71ec0f1f07b619..bec08949d75b8d 100644 --- a/dbus/object_proxy.h +++ b/dbus/object_proxy.h @@ -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 { @@ -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 { +class CHROME_DBUS_EXPORT ObjectProxy + : public base::RefCountedThreadSafe { public: // Client code should use Bus::GetObjectProxy() or // Bus::GetObjectProxyWithOptions() instead of this constructor. diff --git a/dbus/property.h b/dbus/property.h index 87c9806e3b17f1..f2feb05dfbe9b0 100644 --- a/dbus/property.h +++ b/dbus/property.h @@ -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" @@ -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| @@ -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 Property : public PropertyBase { +class CHROME_DBUS_EXPORT Property : public PropertyBase { public: Property() {} diff --git a/dbus/string_util.h b/dbus/string_util.h index ff52290f896da9..60c02d17418e00 100644 --- a/dbus/string_util.h +++ b/dbus/string_util.h @@ -7,10 +7,12 @@ #include +#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 diff --git a/dbus/values_util.h b/dbus/values_util.h index f710fa3758a310..e34c7a039db31e 100644 --- a/dbus/values_util.h +++ b/dbus/values_util.h @@ -5,6 +5,8 @@ #ifndef DBUS_VALUES_UTIL_H_ #define DBUS_VALUES_UTIL_H_ +#include "dbus/dbus_export.h" + namespace base { class Value; } @@ -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