Skip to content

Commit

Permalink
Adding macros that inject the common code that all Platform API code …
Browse files Browse the repository at this point in the history
…will have

DEFINE_BASE_NIX_API_INTERNAL -> Add all copy constructors and assignment operators to convert to/from WebCore <->
NixPlatform types

DEFINE_NIX_API_ASSIGNMENT and DEFINE_NIX_API_ASSIGNMENT_IMPL -> Assignment operators between NixPlatform types
  • Loading branch information
Thiago de Barros Lacerda committed Mar 27, 2014
1 parent 8f0436d commit ec5d676
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 71 deletions.
51 changes: 51 additions & 0 deletions Source/Platform/nix/public/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,60 @@

#include <stddef.h> // For size_t

#define DEFINE_NIX_API_ASSIGNMENT(type) \
type operator=(const type&); \
type operator=(type&); \

#define DEFINE_NIX_API_ASSIGNMENT_IMPL(type) \
type type::operator=(const type& other) \
{ \
m_private = other.m_private; \
return *this; \
} \
type type::operator=(type& other) \
{ \
m_private = other.m_private; \
return *this; \
} \

#if BUILDING_NIX__
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>

#define DEFINE_BASE_NIX_API_INTERNAL(type, webcoreType) \
type(const WTF::PassRefPtr<WebCore::webcoreType>& value) \
: m_private(value) \
{ \
} \
type(WebCore::webcoreType* value) \
: m_private(value) \
{ \
} \
type& operator=(WebCore::webcoreType* value) \
{ \
m_private = value; \
return *this; \
} \
type& operator=(const WTF::PassRefPtr<WebCore::webcoreType>& value) \
{ \
m_private = value; \
return *this; \
} \
operator WTF::PassRefPtr<WebCore::webcoreType>() const \
{ \
return toWebCoreType(); \
} \
operator WebCore::webcoreType*() const \
{ \
return toWebCoreType(); \
} \
protected: \
WebCore::webcoreType* toWebCoreType() const \
{ \
return m_private.get(); \
} \
WTF::RefPtr<WebCore::webcoreType> m_private; \

#endif

#endif // Nix_Common_h
11 changes: 2 additions & 9 deletions Source/Platform/nix/public/MediaStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,9 @@ class NIX_EXPORT MediaStream {
void addSource(const MediaStreamSource&);
void removeSource(const MediaStreamSource&);

DEFINE_NIX_API_ASSIGNMENT(MediaStream);
#if BUILDING_NIX__
MediaStream(WebCore::MediaStreamPrivate*);
MediaStream(const WTF::PassRefPtr<WebCore::MediaStreamPrivate>&);
operator WTF::PassRefPtr<WebCore::MediaStreamPrivate>() const;
operator WebCore::MediaStreamPrivate*() const;
MediaStream& operator=(const WTF::PassRefPtr<WebCore::MediaStreamPrivate>&);
WebCore::MediaStreamPrivate* toWebCoreMediaStreamPrivate() const;

private:
WTF::RefPtr<WebCore::MediaStreamPrivate> m_private;
DEFINE_BASE_NIX_API_INTERNAL(MediaStream, MediaStreamPrivate);
#endif
};

Expand Down
12 changes: 6 additions & 6 deletions Source/Platform/nix/public/MediaStreamAudioSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class MediaStreamAudioSource;
namespace Nix {
class AudioDestinationConsumer;

class MediaStreamAudioSource : public MediaStreamSource {
class NIX_EXPORT MediaStreamAudioSource : public MediaStreamSource {
public:
NIX_EXPORT MediaStreamAudioSource();
MediaStreamAudioSource();

NIX_EXPORT const char* deviceId() const;
NIX_EXPORT void setDeviceId(const char*);
const char* deviceId() const;
void setDeviceId(const char*);

// The Nix::AudioDestinationConsumer is not owned, and has to be disposed of separately
// after calling removeAudioConsumer.
NIX_EXPORT void addAudioConsumer(AudioDestinationConsumer*);
NIX_EXPORT bool removeAudioConsumer(AudioDestinationConsumer*);
void addAudioConsumer(AudioDestinationConsumer*);
bool removeAudioConsumer(AudioDestinationConsumer*);

#if BUILDING_NIX__
MediaStreamAudioSource(const WTF::PassRefPtr<WebCore::MediaStreamAudioSource>&);
Expand Down
9 changes: 2 additions & 7 deletions Source/Platform/nix/public/MediaStreamSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,9 @@ class NIX_EXPORT MediaStreamSource {

// FIXME Add support for capabilites.

DEFINE_NIX_API_ASSIGNMENT(MediaStreamSource);
#if BUILDING_NIX__
MediaStreamSource(const WTF::PassRefPtr<WebCore::MediaStreamSource>&);
MediaStreamSource& operator=(WebCore::MediaStreamSource*);
operator WTF::PassRefPtr<WebCore::MediaStreamSource>() const;
operator WebCore::MediaStreamSource*() const;

protected:
WTF::RefPtr<WebCore::MediaStreamSource> m_private;
DEFINE_BASE_NIX_API_INTERNAL(MediaStreamSource, MediaStreamSource);
#endif
};

Expand Down
28 changes: 1 addition & 27 deletions Source/WebCore/platform/nix/support/MediaStreamNix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,7 @@ using namespace WebCore;

namespace Nix {

#if ENABLE(MEDIA_STREAM)
MediaStream::MediaStream(const PassRefPtr<WebCore::MediaStreamPrivate>& mediaStreamDescriptor)
: m_private(mediaStreamDescriptor)
{
}

MediaStream::MediaStream(WebCore::MediaStreamPrivate* mediaStreamDescriptor)
: m_private(mediaStreamDescriptor)
{
}

MediaStream& MediaStream::operator=(const PassRefPtr<WebCore::MediaStreamPrivate>& mediaStreamDescriptor)
{
m_private = mediaStreamDescriptor;
return *this;
}

MediaStream::operator PassRefPtr<WebCore::MediaStreamPrivate>() const
{
return m_private.get();
}

MediaStream::operator WebCore::MediaStreamPrivate*() const
{
return m_private.get();
}
#endif // ENABLE(MEDIA_STREAM)
DEFINE_NIX_API_ASSIGNMENT_IMPL(MediaStream);

MediaStream::MediaStream()
{
Expand Down
23 changes: 1 addition & 22 deletions Source/WebCore/platform/nix/support/MediaStreamSourceNix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,7 @@

namespace Nix {

#if ENABLE(MEDIA_STREAM)
MediaStreamSource::MediaStreamSource(const PassRefPtr<WebCore::MediaStreamSource>& mediaStreamSource)
: m_private(mediaStreamSource)
{
}

MediaStreamSource& MediaStreamSource::operator=(WebCore::MediaStreamSource* mediaStreamSource)
{
m_private = mediaStreamSource;
return *this;
}

MediaStreamSource::operator PassRefPtr<WebCore::MediaStreamSource>() const
{
return m_private.get();
}

MediaStreamSource::operator WebCore::MediaStreamSource*() const
{
return m_private.get();
}
#endif // ENABLE(MEDIA_STREAM)
DEFINE_NIX_API_ASSIGNMENT_IMPL(MediaStreamSource);

MediaStreamSource::~MediaStreamSource()
{
Expand Down

0 comments on commit ec5d676

Please sign in to comment.